public static void SetButtonText(this Button _button, string _text)
 {
     HMUI.CurvedTextMeshPro textMesh = _button.GetComponentInChildren <HMUI.CurvedTextMeshPro>();
     if (textMesh != null)
     {
         textMesh.SetText(_text);
     }
 }
Ejemplo n.º 2
0
        public void ShowResults()
        {
            if (!levelOk)
            {
                return;
            }
            levelOk = false;
            Logger.log.Debug("Found " + energyList.Count() + " notes");

            panel = new GameObject("PerformanceMeter");
            panel.transform.Rotate(22.5f, 0, 0, Space.World);
            Canvas canvas = panel.AddComponent <Canvas>();

            canvas.renderMode  = RenderMode.WorldSpace;
            canvas.scaleFactor = 0.01f;
            canvas.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.4f, 2.25f);
            canvas.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.5f);
            canvas.transform.Rotate(22.5f, 0, 0, Space.World);
            panel.AddComponent <CanvasRenderer>();
            panel.AddComponent <HMUI.CurvedCanvasSettings>();

            GameObject imageObj = new GameObject("Background");

            imageObj.transform.SetParent(canvas.transform);
            imageObj.transform.Rotate(22.5f, 0, 0, Space.World);
            Image img = imageObj.AddComponent <Image>();

            img.color = new Color(0.1f, 0.1f, 0.1f, 0.25f);
            img.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.0f, 0.0f);
            img.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.6f);

            GameObject textObj = new GameObject("Label");

            textObj.transform.SetParent(canvas.transform);
            textObj.transform.Rotate(22.5f, 0, 0, Space.World);
            HMUI.CurvedTextMeshPro text = textObj.AddComponent <HMUI.CurvedTextMeshPro>();
            text.font                 = Instantiate(Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF No Glow"));
            text.fontSize             = 9.0f;
            text.alignment            = TextAlignmentOptions.Right;
            text.text                 = "Performance";
            text.enableAutoSizing     = true;
            text.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f);
            text.GetComponent <RectTransform>().localPosition = new Vector3(-0.3f, -0.25f, 0.1f);
            text.GetComponent <RectTransform>().sizeDelta     = new Vector2(75.0f, 25.0f);

            GameObject graphObj = new GameObject("GraphContainer");

            graphObj.AddComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.45f, 2.275f);
            graphObj.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.45f);
            graphObj.transform.Rotate(22.5f, 0, 0, Space.World);
            graphObj.transform.SetParent(panel.transform);
            graphObj.transform.name = "GraphContainer";
            WindowGraph graph = panel.AddComponent <WindowGraph>();

            graph.ShowGraph(energyList, false, true, true);

            StartCoroutine(WaitForMenu());
        }
