private GameObject GenerateCombatant(string name, int role, string areas, FACTIONS faction) { Terrain t = GameObject.Find("Terrain").GetComponent<Terrain>(); GameObject[] s = GameObject.FindGameObjectsWithTag(areas); int i = UnityEngine.Random.Range(0, s.Length); Vector3 pos = s[i].transform.position + (UnityEngine.Random.insideUnitSphere * (s[i].transform.localScale.x / 2.0f)); pos.y = 1f + t.SampleHeight(pos); GameObject o = Instantiate(Resources.Load("AIActor"), pos, Quaternion.identity) as GameObject; o.name = name; switch(faction ){ case FACTIONS.ATTACKER: Debug.Log("Setting up controller (" + _attackController+")"); o.GetComponent<MCP_AI.AgentAI>()._controller = ScriptableObject.CreateInstance(_attackController) as AIController; o.GetComponent<MCP_AI.AgentAI>()._controller.faction = FACTIONS.ATTACKER; break; case FACTIONS.DEFENDER: Debug.Log("Setting up controller " + _defendController); o.GetComponent<MCP_AI.AgentAI>()._controller = ScriptableObject.CreateInstance(_defendController) as AIController; o.GetComponent<MCP_AI.AgentAI>()._controller.faction = FACTIONS.DEFENDER; break; default: throw new Exception("ERROR controller initialization failed"); } o.GetComponent<MCP_AI.AgentAI>()._state = ScriptableObject.CreateInstance<AgentState>(); o.GetComponent<MCP_AI.AgentAI>()._state.SetRole(role);// new MCP_AI.AgentState(role); return o; }
private void GenerateTeam(string team,List<GameObject> list,string areas, FACTIONS faction) { GameObject t = new GameObject(team); t.transform.parent = gameObject.transform; GameObject o; o = GenerateCombatant(team+"-Explorer", MCP_AI.AgentState.EXPLORER, areas,faction); o.transform.parent = t.transform; list.Add(o); o = GenerateCombatant(team + "-Sniper", MCP_AI.AgentState.SNIPER, areas,faction); o.transform.parent = t.transform; list.Add(o); o = GenerateCombatant(team + "-Soldier-1", MCP_AI.AgentState.SOLDIER, areas,faction); o.transform.parent = t.transform; list.Add(o); o = GenerateCombatant(team + "-Soldier-2", MCP_AI.AgentState.SOLDIER, areas,faction); o.transform.parent = t.transform; list.Add(o); o = GenerateCombatant(team + "-Support", MCP_AI.AgentState.SUPPORT, areas,faction); o.transform.parent = t.transform; list.Add(o); }