Exemple #1
0
        private InspectorField InstantiateDrawer(InspectorField drawer, Transform drawerParent)
        {
            List <InspectorField> drawerPool;

            if (drawersPool.TryGetValue(drawer.GetType(), out drawerPool))
            {
                for (int i = drawerPool.Count - 1; i >= 0; i--)
                {
                    InspectorField instance = drawerPool[i];
                    drawerPool.RemoveAt(i);

                    if (instance != null && !instance.Equals(null))
                    {
                        instance.transform.SetParent(drawerParent, false);
                        instance.gameObject.SetActive(true);

                        return(instance);
                    }
                }
            }

            InspectorField newDrawer = (InspectorField)Instantiate(drawer, drawerParent, false);

            newDrawer.Initialize();
            return(newDrawer);
        }
Exemple #2
0
        protected override void GenerateElements()
        {
            if (Value == null)
            {
                return;
            }

            if (isArray)
            {
                Array array = (Array)Value;
                for (int i = 0; i < array.Length; i++)
                {
                    InspectorField elementDrawer = Inspector.CreateDrawerForType(elementType, drawArea, Depth + 1);
                    if (elementDrawer == null)
                    {
                        break;
                    }

                    int j = i;
                    elementDrawer.BindTo(elementType, string.Empty, () => ((Array)Value).GetValue(j), (value) =>
                    {
                        Array _array = (Array)Value;
                        _array.SetValue(value, j);
                        Value = _array;
                    });

                    elementDrawer.NameRaw = Inspector.ArrayIndicesStartAtOne ? (i + 1) + ":" : i + ":";
                    elements.Add(elementDrawer);
                }
            }
            else
            {
                IList list = (IList)Value;
                for (int i = 0; i < list.Count; i++)
                {
                    InspectorField elementDrawer = Inspector.CreateDrawerForType(elementType, drawArea, Depth + 1);
                    if (elementDrawer == null)
                    {
                        break;
                    }

                    int    j            = i;
                    string variableName = Inspector.ArrayIndicesStartAtOne ? (i + 1) + ":" : i + ":";
                    elementDrawer.BindTo(elementType, variableName, () => ((IList)Value)[j], (value) =>
                    {
                        IList _list = (IList)Value;
                        _list[j]    = value;
                        Value       = _list;
                    });

                    elements.Add(elementDrawer);
                }
            }

            sizeInput.Text = "" + Length;
        }
Exemple #3
0
        protected InspectorField CreateDrawer(Type variableType, string variableName, Getter getter, Setter setter, bool drawObjectsAsFields = true)
        {
            InspectorField variableDrawer = Inspector.CreateDrawerForType(variableType, drawArea, Depth + 1, drawObjectsAsFields);

            if (variableDrawer != null)
            {
                variableDrawer.BindTo(variableType, variableName, getter, setter);
                elements.Add(variableDrawer);
            }

            return(variableDrawer);
        }
Exemple #4
0
        public void BindTo(InspectorField parent, MemberInfo member, string variableName = null)
        {
            if (member is FieldInfo)
            {
                FieldInfo field = (FieldInfo)member;
                if (variableName == null)
                {
                    variableName = field.Name;
                }

#if UNITY_EDITOR || !NETFX_CORE
                if (!parent.BoundVariableType.IsValueType)
#else
                if (!parent.BoundVariableType.GetTypeInfo().IsValueType)
#endif
                { BindTo(field.FieldType, variableName, () => field.GetValue(parent.Value), (value) => field.SetValue(parent.Value, value)); }
                else
                {
                    BindTo(field.FieldType, variableName, () => field.GetValue(parent.Value), (value) =>
                    {
                        field.SetValue(parent.Value, value);
                        parent.Value = parent.Value;
                    });
                }
            }
            else if (member is PropertyInfo)
            {
                PropertyInfo property = (PropertyInfo)member;
                if (variableName == null)
                {
                    variableName = property.Name;
                }

#if UNITY_EDITOR || !NETFX_CORE
                if (!parent.BoundVariableType.IsValueType)
#else
                if (!parent.BoundVariableType.GetTypeInfo().IsValueType)
#endif
                { BindTo(property.PropertyType, variableName, () => property.GetValue(parent.Value, null), (value) => property.SetValue(parent.Value, value, null)); }
                else
                {
                    BindTo(property.PropertyType, variableName, () => property.GetValue(parent.Value, null), (value) =>
                    {
                        property.SetValue(parent.Value, value, null);
                        parent.Value = parent.Value;
                    });
                }
            }
            else
            {
                throw new ArgumentException("Member can either be a field or a property");
            }
        }
