///------------------------------------------------------------------------------------------------- /// <summary> Creates a station. </summary> /// /// <remarks> MelodicAlbuild, 3/8/2021. </remarks> /// /// <param name="factoryType"> Type of the factory. </param> /// <param name="codename"> The codename. </param> /// <param name="maxStack"> Max Stack Size of this Item. </param> /// <param name="name"> The name. </param> /// <param name="desc"> The description. </param> /// <param name="guidString"> The unique identifier string. </param> /// <param name="icon"> The icon. </param> /// <param name="variantname"> The variantname. </param> /// <param name="categories"> The categories. </param> ///------------------------------------------------------------------------------------------------- public static void CreateStation(FactoryType factoryType, string codename, int maxStack, LocalizedString name, LocalizedString desc, string guidString, Sprite icon, string variantname, RecipeCategory[] categories) { var category = GameResources.Instance.Items.FirstOrDefault(s => s.AssetId == productionStationGUID)?.Category; var item = ScriptableObject.CreateInstance <ItemDefinition>(); if (item == null) { Debug.Log("Item is null"); return; } if (category == null) { Debug.Log("Category is null"); return; } item.name = codename; item.Category = category; item.MaxStack = maxStack; item.Icon = icon; var prefabParent = new GameObject(); var olditem = GameResources.Instance.Items.FirstOrDefault(s => s.AssetId == productionStationGUID); prefabParent.SetActive(false); var newmodule = UnityEngine.Object.Instantiate(olditem.Prefabs[0], prefabParent.transform); var module = newmodule.GetComponentInChildren <FactoryStation>(); var producer = newmodule.GetComponentInChildren <Producer>(); newmodule.SetName("AlloyForgeStation"); var gridmodule = newmodule.GetComponent <GridModule>(); gridmodule.VariantName = variantname; gridmodule.Item = item; var productionGroup = Typings.GetOrCreateTyping(factoryType); LocalizedString nameStr = name; LocalizedString descStr = desc; Initialize(ref nameStr); Initialize(ref descStr); item.SetPrivateField("m_name", nameStr); item.SetPrivateField("m_description", descStr); typeof(FactoryStation).GetField("m_factoryType", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, factoryType); typeof(FactoryStation).GetField("m_productionGroup", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, productionGroup); typeof(Producer).GetField("m_categories", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(producer, categories); var guid = GUID.Parse(guidString); typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, guid); item.Prefabs = new GameObject[] { newmodule }; AssetReference[] assets = new AssetReference[] { new AssetReference() { Object = item, Guid = guid, Labels = new string[0] } }; RuntimeAssetStorage.Add(assets, default); }
///------------------------------------------------------------------------------------------------- /// <summary> Creates production module. </summary> /// /// <remarks> MelodicAlbuild, 3/8/2021. </remarks> /// /// <param name="codename"> The codename. </param> /// <param name="variantname"> The variantname. </param> /// <param name="maxstack"> The maxstack. </param> /// <param name="baseitem"> The baseitem. </param> /// <param name="name"> The name. </param> /// <param name="desc"> The description. </param> /// <param name="guidstring"> The guidstring. </param> /// <param name="categoryname"> The categoryname. </param> /// <param name="factorytypename"> The factorytypename. </param> /// <param name="icon"> The icon. </param> /// <param name="categories"> The categories. </param> ///------------------------------------------------------------------------------------------------- public static void CreateProductionModule(string codename, string variantname, int maxstack, string baseitem, LocalizedString name, LocalizedString desc, string guidstring, string categoryname, string factorytypename, Sprite icon, RecipeCategory[] categories) { var category = GameResources.Instance.Items.FirstOrDefault(s => s.name == categoryname).Category; var item = ScriptableObject.CreateInstance <ItemDefinition>(); item.name = codename; item.Category = category; item.MaxStack = maxstack; item.Icon = icon; var prefabParent = new GameObject(); var olditem = GameResources.Instance.Items.FirstOrDefault(s => s.name == baseitem); var factorytype = GameResources.Instance.FactoryTypes.FirstOrDefault(s => s.name == factorytypename); prefabParent.SetActive(false); var newmodule = Object.Instantiate(olditem.Prefabs[0], prefabParent.transform); var module = newmodule.GetComponentInChildren <ProductionModule>(); var gridmodule = newmodule.GetComponent <GridModule>(); gridmodule.VariantName = variantname; gridmodule.Item = item; newmodule.name = codename; item.Prefabs = new GameObject[] { newmodule }; var modulecategory = RuntimeAssetCacheLookup.Get <ModuleCategory>().First(s => s.name == factorytypename); modulecategory.Modules = modulecategory.Modules.Concat(new ItemDefinition[] { item }).ToArray(); var productionGroup = Typings.GetOrCreateTyping(factorytype); LocalizedString nameStr = name; LocalizedString descStr = desc; Initialize(ref nameStr); Initialize(ref descStr); typeof(ProductionModule).GetField("m_factoryType", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, factorytype); typeof(ProductionModule).GetField("m_module", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, gridmodule); typeof(ProductionModule).GetField("m_categories", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, categories); typeof(ProductionModule).GetField("m_productionGroup", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(module, productionGroup); typeof(ItemDefinition).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, nameStr); typeof(ItemDefinition).GetField("m_description", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, descStr); var guid = GUID.Parse(guidstring); typeof(Definition).GetField("m_assetId", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(item, guid); AssetReference[] assets = new AssetReference[] { new AssetReference() { Object = item, Guid = guid, Labels = new string[0] } }; RuntimeAssetStorage.Add(assets, default); }