Esempio n. 1
0
    public static UnityNoticePopup OpenWindow(string name = "notice", string message = "Message", string[] buttons = null, Action <int> callback = null)
    {
        UnityNoticePopup pop = GetWindow <UnityNoticePopup>(name, true);

        pop.message = message;
        if (null != buttons && 0 < buttons.Length)
        {
            pop.buttons = buttons;
        }
        pop.callback = callback;
        return(pop);
    }
Esempio n. 2
0
        void TryGUI()
        {
            SpriteSheet newSheet = (SpriteSheet)EditorGUILayout.ObjectField("Sheet", this.editedSheet, typeof(SpriteSheet), false);

            if (this.editedSheet != newSheet || this.isReloaded)
            {
                this.isReloaded  = false;
                this.editedSheet = newSheet;
                if (this.editedSheet)
                {
                    this.editedSheet.ResetMap(false);
                    List <int> indexes = this.editedSheet.GetMissingSpriteIndexes();
                    if (null != indexes)
                    {
                        this.popup = UnityNoticePopup.OpenWindow(string.Format("Found missing sprites!:{0}", indexes.Count), "Remove the missing sprites?\nThen it is automatically saved.", new string[] { "Yes", "No" }, (choice) =>
                        {
                            if (0 == choice)
                            {
                                this.Save(this.editedSheet);
                            }
                            else
                            {
                                this.editedSheet = null;
                            }

                            this.popup = null;
                        });
                        return;
                    }
                }
            }

            if (this.popup)
            {
                return;
            }

            this.CheckSelectedSprites(this.editedSheet);

            Color colorOrigin = GUI.color;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(string.Format("Selected Sprites: {0} Item", this.selectedSprites.Count));
            GUI.color = 0 < this.duplicatedSprites.Count ? Color.red : colorOrigin;
            EditorGUILayout.LabelField(string.Format("Duplicated: {0} Item", this.duplicatedSprites.Count));
            GUI.color = colorOrigin;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            bool enableOld = GUI.enabled;

            GUI.enabled = 0 < this.availableSprites.Count;
            GUI.color   = !GUI.enabled ? colorOrigin : this.editedSheet ? Color.green : Color.cyan;
            EditorGUILayout.LabelField(string.Format("Available Sprites: {0} Item", this.availableSprites.Count));
            if (this.editedSheet)
            {
                if (GUILayout.Button("Add Sprites"))
                {
                    this.PushAvailableSprites(this.editedSheet);
                }
            }
            else
            {
                if (GUILayout.Button("Create Sprite Sheet"))
                {
                    string path = EditorUtility.SaveFilePanelInProject("Create Sprite Sheet", "sheet.prefab", "prefab", "Please enter a file name to save the sprite sheet to");
                    if (!string.IsNullOrEmpty(path))
                    {
                        this.editedSheet = ScriptableObject.CreateInstance(typeof(SpriteSheet)) as SpriteSheet;
                        this.PushAvailableSprites(this.editedSheet);

                        AssetDatabase.CreateAsset(this.editedSheet, AssetDatabase.GenerateUniqueAssetPath(path));
                        AssetDatabase.Refresh();
                        this.Repaint();

                        Selection.activeObject = this.editedSheet;
                        return;
                    }
                }
            }
            GUI.color   = colorOrigin;
            GUI.enabled = enableOld;
            EditorGUILayout.EndHorizontal();


            if (!this.editedSheet)
            {
                EditorGUILayout.LabelField("Sprite Sheet is empty.");
                return;
            }

            EditorGUILayout.LabelField(string.Format("Contain Sprites: {0} Item", this.editedSheet.Sprites.Count));

            this.scroll = EditorGUILayout.BeginScrollView(this.scroll);

            Sprite lookAt    = null;
            bool   isRemoved = false;

            this.sortedSprites.Clear();
            foreach (Sprite s in this.editedSheet.Sprites)
            {
                this.sortedSprites.Add(s);
            }
            this.sortedSprites.Sort((l, r) => { return(l.name.CompareTo(r.name)); });
            for (int n = 0; n < this.sortedSprites.Count; ++n)
            {
                Sprite s = this.sortedSprites[n];
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(s.name);
                if (GUILayout.Button("Look At"))
                {
                    lookAt = s;
                }
                if (GUILayout.Button("Remove"))
                {
                    this.editedSheet.Sprites.Remove(s);
                    isRemoved = true;
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();

            if (null != lookAt)
            {
                EditorUtility.FocusProjectWindow();
                Selection.activeObject = lookAt;
            }

            if (isRemoved)
            {
                this.Save(this.editedSheet);
            }
        }