コード例 #1
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
            public InputFieldUnityFloat(TextComp textComp, UnityAction <string> editEndCallback) : base(textComp, editEndCallback)
            {
                this.linkedTextComp = textComp;

                UnityAction <string> action = new UnityAction <string>(UpdateTextWhileTyping);

                this.inputField.GetComponent <UnityEngine.UI.InputField>().onValueChanged.AddListener(action);

                string     path        = RuntimeTextEdit.packagePath + "/Resources/InputFieldPanel.prefab";
                GameObject panelPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));

                if (panelPrefab == null)
                {
                    LogSystem.LogWarning("Failed to locate prefab at path: " + path);
                    return;
                }
                GameObject panel = Instantiate(panelPrefab);

                this.inputField.GetComponent <RectTransform>().offsetMin = new Vector2(10, 10);
                this.inputField.GetComponent <RectTransform>().offsetMax = new Vector2(-10, -10);
                GameObject canvas = GetCanvas();

                panel.transform.SetParent(canvas.transform, false);
                this.inputField.transform.SetParent(panel.transform, false);
                this.inputField = panel;
            }
コード例 #2
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
            public InputFieldUnity(TextComp textComp, UnityAction <string> editEndCallback)
            {
                GameObject inField = (GameObject)AssetDatabase.LoadAssetAtPath(RuntimeTextEdit.packagePath + "/Resources/InputField.prefab", typeof(GameObject));

                if (inField == null)
                {
                    LogSystem.LogWarning("Failed to get input field prefab.");
                    return;
                }
                this.inputField     = Instantiate(inField);
                this.linkedTextComp = textComp;
                this.inputFieldComp = this.inputField.GetComponent <UnityEngine.UI.InputField>();
                this.inputFieldComp.onEndEdit.AddListener(editEndCallback);
                UnityAction <string> action = new UnityAction <string>(UpdateTextWhileTyping);

                this.inputFieldComp.onValueChanged.AddListener(action);

                if (textComp.GetType() == typeof(TextCompUnityUI))
                {
                    MakeInputFieldHaveSameAppearance();
                    void MakeInputFieldHaveSameAppearance()
                    {
                        Preset preset = textComp.GetPresetOfInternalComp();

                        UnityEngine.UI.Text inputFieldTextComp = this.inputField.transform.Find("Text").GetComponent <UnityEngine.UI.Text>();
                        preset.ApplyTo(inputFieldTextComp);
                    }
                }

                return;
            }
コード例 #3
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
 private static void LocatePackagePath()
 {
     if (Directory.Exists("Assets/RuntimeTextEdit"))
     {
         RuntimeTextEdit.packagePath = "Assets/RuntimeTextEdit";
     }
     else
     {
         string[] paths = Directory.GetDirectories("Assets", "RuntimeTextEdit", SearchOption.AllDirectories);
         if (paths.Length == 1)
         {
             RuntimeTextEdit.packagePath = paths[0];
         }
         else
         {
             LogSystem.LogWarning("Found more than one folder named RuntimeTextEdit in the project. Could not locate package path. Please rename all folders called RuntimeTextEdit that do not contain the RuntimeTextEdit package.");
         }
     }
 }
コード例 #4
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
        public static GameObject GetCanvas()
        {
            if (RuntimeTextEdit.canvas == null)
            {
                bool foundCanvas = SearchCanvas();
                bool SearchCanvas()
                {
                    UnityEngine.Object canvasObj = UnityEngine.Object.FindObjectOfType(typeof(Canvas));
                    if (canvasObj == null)
                    {
                        return(false);
                    }
                    else
                    {
                        RuntimeTextEdit.canvas = ((Canvas)canvasObj).gameObject;
                        return(true);
                    }
                }

                if (!foundCanvas)
                {
                    CreateCanvas();
                    void CreateCanvas()
                    {
                        GameObject canvasPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(RuntimeTextEdit.packagePath + "/Resources/Canvas.prefab", typeof(GameObject));

                        if (canvasPrefab == null)
                        {
                            LogSystem.LogWarning("Could not find Canvas.prefab");
                            return;
                        }
                        RuntimeTextEdit.canvas = Instantiate(canvasPrefab);
                        GameObject eventSystemPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(RuntimeTextEdit.packagePath + "/Resources/EventSystem.prefab", typeof(GameObject));

                        Instantiate(eventSystemPrefab);
                    }
                }
            }

            return(RuntimeTextEdit.canvas);
        }
