コード例 #1
0
    // Update is called once per frame
    void onMiscibleclick()
    {
        if (qno == 0)
        {
            t.text      = "water and oil are immiscible. Choose the correct option to proceed";
            t.fontSize  = 12;
            t.fontStyle = FontStyle.Bold;
            t.color     = Color.red;
        }

        else if (qno == 1)
        {
            t.text     = "CORRECT";
            t.fontSize = 15;
            t.color    = Color.green;
            qno++;
            StartCoroutine(wait());
            t.text     = "How will you remove grease stains from cotton fabrics?";
            t.color    = Color.white;
            t.fontSize = 12;
            Destroy(miscibleb.gameObject);
            Destroy(imiscibleb.gameObject);
            RectTransform rt = IF.GetComponent <RectTransform>();
            rt.localScale = new Vector3(1, 1, 1);
            rt            = submitb.GetComponent <RectTransform>();
            rt.localScale = new Vector3(1, 1, 1);
        }
    }
コード例 #2
0
ファイル: Highscores.cs プロジェクト: adamrushton/Augimals
    // Get components from the Unity scene
    private void FindTextComponents()
    {
        addScoreButton    = addScoreButton.GetComponent <UnityEngine.UI.Button>();
        status            = status.GetComponent <UnityEngine.UI.Text>();
        displayScore      = displayScore.GetComponent <UnityEngine.UI.Text>();
        displayScoreLabel = displayScoreLabel.GetComponent <UnityEngine.UI.Text>();
        usernameInput     = usernameInput.GetComponent <UnityEngine.UI.InputField>();

        fileName         = fileName.GetComponent <UnityEngine.UI.Text>();
        fileName.enabled = false; // Invisible text view to store the file name for the highscores
        score            = score.GetComponent <UnityEngine.UI.Text>();

        for (int i = 0; i < TOTAL_SCORES; i++)
        {
            names[i]  = names[i].GetComponent <UnityEngine.UI.Text>();
            scores[i] = scores[i].GetComponent <UnityEngine.UI.Text>();
        }
    }
コード例 #3
0
    //--------------------------------------------------------------------------------
    #region Private Methods

    void UpdatePrompt()
    {
        if (!gameObject.activeInHierarchy)
        {
            return;
        }
        RectTransform promptR = prompt.GetComponent <RectTransform>();
        string        promptStr;

        if (demoScript.interpreter.NeedMoreInput())
        {
            promptStr         = ". . . > ";
            promptR.sizeDelta = new Vector2(60, promptR.sizeDelta.y);
        }
        else if (demoScript.interpreter.Running())
        {
            promptStr = null;
        }
        else
        {
            promptStr         = "> ";
            promptR.sizeDelta = new Vector2(25, promptR.sizeDelta.y);
        }

        prompt.text = promptStr;
        RectTransform inputR = input.GetComponent <RectTransform>();

        inputR.anchoredPosition = new Vector2(promptR.sizeDelta.x, inputR.anchoredPosition.y);
        if (promptStr == null)
        {
            input.DeactivateInputField();
            input.gameObject.SetActive(false);
        }
        else
        {
            input.gameObject.SetActive(true);
            input.ActivateInputField();
        }
    }