Ejemplo n.º 3
0
        public void ShowResults()
        {
            if (!levelOk)
            {
                return;
            }
            levelOk = false;
            Logger.log.Debug("Found " + energyList.Count() + " primary notes, " + secondaryEnergyList.Count() + " secondary notes");

            panel = new GameObject("PerformanceMeter");
            panel.transform.Rotate(22.5f, 0, 0, Space.World);
            Canvas canvas = panel.AddComponent <Canvas>();

            canvas.renderMode  = RenderMode.WorldSpace;
            canvas.scaleFactor = 0.01f;
            canvas.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.4f, 2.25f);
            canvas.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.5f);
            canvas.transform.Rotate(22.5f, 0, 0, Space.World);
            panel.AddComponent <CanvasRenderer>();
            panel.AddComponent <HMUI.CurvedCanvasSettings>();

            GameObject imageObj = new GameObject("Background");

            imageObj.transform.SetParent(canvas.transform);
            imageObj.transform.Rotate(22.5f, 0, 0, Space.World);
            Image img = imageObj.AddComponent <Image>();

            img.color = new Color(0.1f, 0.1f, 0.1f, 0.25f);
            img.GetComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.0f, 0.0f);
            img.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.6f);

            GameObject textObj = new GameObject("Label");

            textObj.transform.SetParent(canvas.transform);
            textObj.transform.Rotate(22.5f, 0, 0, Space.World);
            HMUI.CurvedTextMeshPro text = textObj.AddComponent <HMUI.CurvedTextMeshPro>();
            text.font                 = Instantiate(Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF"));
            text.fontSize             = 9.0f;
            text.alignment            = TextAlignmentOptions.Right;
            text.text                 = "Performance";
            text.enableAutoSizing     = true;
            text.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f);
            text.GetComponent <RectTransform>().localPosition = new Vector3(-0.3f, -0.25f, 0.1f);
            text.GetComponent <RectTransform>().sizeDelta     = new Vector2(75.0f, 25.0f);

            GameObject textObj2 = new GameObject("Label");

            textObj2.transform.SetParent(canvas.transform);
            textObj2.transform.Rotate(22.5f, 0, 0, Space.World);
            HMUI.CurvedTextMeshPro text2 = textObj2.AddComponent <HMUI.CurvedTextMeshPro>();
            text2.font                 = Instantiate(Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF"));
            text2.fontSize             = 9.0f;
            text2.alignment            = TextAlignmentOptions.Right;
            text2.text                 = "By JackMacWindows#9776";
            text2.color                = new Color(0.3f, 0.3f, 0.3f);
            text2.enableAutoSizing     = true;
            text2.transform.localScale = new Vector3(0.002f, 0.002f, 0.002f);
            text2.GetComponent <RectTransform>().localPosition = new Vector3(0.31f, -0.2625f, 0.1f);
            text2.GetComponent <RectTransform>().sizeDelta     = new Vector2(175.0f, 16.0f);

            GameObject graphMask = new GameObject("GraphMask");

            graphMask.AddComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.45f, 2.275f);
            graphMask.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.45f);
            graphMask.transform.Rotate(22.5f, 0, 0, Space.World);
            graphMask.transform.SetParent(panel.transform);
            graphMask.transform.name = "GraphMask";
            graphMask.AddComponent <RectMask2D>();

            GameObject graphObj = new GameObject("GraphContainer");

            graphObj.AddComponent <RectTransform>().localPosition = new Vector3(0.0f, 0.45f, 2.275f);
            graphObj.GetComponent <RectTransform>().sizeDelta     = new Vector2(1.0f, 0.45f);
            graphObj.transform.Rotate(22.5f, 0, 0, Space.World);
            graphObj.transform.SetParent(graphMask.transform);
            graphObj.transform.name = "GraphContainer";

            bool hasPrimary   = PluginConfig.Instance.mode != PluginConfig.MeasurementMode.None && energyList.Count > 0;
            bool hasSecondary = PluginConfig.Instance.secondaryMode != PluginConfig.MeasurementMode.None && secondaryEnergyList.Count > 0;

            if (!hasPrimary && !hasSecondary)
            {
                GameObject textObj3 = new GameObject("Label");
                textObj3.transform.SetParent(canvas.transform);
                textObj3.transform.Rotate(22.5f, 0, 0, Space.World);
                HMUI.CurvedTextMeshPro text3 = textObj3.AddComponent <HMUI.CurvedTextMeshPro>();
                text3.font                 = Instantiate(Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First(t => t.name == "Teko-Medium SDF"));
                text3.fontSize             = 48.0f;
                text3.alignment            = TextAlignmentOptions.Center;
                text3.text                 = "No data available";
                text3.color                = new Color(0.3f, 0.3f, 0.3f);
                text3.enableAutoSizing     = true;
                text3.transform.localScale = new Vector3(0.002f, 0.002f, 0.002f);
                text3.GetComponent <RectTransform>().localPosition = new Vector3(0f, 0f, 0f);
                text3.GetComponent <RectTransform>().sizeDelta     = new Vector2(800.0f, 80.0f);
                StartCoroutine(WaitForMenu(graphObj, graphMask));
                return;
            }

            float width = 0.0f;

            if (hasPrimary && hasSecondary)
            {
                if (energyList.Last().first > secondaryEnergyList.Last().first)
                {
                    secondaryEnergyList.Add(new Pair <float, float>(energyList.Last().first, secondaryEnergyList.Last().second));
                }
                else if (secondaryEnergyList.Last().first > energyList.Last().first)
                {
                    energyList.Add(new Pair <float, float>(secondaryEnergyList.Last().first, energyList.Last().second));
                }
            }
            width = hasPrimary ? energyList.Last().first : secondaryEnergyList.Last().first;

            if (hasPrimary)
            {
                graphMask.AddComponent <WindowGraph>().ShowGraph(energyList, PluginConfig.Instance.mode, width, PluginConfig.Instance.overrideColor, PluginConfig.Instance.sideColor, true);
            }

            if (hasSecondary)
            {
                graphMask.AddComponent <WindowGraph>().ShowGraph(secondaryEnergyList, PluginConfig.Instance.secondaryMode, width, PluginConfig.Instance.overrideSecondaryColor, PluginConfig.Instance.secondarySideColor, false);
            }

            if (PluginConfig.Instance.showMisses)
            {
                var GraphTransform = graphObj.GetComponent <RectTransform>();
                var xSize          = GraphTransform.sizeDelta.x / width;
                var ySize          = GraphTransform.sizeDelta.y;
                foreach (float pos in misses)
                {
                    var xPosition    = pos * xSize;
                    var dotPositionA = new Vector2(xPosition, 0);
                    var dotPositionB = new Vector2(xPosition, ySize);
                    var gameObject   = new GameObject("DotConnection", typeof(Image));
                    gameObject.transform.SetParent(GraphTransform, false);
                    var image = gameObject.GetComponent <Image>();
                    image.color = new Color(0.5f, 0.5f, 0.5f, 0.75f);
                    var rectTransform = gameObject.GetComponent <RectTransform>();
                    var dir           = (dotPositionB - dotPositionA).normalized;
                    var distance      = Vector2.Distance(dotPositionA, dotPositionB);
                    rectTransform.anchorMin        = new Vector2(0, 0);
                    rectTransform.anchorMax        = new Vector2(0, 0);
                    rectTransform.sizeDelta        = new Vector2(distance, 0.0025f);
                    rectTransform.anchoredPosition = dotPositionA + dir * distance * .5f;
                    rectTransform.localEulerAngles = new Vector3(0, 0, Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg);
                }
            }

            StartCoroutine(WaitForMenu(graphObj, graphMask));
        }
