示例#1
0
 private void DetermineSelectedOnTower()
 {
     if (ConstructNodeManager.GetInfo(SelectedPosition, out NodeInfo result))
     {
         SelectedPosition = MapIns.WorldToCell(result.GameObject.transform.position).ZToZero();
     }
 }
示例#2
0
文件: NavAgent.cs 项目: dqtoy/Assets
        private void CalculateCurrentTarget()
        {
            int count = path.Count;

            if (count > 0)
            {
                target         = MapIns.CellToWorld(path[count - 1]);
                Rotator.Target = target;
            }
        }
示例#3
0
文件: NavAgent.cs 项目: dqtoy/Assets
        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);
        }
示例#4
0
文件: NavAgent.cs 项目: dqtoy/Assets
        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)
                );
        }
示例#5
0
文件: NavAgent.cs 项目: dqtoy/Assets
        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();
            }
        }
示例#6
0
    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);
            }
        }
    }
示例#7
0
文件: NavAgent.cs 项目: dqtoy/Assets
        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);
        }
示例#8
0
    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());
            }
        }
    }
示例#9
0
 private bool ShouldHandleSelect(Vector3Int selected)
 {
     return(!(!MapIns.IsValidCell(selected.x, selected.y) ||
              selected == CurrentAgent.CurrentPosition ||
              (CurrentAgent.IsMoving && selected == CurrentAgent.EndPosition)));
 }
示例#10
0
 public void SetPosition()
 {
     Cursor.updateCursor(MapIns.CellToWorld(Position));
 }
示例#11
0
 private void UpdateCursor(Vector3Int position)
 {
     Cursor.PositionCursor.SetPosTxt(position.x.ToString(), position.y.ToString());
     Cursor.updateCursor(MapIns.CellToWorld(position));
 }
示例#12
0
    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;
    }