/*===============*\ |* Utilities *| \*===============*/ public void Die() { // chance to spawn a modification float r = Random.value; if (r <= dropChance) { ModPrefab prefab = ModGenerator.Instance.GetRandomPrefab(); prefab.transform.position = this.transform.position; prefab.gameObject.SetActive(true); } // Add points // --------- WaveController.Instance.AddEnemyKillScore(); // Create on Death Effect // ---------------------- GameObject temp = Instantiate(onDeathEffect, transform.position, onDeathEffect.transform.rotation); // Destroy on Death Effect after 4 secs // ------------------------------------ Destroy(temp, 4); // Destory this // ------------ onDie.Invoke(); Destroy(gameObject); }
[HarmonyPatch(typeof(PrefabDatabase), "GetPrefabForFilename")] // method can be absent internal static bool GetPrefabForFilename_Prefix(string filename, ref GameObject __result) { if (!ModPrefab.TryGetFromFileName(filename, out ModPrefab prefab)) { return(true); } __result = prefab.GetGameObjectInternal(); return(false); }
internal static bool Prefix(ref UnityEngine.Object __result, string path) { if (ModPrefab.TryGetFromFileName(path, out ModPrefab prefab)) { __result = prefab.GetGameObject(); return(false); } return(true); }
public ModPrefab GetRandomPrefab() { ModDrop drop = drops[Random.Range(0, drops.Length)]; ModPrefab prefab = Instantiate(basePrefab, transform); Modification mod = GetModification(drop.typ); mod.SetPlayerMod(drop.playerMod); prefab.InitPrefab(drop.icon, mod); return(prefab); }
internal static bool DeferredSpawner_AddressablesTask_Spawn_Prefix(DeferredSpawner.AddressablesTask __instance, ref IEnumerator __result) { if (!ModPrefab.TryGetFromFileName(__instance.key, out ModPrefab prefab)) { return(true); } __result = SpawnAsyncReplacement(__instance, prefab); return(false); }
internal static bool TryGetPrefabFilename_Prefix(string classId, ref string filename, ref bool __result) { if (!ModPrefab.TryGetFromClassId(classId, out ModPrefab prefab)) { return(true); } filename = prefab.PrefabFileName; __result = true; return(false); }
/*============*\ |* Events *| \*============*/ private void OnTriggerEnter(Collider other) { if (other.CompareTag("Modification")) { ModPrefab prefab = other.gameObject.GetComponent <ModPrefab>(); if (inventory.InsertModification(prefab.GetMod(), prefab.GetIcon())) { Destroy(other.gameObject); } } }
internal static bool GetPrefabAsync_Prefix(ref IPrefabRequest __result, string classId) { if (ModPrefab.TryGetFromClassId(classId, out ModPrefab prefab)) { GameObject go = prefab.GetGameObjectInternal(); __result = new LoadedPrefabRequest(go); return(false); } return(true); }
/// <summary> /// Registers a ModPrefab into the game. /// </summary> /// <param name="prefab">The mod prefab to register. Create a child class inheriting off this one and configure as needed.</param> /// <seealso cref="ModPrefab"/> void IPrefabHandler.RegisterPrefab(ModPrefab prefab) { foreach (ModPrefab modPrefab in ModPrefab.Prefabs) { if (modPrefab.TechType == prefab.TechType || modPrefab.ClassID == prefab.ClassID || modPrefab.PrefabFileName == prefab.PrefabFileName) { return; } } ModPrefab.Add(prefab); }
internal static bool Prefix_Async(ref UnityEngine.ResourceRequest __result, string path) { if (ModPrefab.TryGetFromFileName(path, out ModPrefab prefab)) { __result = new UnityEngine.ResourceRequest(); AssetsInfo.SetValue(__result, prefab.GetGameObject(), null); MPathInfo.SetValue(__result, path); MTypeInfo.SetValue(__result, prefab.GetGameObject().GetType()); return(false); } return(true); }
private static IPrefabRequest GetModPrefabAsync(string classId) { if (!ModPrefab.TryGetFromClassId(classId, out ModPrefab prefab)) { return(null); } try { // trying sync method first if (prefab.GetGameObjectInternal() is GameObject go) { return(new LoadedPrefabRequest(go)); } } catch (Exception e) { Logger.Debug($"Caught exception while calling GetGameObject for {classId}, trying GetGameObjectAsync now. {Environment.NewLine}{e}"); } return(new ModPrefabRequest(prefab)); }
/// <summary> /// Registers a ModPrefab into the game. /// </summary> /// <param name="prefab">The mod prefab to register. Create a child class inheriting off this one and configure as needed.</param> /// <seealso cref="ModPrefab"/> public static void RegisterPrefab(ModPrefab prefab) { Main.RegisterPrefab(prefab); }
/// <summary> /// Adds in a custom entry into the Loot Distribution of the game. /// You must also add the <see cref="WorldEntityInfo"/> into the <see cref="WorldEntityDatabase"/> using <see cref="WorldEntityDatabaseHandler"/>. /// </summary> /// <param name="prefab">The custom prefab which you want to spawn naturally in the game.</param> /// <param name="biomeDistribution">The <see cref="LootDistributionData.BiomeData"/> dictating how the prefab should spawn in the world.</param> /// <param name="info">The WorldEntityInfo of the prefab. For more information on how to set this up, see <see cref="WorldEntityDatabaseHandler"/>.</param> public static void AddLootDistributionData(ModPrefab prefab, IEnumerable <LootDistributionData.BiomeData> biomeDistribution, WorldEntityInfo info) { Main.AddLootDistributionData(prefab, biomeDistribution, info); }
/// <summary> /// Adds in a custom entry into the Loot Distribution of the game. /// </summary> /// <param name="prefab">The custom prefab which you want to spawn naturally in the game.</param> /// <param name="biomeDistribution">The <see cref="LootDistributionData.BiomeData"/> dictating how the prefab should spawn in the world.</param> /// <param name="info">The WorldEntityInfo of the prefab. For more information on how to set this up, see <see cref="WorldEntityDatabaseHandler"/>.</param> void ILootDistributionHandler.AddLootDistributionData(ModPrefab prefab, IEnumerable <LootDistributionData.BiomeData> biomeDistribution, WorldEntityInfo info) { Main.AddLootDistributionData(prefab.ClassID, prefab.PrefabFileName, biomeDistribution); WorldEntityDatabaseHandler.AddCustomInfo(prefab.ClassID, info); }
internal static IEnumerator SpawnAsyncReplacement(DeferredSpawner.AddressablesTask task, ModPrefab modPrefab) { TaskResult <GameObject> prefabResult = new TaskResult <GameObject>(); yield return(modPrefab.GetGameObjectInternalAsync(prefabResult)); GameObject prefab = prefabResult.Get(); if (prefab != null) { task.spawnedObject = UnityEngine.Object.Instantiate <GameObject>(prefab, task.parent, task.position, task.rotation, task.instantiateActivated); } if (task.spawnedObject == null) { task.forceCancelled = true; } task.HandleLateCancelledSpawn(); yield break; }
internal static void Patch() { customPrefabs.ForEach(x => ModPrefab.Add(new WrapperPrefab(x))); }