Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.47 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerManager : GenericSingleton<PlayerManager> {
  6.     // Determine if can move selected unit
  7.     private bool ableToMove;
  8.     // Determine if can use selected unit top attack
  9.     private bool ableToAttack;
  10.     // Determine if unit is moving
  11.     private bool isMoving;
  12.     // Represents the selected Unit
  13.     private Units selectedUnit;
  14.  
  15.     // Use this for initialization
  16.     void Start ()
  17.     {
  18.         // Set to not be able to move unit
  19.         ableToMove = false;
  20.         // Set to not be able to attack
  21.         ableToAttack = false;
  22.         // Set stopped moving to false
  23.         isMoving = false;
  24.         // Set the selected unit to NULL first
  25.         selectedUnit =  null;
  26.     }
  27.    
  28.     // Update Player Units during Player's turn
  29.     public void UpdatePlayerUnits ()
  30.     {
  31.         // Exit function if it is not player's turn
  32.         if (!TurnManager.Instance.IsPlayerTurn ())
  33.             return;
  34.         // Check if there is a unit selected
  35.         if (selectedUnit)
  36.         {
  37.             // Only update menu when selected unit is not null
  38.             UpdateMenu();
  39.  
  40.             // Update the unit's movement
  41.         }
  42.            
  43.     }
  44.  
  45.     // If Player selects another unit
  46.     public void ChangeUnit(Units newUnit)
  47.     {
  48.         if (selectedUnit)
  49.         {
  50.             // To reset the values for the unit
  51.             selectedUnit.TurnEnd ();
  52.         }
  53.         // Set to the new selected unit
  54.         selectedUnit = newUnit;
  55.         if (selectedUnit)
  56.         {
  57.             // Init the new selected unit
  58.             selectedUnit.TurnStart ();
  59.         }
  60.  
  61.         // Set to not be able to move unit
  62.         ableToMove = false;
  63.         // Set to not be able to attack
  64.         ableToAttack = false;
  65.         // Set unit is moving to false
  66.         isMoving = false;
  67.         // Set for menu to be open
  68.         if (selectedUnit)
  69.         {
  70.             selectedUnit.menuOpen = true;
  71.         }
  72.     }
  73.  
  74.     // Update the menu for each unit
  75.     public void UpdateMenu()
  76.     {
  77.         // Only render the unit's menu if no action is selected
  78.         // And if the unit is not moving
  79.         if(selectedUnit.menuOpen && !ableToAttack && !isMoving)
  80.         {
  81.             // This makes the Canvas in the unit to be active
  82.             selectedUnit.transform.GetChild (0).gameObject.SetActive (true);
  83.  
  84.         }
  85.         else if(!selectedUnit.menuOpen || isMoving || ableToAttack)
  86.         {
  87.             Debug.Log ("False 1");
  88.             // This makes the Canvas in the unit to be inactive
  89.             selectedUnit.transform.GetChild (0).gameObject.SetActive (false);
  90.         }
  91.  
  92.         // Check for deselection at the end
  93.         DeselectActions ();
  94.     }
  95.  
  96.     // For deselecting an action
  97.     public void DeselectActions()
  98.     {
  99.         if (!ableToMove && !ableToAttack)
  100.         { // To deselect the selected unit
  101.             if (Input.GetMouseButtonDown(1))
  102.             {
  103.                 selectedUnit.transform.GetChild (0).gameObject.SetActive (false);
  104.                 selectedUnit.menuOpen = false;
  105.                 selectedUnit.TurnEnd ();
  106.                 selectedUnit = null;
  107.             }
  108.         }
  109.         if (ableToMove)
  110.         { // If move is clicked, you can deselect move
  111.             if (Input.GetMouseButtonDown(1))
  112.             {
  113.                 selectedUnit.transform.GetChild (0).gameObject.SetActive (true);
  114.                 selectedUnit.menuOpen = true;
  115.                 isMoving = true;
  116.                 ableToMove = false;
  117.             }
  118.         }
  119.         if (ableToAttack)
  120.         { // If attack is clicked, you can deselect attack
  121.             if (Input.GetMouseButtonDown(1))
  122.             {
  123.                 selectedUnit.transform.GetChild (0).gameObject.SetActive (true);
  124.                 selectedUnit.menuOpen = true;
  125.                 ableToAttack = false;
  126.             }
  127.         }
  128.     }
  129.  
  130.     // Set the selected unit to be able to move
  131.     public void StartMoving()
  132.     {
  133.         // Check if unit is available and if unit can move
  134.         if(selectedUnit && !ableToMove)
  135.         {
  136.             isMoving = true;
  137.             ableToMove = true;
  138.         }
  139.     }
  140.  
  141.     // Set the selected unit to be able to attack
  142.     public void StartAttacking()
  143.     {
  144.         // Check if unit is available and if unit can attack
  145.         if(selectedUnit && !ableToAttack)
  146.         {
  147.             ableToAttack = true;
  148.         }
  149.     }
  150.  
  151.     // Skip current turn
  152.     public void SkipTurn()
  153.     {
  154.         // Check if unit is available and if unit can move
  155.         if(selectedUnit && ableToMove)
  156.         {
  157.             selectedUnit.TurnEnd ();
  158.             TurnManager.Instance.ExitPlayerTurn ();
  159.         }
  160.     }
  161.  
  162.     // Set & Get Selected Unit
  163.     public Units GetSelectedUnit() {return selectedUnit;}
  164.     public void SetSelectedUnit(Units _nextUnit) {selectedUnit = _nextUnit;}
  165.  
  166.     // Set & Get Unit Can Move
  167.     public bool GetAbleToMove() {return ableToMove;}
  168.     public void SetAbleToMove(bool _canMove) {ableToMove = _canMove;}
  169.  
  170.     // Set & Get Unit Can Attack
  171.     public bool GetAbleToAttack() {return ableToAttack;}
  172.     public void SetAbleToAttack(bool _canAttack) {ableToAttack = _canAttack;}
  173.  
  174.     // Set & Get Unit Stop Moving
  175.     public bool GetIsMoving() {return isMoving;}
  176.     public void SetIsMoving(bool _stopMove) {isMoving = _stopMove;}
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement