Esempio n. 1
0
        protected override void InitOverride(object target, MemberInfo memberInfo, string label = null)
        {
            Type elementType = null;

            if (memberInfo is PropertyInfo)
            {
                elementType = ((PropertyInfo)memberInfo).PropertyType.GetElementType();
                if (elementType == null)
                {
                    if (((PropertyInfo)memberInfo).PropertyType.IsGenericType)
                    {
                        elementType = ((PropertyInfo)memberInfo).PropertyType.GetGenericArguments()[0];
                    }
                }
            }
            else if (memberInfo is FieldInfo)
            {
                elementType = ((FieldInfo)memberInfo).FieldType.GetElementType();
                if (elementType == null)
                {
                    if (((FieldInfo)memberInfo).FieldType.IsGenericType)
                    {
                        elementType = ((FieldInfo)memberInfo).FieldType.GetGenericArguments()[0];
                    }
                }
            }



            if (elementType != null)
            {
                GameObject editor = EditorsMap.GetPropertyEditor(elementType);
                if (EditorsMap.IsPropertyEditorEnabled(elementType))
                {
                    m_editorPrefab = editor.GetComponent <PropertyEditor>();
                }

                if (m_editorPrefab == null)
                {
                    Debug.LogWarning("Editor for " + memberInfo.Name + " not found");
                    Destroy(gameObject);
                }

                base.InitOverride(target, memberInfo, label);
            }
            else
            {
                if (elementType == null)
                {
                    Debug.LogWarning("Editor for " + memberInfo.Name + " not found");
                    Destroy(gameObject);
                }
            }

            if (StartExpanded)
            {
                Expander.isOn = GetValue().Count < 8;
            }
        }
Esempio n. 2
0
        private void CreateElementEditor(MemberInfo memberInfo, Type type)
        {
            if (!EditorsMap.IsPropertyEditorEnabled(type))
            {
                return;
            }
            GameObject editorPrefab = EditorsMap.GetPropertyEditor(type);

            if (editorPrefab == null)
            {
                return;
            }
            PropertyEditor editor = Instantiate(editorPrefab).GetComponent <PropertyEditor>();

            if (editor == null)
            {
                return;
            }

            CustomTypeFieldAccessor accessor = null;

            if (ChildDescriptors == null)
            {
                accessor = new CustomTypeFieldAccessor(this, memberInfo, memberInfo.Name);
            }
            else
            {
                PropertyDescriptor childPropertyDescriptor;
                if (ChildDescriptors.TryGetValue(memberInfo, out childPropertyDescriptor))
                {
                    accessor = new CustomTypeFieldAccessor(
                        this,
                        childPropertyDescriptor.MemberInfo, childPropertyDescriptor.Label);
                }
            }
            if (accessor != null)
            {
                editor.transform.SetParent(Panel, false);
                editor.Init(accessor, accessor.GetType().GetProperty("Value"), accessor.Name, OnValueChanging, OnValueChanged, null, false);
            }
        }
Esempio n. 3
0
        private PropertyEditor InstantiatePropertyEditor(PropertyDescriptor descriptor)
        {
            if (descriptor.MemberInfo == null)
            {
                Debug.LogError("desciptor.MemberInfo is null");
                return(null);
            }

            if (descriptor.MemberType == null)
            {
                Debug.LogError("descriptor.MemberType is null");
                return(null);
            }

            GameObject editorGo = EditorsMap.GetPropertyEditor(descriptor.MemberType);

            if (editorGo == null)
            {
                return(null);
            }

            if (!EditorsMap.IsPropertyEditorEnabled(descriptor.MemberType))
            {
                return(null);
            }
            PropertyEditor editor = editorGo.GetComponent <PropertyEditor>();

            if (editor == null)
            {
                Debug.LogErrorFormat("editor {0} is not PropertyEditor", editorGo);
                return(null);
            }
            PropertyEditor instance = Instantiate(editor);

            instance.transform.SetParent(EditorsPanel, false);
            return(instance);
        }
