void Update() { // Hide if the agent died. if (!_agent) { BroadcastMessage("Hide", this, SendMessageOptions.DontRequireReceiver); gameObject.SetActive(false); return; } AgentAttributes attributes = _agent.GetComponent <AgentAttributes> (); gameIDVal.text = attributes.ID.ToString(); AgentInventory inventory = _agent.GetComponent <AgentInventory> (); capacityVal.text = inventory.carryCount.ToString() + " / " + inventory.capacity.ToString(); Health health = _agent.GetComponent <Health> (); hpVal.text = health.GetCurrentHealth() + " / " + health.GetInitialHealth(); statusVal.text = _agent.GetComponent <AgentStates> ().GetStatusString(); taskVal.text = _agent.GetComponent <AgentStates> ().GetTaskString(); Attack attack = _agent.GetComponent <Attack> (); attackRangeVal.text = attack.GetAttackRadius().ToString(); damageVal.text = attack.GetDamage().ToString(); }
public static Agent spawnAgent(AgentAttributes attributes, string role) { var agentSpawn = Instantiate(attributes.agentPrefab); Agent agentScript = agentSpawn.AddComponent <Agent>() as Agent; setRole(agentScript, role); agentScript.Attributes = attributes; return(agentScript); }
//=================\\ //===== Start =====\\ //=================\\ void Start() { _audioController = FindObjectOfType<AudioController> ().gameObject.GetComponent<AudioController> (); showError = false; hospitalAvailable = false; farmAvailable = false; waterstationAvailable = false; powerstationAvailable = false; storageAvailable = false; traininggroundAvailable = false; _gameController = GameObject.Find ("GameController").GetComponent<GameController> (); myCamObj = GameObject.Find ("CameraObject"); myCanvas = GameObject.Find ("Canvas").GetComponent <Canvas>(); selectedIcon = GetComponentInChildren<SpriteRenderer>(); //===============================\\ //=== Settler Info Background ===\\ //===============================\\ SettlerInfoDelBg = (Image)Instantiate (SettlerInfoBg); SettlerInfoDelBg.gameObject.transform.SetParent (myCanvas.gameObject.transform); SettlerInfoDelBg.rectTransform.sizeDelta = new Vector2 (821, 306); SettlerInfoDelBg.transform.Translate (410, 152.5f, 0); SettlerInfoDelBg.gameObject.SetActive (false); SettlerInfoDelBg.CrossFadeAlpha (0.95f, 0, false); //=======================\\ //=== Settler Picture ===\\ //=======================\\ settlerPortraitDel = (Image)Instantiate (settlerPortrait); settlerPortraitDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerPortraitDel.rectTransform.sizeDelta = new Vector2 (200, 300); settlerPortraitDel.transform.Translate (105, 150, 0); settlerPortraitDel.gameObject.SetActive (false); //====================\\ //=== Settler Name ===\\ //====================\\ firstLastNameDel = (Text)Instantiate (firstLastName); firstLastNameDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); firstLastNameDel.rectTransform.sizeDelta = new Vector2 (600, 50); firstLastNameDel.transform.position = new Vector2 (500, 279); firstLastNameDel.fontSize = 28; firstLastNameDel.gameObject.SetActive (false); //==========================\\ //=== Settler Attributes ===\\ //==========================\\ //Fake Attributes rndHP = UnityEngine.Random.Range (1, 101); rndStam = UnityEngine.Random.Range (0, 101); rndMor = UnityEngine.Random.Range (0, 101); rndHung = UnityEngine.Random.Range (0, 101); rndThir = UnityEngine.Random.Range (0, 101); rndStr = UnityEngine.Random.Range (0, 11); rndInt = UnityEngine.Random.Range (0, 11); rndAgil = UnityEngine.Random.Range (0, 11); rndPerc = UnityEngine.Random.Range (0, 11); rndChar = UnityEngine.Random.Range (0, 11); // Attributes Title attributesTitleDel = (Text)Instantiate (attributesTitle); attributesTitleDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); attributesTitleDel.rectTransform.sizeDelta = new Vector2 (1920, 100); attributesTitleDel.text = "Attributes"; attributesTitleDel.fontSize = 28; attributesTitleDel.transform.position = new Vector2 (315, 230); attributesTitleDel.rectTransform.sizeDelta = new Vector2 (200, 50); attributesTitleDel.gameObject.SetActive (false); //Health settlerHealthImageDel = (Image)Instantiate (settlerHealthImage); settlerHealthImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerHealthImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerHealthImageDel.transform.Translate (240, 177, 0); settlerHealthImageDel.gameObject.SetActive (false); //Text settlerHealthTextDel = (Text)Instantiate (settlerHealthText); settlerHealthTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerHealthTextDel.rectTransform.sizeDelta = new Vector2 (300, 100); settlerHealthTextDel.transform.position = new Vector2 (settlerHealthImageDel.rectTransform.position.x + 45, settlerHealthImageDel.rectTransform.position.y); settlerHealthTextDel.gameObject.SetActive (false); settlerHealthTextDel.fontSize = 18; //Stamina settlerStaminaImageDel = (Image)Instantiate (settlerStaminaImage); settlerStaminaImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerStaminaImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerStaminaImageDel.transform.Translate (settlerHealthImageDel.rectTransform.position.x, settlerHealthImageDel.rectTransform.position.y - 50, 0); settlerStaminaImageDel.gameObject.SetActive (false); //Text settlerStaminaTextDel = (Text)Instantiate (settlerStaminaText); settlerStaminaTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerStaminaTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerStaminaTextDel.transform.position = new Vector2 (settlerStaminaImageDel.rectTransform.position.x + 45, settlerStaminaImageDel.rectTransform.position.y); settlerStaminaTextDel.gameObject.SetActive (false); settlerStaminaTextDel.fontSize = 18; //Hunger settlerHungerImageDel = (Image)Instantiate (settlerHungerImage); settlerHungerImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerHungerImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerHungerImageDel.transform.Translate (settlerHealthImageDel.rectTransform.position.x, settlerStaminaImageDel.rectTransform.position.y - 50, 0); settlerHungerImageDel.gameObject.SetActive (false); //Text settlerHungerTextDel = (Text)Instantiate (settlerHungerText); settlerHungerTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerHungerTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerHungerTextDel.transform.position = new Vector2 (settlerHungerImageDel.rectTransform.position.x + 45, settlerHungerImageDel.rectTransform.position.y); settlerHungerTextDel.gameObject.SetActive (false); settlerHungerTextDel.fontSize = 18; //Thirst settlerThirstImageDel = (Image)Instantiate (settlerThirstImage); settlerThirstImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerThirstImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerThirstImageDel.transform.Translate (settlerHealthImageDel.rectTransform.position.x, settlerHungerImageDel.rectTransform.position.y - 50, 0); settlerThirstImageDel.gameObject.SetActive (false); //Text settlerThirstTextDel = (Text)Instantiate (settlerThirstText); settlerThirstTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerThirstTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerThirstTextDel.transform.position = new Vector2 (settlerThirstImageDel.rectTransform.position.x + 45, settlerThirstImageDel.rectTransform.position.y); settlerThirstTextDel.gameObject.SetActive (false); settlerThirstTextDel.fontSize = 18; //======================\\ //=== Settler Traits ===\\ //======================\\ //Strength settlerStrengthImageDel = (Image)Instantiate (settlerStrengthImage); settlerStrengthImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerStrengthImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerStrengthImageDel.transform.Translate (settlerHealthImageDel.transform.position.x + 115, settlerHealthImageDel.rectTransform.position.y, 0); settlerStrengthImageDel.gameObject.SetActive (false); //Text settlerStrengthTextDel = (Text)Instantiate (settlerStrengthText); settlerStrengthTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerStrengthTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerStrengthTextDel.transform.position = new Vector2 (settlerStrengthImageDel.rectTransform.position.x + 45, settlerStrengthImageDel.rectTransform.position.y); settlerStrengthTextDel.gameObject.SetActive (false); settlerStrengthTextDel.fontSize = 18; //Intelligence settlerIntelligenceImageDel = (Image)Instantiate (settlerIntelligenceImage); settlerIntelligenceImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerIntelligenceImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerIntelligenceImageDel.transform.Translate (settlerStrengthImageDel.rectTransform.position.x, settlerStrengthImageDel.rectTransform.position.y - 37.5f, 0); settlerIntelligenceImageDel.gameObject.SetActive (false); //Text settlerIntelligenceTextDel = (Text)Instantiate (settlerIntelligenceText); settlerIntelligenceTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerIntelligenceTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerIntelligenceTextDel.transform.position = new Vector2 (settlerIntelligenceImageDel.rectTransform.position.x + 45, settlerIntelligenceImageDel.rectTransform.position.y); settlerIntelligenceTextDel.gameObject.SetActive (false); settlerIntelligenceTextDel.fontSize = 18; //Agility settlerAgilityImageDel = (Image)Instantiate (settlerAgilityImage); settlerAgilityImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerAgilityImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerAgilityImageDel.transform.Translate (settlerStrengthImageDel.rectTransform.position.x, settlerIntelligenceImageDel.rectTransform.position.y - 37.5f, 0); settlerAgilityImageDel.gameObject.SetActive (false); //Text settlerAgilityTextDel = (Text)Instantiate (settlerAgilityText); settlerAgilityTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerAgilityTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerAgilityTextDel.transform.position = new Vector2 (settlerAgilityImageDel.rectTransform.position.x + 45, settlerAgilityImageDel.rectTransform.position.y); settlerAgilityTextDel.gameObject.SetActive (false); settlerAgilityTextDel.fontSize = 18; //Perception settlerPerceptionImageDel = (Image)Instantiate (settlerPerceptionImage); settlerPerceptionImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerPerceptionImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerPerceptionImageDel.transform.Translate (settlerStrengthImageDel.rectTransform.position.x, settlerAgilityImageDel.rectTransform.position.y - 37.5f, 0); settlerPerceptionImageDel.gameObject.SetActive (false); //Text settlerPerceptionTextDel = (Text)Instantiate (settlerPerceptionText); settlerPerceptionTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerPerceptionTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerPerceptionTextDel.transform.position = new Vector2 (settlerPerceptionImageDel.rectTransform.position.x + 45, settlerPerceptionImageDel.rectTransform.position.y); settlerPerceptionTextDel.gameObject.SetActive (false); settlerPerceptionTextDel.fontSize = 18; //Charisma settlerCharismaImageDel = (Image)Instantiate (settlerCharismaImage); settlerCharismaImageDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerCharismaImageDel.rectTransform.sizeDelta = new Vector2 (30, 30); settlerCharismaImageDel.transform.Translate (settlerStrengthImageDel.rectTransform.position.x, settlerPerceptionImageDel.rectTransform.position.y - 37.5f, 0); settlerCharismaImageDel.gameObject.SetActive (false); //Text settlerCharismaTextDel = (Text)Instantiate (settlerCharismaText); settlerCharismaTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); settlerCharismaTextDel.rectTransform.sizeDelta = new Vector2 (150, 100); settlerCharismaTextDel.transform.position = new Vector2 (settlerCharismaImageDel.rectTransform.position.x + 45, settlerCharismaImageDel.rectTransform.position.y); settlerCharismaTextDel.gameObject.SetActive (false); settlerCharismaTextDel.fontSize = 18; //=========================\\ //=== Settler Inventory ===\\ //=========================\\ // Inventory Title inventoryTitleDel = (Text)Instantiate (inventoryTitle); inventoryTitleDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); inventoryTitleDel.text = "Inventory"; inventoryTitleDel.fontSize = 28; inventoryTitleDel.transform.position = new Vector2 (515, 230); inventoryTitleDel.rectTransform.sizeDelta = new Vector2 (150, 100); inventoryTitleDel.gameObject.SetActive (false); //Inventory Food inventoryFoodTextDel = (Text)Instantiate (inventoryFoodText); inventoryFoodTextDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); inventoryFoodTextDel.text = "Food: " + agentLogic.foodStored; inventoryFoodTextDel.transform.position = new Vector2 (settlerHealthTextDel.rectTransform.position.x + 220, settlerHealthTextDel.rectTransform.position.y); inventoryFoodTextDel.rectTransform.sizeDelta = new Vector2 (150, 50); inventoryFoodTextDel.gameObject.SetActive (false); inventoryFoodTextDel.fontSize = 18; //====================\\ //=== Settler Role ===\\ //====================\\ //Roles Title rolesTitleDel = (Text)Instantiate (rolesTitle); rolesTitleDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); rolesTitleDel.text = "Role"; rolesTitleDel.fontSize = 28; rolesTitleDel.transform.position = new Vector2 (715, 230); rolesTitleDel.rectTransform.sizeDelta = new Vector2 (200, 50); rolesTitleDel.gameObject.SetActive (false); //Farmer Role Button farmerRoleButtonDel = (Button)Instantiate (farmerRoleButton); farmerRoleButtonDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); farmerRoleButtonDel.image.rectTransform.sizeDelta = new Vector2 (160, 45); farmerRoleButtonDel.transform.Translate (settlerHealthImageDel.rectTransform.position.x + 475, settlerHealthImageDel.rectTransform.position.y, 0); farmerRoleButtonDel.GetComponentInChildren<Text> ().text = "Farmer"; farmerRoleButtonDel.GetComponentInChildren<Text> ().font = font_hero; farmerRoleButtonDel.onClick.AddListener (() => farmerRoleClicked()); farmerRoleButtonDel.gameObject.SetActive (false); //Hydrologist Role Button hydrologistRoleButtonDel = (Button)Instantiate (hydrologistRoleButton); hydrologistRoleButtonDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); hydrologistRoleButtonDel.image.rectTransform.sizeDelta = new Vector2 (160, 45); hydrologistRoleButtonDel.transform.Translate (farmerRoleButtonDel.image.rectTransform.position.x, farmerRoleButtonDel.image.rectTransform.position.y - 47.5f, 0); hydrologistRoleButtonDel.GetComponentInChildren<Text> ().text = "Hydrologist"; hydrologistRoleButtonDel.GetComponentInChildren<Text> ().font = font_hero; hydrologistRoleButtonDel.onClick.AddListener (() => waterPurifierRoleClicked()); hydrologistRoleButtonDel.gameObject.SetActive (false); //Power Engineer Role Button powerEngineerRoleButtonDel = (Button)Instantiate (powerEngineerRoleButton); powerEngineerRoleButtonDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); powerEngineerRoleButtonDel.image.rectTransform.sizeDelta = new Vector2 (160, 45); powerEngineerRoleButtonDel.transform.Translate (farmerRoleButtonDel.image.rectTransform.position.x, hydrologistRoleButtonDel.image.rectTransform.position.y - 47.5f, 0); powerEngineerRoleButtonDel.GetComponentInChildren<Text> ().text = "Power Engineer"; powerEngineerRoleButtonDel.GetComponentInChildren<Text> ().font = font_hero; powerEngineerRoleButtonDel.onClick.AddListener (() => powerEngineerRoleClicked()); powerEngineerRoleButtonDel.gameObject.SetActive (false); //Trainee Role Button traineeRoleButtonDel = (Button)Instantiate (traineeRoleButton); traineeRoleButtonDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); traineeRoleButtonDel.image.rectTransform.sizeDelta = new Vector2 (160, 45); traineeRoleButtonDel.transform.Translate (farmerRoleButtonDel.image.rectTransform.position.x, powerEngineerRoleButtonDel.image.rectTransform.position.y - 47.5f, 0); traineeRoleButtonDel.GetComponentInChildren<Text> ().text = "Trainee"; traineeRoleButtonDel.GetComponentInChildren<Text> ().font = font_hero; traineeRoleButtonDel.onClick.AddListener (() => traineeRoleClicked()); traineeRoleButtonDel.gameObject.SetActive (false); //Close Button exBtnDel = (Button)Instantiate (exBtn); exBtnDel.gameObject.transform.SetParent (myCanvas.gameObject.transform); exBtnDel.image.rectTransform.sizeDelta = new Vector2 (20, 20); exBtnDel.transform.Translate (795, 286, 0); exBtnDel.GetComponentInChildren<Text> ().text = ""; exBtnDel.gameObject.SetActive (false); exBtnDel.onClick.AddListener (() => exBtnClicked()); agentAttributes = GetComponent <AgentAttributes> (); //Colours redValue = new Color (255 / 255f, 70 / 255f, 82 / 255f); //Color yellowValue = new Color (115 / 255, 255 / 255, 149 / 255); greenValue = new Color (115 / 255f, 255 / 255f, 149 / 255f); }