Beispiel #1
0
        private void OnSceneGUI()
        {
            bool hasUIElementParent = HasUIElemParent();

            UIColorPicker uiColorPicker = target as UIColorPicker;

            Transform T = uiColorPicker.transform;

            Vector3 posRight   = T.TransformPoint(new Vector3(+uiColorPicker.width, -uiColorPicker.height / 2.0f, 0));
            Vector3 posBottom  = T.TransformPoint(new Vector3(uiColorPicker.width / 2.0f, -uiColorPicker.height, 0));
            Vector3 posAnchor  = T.TransformPoint(uiColorPicker.Anchor);
            float   handleSize = .3f * HandleUtility.GetHandleSize(posAnchor);
            Vector3 snap       = Vector3.one * 0.01f;

            EditorGUI.BeginChangeCheck();

            Handles.color = Handles.xAxisColor;
            Vector3 newTargetPosition_right = Handles.FreeMoveHandle(posRight, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap);

            Handles.color = Handles.yAxisColor;
            Vector3 newTargetPosition_bottom = Handles.FreeMoveHandle(posBottom, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap);

            Handles.color = Handles.zAxisColor;
            //Vector3 newTargetPosition_anchor = hasUIElementParent ? Handles.FreeMoveHandle(posAnchor, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap) : posAnchor;
            Vector3 newTargetPosition_anchor = Handles.FreeMoveHandle(posAnchor, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change Dimensions");

                Vector3 deltaRight  = newTargetPosition_right - posRight;
                Vector3 deltaBottom = newTargetPosition_bottom - posBottom;
                Vector3 deltaAnchor = newTargetPosition_anchor - posAnchor;

                if (Vector3.SqrMagnitude(deltaRight) > Mathf.Epsilon)
                {
                    //Vector3 localDeltaRight = T.InverseTransformPoint(deltaRight);
                    //uiButton.RelativeLocation += new Vector3(deltaRight.x / 2.0f, 0.0f, 0.0f);
                    uiColorPicker.Width += deltaRight.x;
                }
                else if (Vector3.SqrMagnitude(deltaBottom) > Mathf.Epsilon)
                {
                    //Vector3 localDeltaBottom = T.InverseTransformPoint(deltaBottom);
                    //uiButton.RelativeLocation += new Vector3(0.0f, deltaBottom.y / 2.0f, 0.0f);
                    uiColorPicker.Height += -deltaBottom.y;
                }
                else if (Vector3.SqrMagnitude(deltaAnchor) > Mathf.Epsilon)
                {
                    Vector3 localDeltaAnchor = T.InverseTransformVector(deltaAnchor);
                    uiColorPicker.RelativeLocation += new Vector3(localDeltaAnchor.x, localDeltaAnchor.y, 0.0f);
                }
            }
        }
Beispiel #2
0
        void Awake()
        {
#if UNITY_EDITOR
            if (EditorApplication.isPlaying)
#else
            if (Application.isPlaying)
#endif
            {
                colorPicker = GetComponentInParent <UIColorPicker>();
                width       = GetComponent <MeshFilter>().mesh.bounds.size.x;
                height      = GetComponent <MeshFilter>().mesh.bounds.size.y;
                thickness   = GetComponent <MeshFilter>().mesh.bounds.size.z;
            }
        }
        public static void OnCreateFromHierarchy()
        {
            Transform parent = null;
            Transform T      = UnityEditor.Selection.activeTransform;

            if (T != null)
            {
                parent = T;
            }

            UIColorPicker.Create(new UIColorPicker.CreateArgs
            {
                parent = parent
            });
        }
Beispiel #4
0
        public static void Create(CreateArgs input)
        {
            GameObject go = new GameObject(input.widgetName);
            //go.tag = "UICollider"; le colorpicker en lui meme n'a pas de geometrie a collider, seulement ses enfants.

            // Find the anchor of the parent if it is a UIElement
            Vector3 parentAnchor = Vector3.zero;

            if (input.parent)
            {
                UIElement elem = input.parent.gameObject.GetComponent <UIElement>();
                if (elem)
                {
                    parentAnchor = elem.Anchor;
                }
            }

            UIColorPicker uiColorPicker = go.AddComponent <UIColorPicker>();

            uiColorPicker.relativeLocation        = input.relativeLocation;
            uiColorPicker.transform.parent        = input.parent;
            uiColorPicker.transform.localPosition = parentAnchor + input.relativeLocation;
            uiColorPicker.transform.localRotation = Quaternion.identity;
            uiColorPicker.transform.localScale    = Vector3.one;
            uiColorPicker.width          = input.width;
            uiColorPicker.height         = input.height;
            uiColorPicker.thickness      = input.thickness;
            uiColorPicker.padding        = input.padding;
            uiColorPicker.trianglePct    = input.trianglePct;
            uiColorPicker.innerCirclePct = input.innerCirclePct;
            uiColorPicker.outerCirclePct = input.outerCirclePct;

            //
            // Sub Components
            //

            //      HSV

            Vector3 hsvPosition  = new Vector3(0.0f, 0.0f, 0.0f);
            float   hsvWidth     = input.width;
            float   hsvHeight    = (1.0f - input.alphaToSaturationRatio) * (input.height - input.padding);
            float   hsvThickness = input.thickness;

            uiColorPicker.hsv = UIColorPickerHSV.Create(
                new UIColorPickerHSV.CreateParams {
                parent           = go.transform,
                widgetName       = "Hsv",
                relativeLocation = hsvPosition,
                width            = hsvWidth,
                height           = hsvHeight,
                thickness        = hsvThickness
            });
            uiColorPicker.hsv.colorPicker = uiColorPicker;

            //      Alpha

            Vector3 alphaPosition  = new Vector3(0.0f, (1.0f - input.alphaToSaturationRatio) * -(input.height - input.padding) - input.padding, 0.0f);
            float   alphaWidth     = input.alphaToPreviewRatio * (input.width - input.padding);
            float   alphaHeight    = input.alphaToSaturationRatio * (input.height - input.padding);
            float   alphaThickness = input.thickness;

            uiColorPicker.alpha = UIColorPickerAlpha.Create(
                "Alpha", go.transform,
                alphaPosition, alphaWidth, alphaHeight, alphaThickness,
                input.alphaMaterial, input.alphaCursorPrefab);
            uiColorPicker.alpha.colorPicker = uiColorPicker;

            //      Preview

            Vector3 previewPosition  = new Vector3(input.alphaToPreviewRatio * (input.width - input.padding) + input.padding, (1.0f - input.alphaToSaturationRatio) * -(input.height - input.padding) - input.padding, 0.0f);
            float   previewWidth     = (1.0f - input.alphaToPreviewRatio) * (input.width - input.padding);
            float   previewHeight    = input.alphaToSaturationRatio * (input.height - input.padding);
            float   previewThickness = input.thickness;

            uiColorPicker.preview = UIColorPickerPreview.CreateUIColorPickerPreview(
                "Preview", go.transform,
                previewPosition, previewWidth, previewHeight, previewThickness,
                input.previewMaterial);

            UIUtils.SetRecursiveLayer(go, "CameraHidden");
        }