Exemple #1
0
        private static TextMeshProUGUI GetTMProText(ReplaceUnit updatedReference, TextInformation textInfo, GameObject root)
        {
            TextMeshProUGUI newText;

            GameObject textParent = FabulousExtensions
                                    .GetGameObjectAtAddress(root, updatedReference.TextAddress);

            Text oldText = textParent.GetComponent <Text>();

            if (oldText != null)
            {
                UnityEngine.Object.DestroyImmediate(oldText, true);
                newText = textParent.AddComponent <TextMeshProUGUI>();
            }
            else
            {
                newText = FabulousExtensions
                          .GetGameObjectAtAddress(root, updatedReference.TextAddress)
                          .GetComponent <TextMeshProUGUI>();
            }

            if (newText == null)
            {
                Debug.LogError($"TMPro text component is null");
            }

            return(newText);
        }
Exemple #2
0
        //
        // ─── TEXT COMPONENT REPLACEMENT ──────────────────────────────────
        //

        #region TEXT COMPONENT REPLACEMENT

        private void ReplaceTextComponent(ReplaceUnit updatedReference)
        {
            TextInformation textInfo = updatedReference.textInformation;

            // * Don't even think of performing below operations on previously saved prefabs loaded into the memory
            // * They are like lost souls that want to trap your innocent code
            // * Whatever you execute on them gets lost in a limbo and flushed down along the garbage collection
            // * If you want to edit a prefab, make sure you just loaded it and you work on a fresh, crunchy instance

            using (var editScope = new EditPrefabAssetScope(updatedReference.prefabPath))
            {
                GameObject      root      = editScope.prefabRoot;
                TextMeshProUGUI tmProText = GetTMProText(updatedReference, textInfo, root);
                textInfo.StyleTMProText(tmProText, _fontAssetMap);

                if (updatedReference.isReferenced)
                {
                    TMProAdapter tmProAdapter = GetTextAdapter(updatedReference, root, tmProText);
                    if (tmProAdapter == null)
                    {
                        return;
                    }
                    AssignTMProReference(updatedReference, tmProAdapter, root);
                }
            }
        }
 private void SaveBaseData(GameObject rootPrefab, Text originalText)
 {
     rootPrefabName           = rootPrefab.gameObject.name;
     prefabPath               = AssetDatabase.GetAssetPath(rootPrefab);
     textInformation          = new TextInformation(originalText);
     this.rootPrefab          = rootPrefab;
     this.originalText        = originalText;
     this.originalTextContent = originalText.text;
     TextAddress              = GetComponentAddressInHierarchy(rootPrefab, originalText);
 }