Esempio n. 4
0
        private void CreateEditor()
        {
            if (m_editor != null)
            {
                Destroy(m_editor);
            }

            if (EditorSelection.activeObject == null)
            {
                return;
            }

            UnityObject[] selectedObjects = EditorSelection.objects.Where(o => o != null).ToArray();
            if (selectedObjects.Length != 1)
            {
                return;
            }

            Type objType = selectedObjects[0].GetType();

            for (int i = 1; i < selectedObjects.Length; ++i)
            {
                if (objType != selectedObjects[i].GetType())
                {
                    return;
                }
            }

            GameObject editorPrefab;

#if !UNITY_WEBGL
            if (objType == typeof(Material))// || objType == typeof(UnityEngine.ProceduralMaterial))
#else
            if (objType == typeof(Material))
#endif

            {
                Material mat = selectedObjects[0] as Material;
                if (mat.shader == null)
                {
                    return;
                }

                //if(!EditorsMap.IsMaterialEditorEnabled(mat.shader))
                //{
                //    return;
                //}
                editorPrefab = EditorsMap.GetMaterialEditor(mat.shader);
            }
            else
            {
                if (!EditorsMap.IsObjectEditorEnabled(objType))
                {
                    return;
                }
                editorPrefab = EditorsMap.GetObjectEditor(objType);
            }

            if (editorPrefab != null)
            {
                m_editor = Instantiate(editorPrefab);
                m_editor.transform.SetParent(Panel, false);
            }
        }
Esempio n. 5
0
        private void Start()
        {
            GameObject          go               = EditorSelection.activeGameObject;
            ExposeToEditor      exposeToEditor   = go.GetComponent <ExposeToEditor>();
            HierarchyItem       hierarchyItem    = go.GetComponent <HierarchyItem>();
            HashSet <Component> ignoreComponents = new HashSet <Component>();

            if (exposeToEditor != null)
            {
                if (exposeToEditor.Colliders != null)
                {
                    for (int i = 0; i < exposeToEditor.Colliders.Length; ++i)
                    {
                        Collider collider = exposeToEditor.Colliders[i];
                        if (!ignoreComponents.Contains(collider))
                        {
                            ignoreComponents.Add(collider);
                        }
                    }
                }

                ignoreComponents.Add(exposeToEditor);
            }

            if (hierarchyItem != null)
            {
                ignoreComponents.Add(hierarchyItem);
            }

            InputName.text        = go.name;
            TogEnableDisable.isOn = go.activeSelf;

            InputName.onEndEdit.AddListener(OnEndEditName);
            TogEnableDisable.onValueChanged.AddListener(OnEnableDisable);
            Component[] components = go.GetComponents <Component>();
            //Component[] components = go.GetComponentsInChildren<Collider>();
            for (int i = 0; i < components.Length; ++i)
            {
                Component component = components[i];
                if (component == null)
                {
                    continue;
                }

                if (ignoreComponents.Contains(component))
                {
                    continue;
                }

                if ((component.hideFlags & HideFlags.HideInInspector) != 0)
                {
                    continue;
                }

                if (EditorsMap.IsObjectEditorEnabled(component.GetType()))
                {
                    GameObject editorPrefab = EditorsMap.GetObjectEditor(component.GetType());
                    if (editorPrefab != null)
                    {
                        ComponentEditor componentEditorPrefab = editorPrefab.GetComponent <ComponentEditor>();
                        if (componentEditorPrefab != null)
                        {
                            ComponentEditor editor = Instantiate(componentEditorPrefab);
                            editor.EndEditCallback = () =>
                            {
                                RuntimeEditorApplication.SaveSelectedObjects();
                            };
                            editor.transform.SetParent(ComponentsPanel, false);
                            editor.Component = component;
                        }
                        else
                        {
                            Debug.LogErrorFormat("editor prefab {0} does not have ComponentEditor script", editorPrefab.name);
                        }
                    }
                }
            }
        }