IEnumerator AnimateIcon(InteractionIcon icon) { GameObject selectedIcon; if (icon == InteractionIcon.Bite) { selectedIcon = biteIcon; } else if (icon == InteractionIcon.Charm) { selectedIcon = charmIcon; } else if (icon == InteractionIcon.Think) { selectedIcon = thinkIcon; } else { selectedIcon = intimidateIcon; } var image = selectedIcon.GetComponent <UnityEngine.UI.Image>(); while (true) { image.color = new Color(1f, .1f, .1f); yield return(new WaitForSecondsRealtime(m_flashSeconds)); image.color = new Color(1f, 1f, 1f); yield return(new WaitForSecondsRealtime(m_flashSeconds)); } }
// Use this for initialization /*void Start () * { * if (spriteRenderer == null) * { * spriteRenderer = GetComponent<SpriteRenderer>(); * } * }*/ public static InteractionIcon createInteractionIcon(string spriteName, Vector2 coords, Color blendColor, int depth = 0, bool pixelCoords = false) { GameObject go = (GameObject)Instantiate(interactionIconPrefab); InteractionIcon m = (InteractionIcon)go.GetComponent(typeof(InteractionIcon)); m.initialize(spriteName, coords, blendColor, depth, pixelCoords); activeIcons.Add(m); return(m); }
public override void Update() { if (Focused == null) { return; } InteractionIcon icon = WatchedComponents.FirstOrDefault() as InteractionIcon; if (icon == null) { return; } icon.Owner.Components.Get <Spatial>().Position = Focused.Owner.Components.Get <Spatial>().Position + Focused.IconOffset; }
public void Setup() { body_renderer = body.GetComponent <SpriteRenderer>(); head_renderer = head.GetComponent <SpriteRenderer>(); body_w = body_renderer.bounds.size.x * body_renderer.sprite.pixelsPerUnit; head_w = head_renderer.bounds.size.x * head_renderer.sprite.pixelsPerUnit; body_renderer.sortingOrder = ZIndex.UI_OVER_GAME_1; head_renderer.sortingOrder = ZIndex.UI_OVER_GAME_1; GameObject iconPrefab = Resources.Load("prefabs/InteractionIcon") as GameObject; GameObject iconObj = Instantiate(iconPrefab, Vector3.zero, Quaternion.identity); iconObj.transform.SetParent(transform); icon = iconObj.GetComponent <InteractionIcon>(); icon.Setup(); icon.visible = false; }
public override void drawMovementIcons(UnitScript selectedUnit) { if (mode == 0) { for (int i = 0; i < adjustedSelectableLocations.Count; i++) { HexTile tile = gameControllerRef.getTileController().getTileFromHexCoord(selectedUnit.getCoords() + adjustedSelectableLocations[i]); if (tile) { InteractionIcon.createInteractionIcon("SelectableIcon", tile.getCoords(), new Color(1.0f, 0.8f, 0.8f, 1.0f), 0); if (tile.getOccupyingUnit()) { if (tile.getOccupyingUnitTeam() != selectedUnit.getTeam()) { InteractionIcon.createInteractionIcon("CrossIcon", tile.getCoords(), new Color(1.0f, 0.0f, 0.0f, 1.0f), 1); } } else { InteractionIcon.createInteractionIcon("CrossIcon", tile.getCoords(), new Color(1.0f, 0.0f, 0.0f, 1.0f), 1); } } } } if (mode == 1) { //gameControllerRef.printString("radaradaradarada"); for (int i = 0; i < adjustedRepositionLocations.Count; i++) { HexTile tile = gameControllerRef.getTileController().getTileFromHexCoord(selectedUnit.getCoords() + adjustedRepositionLocations[i]); if (tile) { InteractionIcon.createInteractionIcon("PlaceIcon", tile.getCoords(), new Color(1.0f, 0.8f, 0.8f, 1.0f), 0); if (tile.getOccupyingUnit() && tile.getOccupyingUnit() != repositioningUnit) { InteractionIcon.createInteractionIcon("CrossIcon", tile.getCoords(), new Color(1.0f, 0.0f, 0.0f, 1.0f), 1); } } } } }
/*private void drawMoveableTiles(UnitScript selectedUnit, int currentTeam) * { * gameControllerRef.getTileController().switchAllTileStates(); * for (int i = 0; i < repositionLocations.Count; i++) * { * HexTile tile = gameControllerRef.getTileController().getTileFromHexCoord(selectedUnit.getCoords() + adjustedRepositionLocations[i]); * if (tile) * { * tile.switchState(TileState.NONSELECTABLE); * if (!tile.getOccupyingUnit()) * { * tile.switchState(TileState.SELECTABLE); * } * else if (tile.getOccupyingUnitTeam() == selectedUnit.getTeam()) * { * tile.switchState(TileState.SELECTABLE); * } * } * } * }*/ public override void clickedInMode(HexTile clickedTile, UnitScript selectedUnit, int currentTeam) { if (mode == 0) { mode = 1; //drawMoveableTiles(selectedUnit, currentTeam); gameControllerRef.getTileController().switchAllTileStates(); selectedUnit.getOccupyingHex().switchState(TileState.SELECTED); for (int i = 0; i < repositionLocations.Count; i++) { HexTile tile = gameControllerRef.getTileController().getTileFromHexCoord(selectedUnit.getCoords() + adjustedRepositionLocations[i]); if (tile) { if (!tile.getOccupyingUnit() || tile == clickedTile) { tile.switchState(TileState.SELECTABLE); } } } repositioningUnit = clickedTile.getOccupyingUnit(); InteractionIcon.clearAllInteractionIcons(); drawMovementIcons(selectedUnit); return; } if (mode == 1) { if (!clickedTile.getOccupyingUnit()) { gameControllerRef.getTileController().transferUnit(repositioningUnit.getOccupyingHex(), clickedTile); } repositioningUnit.setRotationDirection(selectedUnit.getRotation()); mode = 0; repositioningUnit = null; gameControllerRef.switchInteractionState(InteractionStates.SelectingUnitToRotate); } }
public override void OnInit() { base.OnInit(); // UI생성 this.hud = ObjectPoolManager.inst.New <GameHud>(PrefabPath.UI.GameHUD); this.hud.transform.position = new Vector3(0, -10000, 0); this.hud.Init(this.unit); // 카메라 초기화 PlayerCamera.current.ResetRotation(this.unit.transform.eulerAngles); PlayerCamera.current.FollowUnit(this.unit.transform); this.aimAnimating = false; // 상호작용 아이콘 초기화 this.interactionIcon = ObjectPoolManager.inst.New <InteractionIcon>(PrefabPath.UI.InteractionIcon); this.interactionIcon.gameObject.SetActive(false); // 커서 상태 잠금 Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; }
public override void drawMovementIcons(UnitScript selectedUnit) { for (int i = 0; i < jumpPositions.Count; i++) { HexTile tile = gameControllerRef.getTileController().getTileFromHexCoord(selectedUnit.getOccupyingHex().getCoords() + adjustedJumpPositions[i]); if (tile) { InteractionIcon.createInteractionIcon("JumpIcon", tile.getCoords(), new Color(1.0f, 0.0f, 1.0f, 1.0f), 0); if (tile.getOccupyingUnit()) { if (tile.getOccupyingUnit().getTeam() != selectedUnit.getTeam()) { InteractionIcon.createInteractionIcon("AttackIcon", tile.getCoords(), new Color(1.0f, 0.0f, 0.0f, 1.0f), 1); } else { InteractionIcon.createInteractionIcon("CrossIcon", tile.getCoords(), new Color(1.0f, 0.0f, 0.0f, 1.0f), 1); } } } } //MovementIcon m = new MovementIcon(); //m.initialize("PlaceIcon", ); }
public override void drawMovementIcons(UnitScript selectedUnit) { for (int i = 0; i < adjustedDirections.Count; i++) { HexTile currentTile = selectedUnit.getOccupyingHex(); HexTile prevTile = null; //Color drawingColor = Color.yellow; Color drawingColor = new Color(0.2f, 0.2f, 0.2f, 1.0f); int j = 0; while (j < ranges[i] || ranges[i] == -1) { Vector2 currentTileCoords = currentTile.getCoords() + adjustedDirections[i]; currentTile = gameControllerRef.getTileController().getTileFromHexCoord(currentTile.getCoords() + adjustedDirections[i]); if (j >= blockingExtent[i]) { if (currentTile) { if (currentTile.getOccupyingUnit()) { if (currentTile.getOccupyingUnit().getTeam() == selectedUnit.getTeam()) { InteractionIcon.createInteractionIcon("CrossIcon", currentTileCoords, Color.red, 4); break; } else { InteractionIcon.createInteractionIcon("AttackIcon", currentTileCoords, Color.red, 4); drawingColor = Color.yellow; } } else { drawingColor = Color.yellow; } prevTile = currentTile; } else { InteractionIcon.createInteractionIcon("CrossIcon", currentTileCoords, Color.red, 4); break; } } else { if (currentTile) { prevTile = currentTile;//Have arrow go to the blocked tile if (currentTile.getOccupyingUnit()) { InteractionIcon.createInteractionIcon("CrossIcon", currentTileCoords, Color.red, 4); break; } InteractionIcon.createInteractionIcon("CrossIcon", currentTileCoords, new Color(0.2f, 0.2f, 0.2f, 1.0f), 0); } else { InteractionIcon.createInteractionIcon("CrossIcon", currentTileCoords, Color.red, 4); //drawingColor = new Color(0.2f, 0.2f, 0.2f, 1.0f); //prevTile = currentTile; break; } } j++; } if (prevTile) { InteractionIcon m = InteractionIcon.createInteractionIcon("PathConnectionIcon", selectedUnit.getCoords(), drawingColor, 1); Vector2 lastTileCoords = TileController.hexCoordToPixelCoord(prevTile.getCoords()); Vector2 startTileCoords = TileController.hexCoordToPixelCoord(selectedUnit.getCoords()); Vector2 Q = lastTileCoords - startTileCoords; float dist = Q.magnitude * 100 - 15; if (dist < 0) { dist = 0; } float angle = Mathf.Atan2(Q.y, Q.x) * 180 / Mathf.PI; //gameControllerRef.printString(dist.ToString()); m.transform.Rotate(Vector3.forward, angle); m.transform.localScale = new Vector2(dist / 24, 1.0f); InteractionIcon mHead = InteractionIcon.createInteractionIcon("ArrowHeadIcon", lastTileCoords, drawingColor, 2, true); mHead.transform.Rotate(Vector3.forward, angle); InteractionIcon.createInteractionIcon("PathIcon", lastTileCoords, drawingColor, 3, true); } InteractionIcon.createInteractionIcon("PathIcon", selectedUnit.getCoords(), drawingColor, 3); } }
public void StartSelectionFX(InteractionIcon icon) { StartCoroutine(AnimateIcon(icon)); }