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
        private static object GetFieldOwner(ReplaceUnit replaceUnit, GameObject root)
        {
            object           fieldOwner       = null;
            FieldInformation fieldInformation = replaceUnit.fieldInformation;

            Type monoType = fieldInformation.FieldOwnerType;

            Component mono = FabulousExtensions
                             .GetGameObjectAtAddress(root, replaceUnit.MonoAddress)
                             .GetComponent(monoType);

            if (mono == null)
            {
                throw new NullReferenceException($"Failed to find mono {monoType} for field {fieldInformation.FieldName} and type {fieldInformation.FieldType} by its address for prefab: {root} at path {replaceUnit.prefabPath} and address {string.Join(",", replaceUnit.MonoAddress.ToArray())}");
            }

            if (fieldInformation.FieldType.HasOneOfTheFlags(FieldType.Nested | FieldType.External))
            {
                ExternallyOwnedFieldInformation eofi = fieldInformation.GetFieldInformationParamter <ExternallyOwnedFieldInformation>();

                FieldInfo externalObjectFieldInfo = monoType.GetField(eofi.ExternalOwnerFieldName, ReferenceFinder.GENEROUS_NONSTATIC_FIELD_SEARCH_FLAGS);

                if (eofi.fieldInformation.FieldType.HasOneOfTheFlags(FieldType.Arrayed | FieldType.Listed))
                {
                    var         efi = eofi.fieldInformation.GetFieldInformationParamter <EnumerableFieldInformation>();
                    IEnumerable enumberableOwner = (IEnumerable)externalObjectFieldInfo.GetValue(mono);

                    int index = 0;
                    foreach (var item in enumberableOwner)
                    {
                        if (index == efi.index)
                        {
                            fieldOwner = item;
                        }
                        index++;
                    }
                }
                else
                {
                    fieldOwner = externalObjectFieldInfo.GetValue(mono);
                }
            }
            else
            {
                fieldOwner = mono;
            }

            return(fieldOwner);
        }