Esempio n. 1
0
    public bool ShowGradientEditor(string title, Animations.EditRGBGradient previousGradient, System.Action <bool, Animations.EditRGBGradient> closeAction)
    {
        bool ret = !gradientEditor.isShown;

        if (ret)
        {
            gradientEditor.Show(title, previousGradient, closeAction);
        }
        return(ret);
    }
Esempio n. 2
0
    public void FromGradient(Animations.EditRGBGradient gradient)
    {
        _suspendRepaint = true;

        try
        {
            Clear();

            float startTime = 0.0f;
            float endTime   = 1.0f;
            float eps       = 0.0001f;

            bool dupHandle = false;
            for (int i = 0; i < gradient.keyframes.Count; ++i)
            {
                var kf = gradient.keyframes[i];

                // Skip automatically inserted keyframes
                if ((i == 0) && (Mathf.Abs(kf.time - startTime) < eps) && (kf.color == Color.black))
                {
                    continue;
                }
                if (((i + 1) == gradient.keyframes.Count) && (Mathf.Abs(kf.time - endTime) < eps) && (kf.color == Color.black))
                {
                    continue;
                }

                var handle = AllHandles[0]; // Initially we should have only one handle
                if (dupHandle)
                {
                    handle = handle.Duplicate();
                }

                handle.ChangeColor(kf.color, noRepaint: true);

                var     rect = (transform as RectTransform).rect;
                Vector2 pos  = handle.transform.localPosition;
                pos.x = kf.time * _sliderWidth;
                handle.transform.localPosition = pos;

                dupHandle = true;
            }

            SelectHandle(null);
        }
        finally
        {
            _suspendRepaint = false;
            Repaint();
        }
    }
Esempio n. 3
0
        public EditRGBGradient Duplicate()
        {
            var track = new EditRGBGradient();

            if (keyframes != null)
            {
                track.keyframes = new List <EditRGBKeyframe>(keyframes.Count);
                foreach (var keyframe in keyframes)
                {
                    track.keyframes.Add(keyframe.Duplicate());
                }
            }
            return(track);
        }
Esempio n. 4
0
 public void FromTexture(Texture2D texture)
 {
     gradients.Clear();
     for (int i = 0; i < texture.height; ++i)
     {
         var gradientPixels = texture.GetPixels(0, i, texture.width, 1, 0);
         var keyframes      = ColorUtils.extractKeyframes(gradientPixels);
         // Convert to greyscale (right now us the red channel only)
         var gradient = new EditRGBGradient()
         {
             keyframes = keyframes
         };
         gradients.Add(gradient);
     }
 }
Esempio n. 5
0
    public void TestImportGradient()
    {
        var filePath = System.IO.Path.Combine(Application.persistentDataPath, $"gradientLine.png");

        byte[] fileData = File.ReadAllBytes(filePath);
        var    tex      = new Texture2D(2, 2);

        tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
        var keyframes = ColorUtils.extractKeyframes(tex.GetPixels());
        var gradient  = new Animations.EditRGBGradient()
        {
            keyframes = keyframes
        };

        PixelsApp.Instance.ShowGradientEditor("test", gradient, null);
    }