コード例 #1
0
        public override void RebuildMesh()
        {
            // RAIL
            Vector3 railPosition = new Vector3(margin + (width - 2 * margin) * sliderPositionBegin, railMargin - height / 2, -railThickness);
            float   railWidth    = (width - 2 * margin) * (sliderPositionEnd - sliderPositionBegin);
            float   railHeight   = 2 * railMargin; // no inner rectangle, only margin driven rounded borders.

            rail.RebuildMesh(railWidth, railHeight, railThickness, railMargin);
            rail.transform.localPosition = railPosition;

            // KNOB
            float newKnobRadius = knobRadius;
            float newKnobDepth  = knobDepth;

            knob.RebuildMesh(newKnobRadius, newKnobDepth);

            // BASE
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            Mesh       theNewMesh = UIUtils.BuildRoundedBoxEx(width, height, margin, thickness, nbSubdivCornerFixed, nbSubdivCornerPerUnit);

            theNewMesh.name       = "UISlider_GeneratedMesh";
            meshFilter.sharedMesh = theNewMesh;

            UpdateColliderDimensions();
            UpdateCanvasDimensions();
            UpdateSliderPosition();
        }
コード例 #2
0
        public static UIRangeRail Create(CreateArgs input)
        {
            GameObject go = new GameObject(input.widgetName);

            go.tag   = "UICollider";
            go.layer = LayerMask.NameToLayer("CameraHidden");

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

            UIRangeRail uiRangeRail = go.AddComponent <UIRangeRail>();

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

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

            if (meshFilter != null)
            {
                meshFilter.sharedMesh = UIUtils.BuildRoundedBoxEx(input.width, input.height, input.margin, input.thickness, 6, 3);
            }

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

            if (meshRenderer != null && input.material != null)
            {
                Material newMaterial = Instantiate(input.material);
                newMaterial.name            = "UIRangeRail_Material";
                meshRenderer.sharedMaterial = newMaterial;

                uiRangeRail._color.useConstant = false;
                uiRangeRail._color.constant    = input.c.value;
                uiRangeRail._color.reference   = input.c;
                meshRenderer.sharedMaterial.SetColor("_BaseColor", uiRangeRail.Color);

                meshRenderer.shadowCastingMode  = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.renderingLayerMask = 2; // "LightLayer 1"
            }

            return(uiRangeRail);
        }
コード例 #3
0
        public override void RebuildMesh()
        {
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            Mesh       theNewMesh = UIUtils.BuildRoundedBoxEx(width, height, margin, thickness, nbSubdivCornerFixed, nbSubdivCornerPerUnit);

            theNewMesh.name       = "UIKeyView_GeneratedMesh";
            meshFilter.sharedMesh = theNewMesh;

            UpdateColliderDimensions();
        }
コード例 #4
0
        public void RebuildMesh(float newWidth, float newHeight, float newThickness, float newMargin)
        {
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            Mesh       theNewMesh = UIUtils.BuildRoundedBoxEx(width, height, margin, thickness, 6, 3); // TODO: subdiv parametrable?

            theNewMesh.name       = "UIRangeRail_GeneratedMesh";
            meshFilter.sharedMesh = theNewMesh;

            width     = newWidth;
            height    = newHeight;
            thickness = newThickness;
            margin    = newMargin;
        }
コード例 #5
0
ファイル: UIRangeKnob.cs プロジェクト: ubisoft/vrtist
        public void RebuildMesh(float newWidth, float newKnobRadius, float newKnobDepth, int knobNbSubdivCornerFixed, int knobNbSubdivCornerPerUnit)
        {
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            // Make a cylinder using RoundedBox
            Mesh theNewMesh = UIUtils.BuildRoundedBoxEx(newWidth, 2.0f * newKnobRadius, newKnobRadius, newKnobDepth, knobNbSubdivCornerFixed, knobNbSubdivCornerPerUnit);

            theNewMesh.name       = "UIRangeKnob_GeneratedMesh";
            meshFilter.sharedMesh = theNewMesh;

            width  = newWidth;
            radius = newKnobRadius;
            depth  = newKnobDepth;
            nbSubdivCornerFixed   = knobNbSubdivCornerFixed;
            nbSubdivCornerPerUnit = knobNbSubdivCornerPerUnit;
        }
コード例 #6
0
ファイル: UIPanel.cs プロジェクト: ubisoft/vrtist
        public override void RebuildMesh()
        {
            MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();
            Mesh       theNewMesh = (backgroundGeometryStyle == BackgroundGeometryStyle.Tube)
                ? UIUtils.BuildRoundedRectTubeEx(
                width, height, margin, radius,
                circleSubdiv, nbSubdivPerUnit, nbSubdivCornerFixed, nbSubdivCornerPerUnit)
                : UIUtils.BuildRoundedBoxEx(
                width, height, margin, thickness,
                nbSubdivCornerFixed, nbSubdivCornerPerUnit);

            theNewMesh.name       = "UIPanel_GeneratedMesh";
            meshFilter.sharedMesh = theNewMesh;

            UpdateColliderDimensions();
        }
