Beispiel #1
0
 public virtual Preset GetPresetOfInternalComp()
 {
     LogSystem.LogWarning("Called GetPresetOfInternalComp() on subclass that does not support it.");
     return(null);
 }
Beispiel #2
0
        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);
        }