FilterResourcesForAtlasImport() public static method

Filters the resources for atlas import.
public static FilterResourcesForAtlasImport ( Object resources ) : Object[]
resources Object Resources.
return Object[]
示例#1
0
        /// <summary>
        /// Filters the resources for atlas import.
        /// </summary>
        /// <returns>The resources for atlas import.</returns>
        /// <param name="resources">Resources.</param>
        public static Object[] FilterResourcesForAtlasImport(Object[] resources)
        {
            List <Object> tempList = new List <Object>();

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

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

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

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

            return(tempList.ToArray());
        }
        private void DropAreaGUI()
        {
            Event evt       = Event.current;
            Rect  drop_area = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

            this.boxStyle.alignment = TextAnchor.MiddleCenter;
            GUI.color = SPInstanceEditor.green;
            GUI.Box(drop_area, "Add Sprite (Drop Here)", this.boxStyle);
            GUI.color = Color.white;

            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
            {
                if (!drop_area.Contains(evt.mousePosition))
                {
                    return;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    Object[] filtered = SPTools.FilterResourcesForAtlasImport(DragAndDrop.objectReferences);

                    // Disallow miltiple sprites of the same source, if set so
                    if (!SPTools.GetEditorPrefBool(SPTools.Settings_AllowMuliSpritesOneSource))
                    {
                        // Additional filtering specific to the instance
                        for (int i = 0; i < filtered.Length; i++)
                        {
                            if (this.m_SPInstance.sprites.Find(s => s.source == filtered[i]) != null)
                            {
                                Debug.LogWarning("A sprite with source \"" +
                                                 SimpleSpritePackerEditor.SPTools.GetAssetPath(filtered[i]) +
                                                 "\" already exists in the atlas, consider changing the Sprite Packer settings to allow multiple sprites from the same source.");
                                System.Array.Clear(filtered, i, 1);
                            }
                        }
                    }

                    // Types are handled internally
                    this.m_SPInstance.QueueAction_AddSprites(filtered);
                }
                break;
            }
            }
        }
示例#3
0
        protected void OnGUI()
        {
            EditorGUIUtility.labelWidth = 100f;

            GUILayout.BeginVertical();
            GUILayout.Space(8f);

            GUI.changed     = false;
            this.m_Instance = EditorGUILayout.ObjectField("Sprite Packer", this.m_Instance, typeof(SPInstance), false) as SPInstance;
            if (GUI.changed)
            {
                // Save the instance id
                EditorPrefs.SetInt(SPTools.Settings_SavedInstanceIDKey, (this.m_Instance == null) ? 0 : this.m_Instance.GetInstanceID());
            }

            GUILayout.Space(4f);

            if (this.m_Instance == null)
            {
                EditorGUILayout.HelpBox("Please set the sprite packer instance reference in order to use this feature.", MessageType.Info);
            }
            else
            {
                Event    evt       = Event.current;
                Rect     drop_area = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                GUIStyle boxStyle  = new GUIStyle(GUI.skin.box);
                boxStyle.alignment = TextAnchor.MiddleCenter;
                GUI.color          = SPDropWindow.green;
                GUI.Box(drop_area, "Add Sprite (Drop Here)", boxStyle);
                GUI.color = Color.white;

                switch (evt.type)
                {
                case EventType.DragUpdated:
                case EventType.DragPerform:
                {
                    if (!drop_area.Contains(evt.mousePosition))
                    {
                        return;
                    }

                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                    if (evt.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();

                        Object[] filtered = SPTools.FilterResourcesForAtlasImport(DragAndDrop.objectReferences);

                        // Additional filtering specific to the instance
                        for (int i = 0; i < filtered.Length; i++)
                        {
                            if (this.m_Instance.sprites.Find(s => s.name == filtered[i].name) != null)
                            {
                                Debug.LogWarning("A sprite with source \"" + SimpleSpritePackerEditor.SPTools.GetAssetPath(filtered[i]) + "\" already exists in the atlas, consider changing the Sprite Packer settings to allow multiple sprites from the same source.");
                                System.Array.Clear(filtered, i, 1);
                            }
                        }

                        // Types are handled internally
                        this.m_Instance.QueueAction_AddSprites(filtered);

                        Selection.activeObject = this.m_Instance;
                        //EditorPrefs.SetBool(SPTools.Settings_ShowSpritesKeys, false);
                    }
                    break;
                }
                }
            }

            GUILayout.EndVertical();
        }