public void Assign(Rodent r) { // Debug.Log("ASsign in Employee" + r.name + test); if (!_Locked && !_Occupied) { //Debug.Log("Pass"); // Debug.Log("Assign in Employee" +r.getName()); //This script is on the portrait outline because its the visible clickable thing _PortraitOutline.GetComponent <bWorkerScript>().setWorker(r); _WorkerObj.GetComponent <SpriteRenderer>().sprite = r.GetPortrait(); //Stupid Bugg... makes no sense , something seems to break if u assign and the gameobject is turned off // Debug.Log("Portraitnameis " + r.GetPortrait()); //print(_WorkerObj.GetComponent<SpriteRenderer>()); // print(_WorkerObj.GetComponent<SpriteRenderer>().sprite); // sp = _WorkerObj.GetComponent<SpriteRenderer>(); _Occupied = true; _currentRodent = r; r.SetJob(this); ShowWeaponClass(true); SetWeaponClassImg(r.isRanged()); //subscribe to the event system - unused now //EventSystem.Instance.rodentDead += Dismiss; SoundManager.Instance.PlayAssign(); } }
// A work around to this would be to make it subscribe to the event system // when it triggers, if a current rodent is employed, enable game object, and assign portrait // possible flip back off if it was previous on enabled public void LoadDataFix() { if (_currentRodent) { _WorkerObj.GetComponent <SpriteRenderer>().sprite = _currentRodent.GetPortrait(); } }
//Will need to send in portrait later on? public void CreateButton(Rodent rodent) { // Debug.Log("Make a Button for :" +rodent.getName()); //Make new Buttons if (_index >= _used) { // Debug.Log("Make a new Button!"); //Make a new button from prefab GameObject o = Instantiate(_buttonTemplate); o.gameObject.transform.SetParent(this.transform); //offset it to stack upwards o.transform.localPosition = new Vector3(0, -_aspectHeight + (_index * _aspectHeight), 0); Button b = o.GetComponent <Button>(); if (b) { UIRodentHolder holder = b.GetComponent <UIRodentHolder>(); if (holder) { holder.setRodent(rodent); } _buttons[_index] = b; if (_index < _buttons.Length) // need to find a way to scroll someday { ++_index; ++_used; } //Assign Text Transform t = b.transform.Find("Name"); if (t) { TextMeshProUGUI text = t.GetComponent <TextMeshProUGUI>(); if (text) { text.text = rodent.getName(); } } //Assign Image t = b.transform.Find("Portrait"); if (t) { Image image = t.GetComponent <Image>(); if (image) { image.sprite = rodent.GetPortrait(); } } t = b.transform.Find("Weapon"); if (t) { Image image2 = t.GetComponent <Image>(); if (image2) { if (rodent.isRanged()) { image2.sprite = _iconRanged; } else { image2.sprite = _iconMelee; } } } } } //Reuse Old Buttons else { // Debug.Log("Reuse a Button! for " + rodent.getName()+ " @Index:" +_index +" used:"+ _used ); Button b = _buttons[_index]; if (b) { UIRodentHolder holder = b.GetComponent <UIRodentHolder>(); if (holder) { holder.setRodent(rodent); } ++_index; Transform t = b.transform.Find("Name"); TextMeshProUGUI text = t.GetComponent <TextMeshProUGUI>(); if (t) { if (text) { text.text = rodent.getName(); } } //Assign Image t = b.transform.Find("Portrait"); if (t) { Image image = t.GetComponent <Image>(); if (image) { image.sprite = rodent.GetPortrait(); } } t = b.transform.Find("Weapon"); if (t) { Image image2 = t.GetComponent <Image>(); if (image2) { if (rodent.isRanged()) { image2.sprite = _iconRanged; } else { image2.sprite = _iconMelee; } } } } } showMenu(true); }