Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections.Generic;
- public class AdvancedTaskIconScript : MonoBehaviour
- {
- #region fields
- [SerializeField]
- GameObject abort, addWorker, cancel, UI;
- List<GameObject> taskWorkers = new List<GameObject>();
- CharacterName charName;
- Task task;
- float offsetFromCenter = 125;
- float angleOffset = 45;
- float index = 0;
- float startingAngle = 90;
- #endregion
- #region public methods
- /// <summary>
- /// Initializes the task icon script to have all the right buttons
- /// Will also draw them in the right spots
- /// </summary>
- public void Initialize(CharacterName charName, Task task)
- {
- this.charName = charName;
- this.task = task;
- startingAngle *= Mathf.Deg2Rad;
- angleOffset *= Mathf.Deg2Rad;
- UI.transform.GetComponent<Image>().sprite = task.Icon;
- foreach (CharacterName character in task.WorkingCharacters)
- {
- GameObject newIcon = (Instantiate(GameManager.Instance.RuntimePrefabs[Constants.ADVANCED_TASK_ICON_SUB_ICON_UI], transform.position, Quaternion.identity) as GameObject);
- newIcon.transform.SetParent(UI.transform, false);
- newIcon.GetComponent<AdvancedTaskIconSubIconScript>().Initialize(character);
- taskWorkers.Add(newIcon);
- }
- addWorker.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
- index++;
- //Draw each of the characters here in a foreach loop
- foreach (GameObject obj in taskWorkers)
- {
- obj.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
- index++;
- }
- abort.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
- index++;
- cancel.GetComponent<RectTransform>().localPosition = new Vector3(Mathf.Cos(startingAngle + (angleOffset * -index)) * offsetFromCenter, Mathf.Sin(startingAngle + (angleOffset * -index)) * offsetFromCenter);
- index++;
- }
- /// <summary>
- /// Called when the replace worker button is clicked, returns the worker that we want to replace
- /// </summary>
- public void ReplaceWorker(CharacterName character)
- {
- // "task = new CharacterReplaceTask(blah, blah, bloo)"
- //Perhaps open "are you sure" message
- UIManager.Instance.OpenAgentLoadoutUI(charName, task);
- GameManager.Instance.Audio.PlaySound(GameManager.Instance.Audio.UISource, SoundEffects.minerClick);
- Destroy(this.gameObject);
- }
- /// <summary>
- /// Sends the worker to abort the task, returning all workers that are currently working on it.
- /// </summary>
- public void AbortTask()
- {
- // "task = new AbortTask(blah, blah, bloo)"
- //Perhaps open "are you sure" message
- UIManager.Instance.OpenAgentLoadoutUI(charName, task);
- GameManager.Instance.Audio.PlaySound(GameManager.Instance.Audio.UISource, SoundEffects.minerClick);
- Destroy(this.gameObject);
- }
- /// <summary>
- /// Adds the worker to the selected task
- /// </summary>
- public void AddWorker()
- {
- UIManager.Instance.OpenAgentLoadoutUI(charName, task);
- GameManager.Instance.Audio.PlaySound(GameManager.Instance.Audio.UISource, SoundEffects.minerClick);
- Destroy(this.gameObject);
- }
- public void CancelAction()
- {
- Destroy(this.gameObject);
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement