Unity输出场景中选中的物体数量
时间:2017-04-12 10:04:33
收藏:0
阅读:1993
需要注意的有两点:
1.如果直接输出,每个没选中的物体都会执行一遍命令,需要过滤只让一个物体执行命令,但是我用Validate不太管用.直接在命令里过滤
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CanEditMultipleObjects]
public class SelectionCount : Editor {
[MenuItem("GameObject/Get Selection Count",false,0)]
static public void GetSelectionCount(MenuCommand menuCommand)
{
//Prevent executing multiple times when right-clicking.
if (Selection.objects.Length > 1)
{
if (menuCommand.context != Selection.objects[0])
{
return;
}
}
Debug.Log("<color=yellow>选中的数量为" + Selection.objects.Length + "</color>");
}
}
评论(0)