private void Awake()
 {
     hierarchyItem = GetComponent <HierarchyItem>();
     if (hierarchyItem == null)
     {
         m_hierarchy = GetComponent <RuntimeHierarchy>();
     }
 }
        protected override void GenerateElements()
        {
            if (components.Count == 0)
            {
                return;
            }

            CreateDrawer(typeof(bool), "Is Active", () => ((GameObject)Value).activeSelf, (value) => ((GameObject)Value).SetActive((bool)value));
            nameField = CreateDrawer(typeof(string), "Name", () => ((GameObject)Value).name, (value) =>
            {
                ((GameObject)Value).name = (string)value;

                RuntimeHierarchy hierarchy = Inspector.ConnectedHierarchy;
                if (hierarchy != null)
                {
                    hierarchy.RefreshNameOf(((GameObject)Value).transform);
                }
            }) as StringField;
            tagField = CreateDrawer(typeof(string), "Tag", () =>
            {
                GameObject go = (GameObject)Value;
                if (!go.CompareTag(currentTag))
                {
                    currentTag = go.tag;
                }

                return(currentTag);
            }, (value) => ((GameObject)Value).tag = (string)value) as StringField;
            CreateDrawerForVariable(typeof(GameObject).GetProperty("layer"), "Layer");

            for (int i = 0; i < components.Count; i++)
            {
                CreateDrawerForComponent(components[i]);
            }

            if (nameField != null)
            {
                nameField.SetterMode = StringField.Mode.OnSubmit;
            }

            if (tagField != null)
            {
                tagField.SetterMode = StringField.Mode.OnSubmit;
            }
        }
예제 #3
0
 public HierarchyRootSearch(RuntimeHierarchy hierarch, IHierarchyRootContent reference)
 {
     this.hierarch  = hierarch;
     this.reference = reference;
 }
        public void OnDrop(PointerEventData eventData)
        {
            RuntimeHierarchy hierarchy = Hierarchy;

            if (hierarchy == null || !hierarchy.CanReorganizeItems)
            {
                return;
            }

            Transform droppedTransform = RuntimeInspectorUtils.GetAssignableObjectFromDraggedReferenceItem(eventData, typeof(Transform)) as Transform;

            if (droppedTransform == null)
            {
                return;
            }

            if (hierarchyItem == null)
            {
                if (droppedTransform.parent == null)
                {
                    return;
                }

                droppedTransform.SetParent(null, true);
            }
            else if (hierarchyItem is HierarchyItemTransform)
            {
                Transform newParent = ((HierarchyItemTransform)hierarchyItem).BoundTransform;
                if (droppedTransform.parent == newParent || droppedTransform == newParent)
                {
                    return;
                }

                // Avoid setting child object as parent of the parent object
                Transform curr = newParent;
                while (curr.parent != null && curr.parent != droppedTransform)
                {
                    curr = curr.parent;
                }

                if (curr.parent == droppedTransform)
                {
                    curr.SetParent(droppedTransform.parent, true);
                }

                droppedTransform.SetParent(newParent, true);
            }
            else
            {
                IHierarchyRootContent rootContent = ((HierarchyItemRoot)hierarchyItem).Content;
                if (rootContent is HierarchyRootPseudoScene)
                {
                    //( (HierarchyRootPseudoScene) rootContent ).AddChild( droppedTransform ); // Add object to pseudo-scene
                    return;
                }
                else if (rootContent is HierarchyRootScene)
                {
                    bool parentChanged = false;
                    if (droppedTransform.parent != null)
                    {
                        droppedTransform.SetParent(null, true);
                        parentChanged = true;
                    }

                    Scene scene = ((HierarchyRootScene)rootContent).Scene;
                    if (droppedTransform.gameObject.scene != scene)
                    {
                        SceneManager.MoveGameObjectToScene(droppedTransform.gameObject, scene);
                        parentChanged = true;
                    }

                    if (!parentChanged)
                    {
                        return;
                    }
                }
            }

            if (hierarchyItem != null && !hierarchyItem.IsExpanded)
            {
                hierarchyItem.IsExpanded = true;
            }

            hierarchy.Refresh();
        }