Exemple #1
0
 private void ReloadEditors()
 {
     foreach (Transform t in EditorsPanel)
     {
         PropertyEditor propertyEditor = t.GetComponent <PropertyEditor>();
         if (propertyEditor != null)
         {
             propertyEditor.Reload();
         }
     }
 }
Exemple #2
0
        private void OnResetClick()
        {
            m_editor.Undo.BeginRecord();

            GameObject go = new GameObject();

            go.SetActive(false);

            Component component = go.GetComponent(Component.GetType());

            if (component == null)
            {
                component = go.AddComponent(Component.GetType());
            }

            bool isMonoBehavior = component is MonoBehaviour;

            PropertyDescriptor[] descriptors = GetDescriptors(m_converter);
            for (int i = 0; i < descriptors.Length; ++i)
            {
                PropertyDescriptor descriptor = descriptors[i];
                MemberInfo         memberInfo = descriptor.ComponentMemberInfo;
                if (memberInfo is PropertyInfo)
                {
                    PropertyInfo p            = (PropertyInfo)memberInfo;
                    object       defaultValue = p.GetValue(component, null);
                    m_editor.Undo.RecordValue(Component, memberInfo);
                    p.SetValue(Component, defaultValue, null);
                }
                else
                {
                    if (isMonoBehavior)
                    {
                        if (memberInfo is FieldInfo)
                        {
                            FieldInfo f            = (FieldInfo)memberInfo;
                            object    defaultValue = f.GetValue(component);
                            m_editor.Undo.RecordValue(Component, memberInfo);
                            f.SetValue(Component, defaultValue);
                        }
                    }
                }
            }

            for (int i = 0; i < descriptors.Length; ++i)
            {
                PropertyDescriptor descriptor     = descriptors[i];
                MemberInfo         memberInfo     = descriptor.MemberInfo;
                PropertyEditor     propertyEditor = GetPropertyEditor(memberInfo);
                if (propertyEditor != null)
                {
                    propertyEditor.Reload();
                }
            }

            Destroy(go);

            m_editor.Undo.EndRecord();

            m_editor.Undo.BeginRecord();

            for (int i = 0; i < descriptors.Length; ++i)
            {
                PropertyDescriptor descriptor = descriptors[i];
                MemberInfo         memberInfo = descriptor.ComponentMemberInfo;
                if (memberInfo is PropertyInfo)
                {
                    m_editor.Undo.RecordValue(Component, memberInfo);
                }
                else
                {
                    if (isMonoBehavior)
                    {
                        m_editor.Undo.RecordValue(Component, memberInfo);
                    }
                }
            }

            m_editor.Undo.EndRecord();
        }
Exemple #3
0
        protected virtual void OnResetClick()
        {
            GameObject go = new GameObject();

            go.SetActive(false);

            Component defaultComponent = go.GetComponent(ComponentType);

            if (defaultComponent == null)
            {
                defaultComponent = go.AddComponent(ComponentType);
            }
            bool isMonoBehavior = defaultComponent is MonoBehaviour;

            PropertyDescriptor[] descriptors = m_editorsMap.GetPropertyDescriptors(ComponentType, this, m_converter);
            for (int i = 0; i < descriptors.Length; ++i)
            {
                PropertyDescriptor descriptor = descriptors[i];
                MemberInfo         memberInfo = descriptor.ComponentMemberInfo;
                if (memberInfo is PropertyInfo)
                {
                    PropertyInfo p = (PropertyInfo)memberInfo;
                    foreach (Component component in Components)
                    {
                        if (component == null)
                        {
                            continue;
                        }

                        object defaultValue = p.GetValue(defaultComponent, null);
                        m_editor.Undo.BeginRecordValue(component, memberInfo);
                        p.SetValue(component, defaultValue, null);
                    }
                }
                else
                {
                    if (isMonoBehavior)
                    {
                        if (memberInfo is FieldInfo)
                        {
                            foreach (Component component in Components)
                            {
                                if (component == null)
                                {
                                    continue;
                                }

                                FieldInfo f            = (FieldInfo)memberInfo;
                                object    defaultValue = f.GetValue(defaultComponent);
                                m_editor.Undo.BeginRecordValue(component, memberInfo);
                                f.SetValue(component, defaultValue);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < descriptors.Length; ++i)
            {
                PropertyDescriptor descriptor     = descriptors[i];
                MemberInfo         memberInfo     = descriptor.MemberInfo;
                PropertyEditor     propertyEditor = GetPropertyEditor(memberInfo);
                if (propertyEditor != null)
                {
                    propertyEditor.Reload(true);
                }
            }

            Destroy(go);

            m_editor.Undo.BeginRecord();
            for (int i = 0; i < descriptors.Length; ++i)
            {
                PropertyDescriptor descriptor = descriptors[i];
                MemberInfo         memberInfo = descriptor.ComponentMemberInfo;
                if (memberInfo is PropertyInfo)
                {
                    foreach (Component component in Components)
                    {
                        if (component == null)
                        {
                            continue;
                        }

                        m_editor.Undo.EndRecordValue(component, memberInfo);
                    }
                }
                else
                {
                    if (isMonoBehavior)
                    {
                        foreach (Component component in Components)
                        {
                            if (component == null)
                            {
                                continue;
                            }

                            m_editor.Undo.EndRecordValue(component, memberInfo);
                        }
                    }
                }
            }
            m_editor.Undo.EndRecord();
        }