Beispiel #1
0
        public static Object[] FilterResourcesForAtlasImport(Object[] resources)
        {
            List <Object> tempList = new List <Object>();

            foreach (Object resource in resources)
            {
                string resourcePath = STTools.GetAssetPath(resource);

                // Check if this is a main asset and queue all it's sub assets
                if (STTools.IsMainAsset(resource) && STTools.HasSubAssets(resource))
                {
                    Object[] subAssets = STTools.FilterResourcesForAtlasImport(STTools.GetSubAssets(resource));

                    foreach (Object a in subAssets)
                    {
                        tempList.Add(a);
                    }
                }
                else if (resource is Texture2D || resource is Sprite)
                {
                    tempList.Add(resource);
                }
                else if (STTools.IsDirectory(resourcePath))
                {
                    Object[] subAssets = STTools.FilterResourcesForAtlasImport(STTools.GetDirectoryAssets(resourcePath));

                    foreach (Object a in subAssets)
                    {
                        tempList.Add(a);
                    }
                }
            }

            return(tempList.ToArray());
        }
        public void DragSprites(Rect outerRect)
        {
            Event evt = Event.current;

            //Rect drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));
            //GUI.Box(drop_area, "Add Sprite (Drop Here)", this.boxStyle);

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
            {
                /*if (!outerRect.Contains(evt.mousePosition))
                 *  return;
                 */
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();
                    Object[] filtered = ST.STTools.FilterResourcesForAtlasImport(DragAndDrop.objectReferences);

                    for (int i = 0; i < filtered.Length; i++)
                    {
                        if (this.m_Sprites.Find(s => s.source == filtered[i]) != null)
                        {
                            Debug.LogWarning("A sprite with source \"" + STTools.GetAssetPath(filtered[i]) + "\" already exists in the atlas");
                            System.Array.Clear(filtered, i, 1);
                        }
                    }

                    this.AddSprites(filtered);
                }
                break;
            }
            }
        }