Beispiel #1
0
        public static void Show(DicingTexture dicingTexture, string selection, Action <string> onSelectAction, Action onCloseAction)
        {
            if (instance != null)
            {
                instance.Close();
                instance = null;
            }

            var comp = DisplayWizard <DicingSpriteSelector>("Select DicingSprite");

            comp.onSelectAction = onSelectAction;
            comp.onCloseAction  = onCloseAction;

            comp.dicingTexture        = dicingTexture;
            comp.selectionTextureName = selection;
            comp.preViewSize          = 200f;

            comp.sourceTextures = dicingTexture.GetAllDicingSource()
                                  .Select(x =>
            {
                var path = AssetDatabase.GUIDToAssetPath(x.guid);
                return(AssetDatabase.LoadMainAssetAtPath(path) as Texture2D);
            })
                                  .Where(x => x != null)
                                  .ToArray();
        }
Beispiel #2
0
        void OnDisable()
        {
            if (onCloseAction != null)
            {
                onCloseAction();
            }

            instance = null;
        }
Beispiel #3
0
        private void DrawUpdateGUI(DicingTexture dicingTexture)
        {
            var labelStyle = new GUIStyle(EditorStyles.label);

            var defaultColor           = labelStyle.normal.textColor;
            var defaultBackgroundColor = GUI.backgroundColor;

            var delete = false;

            if (textureInfos.Any())
            {
                EditorLayoutTools.DrawLabelWithBackground("Sprites", EditorLayoutTools.BackgroundColor, EditorLayoutTools.LabelColor);

                EditorGUILayout.Separator();

                using (new EditorGUILayout.VerticalScope())
                {
                    using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition))
                    {
                        int index = 0;

                        for (var i = 0; i < textureInfos.Length; i++)
                        {
                            ++index;

                            GUILayout.Space(-1f);

                            var textureName = textureInfos[i].texture != null ? textureInfos[i].texture.name : null;

                            var highlight = selectionTextureName == textureName;

                            GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);

                            using (new EditorGUILayout.HorizontalScope(EditorLayoutTools.TextAreaStyle, GUILayout.MinHeight(20f)))
                            {
                                GUI.backgroundColor = Color.white;
                                GUILayout.Label(index.ToString(), GUILayout.Width(24f));

                                if (GUILayout.Button(textureName, EditorStyles.label, GUILayout.Height(20f)))
                                {
                                    selectionTextureName = textureName;
                                }

                                switch (textureInfos[i].status)
                                {
                                case TextureStatus.Add:
                                    labelStyle.normal.textColor = Color.green;
                                    GUILayout.Label("Add", labelStyle, GUILayout.Width(27f));
                                    break;

                                case TextureStatus.Update:
                                    labelStyle.normal.textColor = Color.cyan;
                                    GUILayout.Label("Update", labelStyle, GUILayout.Width(45f));
                                    break;

                                case TextureStatus.Missing:
                                    labelStyle.normal.textColor = Color.yellow;
                                    GUILayout.Label("Missing", labelStyle, GUILayout.Width(45f));
                                    break;
                                }

                                labelStyle.normal.textColor = defaultColor;

                                if (deleteNames.Contains(textureName))
                                {
                                    GUI.backgroundColor = Color.red;

                                    if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                                    {
                                        delete = true;
                                    }

                                    GUI.backgroundColor = Color.green;

                                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                                    {
                                        deleteNames.Remove(textureName);
                                    }
                                }
                                else
                                {
                                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                                    {
                                        if (!deleteNames.Contains(textureName))
                                        {
                                            deleteNames.Add(textureName);
                                        }
                                    }
                                }

                                GUILayout.Space(5f);
                            }
                        }

                        scrollPosition = scrollViewScope.scrollPosition;
                    }
                }
            }

            if (calcPerformance)
            {
                GUILayout.Space(5f);

                EditorLayoutTools.DrawLabelWithBackground("Result", EditorLayoutTools.BackgroundColor, EditorLayoutTools.LabelColor);

                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label("MemorySize", GUILayout.Width(75f));

                    var dicingMemSize = infoFileSize + totalAtlasMemSize;

                    labelStyle.normal.textColor = totalMemSize < dicingMemSize ? Color.red : defaultColor;
                    GUILayout.Label(string.Format("{0:F1} MB >>> {1:F1} MB : {2:F1}% ", totalMemSize, dicingMemSize, 100.0f * dicingMemSize / totalMemSize), labelStyle);
                    labelStyle.normal.textColor = defaultColor;
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label("FileSize", GUILayout.Width(75f));

                    var dicingFileSize = infoFileSize + atlasFileSize;

                    labelStyle.normal.textColor = totalFileSize < atlasFileSize ? Color.red : defaultColor;
                    GUILayout.Label(string.Format("{0:F1} MB >>> {1:F1} MB : {2:F1}% ", totalFileSize, dicingFileSize, 100.0f * dicingFileSize / totalFileSize), labelStyle);
                    labelStyle.normal.textColor = defaultColor;
                }
            }

            GUILayout.Space(15f);

            using (new EditorGUILayout.HorizontalScope())
            {
                GUI.backgroundColor = Color.cyan;

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Apply", GUILayout.Width(150f)))
                {
                    GenerateDicingTexture(dicingTexture);
                }

                GUI.backgroundColor = defaultBackgroundColor;

                GUILayout.Space(25f);

                if (GUILayout.Button("View Textures", GUILayout.Width(150f)))
                {
                    Action <string> onSelection = x =>
                    {
                        selectionTextureName = x;
                        Repaint();
                    };

                    DicingSpriteSelector.Show(dicingTexture, selectionTextureName, onSelection, null);
                }

                GUILayout.FlexibleSpace();
            }

            if (delete)
            {
                GenerateDicingTexture(dicingTexture);
            }

            GUILayout.Space(5f);
        }
