private void DetermineSelectedOnTower() { if (ConstructNodeManager.GetInfo(SelectedPosition, out NodeInfo result)) { SelectedPosition = MapIns.WorldToCell(result.GameObject.transform.position).ZToZero(); } }
private void CalculateCurrentTarget() { int count = path.Count; if (count > 0) { target = MapIns.CellToWorld(path[count - 1]); Rotator.Target = target; } }
public List <float> GetTimes() { float distance = 0.0f; List <Vector3Int> currentPath = GetMovePath(); List <float> separateTime = new List <float>(); Vector3 currentPosition = transform.position; for (int i = currentPath.Count; i > 0; i--) { Vector3 nextPosition = MapIns.CellToWorld(currentPath[i - 1]); distance = Vector3.Distance(currentPosition, nextPosition); separateTime.Add(distance / maxSpeed); // time currentPosition = nextPosition; } return(separateTime); }
private void InitalizeMove(bool foundPath) { if (Remote.FixedMove.IsMoving) { Remote.FixedMove.Stop(); } InitForMove(foundPath); pathRenderer.LineRendererGenPath( foundPath: foundPath, worldPath: MapIns.CellToWorld(path), t: GetPerHasGone(), // (count - (maxMoveStep - CurrentMoveStep)) * 1.0f / count position: transform.position, target: MapIns.CellToWorld(EndPosition) ); }
public void MoveFinish() { Vector3Int currentCell = MapIns.WorldToCell(transform.position).ZToZero(); if (!Remote.Binding()) { if (MapIns.GetNearestPosition(currentCell, out Vector3Int result)) { // StartMove(currentCell, result); // main thread // AsyncStartMove(currentCell, result); // another thread AgentController.MoveAgent(this, currentCell, result, currentEnemy); curMoveStep = 0; } } else { Stop(); } }
private void Update() { if (selectConditions.Evaluate()) { try { Vector3 mousePos = CrossInput.Position; //#if UNITY_ANDROID && !UNITY_EDITOR // AndroidAdbLog.LogInfo(mousePos); // //AndroidAdbLog.LogInfo(Input.GetTouch(0).position); //#endif bool raycastHitted = Physics.Raycast( CameraRaycaster.ScreenPointToRay(mousePos), out RaycastHit hitInfo, CameraRaycaster.farClipPlane); if (raycastHitted) { SelectedPosition = MapIns.WorldToCell(hitInfo.point).ZToZero(); DetermineSelectedOnTower(); // DetermineSelectedOnRSS(hitInfo); selectedCallback?.Invoke(SelectedPosition); } } catch (System.Exception e) { //#if UNITY_ANDROID && !UNITY_EDITOR // AndroidAdbLog.LogInfo(e.ToString()); //#endif Debugger.Log(e.ToString()); Debugger.Log(Input.mousePosition); } } }
private bool FindPath(Vector3Int start, Vector3Int end) { StartPosition = start; EndPosition = end; if (curMoveStep >= maxMoveStep || (path != null && path.Count == 0)) { curMoveStep = 0; } bool foundPath = false; foundPath = AStar.FindPath(StartPosition.ZToZero(), EndPosition.ZToZero()); path = AStar.Path; pathRenderer.LineRendererGenPath( foundPath: foundPath, worldPath: MapIns.CellToWorld(path), t: GetPerHasGone(), // (count - (maxMoveStep - CurrentMoveStep)) * 1.0f / count position: transform.position, target: MapIns.CellToWorld(EndPosition) ); return(foundPath); }
private void CameraChanged() { if (!isWaiting) { List <Vector3Int> conners = MapIns.WorldToCell(CameraBinding.Conners); bool isCreateNew = false; for (int i = 0; i < conners.Count; i++) { QuadNode overlapNode = RSSPositionTree.Retrieve(conners[i]); currentOverlapNodeId[i] = overlapNode != null ? overlapNode.Id : -1; if (overlapNode != null) { isCreateNew = AddPositionForCreate(overlapNode) || isCreateNew; } } ReleaseRssOutside(); if (isCreateNew) { StartCoroutine(WaitForCreateComplete()); } } }
private bool ShouldHandleSelect(Vector3Int selected) { return(!(!MapIns.IsValidCell(selected.x, selected.y) || selected == CurrentAgent.CurrentPosition || (CurrentAgent.IsMoving && selected == CurrentAgent.EndPosition))); }
public void SetPosition() { Cursor.updateCursor(MapIns.CellToWorld(Position)); }
private void UpdateCursor(Vector3Int position) { Cursor.PositionCursor.SetPosTxt(position.x.ToString(), position.y.ToString()); Cursor.updateCursor(MapIns.CellToWorld(position)); }
private IEnumerator StartCreateRssWaiting() { AJPHelper.Operation oper = RSSPositionTable.Operation; while (!oper.IsDone) { yield return(null); } //if (!treeInited) //{ // int rssCount = RSSPositionTable.Count; // for (int iter = 0; iter < rssCount; iter++) // { // rssPositionTree.Insert // (RSSPositionTable.ReadOnlyRows[iter].Position.Parse3Int().ToClientPosition()); // } // treeInited = true; //} if (!treeInited) { rssPositionTree.AsyncCreateTree(GetRssPositionEnumerable()); while (!rssPositionTree.IsAsyncCreateComplete) { yield return(null); } treeInited = true; Debugger.Log("quad tree inited"); } isCreateComplete = false; int count = WaitForCreate.Count; //int i = count - 1; while (WaitForCreate.Count > 0 && !isCreateComplete) { Vector3Int pos = WaitForCreate[WaitForCreate.Count - 1].ToSerPosition(); RSS_PositionRow rssData = RSSPositionTable.GetRssAt(pos); if (rssData != null && !Resources.ContainsKey(rssData.ID)) { /// Using pool object for natural resource NaturalResource rs = RssPooling.GetItem(); rs.gameObject.name = "Resource" + rssData.RssType.ToString() + rssData.ID; Vector3 worldPos = MapIns.CellToWorld(rssData.Position.Parse3Int().ToClientPosition()); rs.SetResourceData(rssData, Flag.Owner, worldPos); Resources[rssData.ID] = rs; rs.gameObject.SetActive(true); //Debugger.Log("Created " + rssData.ID); } WaitForCreate.RemoveAt(WaitForCreate.Count - 1); //i--; yield return(null); } isCreateComplete = true; yield break; }