Unity3d Unity编辑器脚本,用于用指定游戏对象的子对象填充序列化数组

Unity3d Unity编辑器脚本,用于用指定游戏对象的子对象填充序列化数组,unity3d,unityscript,unity-editor,Unity3d,Unityscript,Unity Editor,我有一个“GameObject”的序列化字段,我想自动填充我想手动指定的游戏对象的子对象 如果我可以使组件上的阵列无法手动更改,但只能在“灰显”状态下显示,则可以获得额外积分 这个手术可能吗?提前谢谢。这样会有帮助吗 GameObject[] myArray; GameObject parent; void GetChildren() { myArray=new GameObject[parent.transform.childCount]; for (int i=0;i&l

我有一个“GameObject”的序列化字段,我想自动填充我想手动指定的游戏对象的子对象

如果我可以使组件上的阵列无法手动更改,但只能在“灰显”状态下显示,则可以获得额外积分

这个手术可能吗?提前谢谢。

这样会有帮助吗

GameObject[] myArray;
GameObject parent;

void GetChildren()
{

    myArray=new GameObject[parent.transform.childCount];
    for (int i=0;i<parent.transform.childCount;i++)
    myArray[i]=parent.transform.GetChild(i).gameObject;

}
GameObject[]myArray;
配子体父代;
void GetChildren()
{
myArray=新游戏对象[parent.transform.childCount];
对于(int i=0;i溶液:

[CustomEditor( typeOf( ClassYouWantToManage ) )]
class ClassYouWantToManageEditor
{
  ClassYouWantToManage value;

  void OnEnable()
  {
   // target is the upcasted version of your managed class
   value = (ClassYouWantToManage) target;
  }

  public override void OnInspectorGUI()
  {
    // specifiedObject is the 'parent', with whos children you want to populate the array. has to be public
    if (value.specifiedObject == null)
    {
      throw new Exception ("Specified object is null");
    }

    // targetArray is the array you want to populate with children. has to be public
    // simple population alg
    value.targetArray = new GameObject[specifiedObject.transform.ChildCount];
    for (int i = 0; i < specifiedObject.transform.ChildCount; i++)
    {
      value.targetArray[ i ] = specifiedObject.transform.GetChild( i ).gameObject;
    } 
  }
}  
[CustomEditor(typeOf(ClassYouWantToManage))]
类ClassYouWantToManageEditor
{
管理价值;
void OnEnable()
{
//目标是托管类的升级版本
值=(ClassYouWantToManage)目标;
}
公共覆盖无效OnInspectorGUI()
{
//specifiedObject是“父对象”,包含要填充数组的子对象。必须是公共的
if(value.specifiedObject==null)
{
抛出新异常(“指定的对象为空”);
}
//targetArray是要用子数组填充的数组。必须是公共数组
//简单总体alg
value.targetArray=新游戏对象[specifiedObject.transform.ChildCount];
for(int i=0;i
您不能序列化游戏对象。@Bijan我可能误解了您的意思,但unity允许您序列化游戏对象字段您可以设法存储游戏对象,但我认为unity无法从序列化对象重建对象树。我可以肯定的是,
Transform
不能序列化是因为只有它的引用被序列化。首先,预置是序列化的对象树。这些都会起作用。但是如果你能准确地告诉我们你需要什么,我们可以更好地帮助我们。感谢你的回复!幸运的是,我已经解决了这部分问题。只需要在游戏不运行时找到一种方法。基本上是升级ate函数,但仅当游戏未运行时。如果在运行时更新函数根本未执行,则也会非常有用。如果您添加[ExecuteInEditMode],则将执行更新当你声明MonoBehaviuUrYep时,我只想让它执行。我的类包含一系列其他函数,如oneable、Start等。但我想让它只在游戏不玩时执行更新。我可以手动检查游戏是否在更新时运行,但我不想浪费framesvoidStart(){if(Application.isPlaying)enabled=false;}