private void OnCollisionExit2D(Collision2D collision) { CharacterPath characterPath = collision.gameObject.GetComponent <CharacterPath>(); if (characterPath) { Character character = characterPath.CharacterLocomotion.Character; Logger.Log(Logger.Locomotion, "{0} left room {1}", character.Id, Id); if (character.CurrentRoom == this) { character.LeaveRoom(); } foreach (Character c in CharactersInRoom) { if (c.Id == character.Id) { Logger.Log(Logger.Locomotion, "Remove character {0} from room {1}", CharactersInRoom.Count, Id); CharactersInRoom.Remove(c); if (CharactersInRoom.Count == 0 && _deleteRoomTrigger) { _deleteRoomTrigger.ShowDeleteRoomTrigger(); } break; } } if (CharactersInRoom.Count == 0) { Logger.Log(Logger.Locomotion, "Raise wall pieces of room {0}", Id); RaiseWallPieces(); } } }
void Awake() { currentHexGrid = defaultHexGrid; player1Camera = defaultPlayer1Camera; player2Camera = defaultPlayer2Camera; cardPanelPlayer1 = defaultCardPanelPlayer1; cardPanelPlayer2 = defaultCardPanelPlayer2; player2Camera.gameObject.SetActive(false); currentCamera = player1Camera; currentPath = new CharacterPath(); currentAttackPath = new CharacterPath(); characters = new List <Character> (); attackMode = false; attackButton = currentHexGrid.GetComponentInChildren <AttackButton> (); currentlySelectedCharacter = null; turnNumber = 1; manaText = currentHexGrid.transform.Find("Hex Map Editor/Mana Text").GetComponent <Text>(); maximumMana1 = 1; maximumMana2 = 1; currentMana1 = maximumMana1; currentMana2 = maximumMana2; characterObjects [0] = GameResources.wolfCharacter.GetComponent <Character>(); characterObjects [1] = GameResources.dragonCharacter.GetComponent <Character>(); cardDeck = currentHexGrid.GetComponentInChildren <Deck> (); }
public void Attack() { if (GameInformation.attackMode) { GameInformation.ResetAttackingPath(); buttonText.text = "Attack"; } else { try { currentCharacter = GameInformation.currentlySelectedCharacter; if (currentCharacter.team1 == GameInformation.player1Turn) { if (currentCharacter.attacked == false) { List <HexCoordinates> tempCoords = new List <HexCoordinates>(); foreach (HexCoordinates neighbour in currentCharacter.position.CellNeighbours) { tempCoords.Add(neighbour); } if (tempCoords.Count != 0) { CharacterPath attackingPath = new CharacterPath(tempCoords.ToArray(), currentCharacter); GameInformation.currentAttackPath = attackingPath; buttonText.text = "Cancel"; GameInformation.attackMode = true; } } } } catch { GameInformation.attackMode = false; buttonText.text = "Attack"; } } }
// Update is called once per frame void Update() { pathForMovement = GameInformation.currentPath; if (moving == true && pathForMovement.ValidPath()) { editor.pathAvailable = false; transform.position = Vector3.MoveTowards(transform.position, pathForMovement.hexCoords [currentIndex].CentreToWorldPosition(), 0.5F); LookAt(pathForMovement.hexCoords [currentIndex]); if (transform.position == pathForMovement.hexCoords [currentIndex].CentreToWorldPosition()) { character.position = pathForMovement.hexCoords [currentIndex]; currentIndex++; } } if (currentIndex >= pathForMovement.hexCoords.Length) { if (moving == true) { character.moved = true; } moving = false; currentIndex = 0; GameInformation.currentPath = new CharacterPath(); editor.pathAvailable = true; } }
public static void DrawLabel(CharacterPath charPath, string labelText, int index) { GUIStyle labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.black; labelStyle.normal.background = guiBg; labelStyle.padding = new RectOffset(4, 2, 2, 2); Handles.Label(charPath.GetWorldPos(index) + Vector3.up * .2f, labelText, labelStyle); }
private void OnCollisionEnter2D(Collision2D collision) { CharacterPath characterPath = collision.gameObject.GetComponent <CharacterPath>(); if (characterPath) { Character character = characterPath.CharacterLocomotion.Character; Logger.Log(Logger.Locomotion, "{0} entered room {1}", character.Id, Id); CharactersInRoom.Add(character); character.EnterRoom(this); if (_deleteRoomTrigger) { _deleteRoomTrigger.HideDeleteRoomTrigger(); } } }
static void MakeAddButton(CharacterPath charPath, int startIndex, int endIndex, ref List <Vector3> pathPositions, GUIStyle labelStyle) { // button for adding a new point in the path Handles.color = Color.green; Vector3 addBtnPos = (PathPointPos(charPath, startIndex) + PathPointPos(charPath, endIndex)) / 2; float screenSize = HandleUtility.GetHandleSize(addBtnPos); if (Handles.Button(addBtnPos, Quaternion.identity, screenSize * .2f, screenSize * .4f, Handles.SphereHandleCap)) { Undo.RecordObject(charPath, "Add Character Path Point"); charPath.InsertNewPoint(startIndex, addBtnPos); pathPositions.Insert(startIndex, addBtnPos); } // button label Handles.Label(addBtnPos, "+", labelStyle); }
public static void DrawCharacterPathInspector(CharacterPath charPath, bool allowEdit = true, float handleSize = .25f, List <PathEvent> pathEvents = null) { GUIStyle labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.black; labelStyle.normal.background = guiBg; labelStyle.padding = new RectOffset(4, 2, 2, 2); List <Vector3> pathPositions = new List <Vector3>(); int indexToDelete = -1; // Track mouseUp events so that points can be deleted on mouse up bool mouseUp = false; Event e = Event.current; if (e.type == EventType.MouseUp) { mouseUp = true; } EditorGUI.BeginChangeCheck(); for (int i = 0; i < charPath.pathPoints.Count; i++) { Handles.color = Color.yellow; Vector3 thisPos = PathPointPos(charPath, i); // draw the circle for this pathPos Handles.DrawWireArc(thisPos, Vector3.up, Vector3.left, 360, handleSize); // draw move gizmo for path point if (allowEdit) { pathPositions.Add(Handles.PositionHandle(thisPos, Quaternion.identity)); } // draw the label string labelText = "(" + i.ToString() + ")"; // draw labels for path events if (pathEvents != null) { foreach (var pathEvent in pathEvents) { if (pathEvent.index == i) { labelText += pathEvent.ToString(); } } } Handles.Label(thisPos, labelText, labelStyle); if (i > 0) { Vector3 prevPos = PathPointPos(charPath, i - 1); // If a point is too close to it's neighbor, we draw a red circle and mark it // to be deleted. When user lets mouse up, it will be deleted if (Vector3.Distance(prevPos, thisPos) < .5f * HandleUtility.GetHandleSize(thisPos)) { Handles.color = Color.red; Handles.DrawWireArc(thisPos, Vector3.up, Vector3.left, 360, handleSize * 2); indexToDelete = i; } // if not within delete range, draw all the normal stuff else { // draw line between points Handles.DrawDottedLine(prevPos, thisPos, 5); if (allowEdit) { MakeAddButton(charPath, i, i - 1, ref pathPositions, labelStyle); } } } } Handles.color = Color.yellow; // connect edges if the path is looped if (charPath.looped) { Handles.DrawDottedLine( PathPointPos(charPath, 0), PathPointPos(charPath, charPath.pathPoints.Count - 1), 5); MakeAddButton(charPath, 0, charPath.pathPoints.Count - 1, ref pathPositions, labelStyle); } if (indexToDelete >= 0 && mouseUp && allowEdit) { Undo.RecordObject(charPath, "Delete Character Path Point"); charPath.RemovePoint(indexToDelete); } if (EditorGUI.EndChangeCheck() && allowEdit) { Undo.RecordObject(charPath, "Change Character Path Positions"); for (int i = 0; i < charPath.pathPoints.Count; i++) { Vector3 newPos = charPath.transform.InverseTransformPoint(pathPositions[i]); charPath.pathPoints[i].pos = newPos; } } }
static Vector3 PathPointPos(CharacterPath path, int index) => path.transform.TransformPoint(path.pathPoints[index].pos);
protected virtual void OnSceneGUI() { CharacterPath charPath = (CharacterPath)target; DrawCharacterPathInspector(charPath); }
public static void ResetAttackingPath() { attackMode = false; currentAttackPath = new CharacterPath(); }
public void SetPath(CharacterPath path) { Path = path ?? throw new ArgumentNullException(nameof(path)); }
/// <summary> /// Create a new <see cref="Type2Glyph"/>. /// </summary> public Type2Glyph(CharacterPath path, decimal?widthDifferenceFromNominal) { Path = path ?? throw new ArgumentNullException(nameof(path)); WidthDifferenceFromNominal = widthDifferenceFromNominal; }