Пример #1
0
    /// <summary>
    /// Waits for the left mouse button to be clicked, then performs a raycast to determine if the player has clicked
    /// on one of her own squads.
    /// </summary>
    /// <remarks>
    /// Transitions:
    ///     Player Clicks Valid Squad -> SelectingMovement
    /// </remarks>
    private void updateSelectingUnit()
    {
        // Wait for the left mouse button to be pressed.
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            // Perform raycasting and store a list of all objects that have been selected.
            List <RaycastHit> hits = new List <RaycastHit>();
            hits.AddRange(Physics.RaycastAll(ray));

            // Iterate over the selection list to determine if the player has clicked on one of her squads.
            foreach (RaycastHit hitInfo in hits.OrderBy(l => l.distance))
            {
                // Capture the actor behavior on the hit object.
                ActorBehavior actor = hitInfo.transform.GetComponent <ActorBehavior>();
                if (actor == null)
                {
                    continue;
                }

                // Ensure that the unit has not moved and belongs to the player.
                if (!actor.actorHasMovedThisTurn && actor.theSide == inputSide)
                {
                    // Mark the actor as selected.
                    selectedSquad = actor;
                    startingPoint = actor.currentMovePoint;

                    // Begin the scripted "Idle" animation.
                    UnitIdleAnimationBehavior[] idles = selectedSquad.GetComponentsInChildren <UnitIdleAnimationBehavior>();
                    foreach (UnitIdleAnimationBehavior idle in idles)
                    {
                        idle.Active = true;
                    }

                    // Enable rendering of valid target movement nodes.
                    if (actor.currentMovePoint != null)
                    {
                        actor.currentMovePoint.HighlightValidNodes(actor, grid);
                    }

                    // STATE CHANGE: SelectingUnit -> SelectingMovement
                    controlState = GridControlState.SelectingMovement;

                    break;
                }
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Performs necessary steps to deselect the current squad.
    /// </summary>
    private void deselectSquad()
    {
        if (selectedSquad != null)
        {
            UnitIdleAnimationBehavior[] idles = selectedSquad.GetComponentsInChildren <UnitIdleAnimationBehavior>();
            foreach (UnitIdleAnimationBehavior idle in idles)
            {
                idle.Active = false;
            }

            selectedSquad = null;
        }

        startingPoint = null;
        grid.HideMovePoints();
        validTargets = null;
    }
Пример #3
0
	/// <summary>
	/// Waits for the left mouse button to be clicked, then performs a raycast to determine if the player has clicked
	/// on one of her own squads.
	/// </summary>
	/// <remarks>
	/// Transitions:
	/// 	Player Clicks Valid Squad -> SelectingMovement
	/// </remarks>
	private void updateSelectingUnit()
	{
		// Wait for the left mouse button to be pressed.
		if(Input.GetMouseButtonDown (0))
		{
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

			// Perform raycasting and store a list of all objects that have been selected.
			List<RaycastHit> hits = new List<RaycastHit>();
			hits.AddRange(Physics.RaycastAll (ray));

			// Iterate over the selection list to determine if the player has clicked on one of her squads.
			foreach(RaycastHit hitInfo in hits.OrderBy (l => l.distance))
			{
				// Capture the actor behavior on the hit object.
				ActorBehavior actor = hitInfo.transform.GetComponent<ActorBehavior>();
				if(actor == null)
					continue;

				// Ensure that the unit has not moved and belongs to the player.
				if(!actor.actorHasMovedThisTurn && actor.theSide == inputSide)
				{
					// Mark the actor as selected.
					selectedSquad = actor;
					startingPoint = actor.currentMovePoint;

					// Begin the scripted "Idle" animation.
					UnitIdleAnimationBehavior[] idles = selectedSquad.GetComponentsInChildren<UnitIdleAnimationBehavior>();
					foreach(UnitIdleAnimationBehavior idle in idles)
						idle.Active = true;

					// Enable rendering of valid target movement nodes.
					if(actor.currentMovePoint != null)
						actor.currentMovePoint.HighlightValidNodes(actor, grid);

					// STATE CHANGE: SelectingUnit -> SelectingMovement
					controlState = GridControlState.SelectingMovement;

					break;
				}
			}
		}
	}