Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.87 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections.Generic;
  4.  
  5. public class AdvancedTaskIconScript : MonoBehaviour
  6. {
  7.     #region fields
  8.  
  9.     [SerializeField]
  10.     GameObject abort, addWorker, cancel, UI;
  11.  
  12.     List<GameObject> taskWorkers = new List<GameObject>();
  13.  
  14.     CharacterName charName;
  15.     Task task;
  16.  
  17.     float offsetFromCenter = 125;
  18.     float angleOffset = 45;
  19.     float index = 0;
  20.     float startingAngle = 90;
  21.  
  22.     #endregion
  23.  
  24.     #region public methods
  25.  
  26.     /// <summary>
  27.     /// Initializes the task icon script to have all the right buttons
  28.     /// Will also draw them in the right spots
  29.     /// </summary>
  30.     public void Initialize(CharacterName charName, Task task)
  31.     {
  32.         this.charName = charName;
  33.         this.task = task;
  34.  
  35.         startingAngle *= Mathf.Deg2Rad;
  36.         angleOffset *= Mathf.Deg2Rad;
  37.  
  38.         UI.transform.GetComponent<Image>().sprite = task.Icon;
  39.  
  40.         foreach (CharacterName character in task.WorkingCharacters)
  41.         {
  42.             GameObject newIcon = (Instantiate(GameManager.Instance.RuntimePrefabs[Constants.ADVANCED_TASK_ICON_SUB_ICON_UI], transform.position, Quaternion.identity) as GameObject);
  43.             newIcon.transform.SetParent(UI.transform, false);
  44.             newIcon.GetComponent<AdvancedTaskIconSubIconScript>().Initialize(character);
  45.             taskWorkers.Add(newIcon);
  46.         }
  47.  
  48.         addWorker.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
  49.         index++;
  50.  
  51.         //Draw each of the characters here in a foreach loop
  52.         foreach (GameObject obj in taskWorkers)
  53.         {
  54.             obj.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
  55.             index++;
  56.         }
  57.  
  58.         abort.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
  59.         index++;
  60.         cancel.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
  61.         index++;
  62.     }
  63.  
  64.     /// <summary>
  65.     /// Called when the replace worker button is clicked, returns the worker that we want to replace
  66.     /// </summary>
  67.     public void ReplaceWorker(CharacterName character)
  68.     {
  69.         // "task = new CharacterReplaceTask(blah, blah, bloo)"
  70.         //Perhaps open "are you sure" message
  71.         UIManager.Instance.OpenAgentLoadoutUI(charName, task);
  72.         GameManager.Instance.Audio.PlaySound(GameManager.Instance.Audio.UISource, SoundEffects.minerClick);
  73.         Destroy(this.gameObject);
  74.     }
  75.  
  76.     /// <summary>
  77.     /// Sends the worker to abort the task, returning all workers that are currently working on it.
  78.     /// </summary>
  79.     public void AbortTask()
  80.     {
  81.         // "task = new AbortTask(blah, blah, bloo)"
  82.         //Perhaps open "are you sure" message
  83.         UIManager.Instance.OpenAgentLoadoutUI(charName, task);
  84.         GameManager.Instance.Audio.PlaySound(GameManager.Instance.Audio.UISource, SoundEffects.minerClick);
  85.         Destroy(this.gameObject);
  86.     }
  87.  
  88.     /// <summary>
  89.     /// Adds the worker to the selected task
  90.     /// </summary>
  91.     public void AddWorker()
  92.     {
  93.         UIManager.Instance.OpenAgentLoadoutUI(charName, task);
  94.         GameManager.Instance.Audio.PlaySound(GameManager.Instance.Audio.UISource, SoundEffects.minerClick);
  95.         Destroy(this.gameObject);
  96.     }
  97.  
  98.     public void CancelAction()
  99.     {
  100.         Destroy(this.gameObject);
  101.     }
  102.  
  103.     #endregion
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement