コード例 #1
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
        public void OnInputFieldEditExit(string newText)
        {
            // LogSystem.Log("OnInputFieldEditExit(string newText) with text: " + newText);

            textComp.OnLeaveEditMode();
            textComp.SetText(newText);
            inputField.Remove();
            inputField = null;

            TextEditCallback persistTextCallback = textEditCallback.transform.GetComponent(typeof(RuntimeTextEdit.TextEditCallback)) as TextEditCallback;

            if (persistTextCallback != null)
            {
                persistTextCallback.PersistText(newText, textComp.GetID());
            }
            else
            {
                LogSystem.LogWithHighlight("Searched for implementation of interface TextEditCallback on GameObject (" + textEditCallback.name + ") but failed to find it. Could not call PersistText(...). Set inspector property TextEditCallback in RuntimeTextEdit.", this);
            }

            onLeaveEditMode.Invoke();

            this.isInEditMode = false;
            RuntimeTextEdit.oneInstanceInEditMode = false;
            manager.DeactivateMe(this);
        }
コード例 #2
0
ファイル: RuntimeTextEdit.cs プロジェクト: Karim315/Game-it
 void Update()
 {
     if (this.isInEditMode)
     {
         if (this.inputField == null || this.textComp == null)
         {
             return;
         }
         if (this.inputField.GetText() != this.textComp.GetText())
         {
             LogSystem.LogWithHighlight("Text components text does not match input fields text. Maybe some other component changed the text component in its Update() method.", this);
         }
     }
 }
コード例 #3
0
        public void Start()
        {
            if (Camera.main.GetComponent <Physics2DRaycaster>())
            {
                LogSystem.LogWithHighlight("Detected component Physics2DRaycaster on main camera. 3D text will not be clickable. Replace with PhysicsRaycaster.", Camera.main);
            }

            // This will detect both PhysicsRaycaster and Physics2DRaycaster
            if (Camera.main.GetComponent <PhysicsRaycaster>() == null)
            {
                string logMessage = "Could not find PhysicsRaycaster component on main camera. ";
                if (addMissingPhysicsRaycaster)
                {
                    Camera.main.gameObject.AddComponent <PhysicsRaycaster>();
                    logMessage += "Added missing physics raycaster component to main camera. ";
                }
                else
                {
                    logMessage += "Please add one.";
                }

                LogSystem.LogWithHighlight(logMessage, Camera.main);
            }
        }
コード例 #4
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);
        }