public bool Triggerhazard() { List <ForestTree> burnableTrees = new List <ForestTree>(); List <ForestTree> treesToBurn = new List <ForestTree>(); Debug.Log("Entree dans Fire()"); foreach (GameObject o in GameObject.FindGameObjectsWithTag("Tree")) { ForestTree t = o.GetComponent <ForestTree>(); if (t.IsBurnable()) { burnableTrees.Add(t); if (Random.Range(0, 100) <= 25) { treesToBurn.Add(t); } } } if (burnableTrees.Count >= 1 && treesToBurn.Count == 0) { treesToBurn.Add(burnableTrees[Random.Range(0, burnableTrees.Count)]); } if (treesToBurn.Count > 0) { HazardAnimationFire.instance.Trigger(treesToBurn); return(true); } else { return(false); } }
public bool Triggerhazard() { List <ForestTree> drownableTrees = new List <ForestTree>(); List <ForestTree> burnableTrees = new List <ForestTree>(); Debug.Log("Entree dans Tempest()"); foreach (GameObject o in GameObject.FindGameObjectsWithTag("Tree")) { ForestTree t = o.GetComponent <ForestTree>(); if (t.IsDrownable()) { drownableTrees.Add(t); } if (t.IsBurnable()) { burnableTrees.Add(t); } } if (drownableTrees.Count > 0) { HazardAnimationTempest.instance.Trigger(drownableTrees, burnableTrees); return(true); } else { return(false); } }
/// <summary> /// Destroys a Tree, if there is no more trees destroys itself. /// </summary> /// <param name="tree"></param> public void removeTree(ForestTree tree) { Trees.Remove(tree); if (Trees.Count <= 0) { destroySelf(); } }
public bool Triggerhazard() { List <ForestTree> seedTrees = new List <ForestTree>(); foreach (GameObject o in GameObject.FindGameObjectsWithTag("Tree")) { ForestTree t = o.GetComponent <ForestTree>(); if (t.HasSeed() || t.IsPlant()) { seedTrees.Add(t); } } if (seedTrees.Count > 0) { HazardAnimationTornado.instance.Trigger(seedTrees); return(true); } else { return(false); } }
public static void SpreadFire(ForestTree forestTree) { }
public static void StartFire(ForestTree forestTree) { }
public void GenerateMap() { treesOnTheScene.Clear(); treesOnFire.Clear(); foreach (Transform child in TreesParent.transform) { DestroyImmediate(child.gameObject); } MapDisplay display = FindObjectOfType <MapDisplay>(); float[,] heightMap = DecodeFloatTexture(terrainMap); float[,] roadMask = DecodeFloatTexture(roadMap); display.DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap, roadMask, passes, level), terrainMap); List <Temp> result = ForestGenerator.GenerateTreeLocations(percentage, heightMap, trees.Length); GameObject[] temps = new GameObject[trees.Length]; for (int i = 0; i < trees.Length; i++) { temps[i] = Instantiate(trees[i], Vector3.zero, Quaternion.identity, TreesParent.transform); } for (int i = 0; i < result.Count; i++) { Temp temp = result[i]; if (roadMask[(int)temp.pos.x, (int)temp.pos.z] > .5f) { continue; } GameObject parent = Instantiate(emptyGameObjectPrefab, temp.pos, Quaternion.identity, TreesParent.transform); bool next = false; MeshData meshData = MeshGenerator.CombineMeshData( temps[temp.type].GetComponent <MeshFilter>().mesh, trees[temp.type].GetComponent <MeshFilter>().sharedMesh, temp.pos, trees[temp.type].transform.localScale, out next ); temps[temp.type].GetComponent <MeshFilter>().mesh = meshData.CreateMesh(); meshData = null; if (next) { Debug.Log("Next"); temps[temp.type] = Instantiate(trees[temp.type], Vector3.zero, Quaternion.identity, TreesParent.transform); } GameObject burntIcon = Instantiate(burntIconPrefab.gameObject, parent.transform); GameObject fire = Instantiate(firePrefab.gameObject, parent.transform); ForestTree forestTree = new ForestTree(burntIcon, fire, BurnTime, SpreadSpeed); treesOnTheScene.Add(forestTree); } foreach (ForestTree forestTree in treesOnTheScene) { foreach (ForestTree otherForestTree in treesOnTheScene) { if (forestTree == otherForestTree) { continue; } float dist = Vector3.Distance(otherForestTree.burntIcon.transform.position, forestTree.burntIcon.gameObject.transform.position); if (dist < MaxDistanceToSpreadFire) { forestTree.closestTrees.Add(otherForestTree); } } } }