Beispiel #4
0
        //----- property -----

        //----- method -----

        void OnEnable()
        {
            instance = this;
        }
        //----- property -----

        //----- method -----

        public override void OnInspectorGUI()
        {
            instance = target as DicingImage;

            EditorGUILayout.Separator();

            EditorGUI.BeginChangeCheck();

            var dicingTexture = EditorLayoutTools.ObjectField("DicingTexture", instance.DicingTexture, false);

            if (EditorGUI.EndChangeCheck())
            {
                UnityEditorUtility.RegisterUndo("DicingImageInspector-Undo", instance);
                instance.DicingTexture = dicingTexture;
            }

            // Color.
            EditorGUI.BeginChangeCheck();

            var color = EditorGUILayout.ColorField("Color", instance.Color, GUILayout.Height(18f));

            if (EditorGUI.EndChangeCheck())
            {
                UnityEditorUtility.RegisterUndo("DicingImageInspector-Undo", instance);
                instance.Color = color;
            }

            // Material.
            EditorGUI.BeginChangeCheck();

            var material = instance.Material.name == "Default UI Material" ? null : instance.Material;

            material = EditorLayoutTools.ObjectField("Material", material, false, GUILayout.Height(18f));

            if (EditorGUI.EndChangeCheck())
            {
                UnityEditorUtility.RegisterUndo("DicingImageInspector-Undo", instance);
                instance.Material = material;
            }

            // RaycastTarget.
            EditorGUI.BeginChangeCheck();

            var raycastTarget = EditorGUILayout.Toggle("RaycastTarget", instance.RaycastTarget);

            if (EditorGUI.EndChangeCheck())
            {
                UnityEditorUtility.RegisterUndo("DicingImageInspector-Undo", instance);
                instance.RaycastTarget = raycastTarget;
            }

            // CrossFade.
            EditorGUI.BeginChangeCheck();

            var crossFade = EditorGUILayout.Toggle("CrossFade", instance.CrossFade, GUILayout.Height(18f));

            if (EditorGUI.EndChangeCheck())
            {
                UnityEditorUtility.RegisterUndo("DicingImageInspector-Undo", instance);
                instance.CrossFade = crossFade;
            }

            if (instance.CrossFade)
            {
                EditorGUI.BeginChangeCheck();

                var crossFadeTime = EditorGUILayout.FloatField("FadeTime", instance.CrossFadeTime, GUILayout.Height(18f));

                if (EditorGUI.EndChangeCheck())
                {
                    UnityEditorUtility.RegisterUndo("DicingImageInspector-Undo", instance);
                    instance.CrossFadeTime = crossFadeTime;
                }
            }

            GUILayout.Space(2f);

            if (instance.DicingTexture != null)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (EditorLayoutTools.DrawPrefixButton("Sprite"))
                    {
                        Action <string> onSelection = x =>
                        {
                            instance.PatternName = x;

                            EditorUtility.SetDirty(instance);
                            InternalEditorUtility.RepaintAllViews();
                        };

                        var selection = instance.Current != null ? instance.Current.textureName : null;

                        DicingSpriteSelector.Show(instance.DicingTexture, selection, onSelection, null);
                    }

                    if (instance.Current != null)
                    {
                        EditorGUILayout.SelectableLabel(instance.Current.textureName, new GUIStyle("TextArea"), GUILayout.Height(18f));
                    }
                }

                GUILayout.Space(5f);

                if (instance.Current != null)
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.Space(EditorGUIUtility.labelWidth);

                        if (GUILayout.Button("SetNativeSize"))
                        {
                            instance.SetNativeSize();
                        }
                    }
                }
            }
        }