Exemple #5
0
        protected InspectorField CreateDrawerForVariable(MemberInfo variable, string variableName = null)
        {
            Type           variableType   = variable is FieldInfo ? ((FieldInfo)variable).FieldType : ((PropertyInfo)variable).PropertyType;
            InspectorField variableDrawer = Inspector.CreateDrawerForType(variableType, drawArea, Depth + 1);

            if (variableDrawer != null)
            {
                variableDrawer.BindTo(this, variable, variableName);
                elements.Add(variableDrawer);
            }

            return(variableDrawer);
        }
Exemple #6
0
        public InspectorField CreateDrawerForType(Type type, Transform drawerParent, int depth, bool drawObjectsAsFields = true)
        {
            InspectorField variableDrawer = GetDrawerForType(type, drawObjectsAsFields);

            if (variableDrawer != null)
            {
                InspectorField drawer = InstantiateDrawer(variableDrawer, drawerParent);
                drawer.Inspector = this;
                drawer.Skin      = Skin;
                drawer.Depth     = depth;

                return(drawer);
            }

            return(null);
        }
Exemple #7
0
        protected InspectorField CreateDrawerForComponent(Component component, string variableName = null)
        {
            InspectorField variableDrawer = Inspector.CreateDrawerForType(component.GetType(), drawArea, Depth + 1, false);

            if (variableDrawer != null)
            {
                if (variableName == null)
                {
                    variableName = component.GetType().Name + " component";
                }

                variableDrawer.BindTo(component.GetType(), string.Empty, () => component, (value) => { });
                variableDrawer.NameRaw = variableName;

                elements.Add(variableDrawer);
            }

            return(variableDrawer);
        }
Exemple #8
0
        public void StopInspect()
        {
            if (inspectLock)
            {
                return;
            }

            if (currentDrawer != null)
            {
                currentDrawer.Unbind();
                currentDrawer = null;
            }

            m_inspectedObject = null;
            scrollView.verticalNormalizedPosition = 1f;

            ColorPicker.Instance.Close();
            ObjectReferencePicker.Instance.Close();
        }
Exemple #9
0
        public void PoolDrawer(InspectorField drawer)
        {
            List <InspectorField> drawerPool;

            if (!drawersPool.TryGetValue(drawer.GetType(), out drawerPool))
            {
                drawerPool = new List <InspectorField>(poolCapacity);
                drawersPool[drawer.GetType()] = drawerPool;
            }

            if (drawerPool.Count < poolCapacity)
            {
                drawer.gameObject.SetActive(false);
                drawer.transform.SetParent(poolParent, false);
                drawerPool.Add(drawer);
            }
            else
            {
                Destroy(drawer.gameObject);
            }
        }
Exemple #10
0
        public void Inspect(object obj)
        {
            if (inspectLock)
            {
                return;
            }

            isDirty = false;

            if (OnInspectedObjectChanging != null)
            {
                obj = OnInspectedObjectChanging(m_inspectedObject, obj);
            }

            if (m_inspectedObject == obj)
            {
                return;
            }

            StopInspect();

            inspectLock = true;
            try
            {
                m_inspectedObject = obj;

                if (obj.IsNull())
                {
                    return;
                }

#if UNITY_EDITOR || !NETFX_CORE
                if (obj.GetType().IsValueType)
#else
                if (obj.GetType().GetTypeInfo().IsValueType)
#endif
                {
                    m_inspectedObject = null;
                    Debug.LogError("Can't inspect a value type!");
                    return;
                }

                if (!gameObject.activeSelf)
                {
                    m_inspectedObject = null;
                    Debug.LogError("Can't inspect while Inspector is inactive!");
                    return;
                }

                InspectorField inspectedObjectDrawer = CreateDrawerForType(obj.GetType(), drawArea, 0, false);
                if (inspectedObjectDrawer != null)
                {
                    inspectedObjectDrawer.BindTo(obj.GetType(), string.Empty, () => m_inspectedObject, (value) => m_inspectedObject = value);
                    inspectedObjectDrawer.NameRaw = obj.GetNameWithType();
                    inspectedObjectDrawer.Refresh();

                    if (inspectedObjectDrawer is ExpandableInspectorField)
                    {
                        ((ExpandableInspectorField)inspectedObjectDrawer).IsExpanded = true;
                    }

                    currentDrawer = inspectedObjectDrawer;

                    GameObject go = m_inspectedObject as GameObject;
                    if (go == null && m_inspectedObject is Component)
                    {
                        go = ((Component)m_inspectedObject).gameObject;
                    }

                    if (!ConnectedHierarchy.IsNull() && (go == null || !ConnectedHierarchy.Select(go.transform)))
                    {
                        ConnectedHierarchy.Deselect();
                    }
                }
                else
                {
                    m_inspectedObject = null;
                }
            }
            finally
            {
                inspectLock = false;
            }
        }