public static GameObject CreateDaggerfallBlockGameObject(string blockName, Transform parent) { if (string.IsNullOrEmpty(blockName)) { return(null); } blockName = blockName.ToUpper(); GameObject go = null; if (blockName.EndsWith(".RMB")) { go = RMBLayout.CreateGameObject(blockName); } else if (blockName.EndsWith(".RDB")) { go = RDBLayout.CreateGameObject(blockName, false); } else { return(null); } if (parent) { go.transform.parent = parent; } return(go); }
/// <summary> /// Layout a complete RDB block game object. /// </summary> /// <param name="blockName">Name of block to create.</param> /// <param name="textureTable">Optional texture table for dungeon.</param> /// <param name="allowExitDoors">Add exit doors to block (for start blocks).</param> /// <param name="dungeonType">Dungeon type for random encounters.</param> /// <param name="seed">Seed for random encounters.</param> /// <param name="cloneFrom">Clone and build on a prefab object template.</param> public static GameObject CreateRDBBlockGameObject( string blockName, int[] textureTable = null, bool allowExitDoors = true, DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold, float monsterPower = 0.5f, int monsterVariance = 4, int seed = 0, DaggerfallRDBBlock cloneFrom = null) { // Get DaggerfallUnity DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(null); } Dictionary <int, RDBLayout.ActionLink> actionLinkDict = new Dictionary <int, RDBLayout.ActionLink>(); // Create base object DFBlock blockData; GameObject go = RDBLayout.CreateBaseGameObject(blockName, actionLinkDict, out blockData, textureTable, allowExitDoors, cloneFrom); // Add action doors RDBLayout.AddActionDoors(go, actionLinkDict, ref blockData, textureTable); // Add lights RDBLayout.AddLights(go, ref blockData); // Add flats DFBlock.RdbObject[] editorObjects; GameObject[] startMarkers; GameObject[] enterMarkers; RDBLayout.AddFlats(go, actionLinkDict, ref blockData, out editorObjects, out startMarkers, out enterMarkers); // Set start and enter markers DaggerfallRDBBlock dfBlock = go.GetComponent <DaggerfallRDBBlock>(); if (dfBlock != null) { dfBlock.SetMarkers(startMarkers, enterMarkers); } // Add treasure RDBLayout.AddTreasure(go, editorObjects, ref blockData); // Add enemies RDBLayout.AddFixedEnemies(go, editorObjects, ref blockData); RDBLayout.AddRandomEnemies(go, editorObjects, dungeonType, monsterPower, ref blockData, monsterVariance, seed); // Link action nodes RDBLayout.LinkActionNodes(actionLinkDict); return(go); }
/// <summary> /// Creates a new RDB GameObject and performs block layout. /// Can pass information about dungeon for texture swaps and random enemies. /// </summary> /// <param name="dfUnity">DaggerfallUnity singleton. Required for content readers and settings.</param> /// <param name="blockName">Name of RDB block to build.</param> /// <param name="isStartingBlock">True if this is the starting block. Controls exit doors.</param> /// <param name="textureTable">Dungeon texture table.</param> /// <param name="dungeonType">Type of dungeon for random encounter tables.</param> /// <param name="seed">Seed for random encounters.</param> /// <returns>GameObject.</returns> public static GameObject CreateGameObject( string blockName, bool isStartingBlock, int[] textureTable = null, DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold, int seed = 0) { // Validate if (string.IsNullOrEmpty(blockName)) { return(null); } if (!blockName.ToUpper().EndsWith(".RDB")) { return(null); } DaggerfallUnity dfUnity = DaggerfallUnity.Instance; if (!dfUnity.IsReady) { return(null); } // Create gameobject GameObject go = new GameObject(string.Format("DaggerfallBlock [Name={0}]", blockName)); DaggerfallRDBBlock dfBlock = go.AddComponent <DaggerfallRDBBlock>(); // Start new layout RDBLayout layout = new RDBLayout(blockName); layout.isStartingBlock = isStartingBlock; layout.textureTable = textureTable; layout.dungeonType = dungeonType; layout.staticModelsNode = new GameObject("Static Models"); layout.actionModelsNode = new GameObject("Action Models"); layout.doorsNode = new GameObject("Doors"); layout.flatsNode = new GameObject("Flats"); layout.lightsNode = new GameObject("Lights"); layout.enemiesNode = new GameObject("Enemies"); // Parent child game objects layout.staticModelsNode.transform.parent = go.transform; layout.actionModelsNode.transform.parent = go.transform; layout.doorsNode.transform.parent = go.transform; layout.flatsNode.transform.parent = go.transform; layout.lightsNode.transform.parent = go.transform; layout.enemiesNode.transform.parent = go.transform; // List to receive any exit doors found List <StaticDoor> allDoors = new List <StaticDoor>(); // Seed random generator UnityEngine.Random.seed = seed; // Iterate object groups layout.groupIndex = 0; DFBlock blockData = dfUnity.ContentReader.BlockFileReader.GetBlock(blockName); foreach (DFBlock.RdbObjectRoot group in blockData.RdbBlock.ObjectRootList) { // Skip empty object groups if (null == group.RdbObjects) { layout.groupIndex++; continue; } // Iterate objects in this group List <StaticDoor> modelDoors; foreach (DFBlock.RdbObject obj in group.RdbObjects) { // Handle by object type switch (obj.Type) { case DFBlock.RdbResourceTypes.Model: layout.AddRDBModel(obj, out modelDoors, layout.staticModelsNode.transform); if (modelDoors.Count > 0) { allDoors.AddRange(modelDoors); } break; case DFBlock.RdbResourceTypes.Flat: layout.AddRDBFlat(obj, layout.flatsNode.transform); break; case DFBlock.RdbResourceTypes.Light: layout.AddRDBLight(obj, layout.lightsNode.transform); break; default: break; } } // Increment group index layout.groupIndex++; } // Link action nodes layout.LinkActionNodes(); // Combine meshes if (dfUnity.Option_CombineRDB) { layout.combiner.Apply(); GameObject cgo = GameObjectHelper.CreateCombinedMeshGameObject(layout.combiner, "CombinedMeshes", layout.staticModelsNode.transform, dfUnity.Option_SetStaticFlags); cgo.GetComponent <DaggerfallMesh>().SetDungeonTextures(textureTable); } // Fix enemy standing positions for this block // Some enemies are floating in air or sunk into ground // Can only adjust this after geometry instantiated layout.FixEnemyStanding(go); // Store start markers in block dfBlock.SetStartMarkers(layout.startMarkers.ToArray()); // Add doors if (allDoors.Count > 0) { layout.AddDoors(allDoors.ToArray(), go); } return(go); }