public static bool HandleSingleSpriteDragIntoHierarchy(IHierarchyProperty property, Sprite sprite, bool perform)
        {
            GameObject gameObject = null;

            if (property != null && property.pptrValue != null)
            {
                UnityEngine.Object pptrValue = property.pptrValue;
                gameObject = (pptrValue as GameObject);
            }
            if (perform)
            {
                Vector3    defaultInstantiatePosition = SpriteUtility.GetDefaultInstantiatePosition();
                GameObject gameObject2 = SpriteUtility.DropSpriteToSceneToCreateGO(sprite, defaultInstantiatePosition);
                if (gameObject != null)
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop single sprite to existing gameobject", "null", 1);
                    gameObject2.transform.parent        = gameObject.transform;
                    gameObject2.transform.localPosition = Vector3.zero;
                }
                else
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop single sprite to empty hierarchy", "null", 1);
                }
                Selection.activeGameObject = gameObject2;
            }
            return(true);
        }
        private float DoSearchResultPathGUI()
        {
            if (!this.hasSearchFilter)
            {
                return(0.0f);
            }
            GUILayout.FlexibleSpace();
            Rect rect = EditorGUILayout.BeginVertical(EditorStyles.inspectorBig, new GUILayoutOption[0]);

            GUILayout.Label("Path:");
            if (this.m_TreeView.HasSelection())
            {
                int instanceID = this.m_TreeView.GetSelection()[0];
                IHierarchyProperty hierarchyProperty = (IHierarchyProperty) new HierarchyProperty(HierarchyType.GameObjects);
                hierarchyProperty.Find(instanceID, (int[])null);
                if (hierarchyProperty.isValid)
                {
                    do
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label((Texture)hierarchyProperty.icon);
                        GUILayout.Label(hierarchyProperty.name);
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.EndHorizontal();
                    }while (hierarchyProperty.Parent());
                }
            }
            EditorGUILayout.EndVertical();
            GUILayout.Space(0.0f);
            return(rect.height);
        }
        static bool HasSubFolders(IHierarchyProperty property)
        {
            var path       = AssetDatabase.GUIDToAssetPath(property.guid);
            var subFolders = AssetDatabase.GetSubFolders(path);

            return(subFolders.Length > 0);
        }
Beispiel #4
0
 public override void FetchData()
 {
   this.m_RootItem = new TreeViewItem(this.m_RootInstanceID, 0, (TreeViewItem) null, AssetsTreeViewDataSource.CreateDisplayName(this.m_RootInstanceID));
   if (!this.showRootNode)
     this.SetExpanded(this.m_RootItem, true);
   IHierarchyProperty hierarchyProperty = (IHierarchyProperty) new HierarchyProperty(HierarchyType.Assets);
   hierarchyProperty.Reset();
   if (!hierarchyProperty.Find(this.m_RootInstanceID, (int[]) null))
     Debug.LogError((object) ("Root Asset with id " + (object) this.m_RootInstanceID + " not found!!"));
   int minDepth = hierarchyProperty.depth + (!this.showRootNode ? 1 : 0);
   int[] array = this.expandedIDs.ToArray();
   Texture2D texture = EditorGUIUtility.FindTexture(EditorResourcesUtility.emptyFolderIconName);
   this.m_VisibleRows = new List<TreeViewItem>();
   while (hierarchyProperty.NextWithDepthCheck(array, minDepth))
   {
     if (!this.foldersOnly || hierarchyProperty.isFolder)
     {
       int depth = hierarchyProperty.depth - minDepth;
       TreeViewItem treeViewItem = !hierarchyProperty.isFolder ? (TreeViewItem) new AssetsTreeViewDataSource.NonFolderTreeItem(hierarchyProperty.instanceID, depth, (TreeViewItem) null, hierarchyProperty.name) : (TreeViewItem) new AssetsTreeViewDataSource.FolderTreeItem(hierarchyProperty.instanceID, depth, (TreeViewItem) null, hierarchyProperty.name);
       treeViewItem.icon = !hierarchyProperty.isFolder || hierarchyProperty.hasChildren ? hierarchyProperty.icon : texture;
       if (hierarchyProperty.hasChildren)
         treeViewItem.AddChild((TreeViewItem) null);
       this.m_VisibleRows.Add(treeViewItem);
     }
   }
   TreeViewUtility.SetChildParentReferences(this.m_VisibleRows, this.m_RootItem);
   if (this.foldersFirst)
   {
     AssetsTreeViewDataSource.FoldersFirstRecursive(this.m_RootItem);
     this.m_VisibleRows.Clear();
     this.GetVisibleItemsRecursive(this.m_RootItem, this.m_VisibleRows);
   }
   this.m_NeedRefreshVisibleFolders = false;
   this.m_TreeView.SetSelection(Selection.instanceIDs, false);
 }
