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 UIColorPickerPreview CreateUIColorPickerPreview(
            string objectName,
            Transform parent,
            Vector3 relativeLocation,
            float width,
            float height,
            float thickness,
            Material material)
        {
            GameObject go = new GameObject(objectName);

            go.tag = "UICollider";

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

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

            UIColorPickerPreview uiColorPickerPreview = go.AddComponent <UIColorPickerPreview>();

            uiColorPickerPreview.relativeLocation        = relativeLocation;
            uiColorPickerPreview.transform.parent        = parent;
            uiColorPickerPreview.transform.localPosition = parentAnchor + relativeLocation;
            uiColorPickerPreview.transform.localRotation = Quaternion.identity;
            uiColorPickerPreview.transform.localScale    = Vector3.one;
            uiColorPickerPreview.width     = width;
            uiColorPickerPreview.height    = height;
            uiColorPickerPreview.thickness = thickness;

            // TODO : Re-enable
            // Setup the Meshfilter
            MeshFilter meshFilter = go.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                meshFilter.sharedMesh       = UIUtils.BuildBoxEx(width, height, thickness);
                uiColorPickerPreview.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 && material != null)
            {
                meshRenderer.sharedMaterial     = Instantiate(material);
                meshRenderer.shadowCastingMode  = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.renderingLayerMask = 2; // "LightLayer 1"
            }

            UIUtils.SetRecursiveLayer(go, "CameraHidden");

            return(uiColorPickerPreview);
        }