public static SpawnPoint CarCreate( string name, Vector3 spawnPoint, Vector3 nextPoint, float lineSpacing, int pathIndex, bool isForward, WalkPath walkPath, float boxHeight = 3f, float boxLength = 10f ) { var go = new GameObject(name); go.transform.position = spawnPoint; var cl = go.AddComponent <BoxCollider>(); var spComponent = go.AddComponent <SpawnPoint>(); cl.isTrigger = true; cl.transform.localScale = new Vector3(lineSpacing - 0.05f, boxHeight, boxLength); go.transform.LookAt(nextPoint); go.transform.localPosition += new Vector3(0f, boxHeight / 2f, 0f); go.transform.Translate(Vector3.forward * boxLength / 2f); spComponent._walkPath = walkPath; spComponent._isForward = isForward; spComponent._pathIndex = pathIndex; return(spComponent); }
// 길찾기 private void FindPath() { // 다음 이동할 큐브 List <Transform> nextCubes = new List <Transform>(); // 이전 큐브 List <Transform> pastCubes = new List <Transform>(); // 현재 큐브의 연결된 큐브 갯수만큼 루프 for (int i = 0; i < currentCube.GetComponent <Walkable>().possiblePaths.Count; i++) { WalkPath walkPath = currentCube.GetComponent <Walkable>().possiblePaths[i]; if (walkPath.active) { nextCubes.Add(walkPath.target); walkPath.target.GetComponent <Walkable>().previousBlock = currentCube; } } pastCubes.Add(currentCube); ExploreCube(nextCubes, pastCubes); BuildPath(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); WalkPath myWalkPath = target as WalkPath; if (GUILayout.Button("Create and assign new Path")) { // Create a new object, assign a Path Control to it, assign that to this target, then select that object GameObject path = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Path.prefab", typeof(GameObject)) as GameObject; GameObject newPath = PrefabUtility.InstantiatePrefab(path) as GameObject; newPath.transform.position = myWalkPath.transform.position; myWalkPath.pathToWalk = newPath.GetComponent <PathControl>(); EditorUtility.SetDirty(target); Selection.activeGameObject = newPath.gameObject; } if (myWalkPath.pathToWalk != null) { if (GUILayout.Button("Select Path")) { Selection.activeGameObject = myWalkPath.pathToWalk.gameObject; } } }
public void GoesFromLastToFirst() { WalkPath wp = GameManager.Instance.scenario.currentRoom.walkPath; WalkPath_Dot first = wp.wholePath_Dots[wp.wholePath_Dots.Count - 1]; WalkPath_Dot last = wp.wholePath_Dots[0]; GoesFromThisPointToThatPoint(first, last); }
public void GoesFromHereToLast() { WalkPath wp = GameManager.Instance.scenario.currentRoom.walkPath; WalkPath.closestPointResult first = wp.ClosestDot(this.transform.position); WalkPath_Dot last = wp.wholePath_Dots[wp.wholePath_Dots.Count - 1]; GoesFromThisPointToThatPoint(first.firstPoint, last);///TOD OOOOO }
public void GoesFromThisPointToThatPoint(WalkPath_Dot fromThisDot, WalkPath_Dot toThatDot) { walking = true; currentGoal_Dot = toThatDot; WalkPath wp = GameManager.Instance.scenario.currentRoom.walkPath; List <WalkPath_Dot> path = wp.StartPath(fromThisDot, toThatDot); //s.SetEase(Ease.Linear); MakeNextStep(path); //s.AppendCallback(() => ChangeAnimDirection(Vector3.zero)); }
public void LocatePaths() { //Shoots rays in 4 directions to find possible paths //adds positive hits to the walkable list Ray TestUp = new Ray(transform.position, transform.forward); RaycastHit TestUpHit; if (Physics.Raycast(TestUp, out TestUpHit)) { if (TestUpHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestUpHit.transform; possiblePaths.Add(WP); } } Ray TestDown = new Ray(transform.position, -transform.forward); RaycastHit TestDownHit; if (Physics.Raycast(TestDown, out TestDownHit)) { if (TestDownHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestDownHit.transform; possiblePaths.Add(WP); } } Ray TestRight = new Ray(transform.position, transform.right); RaycastHit TestRightHit; if (Physics.Raycast(TestRight, out TestRightHit)) { if (TestRightHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestRightHit.transform; possiblePaths.Add(WP); } } Ray TestLeft = new Ray(transform.position, -transform.right); RaycastHit TestLeftHit; if (Physics.Raycast(TestLeft, out TestLeftHit)) { if (TestLeftHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestLeftHit.transform; possiblePaths.Add(WP); } } }
// 경로 생성 private void BuildPath() { Transform cube = clickedCube; // 클릭한 큐브가 현재큐브와 같지 않을 때까지 while (cube != currentCube) { // 실제 이동할 경로에 삽입 finalPath.Add(cube); // 클릭한 큐브의 이전큐브가 None일 때 if (cube.GetComponent <Walkable>().previousBlock != null) { cube = cube.GetComponent <Walkable>().previousBlock; } else { break; } } if (finalPath.Count > 0) { bool walk = false; for (int i = 0; i < currentCube.GetComponent <Walkable>().possiblePaths.Count; i++) { WalkPath walkCube = currentCube.GetComponent <Walkable>().possiblePaths[i]; if (walkCube.target.Equals(finalPath[finalPath.Count - 1]) && walkCube.active) { walk = true; break; } } if (!walk) { finalPath.Clear(); } else { pastCube = currentCube.GetComponent <Walkable>(); nextCube = finalPath[finalPath.Count - 1].GetComponent <Walkable>(); transform.LookAt(nextCube.GetWalkPoint()); timing = 0; anim.SetBool("Walking", true); } } }
void Update() { if (followingTarget) { if (path) { zombieBreathSound.Stop(); zombieChaseSound.Play(); Destroy(currentPath); path = null; agent.speed = maxSpeed; } if ((transform.position - followingTarget.position).sqrMagnitude <= attackRange * attackRange) { if (!zombieAttacking.IsAttacking) { onAttackRange.Invoke(); zombieChaseSound.Stop(); agent.isStopped = true; } } else { if (zombieAttacking.IsAttacking) { outOfAttackRange.Invoke(); zombieChaseSound.Play(); agent.isStopped = false; } ChaseTarget(); } } else { if (!path) { zombieChaseSound.Stop(); zombieBreathSound.Play(); currentPath = Instantiate(walkPath, transform.position, Quaternion.LookRotation(transform.forward)); path = currentPath.GetComponent <WalkPath>(); agent.speed = maxSpeed / 3; agent.destination = transform.position; currentWaypointIndex = 0; } Wander(); } }
public void Progress(float dT) { Vector2 diff = Actor.Position - WalkTarget; if (diff.Length() <= 0.1f) { if (WalkPath.Count <= 0) { this.State = TaskState.Complete; return; } WalkTarget = WalkPath.Dequeue(); } else { diff.Normalize(); this.Actor.Position += -diff *dT *this.Actor.GetSpeed(); } }
public void GoesToClosestDot(Vector3 positionInSpace) { if (walking) { foreach (Tween tw in currentTween) { tw.Kill(); } currentTween.Clear(); /////If : already seeking this point or a close point AND path is like more than 3 long, then : runSpeedMove and not speedMove } WalkPath wp = GameManager.Instance.scenario.currentRoom.walkPath; //probably will need to watch distance of seeking WalkPath.closestPointResult first = wp.ClosestDot(this.transform.position); WalkPath.closestPointResult last = wp.ClosestDot(positionInSpace); GoesFromThisPointToThatPoint(first.firstPoint, last.firstPoint); }
private void createInnerPoints(Transfer parent, WalkPath path, bool reversed) { IEnumerable <Point> points = path.InnerPoints; if (reversed) { points = points.Reverse(); } foreach (var point in points) { TransferPoint entity = new TransferPoint { Transfer = parent, DLat = (short)Math.Round((point.Latitude - parent.Origin.Latitude) * 10000.0), DLon = (short)Math.Round((point.Longitude - parent.Origin.Longitude) * 10000.0) }; sdb.AddEntity(entity); } }
public void PathCheck(Transform T) { //Debug.Log(1); WalkPath WP = new WalkPath(); WP.target = T; WalkPath[] WalkCheck = possiblePaths.ToArray(); for (int i = 0; i < WalkCheck.Length; i++) { if (WalkCheck[i].target == WP.target) { //Debug.Log(10); break; } if (i == WalkCheck.Length - 1) { possiblePaths.Add(WP); } } }
private void LateUpdate() { if (!WalkPath.Any() || transform.position == WalkPath.Last()) { return; } if (transform.position != WalkPath[_currentPathPos]) { if (_currentPathPos == 0) { transform.position = WalkPath[_currentPathPos]; } Vector3 pos = Vector3.MoveTowards(transform.position, WalkPath[_currentPathPos], Time.deltaTime * WALK_SPEED); transform.position = pos; } else { _currentPathPos = (_currentPathPos + 1) % WalkPath.Length; } }
public override void OnInspectorGUI() { //Debug.Log(1); WalkPath _WalkPath = target as WalkPath; DrawDefaultInspector(); if (GUILayout.Button("Populate!")) { if (_WalkPath.par != null) { DestroyImmediate(_WalkPath.par); } if (_WalkPath.peoplePrefabs != null && _WalkPath.peoplePrefabs.Length > 0 && _WalkPath.peoplePrefabs[0] != null) { _WalkPath.CalPath(); _WalkPath.SpawnPeople(); } } if (GUILayout.Button("Remove people")) { if (_WalkPath.par != null) { DestroyImmediate(_WalkPath.par); } } EditorGUILayout.Space(); if (_WalkPath.peoplePrefabs == null || _WalkPath.peoplePrefabs.Length == 0 || _WalkPath.peoplePrefabs[0] == null) { EditorGUILayout.HelpBox("To create a path must be at least 1 people prefab", MessageType.Warning); } }
private void ExploreCube(List <Transform> nextCubes, List <Transform> visitedCubes) { Transform current = nextCubes.First(); nextCubes.Remove(current); // 클릭한 큐브와 현재 큐브가 같으면 // 목표 좌표에 도착한 것 if (current == clickedCube) { return; } // 현재 큐브의 이동 가능한 큐브만큼 반복 for (int i = 0; i < current.GetComponent <Walkable>().possiblePaths.Count; i++) { WalkPath walkPath = current.GetComponent <Walkable>().possiblePaths[i]; // 이미 지나온 길이 아니고 길이 연결되어 있다면 if (!visitedCubes.Contains(walkPath.target) && walkPath.active) { // 다음 검색 큐브로 nextCubes.Add(walkPath.target); // 이동할 경로에 추가 walkPath.target.GetComponent <Walkable>().previousBlock = current; } } // 방문한 큐브 리스트에 현재 큐브 추가 visitedCubes.Add(current); // 리스트가 하나라도 있다면 if (nextCubes.Count > 0) { ExploreCube(nextCubes, visitedCubes); } }
public override void OnInspectorGUI() { //When you click on a tile, she's had to a list. If you choose to add a type, the type will be add to all tiles in this list InspectElement map = (InspectElement)target; if (!map.elementTest.test.Contains(map)) { map.elementTest.test.Add(map); } if (DrawDefaultInspector()) //-> if something have changed { } EditorGUILayout.Space(); if (GUILayout.Button("City")) //-> so if we decide the tile is a City block, we change the material and his property { foreach (InspectElement element in map.elementTest.test) { element.GetComponent <MeshRenderer>().material = map.elementTest.city; element.type = InspectElement.Tyle_Type.City; } map.elementTest.test.Clear(); //important to clear the list, unless you will change over and over tiles selected before } if (GUILayout.Button("Grass")) // -> same for grass block { foreach (InspectElement element in map.elementTest.test) { element.GetComponent <MeshRenderer>().material = map.elementTest.grass; element.type = InspectElement.Tyle_Type.Grass; } map.elementTest.test.Clear(); } if (GUILayout.Button("ActualizeBoxCollider")) { foreach (Transform element in map.elementTest.Roads_Position) { var go = new GameObject(); go.name = "DetectionCollision_Swipe"; BoxCollider bxCollider = go.AddComponent <BoxCollider>(); bxCollider.center = element.transform.position; bxCollider.gameObject.layer = 9; //-> 9 is layerMask value for road bxCollider.size = new Vector3(map.elementTest.scaleX, 1, map.elementTest.scaleZ); go.transform.SetParent(element); } } if (GUILayout.Button("EMERGENCY")) { map.elementTest.Roads_Position.Clear(); map.elementTest.test.Clear(); map.elementTest.Monuments_Position.Clear(); } //Monument and Road Block are specific case -> like they are event for the player, we need to keep track of them if (GUILayout.Button("Monument")) { //Check for neighbour in Genereate method foreach (InspectElement element in map.elementTest.test) { element.GetComponent <MeshRenderer>().material = map.elementTest.monument_Mat; element.type = InspectElement.Tyle_Type.Monument_Source; if (!map.elementTest.Monuments_Position.Contains(element.transform)) { map.elementTest.Monuments_Position.Add(element.transform); } } map.elementTest.test.Clear(); } if (GUILayout.Button("Malus")) { //Check for neighbour in Genereate method foreach (InspectElement element in map.elementTest.test) { element.GetComponent <MeshRenderer>().material = map.elementTest.Malus_Mat; element.type = InspectElement.Tyle_Type.Malus_Source; if (!map.elementTest.Malus_Position.Contains(element.transform)) { map.elementTest.Malus_Position.Add(element.transform); } } map.elementTest.test.Clear(); } if (GUILayout.Button("Road")) { foreach (InspectElement element in map.elementTest.test) { element.GetComponent <MeshRenderer>().material = map.elementTest.road; element.type = InspectElement.Tyle_Type.Road; if (!map.elementTest.Roads_Position.Contains(element.transform)) { map.elementTest.Roads_Position.Add(element.transform); } } map.elementTest.test.Clear(); } EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Clear Selection")) { map.elementTest.test.Clear(); } EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Clear")) //-> this button clear all materials, prefabs, and event into the map { //Clear all tiles foreach (Transform temp in map.elementTest.isoSphere.transform) { temp.GetComponent <MeshRenderer>().material = map.elementTest.default_Mat; var tmp = temp.GetComponent <InspectElement>(); tmp.type = InspectElement.Tyle_Type.Empty; tmp.Event = InspectElement.Tyle_Evenement.Empty; tmp.neighborHex.Clear(); if (temp.GetComponent <Walkable>() != null) { DestroyImmediate(temp.GetComponent <Walkable>()); } if (temp.transform.childCount > 0) { foreach (Transform child in temp.transform) { DestroyImmediate(child.gameObject); } } } for (int i = 0; i < map.elementTest.Roads_Position.Count; i++) { map.elementTest.Roads_Position[i].GetComponent <InspectElement>().neighborHex.Clear(); map.elementTest.Roads_Position[i].GetComponent <BoxCollider>().size = new Vector3(1, 1, 1); } for (int i = 0; i < map.elementTest.Monuments_Position.Count; i++) { map.elementTest.Monuments_Position[i].GetComponent <InspectElement>().neighborHex.Clear(); } for (int i = 0; i < map.elementTest.Malus_Position.Count; i++) { map.elementTest.Malus_Position[i].GetComponent <InspectElement>().neighborHex.Clear(); } map.elementTest.Roads_Position.Clear(); map.elementTest.Monuments_Position.Clear(); map.elementTest.Malus_Position.Clear(); map.elementTest.test.Clear(); } //GENERATION if (GUILayout.Button("Generate")) { if (EditorUtility.DisplayDialog("Confirm Generation ? ", " Make sure every road are interconnected\n\n And that you have place everything where you really want", "Place", "Do not Generate")) { //So we iterate over the list of the road position, if a walkable script is not found, we had it and we connect it with all of his neighbor for (int i = 0; i < map.elementTest.Roads_Position.Count; i++) { for (int j = 0; j < map.elementTest.Roads_Position.Count; j++) { if (map.elementTest.Roads_Position[i] != map.elementTest.Roads_Position[j]) { if (Vector3.Distance(map.elementTest.Roads_Position[i].transform.position, map.elementTest.Roads_Position[j].transform.position) < map.distance_Check) { map.elementTest.Roads_Position[i].GetComponent <InspectElement>().neighborHex.Add(map.elementTest.Roads_Position[j]); } } } if (map.elementTest.Roads_Position[i].GetComponent <InspectElement>().Event == InspectElement.Tyle_Evenement.Restaurant) { map.elementTest.Roads_Position[i].GetComponent <MeshRenderer>().sharedMaterial = map.elementTest.restaurant_Mat; } if (map.elementTest.Roads_Position[i].GetComponent <InspectElement>().Event == InspectElement.Tyle_Evenement.Chantier) { map.elementTest.Roads_Position[i].GetComponent <MeshRenderer>().sharedMaterial = map.elementTest.chantier_Mat; } } } foreach (Transform temp in map.elementTest.Roads_Position) { //Crossroads if (temp.GetComponent <InspectElement>().type == InspectElement.Tyle_Type.Road || temp.GetComponent <InspectElement>().type == InspectElement.Tyle_Type.CrossRoads) { if (temp.GetComponent <Walkable>() == null) { var walk_Script = temp.gameObject.AddComponent <Walkable>(); foreach (Transform element in temp.gameObject.GetComponent <InspectElement>().neighborHex) { WalkPath walk = new WalkPath(); walk.target = element; walk.active = true; walk_Script.possiblePaths.Add(walk); } } } } //Monument /*if (map.elementTest.Monuments_Position.Count != 0){ * for (int j = 0; j < map.elementTest.isoSphere.childCount; j++){ * for (int i = 0; i < map.elementTest.Monuments_Position.Count; i++){ * if (Vector3.Distance(map.elementTest.isoSphere.GetChild(j).position, map.elementTest.Monuments_Position[i].position) < map.distance_Check && map.elementTest.isoSphere.GetChild(j) != map.elementTest.Monuments_Position[i]){ * if(map.elementTest.isoSphere.GetChild(j).GetComponent<InspectElement>().Event == InspectElement.Tyle_Evenement.Empty) * map.elementTest.isoSphere.GetChild(j).GetComponent<InspectElement>().Event = InspectElement.Tyle_Evenement.Monument; * } * } * } * }*/ /*if (map.elementTest.Malus_Position.Count != 0) * { * for (int j = 0; j < map.elementTest.isoSphere.childCount; j++) * { * for (int i = 0; i < map.elementTest.Malus_Position.Count; i++) * { * if (Vector3.Distance(map.elementTest.isoSphere.GetChild(j).position, map.elementTest.Malus_Position[i].position) < map.distance_Check && map.elementTest.isoSphere.GetChild(j) != map.elementTest.Malus_Position[i]) * { * if (map.elementTest.isoSphere.GetChild(j).GetComponent<InspectElement>().Event == InspectElement.Tyle_Evenement.Empty) * map.elementTest.isoSphere.GetChild(j).GetComponent<InspectElement>().Event = InspectElement.Tyle_Evenement.Monument; * } * } * } * }*/ //Prefabs instantiation /*for (int i = 0; i < map.elementTest.isoSphere.transform.childCount; i++){ * //We spawn prefabs depending of the type of the event we found on the planet * //We calculate the normal to spawn the object on the ground of the tile * if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent<InspectElement>().type == InspectElement.Tyle_Type.Monument_Source){ * Vector3 normal = map.elementTest.isoSphere.transform.position - map.elementTest.isoSphere.transform.GetChild(i).transform.position; //Normal calculation of the actual tile * * GameObject gameObject_ = Instantiate(map.elementTest.monumentPrefab[Random.Range(0, map.elementTest.monumentPrefab.Length)], map.elementTest.isoSphere.transform.GetChild(i)); * gameObject_.transform.localScale = new Vector3(0.0006f, 0.0006f, 0.0006f); * gameObject_.transform.localPosition = new Vector3(0, 0, 0); * gameObject_.transform.up = -normal; * } * else if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent<InspectElement>().type == InspectElement.Tyle_Type.City){ * Vector3 normal = map.elementTest.isoSphere.transform.position - map.elementTest.isoSphere.transform.GetChild(i).transform.position; * * GameObject gameObject_ = Instantiate(map.elementTest.cityPrefab[Random.Range(0, map.elementTest.cityPrefab.Length)], map.elementTest.isoSphere.transform.GetChild(i)); * gameObject_.transform.localScale = new Vector3(0.0006f, 0.0006f, 0.0006f); * gameObject_.transform.localPosition = new Vector3(0, 0, 0); * gameObject_.transform.up = -normal; * } * else if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent<InspectElement>().type == InspectElement.Tyle_Type.Grass){ * Vector3 normal = map.elementTest.isoSphere.transform.position - map.elementTest.isoSphere.transform.GetChild(i).transform.position; * * GameObject gameObject_ = Instantiate(map.elementTest.grassPrefab[Random.Range(0, map.elementTest.grassPrefab.Length)], map.elementTest.isoSphere.transform.GetChild(i)); * gameObject_.transform.localScale = new Vector3(0.0006f, 0.0006f, 0.0006f); * gameObject_.transform.localPosition = new Vector3(0, 0, 0); * gameObject_.transform.up = -normal; * } * * }*/ } EditorGUILayout.Space(); EditorGUILayout.Space(); //Rare utilisation Button -> if we import a map previously contruct, she will not have all of her events, we can use the Update button to replace everything // //Issue where encounters with materials -> use of the shared material, instead it create instance of material and it can break the game later on // if (GUILayout.Button("Update")) { if (EditorUtility.DisplayDialog("Confirm Update ? ", "You want to use update button only in the case where you have imported a new planet", "Update", "Do not Update")) { for (int i = 0; i < map.elementTest.isoSphere.transform.childCount; i++) { if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent <MeshRenderer>().sharedMaterial == map.elementTest.road || map.elementTest.isoSphere.transform.GetChild(i).GetComponent <MeshRenderer>().sharedMaterial == map.elementTest.crossroadsMat) { InspectElement tile = map.elementTest.isoSphere.transform.GetChild(i).GetComponent <InspectElement>(); tile.type = InspectElement.Tyle_Type.Road; if (!map.elementTest.Roads_Position.Contains(tile.transform)) { map.elementTest.Roads_Position.Add(tile.transform); } } else if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent <MeshRenderer>().sharedMaterial == map.elementTest.grass) { InspectElement tile = map.elementTest.isoSphere.transform.GetChild(i).GetComponent <InspectElement>(); tile.type = InspectElement.Tyle_Type.Grass; } else if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent <MeshRenderer>().sharedMaterial == map.elementTest.monument_Mat) { InspectElement tile = map.elementTest.isoSphere.transform.GetChild(i).GetComponent <InspectElement>(); tile.type = InspectElement.Tyle_Type.Monument_Source; if (!map.elementTest.Monuments_Position.Contains(tile.transform)) { map.elementTest.Monuments_Position.Add(tile.transform); } } else if (map.elementTest.isoSphere.transform.GetChild(i).GetComponent <MeshRenderer>().sharedMaterial == map.elementTest.city) { InspectElement tile = map.elementTest.isoSphere.transform.GetChild(i).GetComponent <InspectElement>(); tile.type = InspectElement.Tyle_Type.City; } } //Monument if (map.elementTest.Monuments_Position.Count != 0) { for (int j = 0; j < map.elementTest.isoSphere.childCount; j++) { for (int i = 0; i < map.elementTest.Monuments_Position.Count; i++) { if (Vector3.Distance(map.elementTest.isoSphere.GetChild(j).position, map.elementTest.Monuments_Position[i].position) < map.distance_Check && map.elementTest.isoSphere.GetChild(j) != map.elementTest.Monuments_Position[i]) { map.elementTest.isoSphere.GetChild(j).GetComponent <InspectElement>().Event = InspectElement.Tyle_Evenement.Monument; } } } } for (int i = 0; i < map.elementTest.Roads_Position.Count; i++) { for (int j = 0; j < map.elementTest.Roads_Position.Count; j++) { //TODO : Check if needed in Upgrade Case /*if (map.elementTest.Roads_Position[i] != map.elementTest.Roads_Position[j]){ * /*if (Vector3.Distance(map.elementTest.Roads_Position[i].transform.position, map.elementTest.Roads_Position[j].transform.position) < map.distance_Check) * map.elementTest.Roads_Position[i].GetComponent<InspectElement>().neighborHex.Add(map.elementTest.Roads_Position[j]); * }*/ } /*if (map.elementTest.Roads_Position[i].GetComponent<InspectElement>().Event == InspectElement.Tyle_Evenement.Trafic_Jam) * map.elementTest.Roads_Position[i].GetComponent<MeshRenderer>().material = map.elementTest.traficJam_Mat;*/ if (map.elementTest.Roads_Position[i].GetComponent <InspectElement>().Event == InspectElement.Tyle_Evenement.Restaurant) { map.elementTest.Roads_Position[i].GetComponent <MeshRenderer>().material = map.elementTest.restaurant_Mat; } else if (map.elementTest.Roads_Position[i].GetComponent <InspectElement>().Event == InspectElement.Tyle_Evenement.Chantier) { map.elementTest.Roads_Position[i].GetComponent <MeshRenderer>().material = map.elementTest.chantier_Mat; } else if (map.elementTest.Roads_Position[i].GetComponent <InspectElement>().Event == InspectElement.Tyle_Evenement.Monument) { map.elementTest.Roads_Position[i].GetComponent <MeshRenderer>().material = map.elementTest.monument_Mat; } else if (map.elementTest.Roads_Position[i].GetComponent <InspectElement>().Event == InspectElement.Tyle_Evenement.Feux_Rouge) { map.elementTest.Roads_Position[i].GetComponent <MeshRenderer>().material = map.elementTest.feux_Rouge_Mat; } } } } //Not used anymore /*if (GUILayout.Button("Clear unnecessary color")){ * if (EditorUtility.DisplayDialog("Confirm Update ? ", "This will clear all unnecessary color in the map", "Update", "Do not Update")){ * foreach (Transform element in map.elementTest.isoSphere.transform){ * if (element.GetComponent<InspectElement>().type != InspectElement.Tyle_Type.CrossRoads && element.GetComponent<InspectElement>().type != InspectElement.Tyle_Type.Road) * element.GetComponent<MeshRenderer>().material = map.elementTest.default_Mat; * } * } * }*/ }
private bool calculateTransferTimes() { int errorCount = 0; PathFinder pathFinder = new PathFinder(); pathFinder.LoadData(Path.Combine(config.KnowledgePath, "transfers.xml")); var stops = sdb.GetTable <Stop>().ToArray(); for (int i = 0; i < stops.Length - 1; i++) { for (int k = i + 1; k < stops.Length; k++) { if (PathFinder.IsNear(stops[i], stops[k])) { WalkPath path = null; short dist = (short)stops[i].StraightLineDistanceTo(stops[k]); bool notSame = PathFinder.IsNearNotSamePace(stops[i], stops[k]); if (notSame) { path = pathFinder.GetPath( new Point { Latitude = stops[i].Latitude, Longitude = stops[i].Longitude }, new Point { Latitude = stops[k].Latitude, Longitude = stops[k].Longitude } ); if (path == null) { errorCount++; continue; } dist = short.Parse(Math.Round(path.Distance).ToString()); } Transfer transfer1 = new Transfer { Distance = dist, Origin = stops[i], Target = stops[k] }; Transfer transfer2 = new Transfer { Distance = dist, Origin = stops[k], Target = stops[i] }; if (notSame) { if (stops[i].Latitude == path.From.Latitude && stops[i].Longitude == path.From.Longitude) { createInnerPoints(transfer1, path, false); createInnerPoints(transfer2, path, true); } else if (stops[k].Latitude == path.From.Latitude && stops[k].Longitude == path.From.Longitude) { createInnerPoints(transfer1, path, true); createInnerPoints(transfer2, path, false); } else { throw new Exception("Something is wrong."); } } sdb.AddEntity(transfer1); sdb.AddEntity(transfer2); } } log(i * 100 / (stops.Length - 1), null); } if (errorCount > 0) { log(0, "Missing transfers: " + errorCount + ". Calculate transfers then rerun the process."); return(false); } return(true); }
public void LocatePaths() { possiblePaths.Clear(); //Shoots rays in 4 directions to find possible paths //adds positive hits to the walkable list Ray TestUp = new Ray(transform.position, transform.forward); RaycastHit TestUpHit; if (Physics.Raycast(TestUp, out TestUpHit, .5f)) { if (TestUpHit.transform.CompareTag("Path")) { //Debug.Log(1); WalkPath WP = new WalkPath(); WP.target = TestUpHit.transform; possiblePaths.Add(WP); TestUpHit.transform.GetComponent <PathBuilder>().PathCheck(this.transform); } } Ray TestDown = new Ray(transform.position, -transform.forward); RaycastHit TestDownHit; if (Physics.Raycast(TestDown, out TestDownHit, .5f)) { if (TestDownHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestDownHit.transform; possiblePaths.Add(WP); TestDownHit.transform.GetComponent <PathBuilder>().PathCheck(this.transform); } } Ray TestRight = new Ray(transform.position, transform.right); RaycastHit TestRightHit; if (Physics.Raycast(TestRight, out TestRightHit, .5f)) { if (TestRightHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestRightHit.transform; possiblePaths.Add(WP); TestRightHit.transform.GetComponent <PathBuilder>().PathCheck(this.transform); } } Ray TestLeft = new Ray(transform.position, -transform.right); RaycastHit TestLeftHit; if (Physics.Raycast(TestLeft, out TestLeftHit, .5f)) { if (TestLeftHit.transform.CompareTag("Path")) { WalkPath WP = new WalkPath(); WP.target = TestLeftHit.transform; possiblePaths.Add(WP); TestLeftHit.transform.GetComponent <PathBuilder>().PathCheck(this.transform); } } }