public void InstantiateToolsUI(List <Tool> tools) { for (int i = 0; i < tools.Count; i++) { ToolUI toolUI = Instantiate(toolUIPrefab, slots[i]); toolUI.Init(tools[i]); toolsUI.Add(toolUI); } }
/// <summary> /// provide a static reference to ToolUI that can be accessed from any script /// </summary> /// <returns></returns> public static ToolUI Instance() { if (!toolUI) { toolUI = FindObjectOfType(typeof(ToolUI)) as ToolUI; if (!toolUI) { Debug.LogError("There needs to be one active toolUI script on a GameObject in your scene"); } } return(toolUI); }
private void Start() { foreach (Tool tool in GameManager.Instance.LocalPlayer.PlayerTools.Tools) { GameObject tmp = Instantiate(ToolUIPrefab, transform); ToolUI toolUI = new ToolUI(); toolUI.BackgroundImage = tmp.GetComponent <Image>(); toolUI.Image = tmp.transform.Find("Tool Image").GetComponent <Image>(); toolUI.EmptyImage = tmp.transform.Find("Empty Image").gameObject; toolUI.Tool = tool; toolUI.Image.sprite = tool.Sprite; _toolUIS.Add(toolUI); } }
private void Awake() { scene = SceneManager.GetActiveScene(); //only run if Internal tools scene if (scene.name.Equals("Internal_Tools", StringComparison.Ordinal) == true) { //check if instance already exists if (i == null) { i = this; } //if instance already exists and it's not this else if (i != this) { //Then destroy this in order to reinforce the singleton pattern (can only ever be one instance of toolManager) Destroy(gameObject); } //components adventureScript = GetComponent <AdventureManager>(); actorScript = GetComponent <ActorPoolManager>(); toolDataScript = GetComponent <ToolDataManager>(); toolFileScript = GetComponent <ToolFileManager>(); toolInputScript = GetComponent <ToolInput>(); toolDetailScript = GetComponent <ToolDetails>(); jointScript = GetComponent <JointManager>(); actorFileScript = GetComponent <ActorFileManager>(); //gui adventureUIScript = AdventureUI.Instance(); actorPoolUIScript = ActorPoolUI.Instance(); toolUIScript = ToolUI.Instance(); //error Check Debug.Assert(adventureScript != null, "Invalid adventureScript (Null)"); Debug.Assert(actorScript != null, "Invalid actorScript (Null)"); Debug.Assert(toolDataScript != null, "Invalid toolDataScript (Null)"); Debug.Assert(adventureUIScript != null, "Invalid adventureUIScript (Null)"); Debug.Assert(actorPoolUIScript != null, "Invalid actorPoolUIScript (Null)"); Debug.Assert(toolUIScript != null, "Invalid toolUIScript (Null)"); Debug.Assert(toolInputScript != null, "Invalid toolInputScript (Null)"); Debug.Assert(toolDetailScript != null, "Invalid toolDetailScript (Null)"); Debug.Assert(jointScript != null, "Invalid loadScript (Null)"); Debug.Assert(actorFileScript != null, "Invalid actorFileScript (Null)"); } }
void Awake() { instance = this; }