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); }
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); } } } }
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; } }
private void Start() { m_editor = IOC.Resolve <IRTE>(); GameObject go = m_editor.Selection.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>(); 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 = () => { m_editor.IsDirty = true; }; editor.transform.SetParent(ComponentsPanel, false); editor.Component = component; } else { Debug.LogErrorFormat("editor prefab {0} does not have ComponentEditor script", editorPrefab.name); } } } } }
private void Awake() { if (DisableOnAwake) { gameObject.SetActive(false); } List <Collider> colliders = new List <Collider>(); MeshFilter filter = GetComponent <MeshFilter>(); Rigidbody rigidBody = GetComponent <Rigidbody>(); bool isRigidBody = rigidBody != null; if (filter != null) { if (!isRigidBody && AddColliders) { MeshCollider collider = gameObject.AddComponent <MeshCollider>(); collider.convex = isRigidBody; collider.sharedMesh = filter.mesh; colliders.Add(collider); } } SkinnedMeshRenderer skinnedMeshRenderer = GetComponent <SkinnedMeshRenderer>(); if (skinnedMeshRenderer != null) { if (!isRigidBody && AddColliders) { MeshCollider collider = gameObject.AddComponent <MeshCollider>(); collider.convex = isRigidBody; collider.sharedMesh = skinnedMeshRenderer.sharedMesh; colliders.Add(collider); } } m_colliders = colliders.ToArray(); if (transform.parent != null) { ExposeToEditor parent = transform.parent.GetComponentInParent <ExposeToEditor>(); if (m_parent != parent) { m_parent = parent; if (m_parent != null) { m_parent.m_children.Add(this); } } } m_hierarchyItem = gameObject.GetComponent <HierarchyItem>(); if (m_hierarchyItem == null) { m_hierarchyItem = gameObject.AddComponent <HierarchyItem>(); } if (Awaked != null) { Awaked(this); } }