public void MovementPhase(GameObject target) { SkipperVar = target; CP.Clear(); moving = true; gameObject.GetComponent <UnitAttributes>().FuelPool -= target.GetComponent <TerrainProperty>().distance; if (GameManager.Opt_SkipMoveAnim) { Debug.Log("Skipping Move Anim"); transform.position = target.transform.position; transform.position += Vector3.up; } else { Debug.Log("Using Move Anim"); //Systems Control GameManager.Playing_MoveAnim = true; GameManager.FreezeClicks = true; TerrainProperty terrain = target.GetComponent <TerrainProperty>(); while (terrain != null) { CP.Push(terrain); terrain = terrain.parent; } } }
public void Cast_Movement() { FindMoveConnect(); GetCoordinate(); Queue <TerrainProperty> queue = new Queue <TerrainProperty>(); queue.Enqueue(SitCoordinate); SitCoordinate.isAccounted = true; while (queue.Count > 0) { TerrainProperty terrain = queue.Dequeue(); ValidSpace.Add(terrain); terrain.isValid = true; if (terrain.distance < gameObject.GetComponent <UnitAttributes>().Movement) { foreach (TerrainProperty item in terrain.MovementTileLinks) { if (!item.isAccounted) { item.parent = terrain; item.isAccounted = true; item.distance = item.TCost(gameObject.GetComponent <UnitAttributes>().UnitType) + terrain.distance; if (item.distance <= gameObject.GetComponent <UnitAttributes>().FuelPool) { queue.Enqueue(item); } } } } } }
public bool SetFire(Loc pos) { int index = ToIndex(pos); if (Fires.TryGetValue(index, out _)) { return(false); } Tile tile = Field[pos]; if (tile.IsWall) { return(false); } TerrainProperty terrain = tile.Type.ToProperty(); if (Game.Random.NextDouble() < terrain.Flammability.ToIgniteChance()) { Fire fire = new Fire(pos); Fires.Add(index, fire); Game.EventScheduler.AddActor(fire); return(true); } else { return(false); } }
public void CapturedTilesRemove(TerrainProperty terrain) { if (TerrainList.Contains(terrain)) { TerrainList.Remove(terrain); } }
public void MovementConnections(Vector3 Axis, GameObject Searcher) { Vector3 halfExtents = new Vector3(0.25f, 0.25f, 0.25f); Collider[] colliders = Physics.OverlapBox(transform.position + Axis, halfExtents); foreach (Collider item in colliders) { TerrainProperty terrain = item.GetComponent <TerrainProperty>(); if (terrain != null && !terrain.isOccupied) { RaycastHit hit; if (!Physics.Raycast(terrain.transform.position, Vector3.up, out hit, 1)) { MovementTileLinks.Add(terrain); } else { if (hit.collider.tag == Searcher.tag) { MovementTileLinks.Add(terrain); } } } } }
public void Action_Defend() { gameObject.GetComponent <UnitAttributes>().isDefending = true; RaycastHit hit; if (Physics.Raycast(this.transform.position, Vector3.down * 10, out hit, 10)) { if (hit.collider.GetComponent <TerrainProperty>() != null) { TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>(); if (terrain.isCapturable) { if (!terrain.isCaptured || terrain.Heldby != gameObject.tag) { terrain.CapturePower += this.GetComponent <UnitAttributes>().HealthPool; if (terrain.CapturePower >= 200) { terrain.isCaptured = true; terrain.Heldby = this.tag; terrain.CaptureCall(gameObject.GetComponent <UnitAttributes>().FactionSided.GetComponent <Faction>()); } } } } } EndPhase(); }
public void CapturedTilesAdd(TerrainProperty terrain) { if (!TerrainList.Contains(terrain)) { if (terrain.isCapturable) { TerrainList.Add(terrain); } } }
public void Cast_AttackTiles() { if (gameObject.GetComponent <UnitAttributes>().LoS) { foreach (GameObject item in Coordinates) { item.GetComponent <TerrainProperty>().Reset(); } GetCoordinate(); SitCoordinate.LoSAttackGrid(gameObject, Vector3.forward, gameObject.GetComponent <UnitAttributes>().Range + 1); SitCoordinate.LoSAttackGrid(gameObject, Vector3.right, gameObject.GetComponent <UnitAttributes>().Range + 1); SitCoordinate.LoSAttackGrid(gameObject, Vector3.back, gameObject.GetComponent <UnitAttributes>().Range + 1); SitCoordinate.LoSAttackGrid(gameObject, Vector3.left, gameObject.GetComponent <UnitAttributes>().Range + 1); } else { foreach (GameObject item in Coordinates) { item.GetComponent <TerrainProperty>().ViableTargetGrid(gameObject); } GetCoordinate(); //Pulls current position Queue <TerrainProperty> queue = new Queue <TerrainProperty>(); //Assigns a queue order to create an area check queue.Enqueue(SitCoordinate); //Assigns the current position SitCoordinate.isAccounted = true; //to be ignored during grid check as it's already assigned while (queue.Count > 0) { TerrainProperty terrain = queue.Dequeue();//Assigns it already ValidSpace.Add(terrain); terrain.isValid = true; if (terrain.Range < gameObject.GetComponent <UnitAttributes>().Range) { //Pulls each connected tile into a loop that will then assign them within the queue //This creates a loop that will run until the all connected tiles are no longer in range foreach (TerrainProperty item in terrain.AttackRangeList) { if (!item.isAccounted) { item.parent = terrain; item.isAccounted = true; item.Range = terrain.Range + 1; if (item.Range <= gameObject.GetComponent <UnitAttributes>().Range) { queue.Enqueue(item); } } } } } } }
public TerrainProperty Destination(GameObject Destination) { RaycastHit hit; TerrainProperty coordinate = null; //Debug.DrawRay(Destination.transform.position, Vector3.down, Color.red, 1); if (Physics.Raycast(Destination.transform.position, Vector3.down, out hit, 1)) { coordinate = hit.collider.GetComponent <TerrainProperty>(); } //Debug.Log(coordinate); return(coordinate); }
public void Reset() { AttackRangeList.Clear(); MovementTileLinks.Clear(); Occuping = false; isHostile = false; isOccupied = false; isTarget = false; isValid = false; isAccounted = false; parent = null; distance = 0; Range = 0; }
public void TargetGridHighlighter(Vector3 Axis, GameObject Searcher) { Vector3 halfExtents = new Vector3(0.25f, 0.25f, 0.25f); Collider[] colliders = Physics.OverlapBox(transform.position + Axis, halfExtents); foreach (Collider item in colliders) { TerrainProperty terrain = item.GetComponent <TerrainProperty>(); if (terrain != null) { AttackRangeList.Add(terrain); isHostile = true; } } }
private void CreateBasicGrid() { float YStep = Mathf.Sqrt(HexRadius * HexRadius - HexRadius * HexRadius / 4); float XStep = HexRadius - Mathf.Sqrt(HexRadius * HexRadius - YStep * YStep) / 2; float OddRowPush = 0.0F; int GridCorrector = 0; Vector3 GlobalCoordinates = new Vector3(0.0F, 0.0F, 0.0F); GameObject CurrentTile; System.Random Rand = new System.Random(); for (int GridX = 0; GridX < (int)GridSize.x; GridX++) { OddRowPush = (GridX % 2 == 1) ? (YStep / 2) : 0; for (int GridY = GridCorrector; GridY < (int)GridSize.y + GridCorrector; GridY++) { GlobalCoordinates.x = ((GridY - GridCorrector) * YStep) + OddRowPush; GlobalCoordinates.y = -GridX * XStep; //Instantiating a tile CurrentTile = (GameObject)Instantiate(DefaultTile, new Vector3(GlobalCoordinates.x, 0, GlobalCoordinates.y), Quaternion.identity); CurrentTile.name = "[" + GridY + "," + GridX + "]"; CurrentTile.transform.SetParent(this.transform); CurrentTile.AddComponent <HexTile>(); HexTile currentHex = CurrentTile.GetComponent <HexTile>(); currentHex.AxialCoordinates = new Vector2(GridX, GridY); currentHex.Type = (TerrainType)Rand.Next(0, 5); TerrainProperty terrainProp = FindProperty(currentHex); CurrentTile.GetComponent <Renderer>().material.color = terrainProp.DebugColor; if (GridX == 0 && GridY == 0) { PlayersTile = currentHex; } } if (GridX % 2 == 1) { GridCorrector--; } } }
public void StartTurn_Faction() { UIManager.UpdateProfiles(this.GetComponent <Faction>()); Funds += TerrainList.Count * GameManager.GManager.Mod_Funds_Generated; print(Faction_Name + " is Starting their turn. Their funds are at: " + Funds + "and have " + TerrainList.Count + " tiles under their control, producing: " + GameManager.GManager.Mod_Funds_Generated); foreach (UnitAttributes item in UnitList) { if (item != null) { if (item.isWaiting) { RaycastHit hit; if (Physics.Raycast(item.transform.position, Vector3.down * 10, out hit, 10)) { if (hit.collider.GetComponent <TerrainProperty>() != null) { TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>(); if (terrain.isCaptured) { if (item.tag == terrain.Heldby) { item.GetComponent <UnitActions>().Action_Recover(terrain.RecoverID(), item.MaxFuelPool); } } } } } else if (item.isDefending) { item.FuelPool -= (item.FuelPool / 10); } item.GetComponent <UnitProperties>().BeginPhase(); } else { UnitList.Remove(item); } } }
public bool ValidAttack(GameObject target) { bool isValid = false; RaycastHit hit; if (Physics.Raycast(this.transform.position, Vector3.down * 10, out hit, 10)) { if (hit.collider.GetComponent <TerrainProperty>() != null) { TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>(); if (terrain.isHostile) { isValid = true; return(isValid); } } } print("THis is " + isValid + " target"); return(isValid); }
//Line of Sight based Attacks public void LoSAttackGrid(GameObject Searcher, Vector3 Direction, int Distance) { Vector3 halfExtents = new Vector3(0.25f, 0.25f, 0.25f); Collider[] colliders = Physics.OverlapBox(transform.position + Direction, halfExtents); isValid = true; isHostile = true; Range = Distance; foreach (Collider item in colliders) { TerrainProperty terrain = item.GetComponent <TerrainProperty>(); if (terrain != null) { AttackRangeList.Add(terrain); terrain.parent = gameObject.GetComponent <TerrainProperty>(); if (Range > 1) { terrain.LoSAttackGrid(Searcher, Direction, Range - 1); } } } }
public bool HasTerrainProperty(TerrainProperty property) { return((property & properties) == property); }
public void SetShaderProperty(TerrainProperty terrain, List <DividedDetailProperty> detailProperties) { _terrainProperty = terrain; _detailProperties = detailProperties; }
set => SetValue(TerrainProperty, value);
public bool TerrainLoaded(UnityEngine.Terrain setting, float detailDistance) { var data = setting.terrainData; var detailResolution = data.detailResolution; var heightMapResolution = data.heightmapResolution; var prototypes = data.detailPrototypes; var detailCount = prototypes.Length; var division = Mathf.CeilToInt(detailResolution / (float)_detailNodeSize); if (!Helper.AlmostEqual(detailResolution, division * _detailNodeSize)) { return(false); } var detailData = new List <int[, ]>(); if (_instancingDraw == null) { _instancingDraw = new DetailInstancingDraw[detailCount]; } List <DividedDetailProperty> detailProps = new List <DividedDetailProperty>(); for (int i = 0; i < detailCount; ++i) { detailData.Add(data.GetDetailLayer(0, 0, detailResolution, detailResolution, i)); detailProps.Add(new DividedDetailProperty(data, prototypes[i], _detailNodeSize, i)); if (_instancingDraw[i] == null) { var renderer = new InstancingRenderer(prototypes[i]); _instancingDraw[i] = new DetailInstancingDraw(renderer, VisibilityShader, setting, data); } } var nodeSize = new Vector2(data.size.x / division, data.size.z / division); var cluster = new GpuInstancingNodeCluster <GpuInstancingDetailNode>(); cluster.InitDivision(setting.transform.position, nodeSize, division, division, detailDistance); cluster.InitHeightMap(data.GetHeights(0, 0, heightMapResolution, heightMapResolution), data.size.y); cluster.TerrainName = setting.name; _data.SetGridParam(data.size.x, detailDistance, nodeSize); _terrainProperty = new TerrainProperty(setting, data, detailDistance); for (int x = 0; x < division; ++x) { for (int z = 0; z < division; ++z) { var node = new GpuInstancingDetailNode(); node.TerrainName = setting.name; node.X = x; node.Z = z; node.SetInstantiationShader(_instantiationShader); node.SetShaderProperty(_terrainProperty, detailProps); node.InitCountInUnit(detailData, x, z, _detailNodeSize); cluster.AddNode(x, z, node); cluster.UpdateMaxCountInLayer(node); } } _data.AddCluster(cluster); return(true); }
public TerrainDefinition(TerrainType newType, TerrainProperty newProperties) { type = newType; properties = newProperties; }
private bool TerrainLoadedInternal(UnityEngine.Terrain setting, float treeDistance, Vector3 basePos, float[,] heightMap, TextAsset asset) { var data = setting.terrainData; var prototypes = data.treePrototypes; var prototypeCount = prototypes.Length; if (prototypeCount == 0) { _logger.Warn("no tree prototypes exists"); return(false); } var heightMapResolution = data.heightmapResolution; var division = (heightMapResolution - 1) / _nodeSize; if (!Helper.AlmostEqual(heightMapResolution, division * _nodeSize + 1)) { _logger.WarnFormat("unmatch param in tree: heightMapResolution -> {0}, nodeSize -> {1}, division -> {2}", heightMapResolution, _nodeSize, division); return(false); } var allTrees = data.treeInstances; var treeCount = allTrees.Length; var nodeMargin = float.MinValue; if (_instancingDraw == null) { _instancingDraw = new TreeInstancingDraw[prototypeCount]; } for (int i = 0; i < prototypeCount; ++i) { if (_instancingDraw[i] == null) { var renderer = new InstancingRenderer(prototypes[i].prefab); nodeMargin = Mathf.Max(nodeMargin, renderer.SphereRadius); _instancingDraw[i] = new TreeInstancingDraw(renderer, VisibilityShader); } else { nodeMargin = Mathf.Max(nodeMargin, _instancingDraw[i].RendererSphereRadius); } } var nodeSize = new Vector2(data.size.x / division, data.size.z / division); _data.SetGridParam(data.size.x, treeDistance, nodeSize); var cluster = new GpuInstancingNodeCluster <GpuInstancingTreeNode>(); cluster.InitDivision(basePos, nodeSize, division, division, treeDistance); if (heightMap != null) { cluster.InitHeightMap(heightMap, data.size.y, nodeMargin); } else { // ignore version int dataIndex = 6; unsafe { var head = new IntPtr(asset.GetBytesIntPtr().ToInt64() + dataIndex); ushort *flowData = (ushort *)head.ToPointer(); var detailCount = *flowData; dataIndex += 2 * (1 + detailCount); } cluster.InitHeightMap(asset, dataIndex, data.size.y, heightMapResolution, nodeMargin); } cluster.TerrainName = setting.name; _terrainProperty = new TerrainProperty(); _terrainProperty.InitForTree(setting, data, treeDistance, basePos); var treeIndex = new List <int> [division, division][]; var maxIndex = division - 1; var maxCountInPrototype = new List <int>(prototypeCount); var dummy = new List <int> [prototypeCount]; for (int i = 0; i < prototypeCount; ++i) { maxCountInPrototype.Add(0); dummy[i] = new List <int>(); } for (int i = 0; i < treeCount; ++i) { var tree = allTrees[i]; var x = Mathf.Min(Mathf.FloorToInt(tree.position.x * division), maxIndex); var z = Mathf.Min(Mathf.FloorToInt(tree.position.z * division), maxIndex); if (treeIndex[x, z] == null) { treeIndex[x, z] = new List <int> [prototypeCount]; } if (treeIndex[x, z][tree.prototypeIndex] == null) { treeIndex[x, z][tree.prototypeIndex] = new List <int>(); } treeIndex[x, z][tree.prototypeIndex].Add(i); maxCountInPrototype[tree.prototypeIndex] = Mathf.Max(maxCountInPrototype[tree.prototypeIndex], treeIndex[x, z][tree.prototypeIndex].Count); } for (int x = 0; x < division; ++x) { for (int z = 0; z < division; ++z) { var node = new GpuInstancingTreeNode { TerrainName = setting.name, X = x, Z = z }; node.SetTreeInstances(treeIndex[x, z] ?? dummy, allTrees); node.SetInstantiationShader(_instantiationShader); node.SetShaderProperty(_terrainProperty); cluster.AddNode(x, z, node); } } cluster.SetMaxCountInLayer(maxCountInPrototype); _data.AddCluster(cluster); return(true); }
public void SetShaderProperty(TerrainProperty property) { _terrainProperty = property; }
protected void Move() { if (CP.Count > 0) { TerrainProperty terrain = CP.Peek(); Vector3 Goal = terrain.transform.position; Goal += Vector3.up; if (Vector3.Distance(transform.position, Goal) > 0.3f) { Transition(Goal); AxisTransition(); transform.forward = TransitionNode; transform.position += velocity * Time.fixedDeltaTime * 20; //Debug.Log("Rotate! " + transform.rotation.y); ////Debug.Log("Rotate! " + (Mathf.Deg2Rad* 90)); //Debug.Log("Rotate! " + Mathf.RoundToInt(Mathf.Rad2Deg * transform.rotation.y)); //switch (Mathf.RoundToInt(transform.rotation.y)) //{ // case -270: // Debug.Log("-270"); // transform.GetChild(0).transform.rotation = Quaternion.Euler(0, 270, 0); // break; // case -180: // Debug.Log("-180"); // transform.GetChild(0).transform.rotation = Quaternion.Euler(0, 180, 0); // break; // case -90: // Debug.Log("-90"); // transform.GetChild(0).transform.rotation = Quaternion.Euler(0, 90, 0); // break; // case 90: // Debug.Log("90"); // transform.GetChild(0).transform.rotation = Quaternion.Euler(0, -90, 0); // break; // case 180: // Debug.Log("180"); // transform.GetChild(0).transform.rotation = Quaternion.Euler(0, -180, 0); // break; // case 270: // Debug.Log("270"); // transform.GetChild(0).transform.rotation = Quaternion.Euler(0, -270, 0); // break; // default: // break; //} } else { transform.position = Goal; CP.Pop(); } } else { Reset(); transform.GetChild(0).GetComponent <SpriteRenderer>().color = Color.green; ActionsMove = false; //LevelManager.EndTurn(); } }
public TerrainDefinition(TerrainDefinition source) { type = source.type; properties = source.properties; }
void Update_UI_Terrain() { if (EventSystem.current.IsPointerOverGameObject()) { return; } RaycastHit hit; int TerrainMask = 1 << 9; //Debug.DrawRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down * 10, Color.blue, 3); if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down, out hit, 10, TerrainMask)) { if (hit.collider.tag.Contains("Land")) { if (hit.collider.GetComponent <TerrainProperty>() != null) { TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>(); Terrain_Viewer.GetComponent <Image>().sprite = terrain.transform.GetChild(0).GetComponent <SpriteRenderer>().sprite; Terrain_Viewer.GetComponent <Image>().color = terrain.transform.GetChild(0).GetComponent <SpriteRenderer>().color; if (terrain.isCapturable) { if (terrain.CapturePower > 0) { Terrain_Viewer.transform.GetChild(0).GetComponent <Slider>().value = terrain.CapturePower; Terrain_Viewer.transform.GetChild(0).GetChild(3).GetComponent <Text>().text = "Capturing " + terrain.name + "!"; RaycastHit UnitDetection; int UnitMask = 1 << 8; if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down, out UnitDetection, 10, UnitMask)) { if (UnitDetection.collider.tag.Contains("Faction") && UnitDetection.collider.GetComponent <UnitAttributes>() != null) { //Change the silder's fore-colour to capturing Unit's Faction Colour Terrain_Viewer.transform.GetChild(0).GetChild(1).GetChild(0).GetComponent <Image>().color = UnitDetection.collider.GetComponent <UnitAttributes>().FactionSided.GetComponent <Faction>().inGameID_Col; //Change the silder's background colour to the Terrain_Viewer.transform.GetChild(0).GetChild(0).GetComponent <Image>().color = terrain.transform.GetChild(0).GetComponent <SpriteRenderer>().color; } } } else { Terrain_Viewer.transform.GetChild(0).GetComponent <Slider>().value = 200; //Changes name to match it's been taken or not if (terrain.isCaptured) { Terrain_Viewer.transform.GetChild(0).GetChild(3).GetComponent <Text>().text = terrain.Heldby + "'s " + terrain.name; Terrain_Viewer.transform.GetChild(0).GetChild(1).GetChild(0).GetComponent <Image>().color = terrain.transform.GetChild(0).GetComponent <SpriteRenderer>().color; Terrain_Viewer.transform.GetChild(0).GetChild(0).GetComponent <Image>().color = terrain.transform.GetChild(0).GetComponent <SpriteRenderer>().color; } else { Terrain_Viewer.transform.GetChild(0).GetChild(3).GetComponent <Text>().text = "Neutral " + terrain.name; Terrain_Viewer.transform.GetChild(0).GetChild(0).GetComponent <Image>().color = Color.white; } } } else { //Default Response for terrain if it's not able to be captured Terrain_Viewer.transform.GetChild(0).GetComponent <Slider>().value = 200; Terrain_Viewer.transform.GetChild(0).GetChild(3).GetComponent <Text>().text = terrain.name; Terrain_Viewer.transform.GetChild(0).GetChild(0).GetComponent <Image>().color = Color.white; } } } } }
public bool TerrainLoaded(TextAsset asset, UnityEngine.Terrain setting, float detailDistance) { var data = setting.terrainData; // ignore version int dataIndex = 2; int heightMapResolution = 0; int detailResolution = 0; int detailCount = 0; List <int> maxCountInLayer = new List <int>(); unsafe { var head = new IntPtr(asset.GetBytesIntPtr().ToInt64() + dataIndex); ushort *flowData = (ushort *)head.ToPointer(); heightMapResolution = *flowData++; detailResolution = *flowData++; _detailNodeSize = *flowData++; detailCount = *flowData++; for (int i = 0; i < detailCount; ++i) { maxCountInLayer.Add(*flowData++); } dataIndex += 2 * (4 + detailCount); } var division = detailResolution / _detailNodeSize; var prototypes = data.detailPrototypes; if (heightMapResolution != data.heightmapResolution || detailResolution != data.detailResolution || detailCount != prototypes.Length) { return(false); } if (_instancingDraw == null) { _instancingDraw = new DetailInstancingDraw[detailCount]; } List <DividedDetailProperty> detailProps = new List <DividedDetailProperty>(); for (int i = 0; i < detailCount; ++i) { detailProps.Add(new DividedDetailProperty(data, prototypes[i], _detailNodeSize, i)); if (_instancingDraw[i] == null) { var renderer = new InstancingRenderer(prototypes[i]); _instancingDraw[i] = new DetailInstancingDraw(renderer, VisibilityShader, setting, data); } } var nodeSize = new Vector2(data.size.x / division, data.size.z / division); var cluster = new GpuInstancingNodeCluster <GpuInstancingDetailNode>(); cluster.InitDivision(setting.transform.position, nodeSize, division, division, detailDistance); cluster.InitHeightMap(asset, dataIndex, data.size.y, heightMapResolution); cluster.TerrainName = setting.name; dataIndex += heightMapResolution * heightMapResolution * 2; _data.SetGridParam(data.size.x, detailDistance, nodeSize); _terrainProperty = new TerrainProperty(setting, data, detailDistance); var layerLength = (detailResolution * detailResolution + division * division) * 2; for (int z = 0; z < division; ++z) { for (int x = 0; x < division; ++x) { var node = new GpuInstancingDetailNode(); node.TerrainName = setting.name; node.X = x; node.Z = z; node.SetInstantiationShader(_instantiationShader); node.SetShaderProperty(_terrainProperty, detailProps); node.InitCountInUnit(x, z, _detailNodeSize, asset, maxCountInLayer, dataIndex, layerLength, division); cluster.AddNode(x, z, node); } } cluster.SetMaxCountInLayer(maxCountInLayer); _data.AddCluster(cluster); return(true); }
void BattleScreen() { if (Input.GetButtonDown("Escape")) { Toggle(); } if (Input.GetButtonDown("Switch")) { StatToggle(); } //Camera Controls if (Input.GetButton("Horizontal")) { gameObject.transform.Translate(new Vector2(Input.GetAxis("Horizontal"), 0)); } if (Input.GetButton("Vertical")) { gameObject.transform.Translate(new Vector2(0, Input.GetAxis("Vertical"))); } if (Input.GetButtonDown("Select")) { if (FreezeClicks) { //Skips Playing Animation for Battles and Moving skipToggle(); skipToggle(); return; } RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector3.down * 10, out hit, 10)) { if (hit.collider != null) { if (EventSystem.current.IsPointerOverGameObject()) { } else if (hit.collider.GetComponent <UnitActions>() != null) { if (!hit.collider.GetComponent <UnitActions>().ActionAvailable&& hit.collider.tag == LevelManager.DM.ActiveFactionReturn()) { return; //Stops check if the unit is able to be interacted with } if (hit.collider.gameObject != HeldObject) { //Checks if the Unit is is checking for viable targets if (HeldObject != null) { print("Unit is searching target = " + HeldObject.GetComponent <UnitActions>().AttackChecking); } if (HeldObject != null && HeldObject.GetComponent <UnitActions>().AttackChecking) { print("Unit is checking for Valid Targets"); UnitActions unitActions = HeldObject.GetComponent <UnitActions>(); if (hit.collider.tag == HeldObject.tag) { return;//Ends function check } else if (hit.collider.tag != HeldObject.tag) { //Checks if selected unit is within the target space if (unitActions.ValidAttack(hit.collider.gameObject)) { HeldObject.GetComponent <UnitActions>().AttackPhase(hit.collider.gameObject); Cancel(); return; } } } else { if (HeldObject != null) { GameManager.GManager.HeldObject.GetComponent <UnitActions>().WipeSelect(); } if (!UIManager.ActionsActive) { ActToggle(); } HeldObject = hit.collider.gameObject; HeldObject.GetComponent <UnitActions>().isSelected = true; return; } } else if (hit.collider.gameObject == HeldObject) { if (HeldObject.GetComponent <UnitActions>().ActionsMove) { CallAction_Move(); } else if (HeldObject.GetComponent <UnitActions>().ActionAvailable) { CallAction_Attack(); } } } else if (hit.collider.GetComponent <TerrainProperty>() != null) { TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>(); if (terrain.isValid && !terrain.isHostile) { if (HeldObject != null) { //Move Agent terrain.isTarget = true; HeldObject.GetComponent <UnitActions>().MovementPhase(hit.collider.gameObject); GameManager.GManager.HeldObject.GetComponent <UnitActions>().WipeSelect(); GameManager.GManager.HeldObject.GetComponent <UnitActions>().isSelected = true; //Cancel(); //HeldObject = null; } } else if (terrain.isValid && terrain.isHostile) { HeldObject.GetComponent <UnitActions>().AttackPhase(hit.collider.gameObject); } } else { Debug.Log("Unit Not Found"); } } else { Debug.Log("Nothing Found"); } } } if (Input.GetButtonDown("Cancel")) { Cancel(); } if (Input.GetButtonDown("Action1")) { CallAction_Move(); } if (Input.GetButtonDown("Action2")) { CallAction_Attack(); } if (Input.GetButtonDown("Action3")) { CallAction_Sync(); } if (Input.GetButtonDown("Action4")) { CallAction_Defend(); } if (Input.GetButtonDown("Action5")) { CallAction_Wait(); } }
public void GetCoordinate() { SitCoordinate = Destination(gameObject); SitCoordinate.isOccupied = true; }
public float EffectiveDefenceReturn() { float EFR = 0; //Terrain Modification RaycastHit hit; if (Physics.Raycast(this.transform.position, Vector3.down * 10, out hit, 10)) { if (hit.collider.GetComponent <TerrainProperty>() != null) { TerrainProperty terrain = hit.collider.GetComponent <TerrainProperty>(); //Checks if Unit is defending at all if (terrain.isDefendable && this.isDefending) { EFR = Defence * GameManager.GManager.Gameplay_Unit_Defending_Mod * GameManager.GManager.Gameplay_Unit_isDefendable_Boost; } else if (this.isDefending) { EFR = Defence * GameManager.GManager.Gameplay_Unit_Defending_Mod; } else { EFR = Defence; } //Checks for terrain bonuses switch (terrain.DefenceValue) { case 1: EFR = EFR * GameManager.GManager.Gameplay_Terrain_Boost1; break; case 2: EFR = EFR * GameManager.GManager.Gameplay_Terrain_Boost2; break; case 3: EFR = EFR * GameManager.GManager.Gameplay_Terrain_Boost3; break; default: break; } } } //Rank modification switch (Rank) { case 1: EFR = EFR * GameManager.GManager.Gameplay_Unit_Rank1_boost; break; case 2: EFR = EFR * GameManager.GManager.Gameplay_Unit_Rank2_boost; break; case 3: EFR = EFR * GameManager.GManager.Gameplay_Unit_Rank3_boost; break; default: break; } EFR = EFR * (HealthPool / WeaknessMod); //Percentage Strength return(EFR); }
public bool TerrainLoaded(UnityEngine.Terrain setting, float detailDistance, Vector3 basePos, float[,] heightMap) { var data = setting.terrainData; var detailResolution = data.detailResolution; var prototypes = data.detailPrototypes; var detailCount = prototypes.Length; var division = Mathf.CeilToInt(detailResolution / (float)_nodeSize); if (!Helper.AlmostEqual(detailResolution, division * _nodeSize)) { _logger.WarnFormat("unmatch param in detail: detailResolution -> {0}, unitSize -> {1}, division -> {2}", detailResolution, _nodeSize, division); return(false); } if (detailCount == 0) { _logger.Warn("no grass prototypes exists"); return(false); } var detailData = new List <int[, ]>(); if (_instancingDraw == null) { _instancingDraw = new DetailInstancingDraw[detailCount]; } List <DividedDetailProperty> detailProps = new List <DividedDetailProperty>(); float nodeMargin = float.MinValue; for (int i = 0; i < detailCount; ++i) { detailData.Add(data.GetDetailLayer(0, 0, detailResolution, detailResolution, i)); detailProps.Add(new DividedDetailProperty(prototypes[i], _nodeSize, i)); if (_instancingDraw[i] == null) { var renderer = new InstancingRenderer(prototypes[i]); nodeMargin = Mathf.Max(nodeMargin, renderer.SphereRadius); _instancingDraw[i] = new DetailInstancingDraw(renderer, VisibilityShader, SortShader, setting, data, basePos); } } var nodeSize = new Vector2(data.size.x / division, data.size.z / division); var cluster = new GpuInstancingNodeCluster <GpuInstancingDetailNode>(); cluster.InitDivision(basePos, nodeSize, division, division, detailDistance); cluster.InitHeightMap(heightMap, data.size.y, nodeMargin); cluster.TerrainName = setting.name; _data.SetGridParam(data.size.x, detailDistance, nodeSize); _terrainProperty = new TerrainProperty(); _terrainProperty.InitForDetail(setting, data, detailDistance, basePos); for (int x = 0; x < division; ++x) { for (int z = 0; z < division; ++z) { var node = new GpuInstancingDetailNode(); node.TerrainName = setting.name; node.X = x; node.Z = z; node.SetInstantiationShader(_instantiationShader); node.SetShaderProperty(_terrainProperty, detailProps); node.InitCountInUnit(detailData, x, z, _nodeSize); cluster.AddNode(x, z, node); cluster.UpdateMaxCountInLayer(node); } } _data.AddCluster(cluster); return(true); }