|
@@ -19,13 +19,15 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
public GameObject route;
|
|
|
public GameObject deviceName;
|
|
|
public Transform lookPoint;
|
|
|
- private List<GameObject> listRoot;
|
|
|
+ public List<Route> listRoot;
|
|
|
private List<GameObject> listDeviceDoorName;
|
|
|
|
|
|
private void Start()
|
|
|
{
|
|
|
- listRoot = new List<GameObject>();
|
|
|
+ listRoot = new List<Route>();
|
|
|
listDeviceDoorName = new List<GameObject>();
|
|
|
+
|
|
|
+ StartCoroutine(SetHighRoute());
|
|
|
}
|
|
|
|
|
|
private void Update()
|
|
@@ -37,7 +39,7 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
line.positionCount = 0;
|
|
|
oldServerItem = serverItem;
|
|
|
serverItem = null;
|
|
|
- MachineRoomManager.Instance.RandomRange();
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -90,9 +92,10 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
|
|
|
public void NavigatorServer(MachineObj serverItem)
|
|
|
{
|
|
|
+ if(listRoot!=null)
|
|
|
for (int i = 0; i < listRoot.Count; i++)
|
|
|
{
|
|
|
- listRoot[i].SetActive(false);
|
|
|
+ listRoot[i].gameObject.SetActive(false);
|
|
|
}
|
|
|
listRoot.Clear();
|
|
|
|
|
@@ -109,34 +112,34 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
{
|
|
|
|
|
|
|
|
|
- Vector3 pos1 = new Vector3(player.localPosition.x, 0, player.localPosition.z);
|
|
|
- Vector3 pos2 = new Vector3(serverItem.transform.localPosition.x, 0, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
+ Vector3 pos1 = new Vector3(player.localPosition.x, -1, player.localPosition.z);
|
|
|
+ Vector3 pos2 = new Vector3(serverItem.transform.localPosition.x, -1, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
|
|
|
|
|
|
List<Vector3> listPos = new List<Vector3>();
|
|
|
listPos.Add(pos1);
|
|
|
listPos.Add(pos2);
|
|
|
- listPos.Add(new Vector3(serverItem.transform.localPosition.x,0,serverItem.transform.localPosition.z));
|
|
|
+ listPos.Add(new Vector3(serverItem.transform.localPosition.x, -1, serverItem.transform.localPosition.z));
|
|
|
CreateRoute(listPos,serverItem,true);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- float leftDis = Vector3.Distance(new Vector3(player.localPosition.x, 0, player.localPosition.z), new Vector3(leftLine.localPosition.x, 0, leftLine.localPosition.z));
|
|
|
+ float leftDis = Vector3.Distance(new Vector3(player.localPosition.x, -1, player.localPosition.z), new Vector3(leftLine.localPosition.x, -1, leftLine.localPosition.z));
|
|
|
|
|
|
- float rightDis = Vector3.Distance(new Vector3(player.localPosition.x, 0, player.localPosition.z), new Vector3(rightLine.localPosition.x, 0, rightLine.localPosition.z));
|
|
|
+ float rightDis = Vector3.Distance(new Vector3(player.localPosition.x, -1, player.localPosition.z), new Vector3(rightLine.localPosition.x, -1, rightLine.localPosition.z));
|
|
|
|
|
|
if (Mathf.Abs(leftDis) < Mathf.Abs(rightDis))
|
|
|
{
|
|
|
|
|
|
- Vector3 pos1 = new Vector3(player.localPosition.x, 0, player.localPosition.z);
|
|
|
- Vector3 pos2 = new Vector3(leftLine.localPosition.x, 0, player.localPosition.z);
|
|
|
+ Vector3 pos1 = new Vector3(player.localPosition.x, -1, player.localPosition.z);
|
|
|
+ Vector3 pos2 = new Vector3(leftLine.localPosition.x, -1, player.localPosition.z);
|
|
|
|
|
|
|
|
|
|
|
|
- Vector3 pos3 = new Vector3(leftLine.localPosition.x,0,serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
+ Vector3 pos3 = new Vector3(leftLine.localPosition.x, -1, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
|
|
|
- Vector3 pos4 = new Vector3(serverItem.transform.localPosition.x, 0, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
+ Vector3 pos4 = new Vector3(serverItem.transform.localPosition.x, -1, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
|
|
|
|
|
|
List<Vector3> listpos = new List<Vector3>();
|
|
@@ -156,14 +159,14 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
|
|
|
|
|
|
|
|
|
- Vector3 pos1 = new Vector3(player.localPosition.x, 0, player.localPosition.z);
|
|
|
- Vector3 pos2 = new Vector3(rightLine.localPosition.x, 0, player.localPosition.z);
|
|
|
+ Vector3 pos1 = new Vector3(player.localPosition.x, -1, player.localPosition.z);
|
|
|
+ Vector3 pos2 = new Vector3(rightLine.localPosition.x, -1, player.localPosition.z);
|
|
|
|
|
|
|
|
|
|
|
|
- Vector3 pos3 = new Vector3(rightLine.localPosition.x, 0, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
+ Vector3 pos3 = new Vector3(rightLine.localPosition.x, -1, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
|
|
|
- Vector3 pos4 = new Vector3(serverItem.transform.localPosition.x, 0, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
+ Vector3 pos4 = new Vector3(serverItem.transform.localPosition.x, -1, serverItem.transform.localPosition.z + ((serverItem.isSingle ? 1 : -1) * 1));
|
|
|
|
|
|
List<Vector3> listpos = new List<Vector3>();
|
|
|
listpos.Add(pos1);
|
|
@@ -176,85 +179,38 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- private void CreateRoute(List<Vector3> listPos,MachineObj machineObj, bool isdevice)
|
|
|
- {
|
|
|
- for (int i = 0; i < listPos.Count - 1; i++)
|
|
|
- {
|
|
|
- GameObject route1 = GameObject.Instantiate(route, MachineRoomManager.Instance.transform);
|
|
|
- route1.transform.localPosition = listPos[i];
|
|
|
- lookPoint.localPosition = listPos[i + 1];
|
|
|
- route1.transform.LookAt(lookPoint);
|
|
|
- route1.SetActive(true);
|
|
|
- listRoot.Add(route1);
|
|
|
- }
|
|
|
-
|
|
|
- if(isdevice&& machineObj)
|
|
|
- {
|
|
|
- GameObject devicedoorName = GameObject.Instantiate(deviceName, MachineRoomManager.Instance.transform);
|
|
|
- devicedoorName.transform.localPosition = listPos[listPos.Count - 2];
|
|
|
- devicedoorName.transform.LookAt(lookPoint);
|
|
|
- devicedoorName.transform.localPosition = machineObj.transform.localPosition + new Vector3(0, 1, 0);
|
|
|
- listDeviceDoorName.Add(devicedoorName);
|
|
|
- devicedoorName.GetComponent<SettingDeviceName>().SettingName(machineObj.deviceParameters.deviceName);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- private void CreateRoute(List<Vector3> listPos , bool isDevice)
|
|
|
- {
|
|
|
- for (int i = 0; i < listPos.Count-1; i++)
|
|
|
- {
|
|
|
- GameObject route1 = GameObject.Instantiate(route, MachineRoomManager.Instance.transform);
|
|
|
- route1.transform.localPosition = listPos[i];
|
|
|
- lookPoint.localPosition = listPos[i + 1];
|
|
|
- route1.transform.LookAt(lookPoint);
|
|
|
- route1.SetActive(true);
|
|
|
- listRoot.Add(route1);
|
|
|
- }
|
|
|
-
|
|
|
- if(isDevice)
|
|
|
- {
|
|
|
- GameObject devicedoorName = GameObject.Instantiate(deviceName, MachineRoomManager.Instance.transform);
|
|
|
- devicedoorName.transform.localPosition = listPos[listPos.Count - 2];
|
|
|
- lookPoint.localPosition += new Vector3(0, 0, 10);
|
|
|
- devicedoorName.transform.LookAt(lookPoint);
|
|
|
- listDeviceDoorName.Add(devicedoorName);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
public void NavigatorServer(List<MachineObj> listServerItem)
|
|
|
{
|
|
|
for (int i = 0; i < listRoot.Count; i++)
|
|
|
{
|
|
|
- listRoot[i].SetActive(false);
|
|
|
+ listRoot[i].transform.parent.gameObject.SetActive(false);
|
|
|
}
|
|
|
listRoot.Clear();
|
|
|
- listRoot = new List<GameObject>();
|
|
|
+
|
|
|
|
|
|
|
|
|
- float leftDis = Vector3.Distance(new Vector3(player.localPosition.x, 0, player.localPosition.z), new Vector3(leftLine.localPosition.x, 0, leftLine.localPosition.z));
|
|
|
+ float leftDis = Vector3.Distance(new Vector3(player.localPosition.x, -1, player.localPosition.z), new Vector3(leftLine.localPosition.x, 0, leftLine.localPosition.z));
|
|
|
|
|
|
- float rightDis = Vector3.Distance(new Vector3(player.localPosition.x, 0, player.localPosition.z), new Vector3(rightLine.localPosition.x, 0, rightLine.localPosition.z));
|
|
|
+ float rightDis = Vector3.Distance(new Vector3(player.localPosition.x, -1, player.localPosition.z), new Vector3(rightLine.localPosition.x, 0, rightLine.localPosition.z));
|
|
|
|
|
|
- Vector3 pos1 = new Vector3(player.localPosition.x, 0, player.localPosition.z);
|
|
|
+ Vector3 pos1 = new Vector3(player.localPosition.x, -1, player.localPosition.z);
|
|
|
Vector3 pos2;
|
|
|
if(Mathf.Abs( leftDis)<Mathf.Abs( rightDis))
|
|
|
{
|
|
|
- pos2 = new Vector3(leftLine.localPosition.x, 0, player.localPosition.z);
|
|
|
+ pos2 = new Vector3(leftLine.localPosition.x, -1, player.localPosition.z);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- pos2 = new Vector3(rightLine.localPosition.x, 0, player.localPosition.z);
|
|
|
+ pos2 = new Vector3(rightLine.localPosition.x, -1, player.localPosition.z);
|
|
|
}
|
|
|
|
|
|
List<Vector3> listpos = new List<Vector3>();
|
|
|
|
|
|
listpos.Add(pos1);
|
|
|
listpos.Add(pos2);
|
|
|
- listpos.Add(new Vector3(rightLine.localPosition.x, 0, player.localPosition.z + 10000));
|
|
|
+ listpos.Add(new Vector3(rightLine.localPosition.x, -1, player.localPosition.z + 10000));
|
|
|
CreateRoute(listpos,null,false);
|
|
|
|
|
|
|
|
@@ -263,11 +219,11 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
{
|
|
|
listpos.Clear();
|
|
|
|
|
|
- listpos.Add(new Vector3(listServerItem[i].transform.localPosition.x, 0, listServerItem[i].transform.localPosition.z + ((listServerItem[i].isSingle ? 1 : -1) * 1)));
|
|
|
+ listpos.Add(new Vector3(listServerItem[i].transform.localPosition.x, -1, listServerItem[i].transform.localPosition.z + ((listServerItem[i].isSingle ? 1 : -1) * 1)));
|
|
|
listpos.Add(listServerItem[i].transform.localPosition);
|
|
|
CreateRoute(listpos,listServerItem[i],true);
|
|
|
|
|
|
- Vector3 entrance = new Vector3(Mathf.Abs(leftDis) < Mathf.Abs(rightDis)?leftLine.localPosition.x:rightLine.localPosition.x,0, listServerItem[i].transform.localPosition.z + ((listServerItem[i].isSingle ? 1 : -1) * 1));
|
|
|
+ Vector3 entrance = new Vector3(Mathf.Abs(leftDis) < Mathf.Abs(rightDis)?leftLine.localPosition.x:rightLine.localPosition.x, -1, listServerItem[i].transform.localPosition.z + ((listServerItem[i].isSingle ? 1 : -1) * 1));
|
|
|
bool finish = true;
|
|
|
|
|
|
|
|
@@ -290,11 +246,89 @@ public class WayFindingManager : MonoSingleton<WayFindingManager>
|
|
|
{
|
|
|
List<Vector3> listentrancePos = new List<Vector3>();
|
|
|
listentrancePos.Add(entrance);
|
|
|
- listentrancePos.Add(new Vector3(listServerItem[i].transform.localPosition.x, 0, listServerItem[i].transform.localPosition.z + ((listServerItem[i].isSingle ? 1 : -1) * 1)));
|
|
|
+ listentrancePos.Add(new Vector3(listServerItem[i].transform.localPosition.x, -1, listServerItem[i].transform.localPosition.z + ((listServerItem[i].isSingle ? 1 : -1) * 1)));
|
|
|
CreateRoute(listentrancePos, listServerItem[i], false);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void CreateRoute(List<Vector3> listPos, MachineObj machineObj, bool isdevice)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < listPos.Count - 1; i++)
|
|
|
+ {
|
|
|
+ GameObject route1 = GameObject.Instantiate(route, MachineRoomManager.Instance.transform);
|
|
|
+ route1.transform.localPosition = listPos[i];
|
|
|
+ lookPoint.localPosition = listPos[i + 1];
|
|
|
+ route1.transform.LookAt(lookPoint);
|
|
|
+ route1.SetActive(true);
|
|
|
+ listRoot.Add(route1.transform.GetChild(0).GetComponent<Route>());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isdevice && machineObj)
|
|
|
+ {
|
|
|
+ GameObject devicedoorName = GameObject.Instantiate(deviceName, MachineRoomManager.Instance.transform);
|
|
|
+ devicedoorName.transform.localPosition = listPos[listPos.Count - 2];
|
|
|
+ devicedoorName.transform.LookAt(lookPoint);
|
|
|
+ devicedoorName.transform.localPosition = machineObj.transform.localPosition + new Vector3(0, 1, 0);
|
|
|
+ listDeviceDoorName.Add(devicedoorName);
|
|
|
+ devicedoorName.GetComponent<SettingDeviceName>().SettingName(machineObj.deviceParameters.deviceName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ private void CreateRoute(List<Vector3> listPos, bool isDevice)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < listPos.Count - 1; i++)
|
|
|
+ {
|
|
|
+ GameObject route1 = GameObject.Instantiate(route, MachineRoomManager.Instance.transform);
|
|
|
+ route1.transform.localPosition = listPos[i];
|
|
|
+ lookPoint.localPosition = listPos[i + 1];
|
|
|
+ route1.transform.LookAt(lookPoint);
|
|
|
+ route1.SetActive(true);
|
|
|
+ listRoot.Add(route1.transform.GetChild(0).GetComponent<Route>());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isDevice)
|
|
|
+ {
|
|
|
+ GameObject devicedoorName = GameObject.Instantiate(deviceName, MachineRoomManager.Instance.transform);
|
|
|
+ devicedoorName.transform.localPosition = listPos[listPos.Count - 2];
|
|
|
+ lookPoint.localPosition += new Vector3(0, 0, 10);
|
|
|
+ devicedoorName.transform.LookAt(lookPoint);
|
|
|
+ listDeviceDoorName.Add(devicedoorName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private IEnumerator SetHighRoute()
|
|
|
+ {
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ yield return new WaitForSeconds(0.2f);
|
|
|
+
|
|
|
+ if(listRoot!=null&& listRoot.Count>1)
|
|
|
+ {
|
|
|
+ Route route = null;
|
|
|
+ route = listRoot[0];
|
|
|
+ for (int i = 1; i < listRoot.Count; i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (Mathf.Abs(Vector3.Distance(player.transform.position, listRoot[i].transform.position)) < Mathf.Abs(Vector3.Distance(player.transform.position, route.transform.position)))
|
|
|
+ {
|
|
|
+
|
|
|
+ route.setHighLight(false);
|
|
|
+ route = listRoot[i];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ route.setHighLight(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|