Пример #1
0
        public static ResolvedReplacer GetReplacer(IFieldReplacer replacer)
        {
            if (replacers.TryGetValue(replacer, out var resolved))
            {
                return(resolved);
            }
            var newreplacer = ResolvedReplacer.Resolve(replacer);

            replacers.Add(replacer, newreplacer);
            return(newreplacer);
        }
Пример #2
0
        static void FixPrefabFieldsInternal(GameObject prefab, IFieldReplacer replacementInfo)
        {
            var replacer = ReplacerCache.GetReplacer(replacementInfo);

            var components = replacementInfo.ReplaceInChildren? prefab.GetComponentsInChildren <Component>(true):prefab.GetComponents <Component>();

            foreach (var comp in components)
            {
                if (!comp)
                {
                    continue;
                }
                foreach (var field in replacer.FieldToField.Where((x) => x.Value.DeclaringType == comp.GetType()))
                {
                    field.Value.SetValue(comp, field.Key.GetValue((replacer.InstanceInfo.Instance as GameObject).GetComponentInChildren(comp.GetType())));
                }
            }
        }
Пример #3
0
        public static ResolvedReplacer Resolve(IFieldReplacer replacer)
        {
            ResolvedReplacer rep = new ResolvedReplacer();

            rep.InstanceInfo = ResolvedInstance.Resolve(replacer.InstanceInfo);
            if (replacer.FieldReplacements == null)
            {
                throw new Exception("No replacements found!");
            }
            foreach (var v in replacer.FieldReplacements)
            {
                if (!v.TryResolveTarget(out var field1) || !v.TryResolveSource(out var field2))
                {
                    throw new Exception($"Unable to resolve field!");
                }
                rep.FieldToField.Add(field1, field2);
            }

            return(rep);
        }
Пример #4
0
 public static void FixPrefabFields(GameObject prefab, IFieldReplacer replacer)
 {
     replacers.Add(new KeyValuePair <GameObject, IFieldReplacer>(prefab, replacer));
 }