/// <summary> /// Creates a generic loot container. /// </summary> /// <param name="containerType">Type of container.</param> /// <param name="containerImage">Icon to display in loot UI.</param> /// <param name="position">Position to spawn container.</param> /// <param name="parent">Parent GameObject.</param> /// <param name="textureArchive">Texture archive for billboard containers.</param> /// <param name="textureRecord">Texture record for billboard containers.</param> /// <param name="loadID">Unique LoadID for save system.</param> /// <returns>DaggerfallLoot.</returns> public static DaggerfallLoot CreateLootContainer( LootContainerTypes containerType, InventoryContainerImages containerImage, Vector3 position, Transform parent, int textureArchive, int textureRecord, ulong loadID = 0) { // Setup initial loot container prefab GameObject go = InstantiatePrefab(DaggerfallUnity.Instance.Option_LootContainerPrefab.gameObject, containerType.ToString(), parent, position); // Setup billboard component DaggerfallBillboard dfBillboard = go.GetComponent <DaggerfallBillboard>(); dfBillboard.SetMaterial(textureArchive, textureRecord); // Setup DaggerfallLoot component to make lootable DaggerfallLoot loot = go.GetComponent <DaggerfallLoot>(); if (loot) { loot.LoadID = loadID; loot.ContainerType = containerType; loot.ContainerImage = containerImage; loot.TextureArchive = textureArchive; loot.TextureRecord = textureRecord; } // Now move up loot icon by half own size so bottom is aligned with position position.y += (dfBillboard.Summary.Size.y / 2f); loot.transform.position = position; return(loot); }
public void RestoreSaveData(object dataIn) { if (!loot) { return; } LootContainerData_v1 data = (LootContainerData_v1)dataIn; if (data.loadID != LoadID) { return; } DaggerfallBillboard billboard = loot.GetComponent <DaggerfallBillboard>(); // Restore position loot.transform.position = data.currentPosition; // Restore appearance if (MeshReplacement.ImportCustomFlatGameobject(data.textureArchive, data.textureRecord, Vector3.zero, loot.transform)) { // Use imported model instead of billboard if (billboard) { Destroy(billboard); } Destroy(GetComponent <MeshRenderer>()); } else if (billboard) { // Restore billboard appearance if present billboard.SetMaterial(data.textureArchive, data.textureRecord); } // Restore items loot.Items.DeserializeItems(data.items); // Restore other data loot.ContainerType = data.containerType; loot.ContainerImage = data.containerImage; loot.LootTableKey = data.lootTableKey; loot.TextureArchive = data.textureArchive; loot.TextureRecord = data.textureRecord; loot.playerOwned = data.playerOwned; loot.customDrop = data.customDrop; loot.name = loot.ContainerType.ToString(); loot.entityName = data.entityName; loot.isEnemyClass = data.isEnemyClass; // Remove loot container if empty if (loot.Items.Count == 0) { GameObjectHelper.RemoveLootContainer(loot); } }
public void RestoreSaveData(object dataIn) { if (!loot) { return; } LootContainerData_v1 data = (LootContainerData_v1)dataIn; if (data.loadID != LoadID) { return; } DaggerfallBillboard billboard = loot.GetComponent <DaggerfallBillboard>(); // Restore position loot.transform.position = data.currentPosition; // Restore billboard appearance if present if (billboard) { billboard.SetMaterial(data.textureArchive, data.textureRecord); // Setup custom material if available if (TextureReplacement.CustomTextureExist(data.textureArchive, data.textureRecord)) { TextureReplacement.SetBillboardCustomMaterial(billboard.gameObject, data.textureArchive, data.textureRecord); } } // Restore items loot.Items.DeserializeItems(data.items); // Restore other data loot.ContainerType = data.containerType; loot.ContainerImage = data.containerImage; loot.LootTableKey = data.lootTableKey; loot.TextureArchive = data.textureArchive; loot.TextureRecord = data.textureRecord; loot.playerOwned = data.playerOwned; loot.customDrop = data.customDrop; loot.name = loot.ContainerType.ToString(); // Remove loot container if empty if (loot.Items.Count == 0) { GameObjectHelper.RemoveLootContainer(loot); } }
public static GameObject CreateDaggerfallBillboardGameObject(int archive, int record, Transform parent, bool dungeon = false) { GameObject go = new GameObject(string.Format("DaggerfallBillboard [TEXTURE.{0:000}, Index={1}]", archive, record)); if (parent) { go.transform.parent = parent; } DaggerfallBillboard dfBillboard = go.AddComponent <DaggerfallBillboard>(); dfBillboard.SetMaterial(archive, record, 0, dungeon); return(go); }
public static GameObject CreateDaggerfallBillboardGameObject(int archive, int record, Transform parent) { GameObject go = new GameObject(string.Format("DaggerfallBillboard [TEXTURE.{0:000}, Index={1}]", archive, record)); if (parent) { go.transform.parent = parent; } DaggerfallBillboard dfBillboard = go.AddComponent <DaggerfallBillboard>(); dfBillboard.SetMaterial(archive, record); // Import custom texture(s) if (AssetInjection.TextureReplacement.CustomTextureExist(archive, record)) { AssetInjection.TextureReplacement.SetBillboardCustomMaterial(go, archive, record); } return(go); }
public void RestoreSaveData(object dataIn) { if (!loot) { return; } LootContainerData_v1 data = (LootContainerData_v1)dataIn; if (data.loadID != LoadID) { return; } // Restore billboard only if this is a billboard-based loot container if (loot.ContainerType == LootContainerTypes.RandomTreasure || loot.ContainerType == LootContainerTypes.CorpseMarker || loot.ContainerType == LootContainerTypes.DroppedLoot) { DaggerfallBillboard billboard = loot.GetComponent <DaggerfallBillboard>(); // Interiors and exteriors need special handling to ensure loot is always placed correctly for pre and post floating y saves // Dungeons are not involved with floating y and don't need any changes WorldContext lootContext = GetLootWorldContext(loot); if (lootContext == WorldContext.Interior) { RestoreInteriorPositionHandler(loot, data, lootContext); } else if (lootContext == WorldContext.Exterior) { RestoreExteriorPositionHandler(loot, data, lootContext); } else { loot.transform.position = data.currentPosition; } // Restore appearance if (MeshReplacement.SwapCustomFlatGameobject(data.textureArchive, data.textureRecord, loot.transform, Vector3.zero, lootContext == WorldContext.Dungeon)) { // Use imported model instead of billboard if (billboard) { Destroy(billboard); } Destroy(GetComponent <MeshRenderer>()); } else if (billboard) { // Restore billboard appearance if present billboard.SetMaterial(data.textureArchive, data.textureRecord); } } // Restore items loot.Items.DeserializeItems(data.items); // Restore other data loot.ContainerType = data.containerType; loot.ContainerImage = data.containerImage; loot.TextureArchive = data.textureArchive; loot.TextureRecord = data.textureRecord; loot.stockedDate = data.stockedDate; loot.playerOwned = data.playerOwned; loot.customDrop = data.customDrop; loot.entityName = data.entityName; loot.isEnemyClass = data.isEnemyClass; // Remove loot container if empty if (loot.Items.Count == 0) { GameObjectHelper.RemoveLootContainer(loot); } }