Exemplo n.º 1
0
        public static Object[] ObjectArrFieldValue(ref bool fold, string fieldDesc, Object[] oldValue, NodeFieldDesc desc)
        {
            if (oldValue == null)
            {
                oldValue = new Object[0];
            }
            Object[] newValue = oldValue;

            fold = EditorGUILayout.Foldout(fold, fieldDesc);
            if (fold)
            {
                int size = EditorGUILayout.IntField("Size", oldValue.Length);

                newValue = new Object[size];
                if (size >= oldValue.Length)
                {
                    for (int i = 0; i < oldValue.Length; i++)
                    {
                        newValue[i] = EditorGUILayout.ObjectField(i.ToString(), oldValue[i], desc.type.GetElementType(), false);
                        if (BehaviorTreeArgsDict.IsGameObjectArrayType(desc.type) &&
                            !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue[i], desc.constraintTypes))
                        {
                            newValue[i] = null;
                        }
                    }
                    for (int i = oldValue.Length; i < size; i++)
                    {
                        newValue[i] = EditorGUILayout.ObjectField(i.ToString(), newValue[i], desc.type.GetElementType(), false);
                        if (BehaviorTreeArgsDict.IsGameObjectArrayType(desc.type) &&
                            !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue[i], desc.constraintTypes))
                        {
                            newValue[i] = null;
                        }
                    }
                }
                else if (size < oldValue.Length)
                {
                    for (int i = 0; i < size; i++)
                    {
                        newValue[i] = EditorGUILayout.ObjectField(i.ToString(), oldValue[i], desc.type.GetElementType(), false);
                        if (BehaviorTreeArgsDict.IsGameObjectArrayType(desc.type) &&
                            !BehaviorTreeArgsDict.SatisfyCondition((GameObject)newValue[i], desc.constraintTypes))
                        {
                            newValue[i] = null;
                        }
                    }
                }
            }

            return(newValue);
        }