コード例 #1
0
ファイル: SpriteEditor.cs プロジェクト: guplem/TS20-Thoughts
        /************************************************************************************************************************/

        private void OnEnable()
        {
            var targets = this.targets;

            _Targets = new Target[targets.Length];
            for (int i = 0; i < targets.Length; i++)
            {
                _Targets[i] = new Target(targets[i]);
            }

            InitializePreview();

            _Name = serializedObject.FindProperty($"m{nameof(_Name)}");

            _Rect = serializedObject.FindProperty($"m{nameof(_Rect)}");
            if (_Rect != null)
            {
                _RectFields = new NormalizedPixelField[]
                {
                    new NormalizedPixelField(_Rect.FindPropertyRelative(nameof(Rect.x)), new GUIContent("X (Left)",
                                                                                                        "The distance from the left edge of the texture to the left edge of the sprite"), false),
                    new NormalizedPixelField(_Rect.FindPropertyRelative(nameof(Rect.y)), new GUIContent("Y (Bottom)",
                                                                                                        "The distance from the bottom edge of the texture to the bottom edge of the sprite"), false),
                    new NormalizedPixelField(_Rect.FindPropertyRelative(nameof(Rect.width)), new GUIContent("Width",
                                                                                                            "The horizontal size of the sprite"), false),
                    new NormalizedPixelField(_Rect.FindPropertyRelative(nameof(Rect.height)), new GUIContent("Height",
                                                                                                             "The vertical size of the sprite"), false),
                };
            }

            _Pivot = serializedObject.FindProperty($"m{nameof(_Pivot)}");
            if (_Pivot != null)
            {
                _PivotFields = new NormalizedPixelField[]
                {
                    new NormalizedPixelField(_Pivot.FindPropertyRelative(nameof(Vector2.x)), new GUIContent("X",
                                                                                                            "The horizontal distance from the left edge of the sprite to the pivot point"), true),
                    new NormalizedPixelField(_Pivot.FindPropertyRelative(nameof(Vector2.y)), new GUIContent("Y",
                                                                                                            "The vertical distance from the bottom edge of the sprite to the pivot point"), true),
                };
            }

            _Border = serializedObject.FindProperty($"m{nameof(_Border)}");
            if (_Border != null)
            {
                _BorderFields = new NormalizedPixelField[]
                {
                    new NormalizedPixelField(_Border.FindPropertyRelative(nameof(Vector4.x)), new GUIContent("Left",
                                                                                                             BorderTooltip), false),
                    new NormalizedPixelField(_Border.FindPropertyRelative(nameof(Vector4.y)), new GUIContent("Bottom",
                                                                                                             BorderTooltip), false),
                    new NormalizedPixelField(_Border.FindPropertyRelative(nameof(Vector4.z)), new GUIContent("Right",
                                                                                                             BorderTooltip), false),
                    new NormalizedPixelField(_Border.FindPropertyRelative(nameof(Vector4.w)), new GUIContent("Top",
                                                                                                             BorderTooltip), false),
                };
            }
        }
コード例 #2
0
ファイル: SpriteEditor.cs プロジェクト: malering/ET
        /************************************************************************************************************************/

        private void DoBorderGUI()
        {
            var size = _Rect.rectValue.size;

            _BorderFields[0].normalizeMultiplier = _BorderFields[2].normalizeMultiplier = 1f / size.x;
            _BorderFields[1].normalizeMultiplier = _BorderFields[3].normalizeMultiplier = 1f / size.y;

            using (ObjectPool.Disposable.AcquireContent(out var label, "Border", BorderTooltip))
                NormalizedPixelField.DoGroupGUI(_Border, label, _BorderFields);
        }
コード例 #3
0
ファイル: SpriteEditor.cs プロジェクト: malering/ET
        /************************************************************************************************************************/

        private void DoRectGUI()
        {
            var texture = ((Sprite)target).texture;

            _RectFields[0].normalizeMultiplier = _RectFields[2].normalizeMultiplier = 1f / texture.width;
            _RectFields[1].normalizeMultiplier = _RectFields[3].normalizeMultiplier = 1f / texture.height;

            using (ObjectPool.Disposable.AcquireContent(out var label, "Rect", RectTooltip))
                NormalizedPixelField.DoGroupGUI(_Rect, label, _RectFields);
        }
コード例 #4
0
ファイル: SpriteEditor.cs プロジェクト: malering/ET
        /************************************************************************************************************************/

        private void DoPivotGUI()
        {
            var showMixedValue = EditorGUI.showMixedValue;

            var targets = this.targets;
            var size    = targets[0] is Sprite sprite ? sprite.rect.size : Vector2.one;

            for (int i = 1; i < targets.Length; i++)
            {
                sprite = targets[i] as Sprite;
                if (sprite == null || sprite.rect.size != size)
                {
                    EditorGUI.showMixedValue = true;
                }
            }

            _PivotFields[0].normalizeMultiplier = 1f / size.x;
            _PivotFields[1].normalizeMultiplier = 1f / size.y;

            using (ObjectPool.Disposable.AcquireContent(out var label, "Pivot", PivotTooltip))
                NormalizedPixelField.DoGroupGUI(_Pivot, label, _PivotFields);

            EditorGUI.showMixedValue = showMixedValue;
        }