Ejemplo n.º 1
0
        private static LayerMask DrawLayerMask(GUIContent guiContent, LayerMask layerMask)
        {
            if (FieldInspector.layerNames == null)
            {
                FieldInspector.InitLayers();
            }
            int num = 0;

            for (int i = 0; i < FieldInspector.layerNames.Length; i++)
            {
                if ((layerMask.value & FieldInspector.maskValues[i]) == FieldInspector.maskValues[i])
                {
                    num |= 1 << i;
                }
            }
            int num2 = EditorGUILayout.MaskField(guiContent, num, FieldInspector.layerNames, new GUILayoutOption[0]);

            if (num2 != num)
            {
                num = 0;
                for (int j = 0; j < FieldInspector.layerNames.Length; j++)
                {
                    if ((num2 & 1 << j) != 0)
                    {
                        num |= FieldInspector.maskValues[j];
                    }
                }
                layerMask.value = num;
            }
            return(layerMask);
        }
Ejemplo n.º 2
0
 private static object DrawField(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, object value)
 {
     if (typeof(IList).IsAssignableFrom(fieldType))
     {
         return(FieldInspector.DrawArrayField(task, guiContent, fieldInfo, fieldType, value));
     }
     return(FieldInspector.DrawSingleField(task, guiContent, fieldInfo, fieldType, value));
 }
 // Token: 0x060001A4 RID: 420 RVA: 0x0000EEF4 File Offset: 0x0000D0F4
 public void OnFocus()
 {
     GlobalVariablesWindow.instance = this;
     this.mVariableSource           = GlobalVariables.Instance;
     if (this.mVariableSource != null)
     {
         this.mVariableSource.CheckForSerialization(!Application.isPlaying);
     }
     FieldInspector.Init();
 }
Ejemplo n.º 4
0
        public static bool DrawFoldout(int hash, GUIContent guiContent)
        {
            bool flag  = FieldInspector.FoldOut(hash);
            bool flag2 = EditorGUILayout.Foldout(flag, guiContent);

            if (flag2 != flag)
            {
                FieldInspector.SetFoldOut(hash, flag2);
            }
            return(flag2);
        }
