Beispiel #1
0
        public static void Delete(GameObject selectionObj)
        {
            if (selectionObj == null)
            {
                return;
            }

            EditorUndo.BeginRecord();

            EditorUndo.BeginDestroyObject(selectionObj);

            EditorUndo.EndRecord();

            bool isEnabled = EditorUndo.Enabled;

            EditorUndo.Enabled      = false;
            EditorSelection.objects = null;
            EditorUndo.Enabled      = isEnabled;

            EditorUndo.BeginRecord();

            EditorUndo.DestroyObject(selectionObj);

            EditorUndo.EndRecord();
        }
Beispiel #2
0
        private void OnResetClick()
        {
            EditorUndo.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);
                    //EditorUndo.RecordValue(Component, memberInfo);
                    p.SetValue(Component, defaultValue, null);
                }
                else
                {
                    if (isMonoBehavior)
                    {
                        if (memberInfo is FieldInfo)
                        {
                            FieldInfo f            = (FieldInfo)memberInfo;
                            object    defaultValue = f.GetValue(component);
                            //EditorUndo.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);

            EditorUndo.EndRecord();

            EditorUndo.BeginRecord();

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

            EditorUndo.EndRecord();
        }