Example #1
0
        private bool HasExposeToEditorChildren(Transform parentTransform)
        {
            int childrenCount = parentTransform.childCount;

            if (childrenCount == 0)
            {
                return(false);
            }

            for (int i = 0; i < childrenCount; ++i)
            {
                Transform      childTransform = parentTransform.GetChild(i);
                ExposeToEditor child          = childTransform.GetComponent <ExposeToEditor>();
                if (child != null)
                {
                    return(true);
                }
                HierarchyItem hierarchyItem = childTransform.GetComponent <HierarchyItem>();
                if (hierarchyItem != null)
                {
                    if (HasExposeToEditorChildren(childTransform))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #2
0
        private void UpdateChildren(Transform parentTransform, ExposeToEditor parentExp)
        {
            int childrenCount = parentTransform.childCount;

            if (childrenCount == 0)
            {
                return;
            }

            for (int i = 0; i < childrenCount; ++i)
            {
                Transform      childTransform    = parentTransform.GetChild(i);
                ExposeToEditor child             = childTransform.GetComponent <ExposeToEditor>();
                HierarchyItem  childHierarcyItem = childTransform.GetComponent <HierarchyItem>();
                if (child != null)
                {
                    child.Parent = parentExp;
                    childHierarcyItem.m_parentExp = parentExp;
                }
                else
                {
                    if (childHierarcyItem != null)
                    {
                        UpdateChildren(childTransform, parentExp);
                    }
                }
            }
        }
Example #3
0
        private void Awake()
        {
            RuntimeEditorApplication.IsOpenedChanged += OnEditorIsOpenedChanged;

            m_objectType = ExposeToEditorObjectType.Undefined;

            Init();

            m_hierarchyItem = gameObject.GetComponent <HierarchyItem>();
            if (m_hierarchyItem == null)
            {
                m_hierarchyItem = gameObject.AddComponent <HierarchyItem>();
            }

            if (hideFlags != HideFlags.HideAndDontSave)
            {
                if (Awaked != null)
                {
                    Awaked(this);
                }
            }
        }
Example #4
0
        private void TryDestroyChainToParent(Transform parent, ExposeToEditor parentExp)
        {
            if (parentExp == null)
            {
                return;
            }

            while (parent != null && parent.gameObject != parentExp.gameObject)
            {
                if (!parent.GetComponent <ExposeToEditor>())
                {
                    HierarchyItem hierarchyItem = parent.GetComponent <HierarchyItem>();
                    if (hierarchyItem)
                    {
                        if (!HasExposeToEditorChildren(parent))
                        {
                            Destroy(hierarchyItem);
                        }
                    }
                }
                parent = parent.parent;
            }
        }
Example #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);
                        }
                    }
                }
            }
        }