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); } }
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); } } } } }