Ejemplo n.º 4
0
        internal void AddCalibrationScreen(CameraPlusBehaviour camplus, Camera camera)
        {
            _targetBehaviour = camplus;

            _webCamCanvas = new GameObject("WebCamCanvas").AddComponent <Canvas>();
            _webCamCanvas.gameObject.transform.SetParent(this.transform);
            _webCamCanvas.renderMode    = RenderMode.ScreenSpaceCamera;
            _webCamCanvas.worldCamera   = camera;
            _webCamCanvas.planeDistance = 1;

            CanvasScaler canvasScaler = _webCamCanvas.gameObject.AddComponent <CanvasScaler>();

            canvasScaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            canvasScaler.referenceResolution = new Vector2(Screen.width, Screen.height);
            canvasScaler.matchWidthOrHeight  = 1;

            RawImage raw = new GameObject("RawImage").AddComponent <RawImage>();

            raw.transform.SetParent(_webCamCanvas.transform);
            raw.transform.localPosition    = Vector3.zero;
            raw.transform.localEulerAngles = Vector3.zero;

            var rect = raw.gameObject.GetComponent <RectTransform>();

            rect.anchorMin        = new Vector2(0.5f, 0.5f);
            rect.anchorMax        = new Vector2(0.5f, 0.5f);
            rect.pivot            = new Vector2(0.5f, 0.5f);
            rect.localScale       = new Vector3(-1f, 1f, 1);
            rect.anchoredPosition = new Vector2(0, 0);
            rect.sizeDelta        = new Vector2(Screen.width / 4, Screen.height / 4);
            rect.localPosition    = new Vector3(0, 0, 0);

            _webCamTexture = new WebCamTexture(camplus.Config.webCamera.name);
            raw.texture    = _webCamTexture;
            Material rawMaterial = new Material(Plugin.cameraController.Shaders["BeatSaber/BlitCopyWithDepth"]);

            rawMaterial.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 0));
            rawMaterial.SetFloat("_CullMode", 0);
            raw.material = rawMaterial;
            _webCamTexture.Play();

            _cursorImage = new GameObject("CursorImage").AddComponent <RawImage>();
            _cursorImage.transform.SetParent(_webCamCanvas.transform);
            _cursorImage.transform.localPosition    = Vector3.zero;
            _cursorImage.transform.localEulerAngles = Vector3.zero;
            _cursorImage.texture = CustomUtils.LoadTextureFromResources("CameraPlus.Resources.Xross.png");
            Material cursorMat = new Material(Plugin.cameraController.Shaders["ChromaKey/Unlit/Cutout"]);

            cursorMat.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 0));
            cursorMat.SetColor("_ChromaKeyColor", Color.white);
            cursorMat.SetFloat("_ChromaKeyHueRange", 0.5f);
            _cursorImage.material        = cursorMat;
            _rectCursor                  = _cursorImage.GetComponent <RectTransform>();
            _rectCursor.anchorMin        = new Vector2(0.5f, 0.5f);
            _rectCursor.anchorMax        = new Vector2(0.5f, 0.5f);
            _rectCursor.pivot            = new Vector2(0.5f, 0.5f);
            _rectCursor.localScale       = new Vector3(1f, 1f, 1);
            _rectCursor.anchoredPosition = new Vector2(0, 0);
            _rectCursor.sizeDelta        = new Vector2(Screen.width / 8, Screen.height / 4.5f);
            _rectCursor.localPosition    = new Vector3(0, 0, -0.1f);

            _calText = new GameObject("CalibrationText").AddComponent <HMUI.CurvedTextMeshPro>();
            _calText.transform.SetParent(_webCamCanvas.transform);
            _calText.transform.localPosition    = Vector3.zero;
            _calText.transform.localEulerAngles = Vector3.zero;
            _calText.alignment = TMPro.TextAlignmentOptions.Bottom;
            _calText.fontSize  = 24;
            _calText.text      = "Pull the trigger in front of the webcam.";
            var cakRect = _calText.gameObject.GetComponent <RectTransform>();

            cakRect.anchorMin        = new Vector2(0.5f, 0.5f);
            cakRect.anchorMax        = new Vector2(0.5f, 0.5f);
            cakRect.pivot            = new Vector2(0.5f, 0.5f);
            cakRect.localScale       = new Vector3(1f, 1f, 1);
            cakRect.anchoredPosition = new Vector2(0, 0);
            cakRect.sizeDelta        = new Vector2(Screen.width / 4, Screen.height / 3);
            cakRect.localPosition    = new Vector3(0, 0, -0.1f);
        }