Ejemplo n.º 5
0
        public void LoadNode(Task task, BehaviorSource behaviorSource, Vector2 offset, ref int id)
        {
            mTask                       = task;
            mTask.Owner                 = (behaviorSource.Owner as Behavior);
            mTask.ID                    = id++;
            mTask.NodeData              = new NodeData();
            mTask.NodeData.Offset       = offset;
            mTask.NodeData.NodeDesigner = this;
            LoadTaskIcon();
            Init();
            mTask.FriendlyName = taskName;
            RequiredComponentAttribute[] array;
            if (mTask.Owner != null && (array = (mTask.GetType().GetCustomAttributes(typeof(RequiredComponentAttribute), true) as RequiredComponentAttribute[])).Length > 0)
            {
                Type componentType = array[0].ComponentType;
                if (typeof(Component).IsAssignableFrom(componentType) && mTask.Owner.gameObject.GetComponent(componentType) == null)
                {
                    mTask.Owner.gameObject.AddComponent(componentType);
                }
            }
            List <Type>  baseClasses = FieldInspector.GetBaseClasses(mTask.GetType());
            BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            for (int i = baseClasses.Count - 1; i > -1; i--)
            {
                FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr);
                for (int j = 0; j < fields.Length; j++)
                {
                    if (typeof(SharedVariable).IsAssignableFrom(fields[j].FieldType) && !fields[j].FieldType.IsAbstract)
                    {
                        SharedVariable sharedVariable = fields[j].GetValue(mTask) as SharedVariable;
                        if (sharedVariable == null)
                        {
                            sharedVariable = (Activator.CreateInstance(fields[j].FieldType) as SharedVariable);
                        }
                        if (TaskUtility.HasAttribute(fields[j], typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fields[j], typeof(SharedRequiredAttribute)))
                        {
                            sharedVariable.IsShared = true;
                        }
                        fields[j].SetValue(mTask, sharedVariable);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static object DrawFields(Task task, object obj, GUIContent guiContent)
        {
            if (obj == null)
            {
                return(null);
            }
            List <Type>  baseClasses = FieldInspector.GetBaseClasses(obj.GetType());
            BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            for (int i = baseClasses.Count - 1; i > -1; i--)
            {
                FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr);
                for (int j = 0; j < fields.Length; j++)
                {
                    if (!BehaviorDesignerUtility.HasAttribute(fields[j], typeof(NonSerializedAttribute)) && !BehaviorDesignerUtility.HasAttribute(fields[j], typeof(HideInInspector)) && ((!fields[j].IsPrivate && !fields[j].IsFamily) || BehaviorDesignerUtility.HasAttribute(fields[j], typeof(SerializeField))) && (!(obj is ParentTask) || !fields[j].Name.Equals("children")))
                    {
                        if (guiContent == null)
                        {
                            string name = fields[j].Name;
                            BehaviorDesigner.Runtime.Tasks.TooltipAttribute[] array;
                            if ((array = (fields[j].GetCustomAttributes(typeof(BehaviorDesigner.Runtime.Tasks.TooltipAttribute), false) as BehaviorDesigner.Runtime.Tasks.TooltipAttribute[])).Length > 0)
                            {
                                guiContent = new GUIContent(BehaviorDesignerUtility.SplitCamelCase(name), array[0].Tooltip);
                            }
                            else
                            {
                                guiContent = new GUIContent(BehaviorDesignerUtility.SplitCamelCase(name));
                            }
                        }
                        EditorGUI.BeginChangeCheck();
                        object value = FieldInspector.DrawField(task, guiContent, fields[j], fields[j].GetValue(obj));
                        if (EditorGUI.EndChangeCheck())
                        {
                            fields[j].SetValue(obj, value);
                            GUI.changed = true;
                        }
                        guiContent = null;
                    }
                }
            }
            return(obj);
        }
Ejemplo n.º 7
0
        // Token: 0x06000190 RID: 400 RVA: 0x0000DB64 File Offset: 0x0000BD64
        public static object DrawField(Task task, GUIContent guiContent, FieldInfo field, object value)
        {
            if (field.FieldType.IsAbstract)
            {
                EditorGUILayout.LabelField(guiContent, new GUILayoutOption[0]);
                return(null);
            }
            ObjectDrawer objectDrawer;

            if ((objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, field)) != null)
            {
                if (value == null && !field.FieldType.IsAbstract)
                {
                    value = Activator.CreateInstance(field.FieldType, true);
                }
                objectDrawer.Value = value;
                objectDrawer.OnGUI(guiContent);
                if (objectDrawer.Value != value)
                {
                    value       = objectDrawer.Value;
                    GUI.changed = true;
                }
                return(value);
            }
            ObjectDrawerAttribute[] array;
            if ((array = (field.GetCustomAttributes(typeof(ObjectDrawerAttribute), true) as ObjectDrawerAttribute[])).Length > 0 && (objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, array[0])) != null)
            {
                if (value == null)
                {
                    value = Activator.CreateInstance(field.FieldType, true);
                }
                objectDrawer.Value = value;
                objectDrawer.OnGUI(guiContent);
                if (objectDrawer.Value != value)
                {
                    value       = objectDrawer.Value;
                    GUI.changed = true;
                }
                return(value);
            }
            return(FieldInspector.DrawField(task, guiContent, field, field.FieldType, value));
        }
Ejemplo n.º 8
0
        private static bool DrawSharedVariable(IVariableSource variableSource, SharedVariable sharedVariable, bool selected)
        {
            if (sharedVariable == null || sharedVariable.GetType().GetProperty("Value") == null)
            {
                return(false);
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            bool result = false;

            if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping))
            {
                if (selected)
                {
                    GUILayout.Label("Property", new GUILayoutOption[0]);
                }
                else
                {
                    GUILayout.Label(sharedVariable.Name, new GUILayoutOption[0]);
                }
                string[] array = sharedVariable.PropertyMapping.Split(new char[]
                {
                    '.'
                });
                GUILayout.Label(array[array.Length - 1].Replace('/', '.'), new GUILayoutOption[0]);
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                FieldInspector.DrawFields(null, sharedVariable, new GUIContent(sharedVariable.Name));
                result = EditorGUI.EndChangeCheck();
            }
            if (!sharedVariable.IsGlobal && GUILayout.Button(BehaviorDesignerUtility.VariableMapButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }))
            {
                VariableInspector.ShowPropertyMappingMenu(variableSource as BehaviorSource, sharedVariable);
            }
            GUILayout.EndHorizontal();
            return(result);
        }
