Esempio n. 1
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");
        }
Esempio n. 2
0
        public static UIColorPickerHSV Create(CreateParams input)
        {
            GameObject go = new GameObject(input.widgetName);

            go.tag = "UICollider";

            // 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;
                }
            }

            UIColorPickerHSV uiColorPickerHSV = go.AddComponent <UIColorPickerHSV>();

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

            // Setup the Meshfilter
            MeshFilter meshFilter = go.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                meshFilter.sharedMesh = UIUtils.BuildHSV(
                    input.width, input.height, input.thickness,
                    input.trianglePct, input.innerCirclePct, input.outerCirclePct, 72, Color.red);
                uiColorPickerHSV.Anchor = Vector3.zero;
                BoxCollider coll = go.GetComponent <BoxCollider>();
                if (coll != null)
                {
                    Vector3 initColliderCenter = meshFilter.sharedMesh.bounds.center;
                    Vector3 initColliderSize   = meshFilter.sharedMesh.bounds.size;
                    if (initColliderSize.z < UIElement.collider_min_depth_deep)
                    {
                        coll.center = new Vector3(initColliderCenter.x, initColliderCenter.y, UIElement.collider_min_depth_deep / 2.0f);
                        coll.size   = new Vector3(initColliderSize.x, initColliderSize.y, UIElement.collider_min_depth_deep);
                    }
                    else
                    {
                        coll.center = initColliderCenter;
                        coll.size   = initColliderSize;
                    }
                    coll.isTrigger = true;
                }
            }

            // Setup the MeshRenderer
            MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>();

            if (meshRenderer != null && input.hueMaterial != null && input.svMaterial != null)
            {
                meshRenderer.sharedMaterials    = new Material[] { Instantiate(input.hueMaterial), Instantiate(input.svMaterial) };
                meshRenderer.shadowCastingMode  = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.renderingLayerMask = 1 << 1; // "LightLayer 1"
            }

            // Add a cursor
            GameObject hueCursor = Instantiate <GameObject>(input.hueCursorPrefab);

            hueCursor.transform.parent        = uiColorPickerHSV.transform;
            hueCursor.transform.localPosition = Vector3.zero;
            hueCursor.transform.localRotation = Quaternion.identity;
            uiColorPickerHSV.hueCursor        = hueCursor.transform;

            GameObject svCursor = Instantiate <GameObject>(input.svCursorPrefab);

            svCursor.transform.parent        = uiColorPickerHSV.transform;
            svCursor.transform.localPosition = Vector3.zero;
            svCursor.transform.localRotation = Quaternion.identity;
            uiColorPickerHSV.svCursor        = svCursor.transform;

            UIUtils.SetRecursiveLayer(go, "CameraHidden");

            return(uiColorPickerHSV);
        }