private void MoveFigure(Assets.Scripts.Map.MapObject figure, Vector2 newPos, string terrainType = null) { this.logger.Log("trying to move figure"); if (!CanFigureMoveTo(figure, newPos, terrainType)) { // can't go that far or is used now this.logger.Log("figure can't be moved"); return; } figure.x = (int)newPos.x; figure.y = (int)newPos.y; figure.isReadyToMove = false; objectRenderer.UpdateObjects(); }
void Start() { globalScript = (Global)GameObject.Find("GLOBAL").GetComponent(typeof(Global)); objectInfoUI = (ObjectInfoUI)GameObject.Find("ObjectInfo").GetComponent(typeof(ObjectInfoUI)); var renderer = GetComponent <Renderer>(); playerColor = renderer ? renderer.material.GetColor("_Color"):Color.black; if (globalScript != null && globalScript.listOfMapObjects != null) { listInstanceRef = globalScript.listOfMapObjects.FindLast(obj => obj.x == mapPosition.x && obj.y == mapPosition.y); if (listInstanceRef != null) { listInstanceRef.instance = gameObject; } } }
public void HandleFigureHighlight(Assets.Scripts.Map.MapObject selectedObj) { if (selectedObj == null) { this.logger.Log("selected object not found in the list"); return; } if (selectedObj == highlightedObject) { this.logger.Log("reser camera pos"); // unselect object cameraBehavior.ResetCamera(); highlightedObject.isHighlighted = false; highlightedObject = null; objectRenderer.UpdateObjects(); return; } if (selectedObj.ownerID != userTurn) { this.logger.Log("other owner"); // player wants to select the unit he doesn't own return; } cameraBehavior.SetCameraOverTransform(selectedObj.instance.transform); highlightedObject = selectedObj; foreach (var obj in listOfMapObjects) { obj.isHighlighted = false; } highlightedObject.isHighlighted = true; objectRenderer.UpdateObjects(); }
private bool CanFigureMoveTo(Assets.Scripts.Map.MapObject figure, Vector2 newPos, string terrainType) { if (figure is Castle) { return(false); } if (!figure.isReadyToMove) { return(false); } //is used now if (newPos == new Vector2(figure.x, figure.y)) { return(false); } if (terrainType == "terrain:water") { return(false); } var currentPos = new Vector2(figure.x, figure.y); var maxDistance = ((Assets.Scripts.Map.IMilitaryUnit)figure).MovementRange; return(Vector2.Distance(currentPos, newPos) <= maxDistance); }