Beispiel #5
0
        // Should return the items that have children from id and below
        protected override HashSet <int> GetParentsBelow(int id)
        {
            // Add all children expanded ids to hashset
            HashSet <int> parentsBelow = new HashSet <int>();

            if (!IsValidHierarchyInstanceID(id))
            {
                return(parentsBelow);
            }

            IHierarchyProperty search = CreateHierarchyProperty();

            if (search.Find(id, null))
            {
                parentsBelow.Add(id);

                int depth = search.depth;
                while (search.Next(null) && search.depth > depth)
                {
                    if (search.hasChildren)
                    {
                        parentsBelow.Add(search.instanceID);
                    }
                }
            }
            return(parentsBelow);
        }
Beispiel #6
0
 protected override HashSet<int> GetParentsBelow(int id)
 {
   HashSet<int> intSet = new HashSet<int>();
   IHierarchyProperty hierarchyProperty = (IHierarchyProperty) new HierarchyProperty(HierarchyType.Assets);
   if (hierarchyProperty.Find(id, (int[]) null))
   {
     intSet.Add(id);
     int depth = hierarchyProperty.depth;
     while (hierarchyProperty.Next((int[]) null) && hierarchyProperty.depth > depth)
     {
       if (hierarchyProperty.hasChildren)
         intSet.Add(hierarchyProperty.instanceID);
     }
   }
   return intSet;
 }
Beispiel #7
0
        protected override void GetParentsAbove(int id, HashSet <int> parentsAbove)
        {
            if (!IsValidHierarchyInstanceID(id))
            {
                return;
            }

            IHierarchyProperty propertyIterator = CreateHierarchyProperty();

            if (propertyIterator.Find(id, null))
            {
                while (propertyIterator.Parent())
                {
                    parentsAbove.Add((propertyIterator.instanceID));
                }
            }
        }
        protected override HashSet <int> GetParentsAbove(int id)
        {
            HashSet <int> intSet = new HashSet <int>();

            if (!this.IsValidHierarchyInstanceID(id))
            {
                return(intSet);
            }
            IHierarchyProperty hierarchyProperty = (IHierarchyProperty) new HierarchyProperty(HierarchyType.GameObjects);

            if (hierarchyProperty.Find(id, (int[])null))
            {
                while (hierarchyProperty.Parent())
                {
                    intSet.Add(hierarchyProperty.instanceID);
                }
            }
            return(intSet);
        }
        public static bool HandleMultipleSpritesDragIntoHierarchy(IHierarchyProperty property, Sprite[] sprites, bool perform)
        {
            GameObject gameObject = null;

            if (property == null || property.pptrValue == null)
            {
                if (perform)
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to empty hierarchy", "null", 1);
                    gameObject      = new GameObject();
                    gameObject.name = ((!string.IsNullOrEmpty(sprites[0].name)) ? sprites[0].name : "Sprite");
                    gameObject.transform.position = SpriteUtility.GetDefaultInstantiatePosition();
                }
            }
            else
            {
                UnityEngine.Object pptrValue = property.pptrValue;
                gameObject = (pptrValue as GameObject);
                if (perform)
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to gameobject", "null", 1);
                }
            }
            if (perform)
            {
                SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
                if (spriteRenderer == null)
                {
                    spriteRenderer = gameObject.AddComponent <SpriteRenderer>();
                }
                if (spriteRenderer == null)
                {
                    return(true);
                }
                if (spriteRenderer.sprite == null)
                {
                    spriteRenderer.sprite = sprites[0];
                }
                SpriteUtility.CreateAnimation(gameObject, sprites);
                Selection.activeGameObject = gameObject;
            }
            return(true);
        }
