csharp 将“Move to Top”和“Move to Bottom”项添加到组件的检查器上下文菜单中。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 将“Move to Top”和“Move to Bottom”项添加到组件的检查器上下文菜单中。相关的知识,希望对你有一定的参考价值。
using UnityEngine;
using UnityEditor;
public class MoveComponentContext
{
enum Destination
{
Top,
Bottom
};
const string kComponentArrayName = "m_Component";
const int kFirstComponentIndex = 1;
[MenuItem ("CONTEXT/Component/Move to Top")]
static void Top (MenuCommand command)
{
Move ((Component)command.context, Destination.Top);
}
[MenuItem ("CONTEXT/Component/Move to Bottom")]
static void Bottom (MenuCommand command)
{
Move ((Component)command.context, Destination.Bottom);
}
static void Move (Component target, Destination destination)
{
SerializedObject gameObject = new SerializedObject (target.gameObject);
SerializedProperty componentArray = gameObject.FindProperty (kComponentArrayName);
int lastComponentIndex = componentArray.arraySize - 1;
int targetIndex = destination == Destination.Top ? kFirstComponentIndex : lastComponentIndex;
for (int index = kFirstComponentIndex; index <= lastComponentIndex; ++index)
{
SerializedProperty iterator = componentArray.GetArrayElementAtIndex (index);
iterator.Next (true);
iterator.Next (true);
if (iterator.objectReferenceValue == target)
{
componentArray.MoveArrayElement (index, targetIndex);
gameObject.ApplyModifiedProperties ();
break;
}
}
}
}
以上是关于csharp 将“Move to Top”和“Move to Bottom”项添加到组件的检查器上下文菜单中。的主要内容,如果未能解决你的问题,请参考以下文章
如何将 mp3 等音频文件转换为 mo3 文件? [关闭]
如何将gettext .mo文件转换为.po文件[关闭]
.Mo翻译文件结构解析
csharp 将字符串“1”和“0”转换为bool值
csharp 此类演示了将对象序列化和反序列化为xml字符串的方法
将 Json 对象转换为数据表和字符串