예제 #1
0
        public static void Show(PatternTexture patternTexture, string selection, Action <string> onSelectAction, Action onCloseAction)
        {
            if (instance != null)
            {
                instance.Close();
                instance = null;
            }

            var comp = DisplayWizard <PatternSpriteSelector>("Select Sprite");

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

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

            comp.sourceTextures = patternTexture.GetAllPatternData()
                                  .Select(x =>
            {
                var path = AssetDatabase.GUIDToAssetPath(x.Guid);
                return(AssetDatabase.LoadMainAssetAtPath(path) as Texture2D);
            })
                                  .Where(x => x != null)
                                  .ToArray();
        }
예제 #2
0
        void OnDisable()
        {
            if (onCloseAction != null)
            {
                onCloseAction();
            }

            instance = null;
        }
예제 #3
0
        //----- property -----

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

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

            EditorGUI.BeginChangeCheck();

            var patternTexture = EditorLayoutTools.ObjectField("PatternTexture", instance.PatternTexture, false);

            if (EditorGUI.EndChangeCheck())
            {
                UnityEditorUtility.RegisterUndo("PatternImageInspector-Undo", instance);
                instance.PatternTexture = patternTexture;
            }

            if (instance.PatternTexture != null)
            {
                // Color.
                EditorGUI.BeginChangeCheck();

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

                if (EditorGUI.EndChangeCheck())
                {
                    UnityEditorUtility.RegisterUndo("PatternImageInspector-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("PatternImageInspector-Undo", instance);
                    instance.Material = material;
                }

                // RaycastTarget.

                var hasAlphaMap = instance.PatternTexture.HasAlphaMap;

                using (new DisableScope(!hasAlphaMap))
                {
                    EditorGUI.BeginChangeCheck();

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

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

                if (!hasAlphaMap)
                {
                    EditorGUILayout.HelpBox("Require generate alpha map for RaycastTarget", MessageType.Info);
                }

                // Maskable.

                EditorGUI.BeginChangeCheck();

                var maskable = EditorGUILayout.Toggle("Maskable", instance.maskable);

                if (EditorGUI.EndChangeCheck())
                {
                    UnityEditorUtility.RegisterUndo("PatternImageInspector-Undo", instance);
                    instance.maskable = maskable;
                }

                // CrossFade.
                EditorGUI.BeginChangeCheck();

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

                if (EditorGUI.EndChangeCheck())
                {
                    UnityEditorUtility.RegisterUndo("PatternImageInspector-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("PatternImageInspector-Undo", instance);
                        instance.CrossFadeTime = crossFadeTime;
                    }
                }

                GUILayout.Space(2f);

                if (instance.PatternTexture != null)
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        using (new EditorGUILayout.VerticalScope(GUILayout.Width(76f)))
                        {
                            GUILayout.Space(2f);

                            if (EditorLayoutTools.PrefixButton("Sprite", GUILayout.Width(76f), GUILayout.Height(18f)))
                            {
                                Action <string> onSelection = x =>
                                {
                                    instance.PatternName = x;

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

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

                                PatternSpriteSelector.Show(instance.PatternTexture, selection, onSelection, null);
                            }
                        }

                        GUILayout.Space(4f);

                        if (instance.Current != null)
                        {
                            EditorGUILayout.SelectableLabel(instance.Current.TextureName, EditorStyles.textArea, GUILayout.Height(18f));
                        }
                    }

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

                            if (GUILayout.Button("SetNativeSize"))
                            {
                                instance.SetNativeSize();
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        //----- property -----

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

        void OnEnable()
        {
            instance = this;
        }
예제 #5
0
        private void DrawUpdateGUI(PatternTexture patternTexture)
        {
            var labelStyle = new GUIStyle(EditorStyles.label);

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

            var delete = false;

            if (textureInfos.Any())
            {
                EditorLayoutTools.Title("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(EditorStyles.textArea, 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.Title("Result", EditorLayoutTools.BackgroundColor, EditorLayoutTools.LabelColor);

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

                    var memSize = infoFileSize + totalAtlasMemSize;

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

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

                    var fileSize = infoFileSize + atlasFileSize;

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

            GUILayout.Space(15f);

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

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Generate", GUILayout.Width(150f)))
                {
                    GeneratePatternTexture(patternTexture);
                }

                GUI.backgroundColor = defaultBackgroundColor;

                GUILayout.Space(25f);

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

                    PatternSpriteSelector.Show(patternTexture, selectionTextureName, onSelection, null);
                }

                GUILayout.FlexibleSpace();
            }

            if (delete)
            {
                GeneratePatternTexture(patternTexture);
            }

            GUILayout.Space(5f);
        }