コード例 #7
0
ファイル: UIRangeKnob.cs プロジェクト: ubisoft/vrtist
        public static UIRangeKnob Create(CreateArgs input)
        {
            GameObject go = new GameObject(input.widgetName);

            go.tag   = "UICollider";
            go.layer = LayerMask.NameToLayer("CameraHidden");

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

            UIRangeKnob uiRangeKnob = go.AddComponent <UIRangeKnob>();

            uiRangeKnob.transform.parent        = input.parent;
            uiRangeKnob.transform.localPosition = parentAnchor + input.relativeLocation;
            uiRangeKnob.transform.localRotation = Quaternion.identity;
            uiRangeKnob.transform.localScale    = Vector3.one;
            uiRangeKnob.width  = input.width;
            uiRangeKnob.radius = input.radius;
            uiRangeKnob.depth  = input.depth;
            uiRangeKnob.nbSubdivCornerFixed      = input.nbSubdivCornerFixed;
            uiRangeKnob.nbSubdivCornerPerUnit    = input.nbSubdivCornerPerUnit;
            uiRangeKnob.baseColor.useConstant    = false;
            uiRangeKnob.baseColor.reference      = input.baseColor;
            uiRangeKnob.pushedColor.useConstant  = false;
            uiRangeKnob.pushedColor.reference    = input.pushedColor;
            uiRangeKnob.hoveredColor.useConstant = false;
            uiRangeKnob.hoveredColor.reference   = input.hoveredColor;
            uiRangeKnob.textColor.useConstant    = false;
            uiRangeKnob.textColor.reference      = input.textColor;

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

            if (meshFilter != null)
            {
                meshFilter.sharedMesh = UIUtils.BuildRoundedBoxEx(input.width, 2.0f * input.radius, input.radius, input.depth, input.nbSubdivCornerFixed, input.nbSubdivCornerPerUnit);
            }

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

            if (meshRenderer != null && input.material != null)
            {
                meshRenderer.sharedMaterial = Instantiate(input.material);
                meshRenderer.sharedMaterial.SetColor("_BaseColor", uiRangeKnob.BaseColor);

                meshRenderer.shadowCastingMode  = UnityEngine.Rendering.ShadowCastingMode.Off;
                meshRenderer.renderingLayerMask = 2; // "LightLayer 1"
            }

            //
            // CANVAS (to hold the text)
            //

            GameObject canvas = new GameObject("Canvas");

            canvas.transform.parent = uiRangeKnob.transform;

            Canvas c = canvas.AddComponent <Canvas>();

            c.renderMode = RenderMode.WorldSpace;

            RectTransform rt = canvas.GetComponent <RectTransform>(); // auto added when adding Canvas

            rt.localScale    = Vector3.one;
            rt.localRotation = Quaternion.identity;
            rt.anchorMin     = new Vector2(0, 1);
            rt.anchorMax     = new Vector2(0, 1);
            rt.pivot         = new Vector2(0, 1); // top left
            rt.sizeDelta     = new Vector2(uiRangeKnob.width, 2.0f * uiRangeKnob.radius);
            rt.localPosition = Vector3.zero;      // top left

            CanvasScaler cs = canvas.AddComponent <CanvasScaler>();

            cs.dynamicPixelsPerUnit   = 300; // 300 dpi, sharp font
            cs.referencePixelsPerUnit = 100; // default?

            // Text VALUE
            {
                GameObject text = new GameObject("TextValue");
                text.transform.parent = canvas.transform;

                TextMeshProUGUI t = text.AddComponent <TextMeshProUGUI>();
                t.text                     = input.initialValue.ToString("#0");
                t.enableAutoSizing         = true;
                t.fontSizeMin              = 1;
                t.fontSizeMax              = 500;
                t.characterWidthAdjustment = 50.0f;
                t.fontStyle                = FontStyles.Normal;
                t.alignment                = TextAlignmentOptions.Center;
                t.enableWordWrapping       = false;
                t.overflowMode             = TextOverflowModes.Truncate;
                t.color                    = input.textColor.value;

                RectTransform trt = t.GetComponent <RectTransform>();
                trt.localScale    = 0.01f * Vector3.one;
                trt.localRotation = Quaternion.identity;
                trt.anchorMin     = new Vector2(0, 1);
                trt.anchorMax     = new Vector2(0, 1);
                trt.pivot         = new Vector2(0, 1); // top left
                trt.sizeDelta     = new Vector2(uiRangeKnob.radius * 2.0f * 100.0f, uiRangeKnob.radius * 2.0f * 100.0f);
                if (input.textBehavior == TextBehavior.Hidden)
                {
                    trt.localPosition = new Vector3(0, 0, -0.002f);
                    text.SetActive(false);
                }
                else if (input.textBehavior == TextBehavior.Center)
                {
                    trt.localPosition = new Vector3(0.0f, -uiRangeKnob.radius, -0.002f);
                }
                else if (input.textBehavior == TextBehavior.Bottom)
                {
                    trt.localPosition = new Vector3(0.0f, -2.0f * uiRangeKnob.radius, -0.002f);
                }
                else if (input.textBehavior == TextBehavior.Top)
                {
                    trt.localPosition = new Vector3(0.0f, uiRangeKnob.radius, -0.002f);
                }
            }

            return(uiRangeKnob);
        }