public void SpawnEnemy(MobileTypes mobileType) { if (DaggerfallUnity.FindDaggerfallUnity(out dfUnity)) { Logger.GetInstance().log("Creating a Daggerfall enemy GameObject.\n", this); tmpEnemy = GameObjectHelper.CreateDaggerfallEnemyGameObject(mobileType, this.transform, MobileReactions.Hostile); if (!tmpEnemy) { return; } GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); GameObject player = GameObject.FindGameObjectWithTag("Player"); //Ray ray = new Ray(mainCamera.transform.position, Quaternion.Euler(45, 0, 0) * mainCamera.transform.forward); Ray ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward); RaycastHit[] hits; hits = Physics.RaycastAll(ray, 100.0f); if (hits != null && hits.Length > 0) { tmpEnemy.transform.position = hits[0].point; tmpEnemy.transform.Translate(new Vector3(0, tmpEnemy.GetComponent <CharacterController>().height / 2 + 1f)); //tmpEnemy.transform.Translate(0, 10f, 0); } else { tmpEnemy.transform.position = player.transform.position; } Logger.GetInstance().log("Created a Daggerfall enemy GameObject.\n", this); } }
public void Die() { if (!mobile) { return; } // Get corpse marker texture indices int archive, record; EnemyBasics.ReverseCorpseTexture(mobile.Summary.Enemy.CorpseTexture, out archive, out record); // Leave corpse marker DaggerfallUnity dfUnity; if (DaggerfallUnity.FindDaggerfallUnity(out dfUnity)) { // Spawn marker GameObject go = GameObjectHelper.CreateDaggerfallBillboardGameObject(archive, record, transform.parent, true); go.transform.position = transform.position; // Align to ground. Be generous with distance as flying enemies might have a way to drop. // This could also be hanlded by adding a Rigidbody and collider then let gravity do the work. GameObjectHelper.AlignBillboardToGround(go, go.GetComponent <DaggerfallBillboard>().Summary.Size, 16f); } // Disable enemy gameobject and schedule for destruction gameObject.SetActive(false); GameObject.Destroy(gameObject); }
public static float GetOriginalTerrainHeight() { DaggerfallUnity dfUnity; DaggerfallUnity.FindDaggerfallUnity(out dfUnity); return(dfUnity.TerrainSampler.MaxTerrainHeight); }
void Awake() { attributes = new Attributes(); _UUID = System.Guid.NewGuid(); // TODO: Sane defaults? creatureType = MobileTypes.Acrobat; behaviour = MobileBehaviour.General; DaggerfallUnity.FindDaggerfallUnity(out dfUnity); //setupMobile(); }
public void ShowBloodSplash(int bloodIndex, Vector3 bloodPosition) { // Create oneshot animated billboard for blood effect DaggerfallUnity dfUnity; if (DaggerfallUnity.FindDaggerfallUnity(out dfUnity)) { GameObject go = GameObjectHelper.CreateDaggerfallBillboardGameObject(bloodArchive, bloodIndex, null, true); go.name = "BloodSplash"; DaggerfallBillboard c = go.GetComponent <DaggerfallBillboard>(); go.transform.position = bloodPosition + transform.forward * 0.02f; c.OneShot = true; c.FramesPerSecond = 10; } }
/// <summary> /// Load constructor. /// </summary> /// <param name="filePath">Absolute path to conf file.</param> /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param> /// <param name="readOnly">File will be read-only if true, read-write if false.</param> public ConfFile(string filePath, FileUsage usage, bool readOnly) { Load(filePath, usage, readOnly); //Writing /*System.Text.StringBuilder sb = new System.Text.StringBuilder(); * sb.AppendLine("name=test"); * System.IO.StreamWriter writer = managedFile.GetStreamWriter(); * writer.Write(sb.ToString()); * writer.Close(); * Logger.GetInstance().log("written"); */ //Reading System.IO.StreamReader reader = managedFile.GetStreamReader(); string line, path; path = ""; string[] id_value = { "", "" }; while ((line = reader.ReadLine()) != null) { id_value = line.Split('='); switch (id_value[0]) { case "path": path = id_value[1].ToString(); DaggerfallUnity dfUnity; if (DaggerfallUnity.FindDaggerfallUnity(out dfUnity)) { dfUnity.Arena2Path = path; } break; } } reader.Close(); Logger.GetInstance().log("read in path=" + path); }
/// <summary> /// Initializes and runs a TerrainComputer GPU job, then processes the generated data. /// </summary> /// <param name="csPrototype"></param> /// <param name="mapData"></param> /// <param name="csParams"></param> public void DispatchAndProcess(ComputeShader csPrototype, ref MapPixelData mapData, TerrainComputerParams csParams) { var woodsFile = DaggerfallUnity.Instance.ContentReader.WoodsFileReader; var cs = UnityEngine.Object.Instantiate(csPrototype); var k = cs.FindKernel("TerrainComputer"); uint _x, _y, _z; cs.GetKernelThreadGroupSizes(k, out _x, out _y, out _z); int res = heightmapResolution + 1; DaggerfallUnity dfUnity; DaggerfallUnity.FindDaggerfallUnity(out dfUnity); int searchSize = 16; var locations = new List <Rect>(); int x, y; for (x = -searchSize; x <= searchSize; x++) { for (y = -searchSize; y <= searchSize; y++) { var mpx = mapData.mapPixelX + x; var mpy = mapData.mapPixelY + y; var key = new DoubleInt() { Item1 = mpx, Item2 = mpy }; if (locationRectCache.ContainsKey(key)) { locations.Add(locationRectCache[key]); continue; } var mapPixelPos = new DFPosition(mpx, mpy); var mapPixelData = TerrainHelper.GetMapPixelData(dfUnity.ContentReader, mpx, mpy); if (!mapPixelData.hasLocation) { continue; } var location = dfUnity.ContentReader.MapFileReader.GetLocation(mapPixelData.mapRegionIndex, mapPixelData.mapLocationIndex); var locationRect = GetLocationRect(location); if (locationRect.width == 0 || locationRect.height == 0) { continue; } locationRect = ExpandInEachDirection(locationRect, 1); locationRectCache.Add(key, locationRect); locations.Add(locationRect); } } x = (int)_x; y = (int)_y; cs.SetVector("terrainPosition", terrainPosition); cs.SetVector("terrainSize", terrainSize); cs.SetInt("heightmapResolution", heightmapResolution); cs.SetVector("locationPosition", locationRect.min); cs.SetVector("locationSize", locationRect.size); cs.SetVectorArray("locationPositions", locations.Select(r => new Vector4(r.min.x, r.min.y)).ToArray()); cs.SetVectorArray("locationSizes", locations.Select(r => new Vector4(r.size.x, r.size.y)).ToArray()); cs.SetInt("locationCount", locations.Count); cs.SetTexture(k, "BiomeMap", InterestingTerrains.biomeMap); cs.SetTexture(k, "DerivMap", InterestingTerrains.derivMap); cs.SetTexture(k, "tileableNoise", InterestingTerrains.tileableNoise); cs.SetFloat("originalHeight", Utility.GetOriginalTerrainHeight()); cs.SetFloat("newHeight", Constants.TERRAIN_HEIGHT); cs.SetTexture(k, "mapPixelHeights", baseHeightmap); cs.SetBuffer(k, "heightmapBuffer", heightmapBuffers.heightmapBuffer); cs.SetBuffer(k, "rawNoise", heightmapBuffers.rawNoise); cs.SetBuffer(k, "locationHeightData", locationHeightData); cs.SetVector("worldSize", Utility.GetWorldVertexSize()); var rd = Compatibility.BasicRoadsUtils.GetRoadData(mapData.mapPixelX, mapData.mapPixelY); cs.SetVectorArray("NW_NE_SW_SE", rd.NW_NE_SW_SE); cs.SetVectorArray("N_E_S_W", rd.N_E_S_W); csParams.ApplyToCS(cs); woodsFile.Buffer = originalHeightmapBuffer; HandleBaseMapSampleParams(ref mapData, ref cs, k); woodsFile.Buffer = alteredHeightmapBuffer; cs.Dispatch(k, res / x, res / y, 1); k = cs.FindKernel("TilemapComputer"); cs.SetTexture(k, "BiomeMap", InterestingTerrains.biomeMap); cs.SetTexture(k, "DerivMap", InterestingTerrains.derivMap); cs.SetBuffer(k, "heightmapBuffer", heightmapBuffers.heightmapBuffer); cs.SetBuffer(k, "tilemapData", heightmapBuffers.tilemapData); cs.SetBuffer(k, "rawNoise", heightmapBuffers.rawNoise); cs.Dispatch(k, res / x, res / y, 1); BufferIO.ProcessBufferValuesAndDispose(heightmapBuffers, ref mapData); }