Beispiel #10
0
        protected override HashSet <int> GetParentsAbove(int id)
        {
            HashSet <int> parents = new HashSet <int>();

            if (!IsValidHierarchyInstanceID(id))
            {
                return(parents);
            }

            IHierarchyProperty propertyIterator = CreateHierarchyProperty();

            if (propertyIterator.Find(id, null))
            {
                while (propertyIterator.Parent())
                {
                    parents.Add((propertyIterator.instanceID));
                }
            }
            return(parents);
        }
        private void ReadAssetDatabase(TreeViewItem parent, int baseDepth)
        {
            IHierarchyProperty hierarchyProperty = (IHierarchyProperty) new HierarchyProperty(HierarchyType.Assets);

            hierarchyProperty.Reset();
            Texture2D           texture1     = EditorGUIUtility.FindTexture(EditorResourcesUtility.folderIconName);
            Texture2D           texture2     = EditorGUIUtility.FindTexture(EditorResourcesUtility.emptyFolderIconName);
            List <TreeViewItem> visibleItems = new List <TreeViewItem>();

            while (hierarchyProperty.Next((int[])null))
            {
                if (hierarchyProperty.isFolder)
                {
                    visibleItems.Add(new TreeViewItem(hierarchyProperty.instanceID, baseDepth + hierarchyProperty.depth, (TreeViewItem)null, hierarchyProperty.name)
                    {
                        icon = !hierarchyProperty.hasChildren ? texture2 : texture1
                    });
                }
            }
            TreeViewUtility.SetChildParentReferences(visibleItems, parent);
        }
        public override void RevealItems(int[] itemIDs)
        {
            // Optimization: Only spend time on revealing item if it is part of the Hierarchy
            HashSet <int> validItemIDs = new HashSet <int>();

            foreach (var itemID in itemIDs)
            {
                if (IsValidHierarchyInstanceID(itemID))
                {
                    validItemIDs.Add(itemID);
                }
            }

            // Get existing expanded in hashset
            HashSet <int> expandedSet = new HashSet <int>(expandedIDs);
            int           orgSize     = expandedSet.Count;

            IHierarchyProperty propertyIterator = CreateHierarchyProperty();

            int[] ancestors = propertyIterator.FindAllAncestors(validItemIDs.ToArray());

            // Add all parents above id
            foreach (var itemID in ancestors)
            {
                expandedSet.Add(itemID);
            }

            if (orgSize != expandedSet.Count)
            {
                // Bulk set expanded ids (is sorted in SetExpandedIDs)
                SetExpandedIDs(expandedSet.ToArray());

                // Refresh immediately if any Item was expanded
                if (m_NeedRefreshRows)
                {
                    FetchData();
                }
            }
        }
        protected override HashSet <int> GetParentsBelow(int id)
        {
            HashSet <int> intSet = new HashSet <int>();

            if (!this.IsValidHierarchyInstanceID(id))
            {
                return(intSet);
            }
            IHierarchyProperty hierarchyProperty = (IHierarchyProperty) new HierarchyProperty(HierarchyType.GameObjects);

            if (hierarchyProperty.Find(id, (int[])null))
            {
                intSet.Add(id);
                int depth = hierarchyProperty.depth;
                while (hierarchyProperty.Next((int[])null) && hierarchyProperty.depth > depth)
                {
                    if (hierarchyProperty.hasChildren)
                    {
                        intSet.Add(hierarchyProperty.instanceID);
                    }
                }
            }
            return(intSet);
        }
		public static bool HandleSingleSpriteDragIntoHierarchy(IHierarchyProperty property, Sprite sprite, bool perform)
		{
			GameObject gameObject = null;
			if (property != null && property.pptrValue != null)
			{
				UnityEngine.Object pptrValue = property.pptrValue;
				gameObject = (pptrValue as GameObject);
			}
			if (perform)
			{
				Vector3 defaultInstantiatePosition = SpriteUtility.GetDefaultInstantiatePosition();
				GameObject gameObject2 = SpriteUtility.DropSpriteToSceneToCreateGO(sprite, defaultInstantiatePosition);
				if (gameObject != null)
				{
					Analytics.Event("Sprite Drag and Drop", "Drop single sprite to existing gameobject", "null", 1);
					gameObject2.transform.parent = gameObject.transform;
					gameObject2.transform.localPosition = Vector3.zero;
				}
				else
				{
					Analytics.Event("Sprite Drag and Drop", "Drop single sprite to empty hierarchy", "null", 1);
				}
				Selection.activeGameObject = gameObject2;
			}
			return true;
		}
		public static bool HandleMultipleSpritesDragIntoHierarchy(IHierarchyProperty property, Sprite[] sprites, bool perform)
		{
			GameObject gameObject = null;
			if (property == null || property.pptrValue == null)
			{
				if (perform)
				{
					Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to empty hierarchy", "null", 1);
					gameObject = new GameObject();
					gameObject.name = ((!string.IsNullOrEmpty(sprites[0].name)) ? sprites[0].name : "Sprite");
					gameObject.transform.position = SpriteUtility.GetDefaultInstantiatePosition();
				}
			}
			else
			{
				UnityEngine.Object pptrValue = property.pptrValue;
				gameObject = (pptrValue as GameObject);
				if (perform)
				{
					Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to gameobject", "null", 1);
				}
			}
			if (perform)
			{
				SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
				if (spriteRenderer == null)
				{
					spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
				}
				if (spriteRenderer == null)
				{
					return true;
				}
				if (spriteRenderer.sprite == null)
				{
					spriteRenderer.sprite = sprites[0];
				}
				SpriteUtility.CreateAnimation(gameObject, sprites);
				Selection.activeGameObject = gameObject;
			}
			return true;
		}