Ejemplo n.º 9
0
 internal static SharedVariable DrawSharedVariableToggleSharedButton(SharedVariable sharedVariable)
 {
     if (sharedVariable == null)
     {
         return(null);
     }
     if (GUILayout.Button((!sharedVariable.IsShared) ? BehaviorDesignerUtility.VariableButtonTexture : BehaviorDesignerUtility.VariableButtonSelectedTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
     {
         GUILayout.Width(15f)
     }))
     {
         bool isShared = !sharedVariable.IsShared;
         if (sharedVariable.GetType().Equals(typeof(SharedVariable)))
         {
             sharedVariable = (Activator.CreateInstance(FieldInspector.FriendlySharedVariableName(sharedVariable.GetType().GetProperty("Value").PropertyType), true) as SharedVariable);
         }
         else
         {
             sharedVariable = (Activator.CreateInstance(sharedVariable.GetType(), true) as SharedVariable);
         }
         sharedVariable.IsShared = isShared;
     }
     return(sharedVariable);
 }
Ejemplo n.º 10
0
        public void LoadTask(Task task, Behavior owner, ref int id)
        {
            if (task == null)
            {
                return;
            }
            mTask       = task;
            mTask.Owner = owner;
            mTask.ID    = id++;
            mTask.NodeData.NodeDesigner = this;
            mTask.NodeData.InitWatchedFields(mTask);
            if (!mTask.NodeData.FriendlyName.Equals(string.Empty))
            {
                mTask.FriendlyName          = mTask.NodeData.FriendlyName;
                mTask.NodeData.FriendlyName = string.Empty;
            }
            LoadTaskIcon();
            Init();
            RequiredComponentAttribute[] array;
            if (mTask.Owner != null && (array = (mTask.GetType().GetCustomAttributes(typeof(RequiredComponentAttribute), true) as RequiredComponentAttribute[])).Length > 0)
            {
                Type componentType = array[0].ComponentType;
                if (typeof(Component).IsAssignableFrom(componentType) && mTask.Owner.gameObject.GetComponent(componentType) == null)
                {
                    mTask.Owner.gameObject.AddComponent(componentType);
                }
            }
            List <Type>  baseClasses = FieldInspector.GetBaseClasses(mTask.GetType());
            BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            for (int i = baseClasses.Count - 1; i > -1; i--)
            {
                FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr);
                for (int j = 0; j < fields.Length; j++)
                {
                    if (typeof(SharedVariable).IsAssignableFrom(fields[j].FieldType) && !fields[j].FieldType.IsAbstract)
                    {
                        SharedVariable sharedVariable = fields[j].GetValue(mTask) as SharedVariable;
                        if (sharedVariable == null)
                        {
                            sharedVariable = (Activator.CreateInstance(fields[j].FieldType) as SharedVariable);
                        }
                        if (TaskUtility.HasAttribute(fields[j], typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fields[j], typeof(SharedRequiredAttribute)))
                        {
                            sharedVariable.IsShared = true;
                        }
                        fields[j].SetValue(mTask, sharedVariable);
                    }
                }
            }
            if (isParent)
            {
                ParentTask parentTask = this.mTask as ParentTask;
                if (parentTask.Children != null)
                {
                    for (int k = 0; k < parentTask.Children.Count; k++)
                    {
                        NodeDesigner nodeDesigner = CreateInstance <NodeDesigner>();
                        nodeDesigner.LoadTask(parentTask.Children[k], owner, ref id);
                        NodeConnection nodeConnection = CreateInstance <NodeConnection>();
                        nodeConnection.LoadConnection(this, NodeConnectionType.Fixed);
                        AddChildNode(nodeDesigner, nodeConnection, true, true, k);
                    }
                }
                mConnectionIsDirty = true;
            }
        }
        private bool DrawSharedVariableSynchronizer(VariableSynchronizerInspector.Synchronizer synchronizer, Type valueType)
        {
            VariableSynchronizerInspector.DrawComponentSelector(synchronizer, typeof(Behavior), VariableSynchronizerInspector.ComponentListType.BehaviorDesignerGroup);
            int num  = 0;
            int num2 = -1;

            string[] array = null;
            if (synchronizer.component != null)
            {
                Behavior behavior = synchronizer.component as Behavior;
                num = FieldInspector.GetVariablesOfType(valueType, synchronizer.global, synchronizer.targetName, behavior.GetBehaviorSource(), out array, ref num2, valueType == null);
            }
            else
            {
                array = new string[]
                {
                    "None"
                };
            }
            EditorGUI.BeginChangeCheck();
            num = EditorGUILayout.Popup("Shared Variable", num, array, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                if (num != 0)
                {
                    if (num2 != -1 && num >= num2)
                    {
                        synchronizer.targetName = array[num].Substring(8, array[num].Length - 8);
                        synchronizer.global     = true;
                    }
                    else
                    {
                        synchronizer.targetName = array[num];
                        synchronizer.global     = false;
                    }
                    if (valueType == null)
                    {
                        SharedVariable variable;
                        if (synchronizer.global)
                        {
                            variable = GlobalVariables.Instance.GetVariable(synchronizer.targetName);
                        }
                        else
                        {
                            Behavior behavior2 = synchronizer.component as Behavior;
                            variable = behavior2.GetVariable(array[num]);
                        }
                        this.sharedVariableValueTypeName = variable.GetType().GetProperty("Value").PropertyType.FullName;
                        this.sharedVariableValueType     = null;
                    }
                }
                else
                {
                    synchronizer.targetName = null;
                }
            }
            if (string.IsNullOrEmpty(synchronizer.targetName))
            {
                GUI.enabled = (false);
            }
            return(GUI.enabled);
        }