コード例 #4
0
ファイル: SwipeListener.cs プロジェクト: sgdc/Quipe
    // Update is called once per frame
    void Update()
    {
        //Give input field constant focus (this ensures we are listening for input always)
        UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(inputField.gameObject, null);
        inputField.OnPointerClick(new UnityEngine.EventSystems.PointerEventData(UnityEngine.EventSystems.EventSystem.current));


        if (Input.GetKeyDown(KeyCode.CapsLock))            //export IDs to AHK file
        {
            string ahkPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Quipe\";
            ahkPath += DateTime.Now.ToString("MM-dd-yyyy");
            ahkPath += " Quipe.ahk";

            System.IO.File.WriteAllText(ahkPath, "");              //ensures file exists and is blank

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(ahkPath, true)) {
                file.WriteLine("Home::");
                foreach (string m in swipes)
                {
                    file.WriteLine("\tSendRaw, `" + m);
                    file.WriteLine("\tSend, {Return}");
                    file.WriteLine("\tKeyWait, CapsLock, D");
                }
                file.WriteLine("Return");
            }

            notification.text  = "Swipes exported to AHK.";
            notification.color = Color.blue;
            notificationClear  = 60;
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            string leaderboardPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Quipe\";
            leaderboardPath += DateTime.Now.ToString("MM-dd-yyyy");
            leaderboardPath += " Scores.csv";

            System.IO.File.WriteAllText(leaderboardPath, "");              //ensure file exists and is empty

            users.Sort((s1, s2) => s2.score.CompareTo(s1.score));

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(leaderboardPath, true)) {
                file.WriteLine("Name, Score");
                file.WriteLine();
                foreach (Player p in users)
                {
                    Player reading = findPlayerInDatabase(p.ID);
                    file.WriteLine(reading.name + ", " + reading.score.ToString());
                }
            }

            notification.text  = "Leaderboard exported to text.";
            notification.color = Color.blue;
            notificationClear  = 60;
        }

        if (Input.GetKeyDown(KeyCode.Tab) && Application.isEditor)
        {
            swipes.Clear();
            notification.text  = "Clearing instance swipe list. Cheater.";
            notification.color = Color.blue;
            notificationClear  = 60;
        }

        if (Input.GetKeyDown(KeyCode.RightControl))
        {
            listeningForNameChange = true;
            notification.text      = "Swipe card whose name you want to change.";
            notification.color     = Color.blue;
            notificationClear      = 90;
        }

        if (Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            //READS FROM names.txt FORMATTED firstName \t lastName \t ID
            string namesPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Quipe\names.txt";
            if (System.IO.File.Exists(namesPath))
            {
                string   line;
                string[] parts;

                // Read the file line by line.
                System.IO.StreamReader file =
                    new System.IO.StreamReader(namesPath);
                while ((line = file.ReadLine()) != null)
                {
                    char[] stupid = new char[1];
                    stupid[0] = '\t';
                    parts     = line.Split(stupid);

                    Player toUpdate = findPlayerInDatabaseByName(parts[2]);                     //2 is their 8 digit Stevens ID, which is their name in the database by default
                    toUpdate.name = parts[0] + " " + parts[1];
                    updatePlayerInDatabase(toUpdate);
                }


                file.Close();
                saveDatabase();

                notification.text  = "Names reconciled with names.txt";
                notification.color = Color.blue;
                notificationClear  = 90;
            }
            else
            {
                notification.text  = "names.txt not found. Please format a names.txt in the format firstName lastName ID";
                notification.color = Color.black;
                notificationClear  = 90;
            }
        }

        if (Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            SceneManager.LoadScene((SceneManager.GetActiveScene().buildIndex + 1) % SceneManager.sceneCountInBuildSettings);
        }

        if (Input.GetKeyDown(KeyCode.BackQuote))
        {
            inputField.GetComponent <UnityEngine.UI.Text>().color = new Color(0, 0, 0, 1 - inputField.GetComponent <UnityEngine.UI.Text>().color.a);
        }


        alarms();
        moveSpawner();
    }
