示例#1
0
        void SelectSprite(FxSpriteSource sprite, bool additive)
        {
            if (additive)
            {
                if (sprite != null)
                {
                    List <Object> objs = new List <Object>(Selection.objects);
                    if (objs.Contains(sprite.gameObject))
                    {
                        objs.Remove(sprite.gameObject);
                    }
                    else
                    {
                        objs.Add(sprite.gameObject);
                    }

                    Selection.objects = objs.ToArray();
                }
            }
            else
            {
                Selection.objects = sprite != null ? new Object[] { sprite.gameObject }
            } : new Object[] { assembler.gameObject };
        }
    }
示例#2
0
        void DrawSprite(FxSpriteSource sprite, Vector2Int atlasSize, Rect atlasRect)
        {
            var spriteDrawRect = sprite.GetRect(atlasRect, atlasSize.x, atlasSize.y);

            _spriteIndex[spriteDrawRect] = sprite;

            if (sprite.Texture != null)
            {
                GUI.DrawTextureWithTexCoords(spriteDrawRect, sprite.Texture, Rect.MinMaxRect(0, 0, 1, 1));
            }

            Color color = Color.green;
            bool  fill  = false;

            if (!sprite.Texture)
            {
                color = Color.gray;
                fill  = true;
            }
            else if (sprite.PositionOverlap && sprite.NameConflict)
            {
                color = Color.cyan;
                fill  = true;
            }
            else if (sprite.PositionOverlap)
            {
                color = Color.red;
                fill  = true;
            }
            else if (sprite.NameConflict)
            {
                color = Color.yellow;
                fill  = true;
            }

            DrawTextureFrame(spriteDrawRect, color, fill);
        }
示例#3
0
        void HandleMove()
        {
            var evt = Event.current;

            if (evt.type == EventType.MouseDown)
            {
                bool selected = false;
                foreach (var s in _spriteIndex)
                {
                    if (s.Value == null)
                    {
                        continue;
                    }

                    if (!s.Key.Contains(evt.mousePosition))
                    {
                        continue;
                    }

                    spriteSelected = s.Value;
                    SelectSprite(spriteSelected, evt.shift);
                    selected = true;
                    break;
                }

                if (!selected && !evt.shift)
                {
                    spriteSelected = null;
                    SelectSprite(null, false);
                }

                EditorGUI.FocusTextInControl("");
            }
            else if (evt.type == EventType.MouseDrag)
            {
                if (spriteSelected != null)
                {
                    bool pass         = false;
                    var  norCenterPos = Rect.PointToNormalized(atlasRect, evt.mousePosition);

                    if (!new Rect(0, 0, 1, 1).Contains(norCenterPos))
                    {
                        return;
                    }

                    foreach (var s in _spriteIndex)
                    {
                        if (s.Key.Contains(evt.mousePosition) && s.Value != spriteSelected)
                        {
                            pass = true;
                            break;
                        }
                    }

                    if (!pass)
                    {
                        Undo.RecordObject(spriteSelected, "Move Sprite");
                        EditorUtility.SetDirty(spriteSelected);
                        spriteSelected.SetUVPosition(norCenterPos, assembler.AtlasWidth, assembler.AtlasHeight);
                        CheckSpriteValid();
                        Repaint();
                    }
                }
            }
        }
示例#4
0
        public static void ShowInspector(FxSpriteSource fxSprite)
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                using (var c = new EditorGUI.ChangeCheckScope())
                {
                    var l = EditorGUILayout.TextField("Identity Name", fxSprite.IdentityName);

                    if (c.changed)
                    {
                        Undo.RecordObject(fxSprite, "Value Change");
                        EditorUtility.SetDirty(fxSprite);
                        fxSprite.IdentityName = l;
                    }
                }

                if (GUILayout.Button("Use Texture Name", EditorStyles.miniButton, GUILayout.Width(100)))
                {
                    if (fxSprite.Texture)
                    {
                        Undo.RecordObject(fxSprite, "Value Change");
                        EditorUtility.SetDirty(fxSprite);
                        fxSprite.IdentityName = fxSprite.Texture.name;
                    }
                }
            }

            using (var c = new EditorGUI.ChangeCheckScope())
            {
                var id = EditorGUILayout.IntField("ID", fxSprite.ID);

                if (c.changed)
                {
                    Undo.RecordObject(fxSprite, "Value Change");
                    EditorUtility.SetDirty(fxSprite);
                    fxSprite.ID = id;
                }
            }

            using (var c = new EditorGUI.ChangeCheckScope())
            {
                var tex = EditorGUILayout.ObjectField(
                    fxSprite.Texture ? fxSprite.Texture.name : "", fxSprite.Texture, typeof(Texture), false);

                if (c.changed)
                {
                    Undo.RecordObject(fxSprite, "Value Change");
                    EditorUtility.SetDirty(fxSprite);
                    fxSprite.Texture = tex as Texture2D;
                }
            }

            using (var c = new EditorGUI.ChangeCheckScope())
            {
                var w = EditorGUILayout.IntSlider("Width(2x)", (int)Mathf.Log(fxSprite.PixelRect.width, 2), 2, 10);
                var h = EditorGUILayout.IntSlider("Height(2x)", (int)Mathf.Log(fxSprite.PixelRect.height, 2), 2, 10);

                if (c.changed)
                {
                    Undo.RecordObject(fxSprite, "Value Change");
                    EditorUtility.SetDirty(fxSprite);
                    fxSprite.PixelRect = new Rect(fxSprite.PixelRect.position, new Vector2Int(1 << w, 1 << h));
                }
            }

            EditorGUILayout.RectField("Pixel Rect", fxSprite.PixelRect);
        }