Ejemplo n.º 12
0
 public static object DrawFields(Task task, object obj)
 {
     return(FieldInspector.DrawFields(task, obj, null));
 }
Ejemplo n.º 13
0
 public static SharedVariable DrawSharedVariable(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, SharedVariable sharedVariable)
 {
     if (!fieldType.Equals(typeof(SharedVariable)) && sharedVariable == null)
     {
         sharedVariable = (Activator.CreateInstance(fieldType, true) as SharedVariable);
         if (TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable.IsShared = true;
         }
         GUI.changed = true;
     }
     if (sharedVariable == null || sharedVariable.IsShared)
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         string[] array           = null;
         int      num             = -1;
         int      num2            = FieldInspector.GetVariablesOfType((sharedVariable == null) ? null : sharedVariable.GetType().GetProperty("Value").PropertyType, sharedVariable != null && sharedVariable.IsGlobal, (sharedVariable == null) ? string.Empty : sharedVariable.Name, FieldInspector.behaviorSource, out array, ref num, fieldType.Equals(typeof(SharedVariable)));
         Color    backgroundColor = GUI.backgroundColor;
         if (num2 == 0 && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             GUI.backgroundColor = Color.red;
         }
         int num3 = num2;
         num2 = EditorGUILayout.Popup(guiContent.text, num2, array, BehaviorDesignerUtility.SharedVariableToolbarPopup, new GUILayoutOption[0]);
         GUI.backgroundColor = backgroundColor;
         if (num2 != num3)
         {
             if (num2 == 0)
             {
                 if (fieldType.Equals(typeof(SharedVariable)))
                 {
                     sharedVariable = null;
                 }
                 else
                 {
                     sharedVariable          = (Activator.CreateInstance(fieldType, true) as SharedVariable);
                     sharedVariable.IsShared = true;
                 }
             }
             else if (num != -1 && num2 >= num)
             {
                 sharedVariable = GlobalVariables.Instance.GetVariable(array[num2].Substring(8, array[num2].Length - 8));
             }
             else
             {
                 sharedVariable = FieldInspector.behaviorSource.GetVariable(array[num2]);
             }
             GUI.changed = true;
         }
         if (!fieldType.Equals(typeof(SharedVariable)) && !TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable = FieldInspector.DrawSharedVariableToggleSharedButton(sharedVariable);
             GUILayout.Space(-3f);
         }
         GUILayout.EndHorizontal();
         GUILayout.Space(3f);
     }
     else
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         ObjectDrawerAttribute[] array2;
         ObjectDrawer            objectDrawer;
         if (fieldInfo != null && (array2 = (fieldInfo.GetCustomAttributes(typeof(ObjectDrawerAttribute), true) as ObjectDrawerAttribute[])).Length > 0 && (objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, array2[0])) != null)
         {
             objectDrawer.Value = sharedVariable;
             objectDrawer.OnGUI(guiContent);
         }
         else
         {
             FieldInspector.DrawFields(task, sharedVariable, guiContent);
         }
         if (!TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable = FieldInspector.DrawSharedVariableToggleSharedButton(sharedVariable);
         }
         GUILayout.EndHorizontal();
     }
     return(sharedVariable);
 }