コード例 #5
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
 public virtual Preset GetPresetOfInternalComp()
 {
     LogSystem.LogWarning("Called GetPresetOfInternalComp() on subclass that does not support it.");
     return(null);
 }
コード例 #6
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
        void Start()
        {
            SearchManager();
            void SearchManager()
            {
                UnityEngine.Object manager = UnityEngine.Object.FindObjectOfType(typeof(RuntimeTextEditManager));
                if (manager == null)
                {
                    LogSystem.LogWarning("Could not find RuntimeTextEditManager. Please add a RuntimeTextEditManager component to your scene. Can not continue.");
                    return;
                }
                this.manager = ((RuntimeTextEditManager)manager);
                this.manager.RegisterComponent(this);
            }

            if (RuntimeTextEdit.packagePath == null)
            {
                RuntimeTextEdit.packagePath = "";
                LocatePackagePath();
            }

            SearchTextComp();
            void SearchTextComp()
            {
                bool foundTextComp = false;

                UnityEngine.UI.Text textCompUnityUI = this.transform.GetComponent <UnityEngine.UI.Text>();
                if (textCompUnityUI)
                {
                    this.textComp = new TextCompUnityUI(textCompUnityUI);
                    foundTextComp = true;
                }

                if (!foundTextComp)
                {
                    TextMeshProUGUI textCompTextMeshProUGUI = this.transform.GetComponent <TextMeshProUGUI>();
                    if (textCompTextMeshProUGUI)
                    {
                        this.textComp = new TextCompTextMeshProUGUI(textCompTextMeshProUGUI);
                        foundTextComp = true;
                    }
                }

                if (!foundTextComp)
                {
                    TextMeshPro textCompTMP = this.transform.GetComponent <TextMeshPro>();
                    if (textCompTMP)
                    {
                        this.textComp = new TextCompTextMeshPro(textCompTMP);
                        Collider collider = textCompTMP.transform.GetComponent <Collider>();
                        if (collider == null)
                        {
                            LogSystem.LogWithHighlight("Text component is missing a collider. Needed for RuntimeTextEdit to work. Added a box collider.", textCompTMP);
                            BoxCollider boxCollider = textCompTMP.gameObject.AddComponent <BoxCollider>();
                            boxCollider.center    = Vector3.zero;
                            boxCollider.isTrigger = true;
                            RectTransform rectTrans = this.GetComponent <RectTransform>();
                            if (rectTrans == null)
                            {
                                LogSystem.LogWarning("No RectTransform component found!");
                                return;
                            }
                            boxCollider.size = new Vector3(rectTrans.sizeDelta.x, rectTrans.sizeDelta.y, 0);
                        }
                        foundTextComp = true;
                    }
                }

                if (!foundTextComp)
                {
                    UnityEngine.TextMesh textCompUnity3D = this.transform.GetComponent <UnityEngine.TextMesh>();
                    if (textCompUnity3D)
                    {
                        this.textComp = new TextCompUnity3D(textCompUnity3D);
                        Collider collider = textCompUnity3D.transform.GetComponent <Collider>();
                        if (collider == null)
                        {
                            LogSystem.LogWithHighlight("Text component is missing a collider. Needed for RuntimeTextEdit to work. Added a box collider.", textCompUnity3D);
                            BoxCollider boxCollider = textCompUnity3D.gameObject.AddComponent <BoxCollider>();
                            boxCollider.isTrigger = true;
                        }
                        foundTextComp = true;
                    }
                }

                if (!foundTextComp)
                {
                    LogSystem.LogWithHighlight("Could not find text component in GameObject: " + this, this);
                    return;
                }
            }

            void VerifyTextIsRaycastTarget()
            {
                if (textComp.IsRaycastTarget() == false)
                {
                    LogSystem.LogWithHighlight("Text component on GameObject (" + textComp.GetGameobjectName() + ") is not a raycast target. Clicking on this text component will not trigger RuntimeTextEdit.", this);
                    // @TODO If not a raycast target, register callback on OnArm and OnDisarm that makes it a raycasting target.
                }
            }

            VerifyTextIsRaycastTarget();

            /// Search for script that implements TextEditCallback
            SearchTextEditCallback();
            void SearchTextEditCallback()
            {
                if (textEditCallback == null)
                {
                    textEditCallback = this.gameObject;
                }
            }

            manager.DeactivateMe(this);
        }