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); } } } }
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); } } }
private static void ProcessFile(string filePath, string fileText) { if (string.IsNullOrEmpty(fileText)) { return; } ProxyObject dict = JSON.Load(fileText) as ProxyObject; if (!JsonUtils.ContainsKey(dict, "GearName")) { PageManager.SetItemPackNotWorking(filePath, "The JSON file doesn't contain the key: 'GearName'"); return; } string gearName = dict["GearName"]; ModExistingEntry modExistingEntry; if (modExistingEntries.ContainsKey(gearName)) { modExistingEntry = modExistingEntries[gearName]; } else { modExistingEntry = new ModExistingEntry(); modExistingEntries.Add(gearName, modExistingEntry); } foreach (var pair in dict) { if (pair.Key == "GearName") { continue; } else if (pair.Key == "WeightKG") { modExistingEntry.SetWeightChange(pair.Value); } else { ProxyObject data = (ProxyObject)pair.Value; if (modExistingEntry.behaviourChanges.ContainsKey(pair.Key)) { modExistingEntry.behaviourChanges[pair.Key] = data; } else { modExistingEntry.behaviourChanges.Add(pair.Key, data); } } } }