Ejemplo n.º 14
0
        private static object DrawSingleField(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, object value)
        {
            if (fieldType.Equals(typeof(int)))
            {
                return(EditorGUILayout.IntField(guiContent, (int)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(float)))
            {
                return(EditorGUILayout.FloatField(guiContent, (float)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(double)))
            {
                return(EditorGUILayout.FloatField(guiContent, Convert.ToSingle((double)value), new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(long)))
            {
                return((long)EditorGUILayout.IntField(guiContent, Convert.ToInt32((long)value), new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(bool)))
            {
                return(EditorGUILayout.Toggle(guiContent, (bool)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(string)))
            {
                return(EditorGUILayout.TextField(guiContent, (string)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(byte)))
            {
                return(Convert.ToByte(EditorGUILayout.IntField(guiContent, Convert.ToInt32(value), new GUILayoutOption[0])));
            }
            if (fieldType.Equals(typeof(Vector2)))
            {
                return(EditorGUILayout.Vector2Field(guiContent.text, (Vector2)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Vector3)))
            {
                return(EditorGUILayout.Vector3Field(guiContent.text, (Vector3)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Vector4)))
            {
                return(EditorGUILayout.Vector4Field(guiContent.text, (Vector4)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Quaternion)))
            {
                Quaternion quaternion = (Quaternion)value;
                Vector4    value2     = Vector4.zero;
                value2.Set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                value2 = EditorGUILayout.Vector4Field(guiContent.text, value2, new GUILayoutOption[0]);
                quaternion.Set(value2.x, value2.y, value2.z, value2.w);
                return(quaternion);
            }
            if (fieldType.Equals(typeof(Color)))
            {
                return(EditorGUILayout.ColorField(guiContent, (Color)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Rect)))
            {
                return(EditorGUILayout.RectField(guiContent, (Rect)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Matrix4x4)))
            {
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                if (FieldInspector.DrawFoldout(value.GetHashCode(), guiContent))
                {
                    EditorGUI.indentLevel++;
                    Matrix4x4 matrix4x = (Matrix4x4)value;
                    for (int i = 0; i < 4; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            EditorGUI.BeginChangeCheck();
                            matrix4x[i, j] = EditorGUILayout.FloatField("E" + i.ToString() + j.ToString(), matrix4x[i, j], new GUILayoutOption[0]);
                            if (EditorGUI.EndChangeCheck())
                            {
                                GUI.changed = true;
                            }
                        }
                    }
                    value = matrix4x;
                    EditorGUI.indentLevel--;
                }
                GUILayout.EndVertical();
                return(value);
            }
            if (fieldType.Equals(typeof(AnimationCurve)))
            {
                if (value == null)
                {
                    value = new AnimationCurve();
                }
                return(EditorGUILayout.CurveField(guiContent, (AnimationCurve)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(LayerMask)))
            {
                return(FieldInspector.DrawLayerMask(guiContent, (LayerMask)value));
            }
            if (typeof(SharedVariable).IsAssignableFrom(fieldType))
            {
                return(FieldInspector.DrawSharedVariable(task, guiContent, fieldInfo, fieldType, value as SharedVariable));
            }
            if (typeof(UnityEngine.Object).IsAssignableFrom(fieldType))
            {
                return(EditorGUILayout.ObjectField(guiContent, (UnityEngine.Object)value, fieldType, true, new GUILayoutOption[0]));
            }
            if (fieldType.IsEnum)
            {
                return(EditorGUILayout.EnumPopup(guiContent, (Enum)value, new GUILayoutOption[0]));
            }
            if (!fieldType.IsClass && (!fieldType.IsValueType || fieldType.IsPrimitive))
            {
                EditorGUILayout.LabelField("Unsupported Type: " + fieldType, new GUILayoutOption[0]);
                return(null);
            }
            int hashCode = guiContent.text.GetHashCode();

            if (FieldInspector.drawnObjects.Contains(hashCode))
            {
                return(null);
            }
            FieldInspector.drawnObjects.Add(hashCode);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            if (fieldType.IsAbstract)
            {
                EditorGUILayout.LabelField(guiContent, new GUILayoutOption[0]);
                GUILayout.EndVertical();
                return(null);
            }
            if (value == null)
            {
                if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    fieldType = Nullable.GetUnderlyingType(fieldType);
                }
                value = Activator.CreateInstance(fieldType, true);
            }
            if (FieldInspector.DrawFoldout(value.GetHashCode(), guiContent))
            {
                EditorGUI.indentLevel++;
                value = FieldInspector.DrawFields(task, value);
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            FieldInspector.drawnObjects.Remove(hashCode);
            return(value);
        }
Ejemplo n.º 15
0
 public static void Init()
 {
     FieldInspector.InitLayers();
 }
Ejemplo n.º 16
0
        private static object DrawArrayField(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, object value)
        {
            Type type;

            if (fieldType.IsArray)
            {
                type = fieldType.GetElementType();
            }
            else
            {
                Type type2 = fieldType;
                while (!type2.IsGenericType)
                {
                    type2 = type2.BaseType;
                }
                type = type2.GetGenericArguments()[0];
            }
            IList list;

            if (value == null)
            {
                if (fieldType.IsGenericType || fieldType.IsArray)
                {
                    list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[]
                    {
                        type
                    }), true) as IList);
                }
                else
                {
                    list = (Activator.CreateInstance(fieldType, true) as IList);
                }
                if (fieldType.IsArray)
                {
                    Array array = Array.CreateInstance(type, list.Count);
                    list.CopyTo(array, 0);
                    list = array;
                }
                GUI.changed = true;
            }
            else
            {
                list = (IList)value;
            }
            EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            if (FieldInspector.DrawFoldout(list.GetHashCode(), guiContent))
            {
                EditorGUI.indentLevel++;
                bool flag = guiContent.text.GetHashCode() == FieldInspector.editingFieldHash;
                int  num  = (!flag) ? list.Count : FieldInspector.savedArraySize;
                int  num2 = EditorGUILayout.IntField("Size", num, new GUILayoutOption[0]);
                if (flag && FieldInspector.editingArray && (GUIUtility.keyboardControl != FieldInspector.currentKeyboardControl || Event.current.keyCode == KeyCode.Return))
                {
                    if (num2 != list.Count)
                    {
                        Array array2 = Array.CreateInstance(type, num2);
                        int   num3   = -1;
                        for (int i = 0; i < num2; i++)
                        {
                            if (i < list.Count)
                            {
                                num3 = i;
                            }
                            if (num3 == -1)
                            {
                                break;
                            }
                            array2.SetValue(list[num3], i);
                        }
                        if (fieldType.IsArray)
                        {
                            list = array2;
                        }
                        else
                        {
                            if (fieldType.IsGenericType)
                            {
                                list = (Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[]
                                {
                                    type
                                }), true) as IList);
                            }
                            else
                            {
                                list = (Activator.CreateInstance(fieldType, true) as IList);
                            }
                            for (int j = 0; j < array2.Length; j++)
                            {
                                list.Add(array2.GetValue(j));
                            }
                        }
                    }
                    FieldInspector.editingArray     = false;
                    FieldInspector.savedArraySize   = -1;
                    FieldInspector.editingFieldHash = -1;
                    GUI.changed = true;
                }
                else if (num2 != num)
                {
                    if (!FieldInspector.editingArray)
                    {
                        FieldInspector.currentKeyboardControl = GUIUtility.keyboardControl;
                        FieldInspector.editingArray           = true;
                        FieldInspector.editingFieldHash       = guiContent.text.GetHashCode();
                    }
                    FieldInspector.savedArraySize = num2;
                }
                for (int k = 0; k < list.Count; k++)
                {
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    guiContent.text = "Element " + k;
                    list[k]         = FieldInspector.DrawField(task, guiContent, fieldInfo, type, list[k]);
                    GUILayout.Space(6f);
                    GUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndVertical();
            return(list);
        }