Exemplo n.º 1
0
        private DetourElement FillDetourElement(BaseMonoEntity entity, Vector3 sourcePosition, Vector3 targetPosition)
        {
            uint          runtimeID = entity.GetRuntimeID();
            DetourElement element   = this.GetNewDetourElement(entity, sourcePosition, targetPosition);

            if (element == null)
            {
                this.RemoveDetourElement(runtimeID);
                return(null);
            }
            if (this._detours.ContainsKey(runtimeID))
            {
                this._detours[runtimeID] = element;
                return(element);
            }
            this._detours.Add(runtimeID, element);
            return(element);
        }
Exemplo n.º 2
0
        private bool GetCornerAndCalcPathWhenNeed(BaseMonoEntity entity, Vector3 sourcePosition, Vector3 targetPosition, ref Vector3 targetCorner)
        {
            DetourElement element;
            uint          runtimeID = entity.GetRuntimeID();

            if (this._getPathNumPerFrame >= this._getPathMaxNumPerFrame)
            {
                return(this.GetTargetCorner(entity, sourcePosition, targetPosition, ref targetCorner));
            }
            this._detours.TryGetValue(runtimeID, out element);
            if (element == null)
            {
                DetourElement element2 = this.FillDetourElement(entity, sourcePosition, targetPosition);
                if (element2 != null)
                {
                    targetCorner = element2.corners[element2.targetCornerIndex];
                    return(true);
                }
                targetCorner = targetPosition;
                return(true);
            }
            bool flag = this.GetTargetCorner(entity, sourcePosition, targetPosition, ref targetCorner);

            if (flag)
            {
                return(flag);
            }
            if ((Time.time - element.lastGetPathTime) <= this._getPathTimeThreshold)
            {
                return(flag);
            }
            DetourElement element3 = this.FillDetourElement(entity, sourcePosition, targetPosition);

            if (element3 != null)
            {
                targetCorner = element3.corners[element3.targetCornerIndex];
                return(true);
            }
            targetCorner = targetPosition;
            return(true);
        }
Exemplo n.º 3
0
        private DetourElement GetNewDetourElement(BaseMonoEntity entity, Vector3 sourcePosition, Vector3 targetPosition)
        {
            NavMeshPath path = new NavMeshPath();
            bool        flag = NavMesh.CalculatePath(sourcePosition, targetPosition, this._stageAreaWalkMask, path);

            for (int i = 0; i < (path.corners.Length - 1); i++)
            {
                Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.green, 0.1f);
            }
            this._getPathNumPerFrame++;
            DetourElement element = new DetourElement {
                id              = entity.GetRuntimeID(),
                targetPosition  = targetPosition,
                isCompletePath  = flag,
                lastGetPathTime = Time.time
            };

            Vector3[] vectorArray = this.SimplifyPath(sourcePosition, path);
            if (vectorArray.Length == 0)
            {
                return(null);
            }
            CapsuleCollider componentInChildren = entity.GetComponentInChildren <CapsuleCollider>();

            if (componentInChildren != null)
            {
                element.disReachCornerThreshold = componentInChildren.radius;
            }
            else
            {
                element.disReachCornerThreshold = this._disReachCornerThreshold;
            }
            element.corners           = vectorArray;
            element.targetCornerIndex = 0;
            return(element);
        }