123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.AI;
- public class LocationController : MonoBehaviour
- {
- public List<GameObject> rooms;
- public GameObject Location;
-
- void Start()
- {
-
-
-
-
-
-
-
-
- var rooms_0 = Instantiate(Resources.Load("GameObjects/Cube", typeof(GameObject)) as GameObject);
- rooms_0.transform.SetParent(Location.transform);
- Cube(rooms_0, new Vector3(3.57f, 6.31f, 1));
- rooms.Add(rooms_0);
- var rooms_1 = Instantiate(Resources.Load("GameObjects/Cube", typeof(GameObject)) as GameObject);
- rooms_1.transform.SetParent(Location.transform);
- Cube(rooms_1, new Vector3(4, 3.7f, 1), new Vector2(3.57f, 0));
- rooms.Add(rooms_1);
- var rooms_2 = Instantiate(Resources.Load("GameObjects/Cube", typeof(GameObject)) as GameObject);
- rooms_2.transform.SetParent(Location.transform);
- Cube(rooms_2, new Vector3(3, 4.46f, 1), new Vector2(3.57f, 1.85f));
- rooms.Add(rooms_2);
-
-
-
-
-
-
-
- }
-
- void Update()
- {
- }
- public static void Cube(GameObject cube, Vector3 cube_size, Vector2 position = new Vector2())
- {
-
- cube_size = new Vector3(cube_size.x, cube_size.y, cube_size.z);
- Vector3 pos_cube = new Vector3(cube_size.x / 2f, cube_size.z / 2f, cube_size.y / 2f);
- cube.transform.position = new Vector3(pos_cube.x + position.x, pos_cube.y, pos_cube.z + position.y);
-
- GameObject plane_a = cube.transform.GetChild(0).gameObject;
-
- plane_a.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.y);
- plane_a.transform.localPosition = new Vector3(0, pos_cube.y, 0);
-
- GameObject plane_b = cube.transform.GetChild(1).gameObject;
- plane_b.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.z);
- plane_b.transform.localPosition = new Vector3(0, 0, -pos_cube.z);
-
- GameObject plane_c = cube.transform.GetChild(2).gameObject;
- plane_c.transform.localScale = new Vector3(cube_size.y, 0.01f, cube_size.z);
- plane_c.transform.localPosition = new Vector3(-pos_cube.x, 0, 0);
-
- GameObject plane_d = cube.transform.GetChild(3).gameObject;
- plane_d.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.y);
- plane_d.transform.localPosition = new Vector3(0, -pos_cube.y, 0);
-
- GameObject plane_e = cube.transform.GetChild(4).gameObject;
- plane_e.transform.localScale = new Vector3(cube_size.y, 0.01f, cube_size.z);
- plane_e.transform.localPosition = new Vector3(pos_cube.x, 0, 0);
-
- GameObject plane_f = cube.transform.GetChild(5).gameObject;
- plane_f.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.z);
- plane_f.transform.localPosition = new Vector3(0, 0, pos_cube.z);
- }
- public static void Room(string room_name, Vector3 cube_size, Vector2 position = new Vector2())
- {
-
- var room = Instantiate(Resources.Load("GameObjects/RoomTest", typeof(GameObject)) as GameObject);
- room.name = room_name;
- cube_size = new Vector3(cube_size.x, cube_size.y, cube_size.z);
- Vector3 pos_cube = new Vector3(cube_size.x / 2f, cube_size.z / 2f, cube_size.y / 2f);
- room.transform.position = new Vector3(pos_cube.x + position.x, pos_cube.y, pos_cube.z + position.y);
-
- var SideA = room.transform.GetChild(0).gameObject;
- var panel_a = Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject)) as GameObject);
- panel_a.name = "Plane_a_" + 0;
- panel_a.transform.SetParent(SideA.transform);
-
-
- panel_a.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.y);
- panel_a.transform.localPosition = new Vector3(0, pos_cube.y, 0);
- panel_a.transform.rotation = SideA.transform.rotation;
-
- var SideB = room.transform.GetChild(1).gameObject;
-
-
- for (int i = 0; i < cube_size.x; i++)
- {
- var panel = Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject;
- panel.name = "Plane_b_" + i;
- panel.transform.SetParent(SideB.transform);
- panel.transform.localPosition = new Vector3(i, 0, -pos_cube.z);
- panel.transform.rotation = SideB.transform.rotation;
- }
-
- var SideC = room.transform.GetChild(2).gameObject;
-
- for (int i = 0; i > -cube_size.x; i--)
- {
- var panel = Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject;
- panel.name = "Plane_c_" + i;
- panel.transform.SetParent(SideC.transform);
- panel.transform.position = new Vector3(i, 0, 0);
- panel.transform.rotation = SideC.transform.rotation;
- }
-
- var SideD = room.transform.GetChild(3).gameObject;
- var panel_d = Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject;
-
- panel_d.name = "Plane_d_" + 0;
- panel_d.transform.SetParent(SideD.transform);
- panel_d.transform.localScale = new Vector3(cube_size.x, 0.01f, cube_size.y);
- panel_d.transform.position = new Vector3(0, -pos_cube.y, 0);
- panel_d.transform.rotation = SideD.transform.rotation;
-
- var SideE = room.transform.GetChild(4).gameObject;
- for (int i = 0; i > -cube_size.x; i--)
- {
- var panel = Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject;
-
- panel.name = "Plane_e_" + i;
- panel.transform.SetParent(SideE.transform);
- panel.transform.position = new Vector3(pos_cube.x, 0, 0);
- panel.transform.rotation = SideE.transform.rotation;
- }
-
- var SideF = room.transform.GetChild(5).gameObject;
- for (int i = 0; i > -cube_size.x; i--)
- {
- var panel = Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject;
-
- panel.name = "Plane_f_" + i;
- panel.transform.SetParent(SideF.transform);
- panel.transform.position = new Vector3(0, 0, pos_cube.z);
- panel.transform.rotation = SideF.transform.rotation;
- }
- }
-
-
- private NavMeshAgent agent;
- public GameObject SpotSpawn;
- public Vector3 target;
- private bool b_target = true;
- public void TakePosition()
- {
- var Tank = Instantiate(Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject);
- Tank.transform.position = SpotSpawn.transform.position;
- if (Tank != null)
- {
- Ray ray;
- RaycastHit hit;
- ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out hit, 10000.0f))
- {
-
- target = hit.point;
- if (b_target)
- {
- if (Vector3.Distance(target, transform.position) > 2f)
- {
- agent.SetDestination(target);
- b_target = false;
- Tank = null;
- }
- }
- }
- }
- }
-
-
- public LayerMask terrainMask;
-
- public void makeTankOnClick()
- {
-
- StartCoroutine("setTankPosition");
- }
-
-
-
-
- IEnumerator setTankPosition()
- {
-
- GameObject tankTemplate = Instantiate<GameObject>(Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject);
-
- Ray ray;
- RaycastHit hit;
-
- while (true)
- {
-
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
-
- if (Physics.Raycast(ray, out hit, terrainMask))
- {
-
- tankTemplate.transform.position = hit.point;
-
-
- if (Input.GetMouseButtonDown(0))
- {
-
- Destroy(tankTemplate);
-
- GameObject tank = Instantiate<GameObject>(Instantiate(Resources.Load("GameObjects/Panel", typeof(GameObject))) as GameObject);
- tank.transform.position = hit.point;
-
-
- yield break;
- }
- }
- yield return null;
- }
- }
- }
|