示例#1
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;
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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;
            }
        }