コード例 #5
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.InputField temp       = AssetDatabase.LoadAssetAtPath(PSDImporterConst.ASSET_PATH_INPUTFIELD, typeof(UnityEngine.UI.InputField)) as UnityEngine.UI.InputField;
            UnityEngine.UI.InputField inputfield = GameObject.Instantiate(temp) as UnityEngine.UI.InputField;
            inputfield.transform.SetParent(parent.transform, false);//.parent = parent.transform;
            inputfield.name = layer.name;

            // 背景尺寸,用来限制文本框尺寸
            float _bgSize = 0;

            for (int i = 0; i < layer.layers.Length; ++i)
            {
                var _temp = layer.layers[i];

                if (_temp.image != null)
                {
                    //for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
                    //{
                    PSImage image = _temp.image;

                    if (image.imageType == ImageType.Label)
                    {
                        if (image.name.ToLower().Contains("text"))
                        {
                            this.pSDImportCtrl.DrawLayer(_temp, inputfield.gameObject);

                            var _text = PSDImportUtility.canvas.transform.Find(_temp.name).GetComponent <Text>();

                            RectTransform _rectTransform = _text.GetComponent <RectTransform>();

                            // 需要重设锚点,目前默认left
                            var _offsetMin = _rectTransform.offsetMin;
                            var _offsetMax = _rectTransform.offsetMax;

                            _rectTransform.pivot = new Vector2(0, 1);

                            _rectTransform.offsetMin = _offsetMin;
                            _rectTransform.offsetMax = _offsetMax;

                            if (Math.Abs(_bgSize) < float.Epsilon)
                            {
                                for (int j = 0; j < layer.layers.Length; ++j)
                                {
                                    var _layerLayer = layer.layers[i];

                                    if (_layerLayer.image != null)
                                    {
                                        if (_layerLayer.image.imageType != ImageType.Label &&
                                            _layerLayer.image.name.Contains("background"))
                                        {
                                            _bgSize = _layerLayer.image.size.width;

                                            break;
                                        }
                                    }
                                }
                            }

                            if (_rectTransform.sizeDelta.x < _bgSize)
                            {
                                _rectTransform.sizeDelta = new Vector2(_bgSize, _rectTransform.sizeDelta.y);
                            }

                            _text.supportRichText = false;
                            _text.text            = "";

                            if (inputfield.textComponent != null)
                            {
                                Object.DestroyImmediate(inputfield.textComponent.gameObject);
                            }

                            inputfield.textComponent = _text;

                            //UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.textComponent;//inputfield.transform.Find("Text").GetComponent<UnityEngine.UI.Text>();
                            //Color color;
                            //if (UnityEngine.ColorUtility.TryParseHtmlString(("#" + image.arguments[0]), out color))
                            //{
                            //    text.color = color;
                            //}

                            //int size;
                            //if (int.TryParse(image.arguments[2], out size))
                            //{
                            //    text.fontSize = size;
                            //}
                        }
                        else if (image.name.ToLower().Contains("holder"))
                        {
                            this.pSDImportCtrl.DrawLayer(_temp, inputfield.gameObject);

                            if (inputfield.placeholder != null)
                            {
                                Object.DestroyImmediate(inputfield.placeholder.gameObject);
                            }

                            inputfield.placeholder = PSDImportUtility.canvas.transform.Find(_temp.name).GetComponent <Text>();
                            ((Text)inputfield.placeholder).supportRichText = false;

                            //UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.placeholder;//.transform.Find("Placeholder").GetComponent<UnityEngine.UI.Text>();
                            //Color color;
                            //if (UnityEngine.ColorUtility.TryParseHtmlString(("#" + image.arguments[0]), out color))
                            //{
                            //    text.color = color;
                            //}

                            //int size;
                            //if (int.TryParse(image.arguments[2], out size))
                            //{
                            //    text.fontSize = size;
                            //}
                        }
                    }
                    else
                    {
                        if (image.name.ToLower().Contains("background"))
                        {
                            if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
                            {
                                string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                                Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
                                inputfield.image.sprite = sprite;

                                RectTransform rectTransform = inputfield.GetComponent <RectTransform>();
                                rectTransform.sizeDelta = new Vector2(image.size.width, image.size.height);
                                _bgSize = image.size.width;

                                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
                            }
                        }
                    }
                    //}
                }
            }

            //if (layer.image != null)
            //{
            //    //for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
            //    //{
            //        PSImage image = layer.image;

            //        if (image.imageType == ImageType.Label)
            //        {
            //            if (image.name.ToLower().Contains("text"))
            //            {
            //                UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.textComponent;//inputfield.transform.Find("Text").GetComponent<UnityEngine.UI.Text>();
            //                Color color;
            //                if (UnityEngine.ColorUtility.TryParseHtmlString(("#" + image.arguments[0]), out color))
            //                {
            //                    text.color = color;
            //                }

            //                int size;
            //                if (int.TryParse(image.arguments[2], out size))
            //                {
            //                    text.fontSize = size;
            //                }
            //            }
            //            else if (image.name.ToLower().Contains("holder"))
            //            {
            //                UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.placeholder;//.transform.Find("Placeholder").GetComponent<UnityEngine.UI.Text>();
            //                Color color;
            //                if (UnityEngine.ColorUtility.TryParseHtmlString(("#" + image.arguments[0]), out color))
            //                {
            //                    text.color = color;
            //                }

            //                int size;
            //                if (int.TryParse(image.arguments[2], out size))
            //                {
            //                    text.fontSize = size;
            //                }
            //            }
            //        }
            //        else
            //        {
            //            if (image.name.ToLower().Contains("background"))
            //            {
            //                if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
            //                {
            //                    string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            //                    Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
            //                    inputfield.image.sprite = sprite;

            //                    RectTransform rectTransform = inputfield.GetComponent<RectTransform>();
            //                    rectTransform.sizeDelta = new Vector2(image.size.width, image.size.height);
            //                    rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
            //                }
            //            }
            //        }
            //    //}
            //}
        }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        if (open && ((cachedCavasSize.x != consoleRoot.rect.width) || (cachedCavasSize.y != consoleRoot.rect.height)))
        {
            consolePanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, consoleRoot.rect.height / 2);
            cachedCavasSize = new Vector2(consoleRoot.rect.width, consoleRoot.rect.height);
            Canvas.ForceUpdateCanvases();
            maxTextVerticalSize = consolePanel.rect.height - inputField.GetComponent <RectTransform>().rect.height;
            text.GetComponent <UnityEngine.UI.LayoutElement>().flexibleHeight = 0f;
            dirty = true;
        }

        if (MenuActions.instance.toggleConsole.pressed)
        {
            InternalToggle();
        }

        if (MenuActions.instance.cancel.pressed && open)
        {
            InternalClose();
        }

        if (open)
        {
            if (MenuActions.instance.consoleHistoryUp.repeat)
            {
                ++scrollOffset;
                dirty = true;
            }
            else if (MenuActions.instance.consoleHistoryDown.repeat)
            {
                scrollOffset = Mathf.Max(0, scrollOffset - 1);
                dirty        = true;
            }
            else if (MenuActions.instance.consoleHistoryEnd.pressed)
            {
                if (scrollOffset > 0)
                {
                    scrollOffset = 0;
                    dirty        = true;
                }
            }
            else if (MenuActions.instance.up.pressed)
            {
                RecallDown();
            }
            else if (MenuActions.instance.down.pressed)
            {
                RecallUp();
            }
            else if (MenuActions.instance.consoleTabComplete.pressed)
            {
                CycleTabComplete();
            }
        }

        // animate the console.
        if (open)
        {
            lerp = Mathf.Clamp01(lerp - Time.unscaledDeltaTime * 1 / ascendSpeed);
        }
        else
        {
            lerp = Mathf.Clamp01(lerp + Time.unscaledDeltaTime * 1 / descendSpeed);
        }

        canvas.enabled = lerp != 1f;

        var consolePos = consolePanel.transform.localPosition;

        consolePos.y = (lerp * consolePanel.rect.height);

        consolePanel.transform.localPosition = consolePos;

        if (dirty && open)
        {
            scrollOffset = UpdateText(scrollOffset);
            dirty        = false;
        }
    }