devNotes 10-12-2016 Color Picker – Scaling – Play Modes

 

///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/

using UnityEngine.EventSystems;

namespace UnityEngine.UI.Extensions
{
    public class HsvBoxSelector : MonoBehaviour, IDragHandler, IPointerDownHandler
    {
        public HSVPicker picker;

        void PlaceCursor(PointerEventData eventData)
        {
            UI_Ladder.Instance.Info_Box(1, " eD.pos X:" + eventData.position.x.ToString("F2") +                     " eD.pos Y:" + eventData.position.y.ToString("F2"));
            UI_Ladder.Instance.Info_Box(2, " RT X:    " + picker.hsvImage.rectTransform.position.x.ToString("F2") + " RT Y:    " + picker.hsvImage.rectTransform.position.y.ToString("F2"));
            UI_Ladder.Instance.Info_Box(3, " LsyScl X:" + picker.hsvImage.transform.lossyScale.x.ToString("F2") +   " LsyScl Y:" + picker.hsvImage.transform.lossyScale.y.ToString("F2"));
            var pos = new Vector2(eventData.position.x - picker.hsvImage.rectTransform.position.x, picker.hsvImage.rectTransform.rect.height * picker.hsvImage.transform.lossyScale.y - (picker.hsvImage.rectTransform.position.y - eventData.position.y));
            // Debug.Log(pos);
            pos.x /= picker.hsvImage.rectTransform.rect.width * picker.hsvImage.transform.lossyScale.x;
            pos.y /= picker.hsvImage.rectTransform.rect.height * picker.hsvImage.transform.lossyScale.y;

            pos.x = Mathf.Clamp(pos.x, 0, .9999f);  //1 is the same as 0
            pos.y = Mathf.Clamp(pos.y, 0, .9999f);

            //Debug.Log(pos);
            picker.MoveCursor(pos.x, pos.y);
        }


        public void OnDrag(PointerEventData eventData)
        {
            PlaceCursor(eventData);
            picker.slide_HueBox_Horz.OnDrag(eventData);
            picker.slide_HueBox_Vert.OnDrag(eventData);
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            PlaceCursor(eventData);
            picker.slide_HueBox_Horz.OnPointerDown(eventData);
            picker.slide_HueBox_Vert.OnPointerDown(eventData);
        }

        public void TakeScreenShot()
        {
            print("Screen SHOT!");
            Application.CaptureScreenshot("Screenshot_" + Time.fixedTime.ToString("F4") + "_.png");
        }
    }
}

 

gfhjghjhgj7