Esempio n. 1
0
        private static void ChangePrefabs()
        {
            foreach (var pair in modExistingEntries)
            {
                GameObject item = Resources.Load(pair.Key).TryCast <GameObject>();
                if (item is null)
                {
                    continue;
                }

                ModExistingEntry entry = pair.Value;
                if (entry.changeWeight)
                {
                    ChangeWeight(item, entry.newWeight);
                }
                if (entry.behaviourChanges.Count > 0)
                {
                    ProxyObject dict = JSON.Load(JSON.Dump(entry.behaviourChanges)) as ProxyObject;
                    ComponentJson.InitializeComponents(ref item, dict);
                    if (ComponentUtils.GetComponent <ModComponent>(item) is null)
                    {
                        var placeholder = item.AddComponent <ModPlaceHolderComponent>();
                        Mapper.Map(item);
                        UnityEngine.Object.Destroy(placeholder);
                    }
                    else
                    {
                        Mapper.Map(item);
                    }
                }
            }
        }
Esempio n. 2
0
        private static void ChangeGameObject(GameObject item)
        {
            if (item is null)
            {
                return;
            }
            string name = NameUtils.NormalizeName(item.name);

            if (!modExistingEntries.ContainsKey(name))
            {
                return;
            }
            ModExistingEntry entry = modExistingEntries[name];

            if (entry.changeWeight)
            {
                ChangeWeight(item, entry.newWeight);
            }
            if (entry.behaviourChanges.Count > 0)
            {
                ProxyObject dict = JSON.Load(JSON.Dump(entry.behaviourChanges)) as ProxyObject;
                ComponentJson.InitializeComponents(ref item, dict);
                if (ComponentUtils.GetComponent <ModComponent>(item) is null)
                {
                    var placeholder = item.AddComponent <ModPlaceHolderComponent>();
                    Mapper.Map(item);
                    UnityEngine.Object.Destroy(placeholder);
                }
                else
                {
                    Mapper.Map(item);
                }
            }
        }
Esempio n. 3
0
        internal static void MapModComponent(GameObject prefab)
        {
            if (prefab is null)
            {
                throw new System.ArgumentNullException("Prefab was null in AutoMapper.MapModComponent");
            }

            ComponentJson.InitializeComponents(ref prefab);
            ModComponent modComponent = ModComponentUtils.ComponentUtils.GetModComponent(prefab);

            if (modComponent is null)
            {
                throw new System.NullReferenceException("In AutoMapper.MapModComponent, the mod component from the prefab was null.");
            }

            Logger.Log("Mapping {0}", prefab.name);
            Mapper.Map(prefab);
        }