Beispiel #1
0
 public bool Contains(VInt3 point)
 {
     return(point.x >= this.xMin && point.x < this.xMax && point.y >= this.yMin && point.y < this.yMax);
 }
Beispiel #2
0
        public PoolObjHandle <ActorRoot> SpawnActorEx(GameObject rootObj, ref ActorMeta actorMeta, VInt3 pos, VInt3 dir, bool useLobbyModel, bool addComponent)
        {
            if (actorMeta.Difficuty == 0)
            {
                actorMeta.Difficuty = (byte)Singleton <BattleLogic> .get_instance().GetCurLvelContext().m_levelDifficulty;
            }
            ActorStaticData        theStaticData     = default(ActorStaticData);
            IGameActorDataProvider actorDataProvider = Singleton <ActorDataCenter> .get_instance().GetActorDataProvider(GameActorDataProviderType.StaticBattleDataProvider);

            actorDataProvider.GetActorStaticData(ref actorMeta, ref theStaticData);
            ActorServerData        actorServerData    = default(ActorServerData);
            IGameActorDataProvider actorDataProvider2 = Singleton <ActorDataCenter> .get_instance().GetActorDataProvider(GameActorDataProviderType.ServerDataProvider);

            actorDataProvider2.GetActorServerData(ref actorMeta, ref actorServerData);
            if (actorMeta.SkinID == 0u)
            {
                actorMeta.SkinID = actorServerData.SkinId;
            }
            GameObject  gameObject = null;
            ActorConfig component;

            if (rootObj == null)
            {
                rootObj = MonoSingleton <SceneMgr> .GetInstance().Spawn(typeof(ActorRoot).get_Name(), (SceneObjType)theStaticData.TheActorMeta.ActorType, pos, dir);

                component = rootObj.GetComponent <ActorConfig>();
            }
            else
            {
                component = rootObj.GetComponent <ActorConfig>();
                Animation componentInChildren = rootObj.GetComponentInChildren <Animation>();
                if (componentInChildren != null)
                {
                    gameObject = componentInChildren.gameObject;
                }
                rootObj.transform.parent = MonoSingleton <SceneMgr> .GetInstance().GetRoot((SceneObjType)theStaticData.TheActorMeta.ActorType).transform;
            }
            component.ConfigID = actorMeta.ConfigId;
            CActorInfo cActorInfo = null;

            if (!string.IsNullOrEmpty(theStaticData.TheResInfo.ResPath))
            {
                CActorInfo actorInfo = CActorInfo.GetActorInfo(theStaticData.TheResInfo.ResPath, 0);
                if (actorInfo != null)
                {
                    cActorInfo = (CActorInfo)Object.Instantiate(actorInfo);
                    string text = (!useLobbyModel) ? cActorInfo.GetArtPrefabName((int)actorMeta.SkinID, -1) : cActorInfo.GetArtPrefabNameLobby((int)actorMeta.SkinID);
                    if (gameObject == null && !string.IsNullOrEmpty(text))
                    {
                        bool flag = false;
                        gameObject = MonoSingleton <SceneMgr> .GetInstance().GetPooledGameObjLOD(text, false, SceneObjType.ActionRes, Vector3.zero, Quaternion.identity, out flag);

                        if (gameObject != null)
                        {
                            Transform component2 = gameObject.GetComponent <Transform>();
                            component2.SetParent(rootObj.transform);
                            component2.localPosition = Vector3.zero;
                            component2.localRotation = Quaternion.identity;
                            TransformConfig transformConfigIfHaveOne = cActorInfo.GetTransformConfigIfHaveOne(ETransformConfigUsage.CharacterInGame);
                            if (transformConfigIfHaveOne != null)
                            {
                                component2.localPosition += transformConfigIfHaveOne.Offset;
                                component2.localScale    *= transformConfigIfHaveOne.Scale;
                            }
                        }
                    }
                }
            }
            PoolObjHandle <ActorRoot> result = component.AttachActorRoot(rootObj, ref actorMeta, cActorInfo);

            result.get_handle().TheStaticData = theStaticData;
            if (addComponent)
            {
                result.get_handle().Spawned();
            }
            return(result);
        }
Beispiel #3
0
        public override void Prepare()
        {
            AstarData targetAstarData = this.targetAstarData;
            VInt3     vInt;

            this.startNode = targetAstarData.GetNearestByRasterizer(this.startPoint, out vInt);
            if (this.startNode != null)
            {
                this.startPoint = vInt;
            }
            if (this.hasEndPoint)
            {
                this.endNode = targetAstarData.GetNearestByRasterizer(this.endPoint, out vInt);
                if (this.endNode != null)
                {
                    this.endPoint = vInt;
                }
                this.hTarget     = this.endPoint;
                this.hTargetNode = this.endNode;
            }
            if (this.startNode == null && this.hasEndPoint && this.endNode == null)
            {
                base.Error();
                base.LogError("Couldn't find close nodes to the start point or the end point");
                return;
            }
            if (this.startNode == null)
            {
                base.Error();
                base.LogError("Couldn't find a close node to the start point");
                return;
            }
            if (this.endNode == null && this.hasEndPoint)
            {
                base.Error();
                base.LogError("Couldn't find a close node to the end point");
                return;
            }
            if (!this.startNode.Walkable)
            {
                base.Error();
                base.LogError("The node closest to the start point is not walkable");
                return;
            }
            if (this.hasEndPoint && !this.endNode.Walkable)
            {
                base.Error();
                base.LogError("The node closest to the end point is not walkable");
                return;
            }
            if (this.hasEndPoint && this.startNode.Area != this.endNode.Area)
            {
                base.Error();
                base.LogError(string.Concat(new object[]
                {
                    "There is no valid path to the target (start area: ",
                    this.startNode.Area,
                    ", target area: ",
                    this.endNode.Area,
                    ")"
                }));
                return;
            }
        }
        private void GenerateNodes(Vector3[] vectorVertices, int[] triangles, out Vector3[] originalVertices, out VInt3[] vertices)
        {
            if (vectorVertices.Length == 0 || triangles.Length == 0)
            {
                originalVertices = vectorVertices;
                vertices         = new VInt3[0];
                this.nodes       = new TriangleMeshNode[0];
                return;
            }
            vertices = new VInt3[vectorVertices.Length];
            int num = 0;

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = (VInt3)this.matrix.MultiplyPoint3x4(vectorVertices[i]);
            }
            Dictionary <VInt3, int> dictionary = new Dictionary <VInt3, int>();

            int[] array = new int[vertices.Length];
            for (int j = 0; j < vertices.Length; j++)
            {
                if (!dictionary.ContainsKey(vertices[j]))
                {
                    array[num] = j;
                    dictionary.Add(vertices[j], num);
                    num++;
                }
            }
            for (int k = 0; k < triangles.Length; k++)
            {
                VInt3 vInt = vertices[triangles[k]];
                triangles[k] = dictionary.get_Item(vInt);
            }
            VInt3[] array2 = vertices;
            vertices         = new VInt3[num];
            originalVertices = new Vector3[num];
            for (int l = 0; l < num; l++)
            {
                vertices[l]         = array2[array[l]];
                originalVertices[l] = vectorVertices[array[l]];
            }
            this.nodes = new TriangleMeshNode[triangles.Length / 3];
            int graphIndex = this.active.astarData.GetGraphIndex(this);

            for (int m = 0; m < this.nodes.Length; m++)
            {
                this.nodes[m] = new TriangleMeshNode(this.active);
                TriangleMeshNode triangleMeshNode = this.nodes[m];
                triangleMeshNode.GraphIndex = (uint)graphIndex;
                triangleMeshNode.Penalty    = this.initialPenalty;
                triangleMeshNode.Walkable   = true;
                triangleMeshNode.v0         = triangles[m * 3];
                triangleMeshNode.v1         = triangles[m * 3 + 1];
                triangleMeshNode.v2         = triangles[m * 3 + 2];
                if (!Polygon.IsClockwise(vertices[triangleMeshNode.v0], vertices[triangleMeshNode.v1], vertices[triangleMeshNode.v2]))
                {
                    int v = triangleMeshNode.v0;
                    triangleMeshNode.v0 = triangleMeshNode.v2;
                    triangleMeshNode.v2 = v;
                }
                if (Polygon.IsColinear(vertices[triangleMeshNode.v0], vertices[triangleMeshNode.v1], vertices[triangleMeshNode.v2]))
                {
                    Debug.DrawLine((Vector3)vertices[triangleMeshNode.v0], (Vector3)vertices[triangleMeshNode.v1], Color.red);
                    Debug.DrawLine((Vector3)vertices[triangleMeshNode.v1], (Vector3)vertices[triangleMeshNode.v2], Color.red);
                    Debug.DrawLine((Vector3)vertices[triangleMeshNode.v2], (Vector3)vertices[triangleMeshNode.v0], Color.red);
                }
                triangleMeshNode.UpdatePositionFromVertices();
            }
            DictionaryView <VInt2, TriangleMeshNode> dictionaryView = new DictionaryView <VInt2, TriangleMeshNode>();
            int n    = 0;
            int num2 = 0;

            while (n < triangles.Length)
            {
                dictionaryView[new VInt2(triangles[n], triangles[n + 1])]     = this.nodes[num2];
                dictionaryView[new VInt2(triangles[n + 1], triangles[n + 2])] = this.nodes[num2];
                dictionaryView[new VInt2(triangles[n + 2], triangles[n])]     = this.nodes[num2];
                num2++;
                n += 3;
            }
            ListLinqView <MeshNode> listLinqView = new ListLinqView <MeshNode>();
            List <uint>             list         = new List <uint>();
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;

            while (num4 < triangles.Length)
            {
                listLinqView.Clear();
                list.Clear();
                TriangleMeshNode triangleMeshNode2 = this.nodes[num5];
                for (int num6 = 0; num6 < 3; num6++)
                {
                    TriangleMeshNode triangleMeshNode3;
                    if (dictionaryView.TryGetValue(new VInt2(triangles[num4 + (num6 + 1) % 3], triangles[num4 + num6]), out triangleMeshNode3))
                    {
                        listLinqView.Add(triangleMeshNode3);
                        list.Add((uint)(triangleMeshNode2.position - triangleMeshNode3.position).costMagnitude);
                    }
                }
                triangleMeshNode2.connections     = listLinqView.ToArray();
                triangleMeshNode2.connectionCosts = list.ToArray();
                num5++;
                num4 += 3;
            }
            if (num3 > 0)
            {
                Debug.LogError("One or more triangles are identical to other triangles, this is not a good thing to have in a navmesh\nIncreasing the scale of the mesh might help\nNumber of triangles with error: " + num3 + "\n");
            }
            NavMeshGraph.RebuildBBTree(this);
        }
Beispiel #5
0
 public void LateUpdate(int nDelta)
 {
     if (this.skillSlot == null || this.skillSlot.SkillObj == null || this.skillSlot.SkillObj.cfgData == null)
     {
         return;
     }
     if (this.effectHideFrameNum > 0 && Time.frameCount > this.effectHideFrameNum)
     {
         this.ForceSetGuildPrefabShow(false);
         this.effectHideFrameNum = 0;
     }
     this.pressTime += nDelta;
     if (this.effectPrefab != null)
     {
         if (this.bMoveFlag)
         {
             Vector3 b = this.deltaDirection * this.moveSpeed * (float)nDelta;
             this.deltaPosition += b;
             if (this.deltaPosition.sqrMagnitude >= this.movePosition.sqrMagnitude)
             {
                 this.bMoveFlag        = false;
                 this.useSkillPosition = this.skillSlot.Actor.handle.myTransform.position + this.useOffsetPosition;
                 this.effectPrefab.transform.position = this.useSkillPosition;
             }
             else
             {
                 this.useSkillPosition  = this.effectPrefab.transform.position + b;
                 this.useSkillPosition += this.skillSlot.Actor.handle.myTransform.position - this.rootRosition;
                 this.effectPrefab.transform.position = this.useSkillPosition;
                 this.rootRosition = this.skillSlot.Actor.handle.myTransform.position;
             }
         }
         else
         {
             this.useSkillPosition += this.skillSlot.Actor.handle.myTransform.position - this.rootRosition;
             this.effectPrefab.transform.position = this.useSkillPosition;
             this.rootRosition = this.skillSlot.Actor.handle.myTransform.position;
         }
         if (this.bRotateFlag)
         {
             float num = this.rotateSpeed * (float)nDelta;
             this.deltaAngle += num;
             if (this.deltaAngle >= this.rotateAngle)
             {
                 this.bRotateFlag       = false;
                 this.useSkillDirection = this.rotateDirection;
                 this.effectPrefab.transform.forward = this.useSkillDirection;
             }
             else
             {
                 Vector3 point = this.effectPrefab.transform.forward;
                 if (Vector3.Cross(this.useSkillDirection, this.rotateDirection).y < 0f)
                 {
                     point = Quaternion.Euler(0f, -num, 0f) * point;
                 }
                 else
                 {
                     point = Quaternion.Euler(0f, num, 0f) * point;
                 }
                 this.useSkillDirection = point;
                 this.effectPrefab.transform.forward = this.useSkillDirection;
             }
         }
         VInt ob = 0;
         if (PathfindingUtility.GetGroundY((VInt3)this.effectPrefab.transform.position, out ob))
         {
             Vector3 position = this.effectPrefab.transform.position;
             position.y = (float)ob + 0.3f;
             this.effectPrefab.transform.position = position;
         }
     }
     if (this.effectWarnPrefab != null && this.effectPrefab != null)
     {
         this.effectWarnPrefab.transform.position = this.effectPrefab.transform.position;
         this.effectWarnPrefab.transform.forward  = this.effectPrefab.transform.forward;
     }
     this.SetUseSkillTarget();
     if (this.bSelectEffectPrefab && this.IsPrefabVisible(this.effectPrefab) && FogOfWar.enable)
     {
         VInt3 vInt = (VInt3)this.effectPrefab.transform.position;
         if (!PathfindingUtility.IsValidTarget(this.skillSlot.Actor.handle, vInt))
         {
             this.PrefabSelecter = SkillControlIndicator.EEffectPrefabSelect.Block;
         }
         else if (Singleton <GameFowManager> .instance.QueryAttr(vInt) == FieldObj.EViewBlockType.Grass)
         {
             this.PrefabSelecter = SkillControlIndicator.EEffectPrefabSelect.Grass;
         }
         else if (SkillControlIndicator.CheckGrassAttaching(ref vInt))
         {
             this.PrefabSelecter = SkillControlIndicator.EEffectPrefabSelect.Grass;
         }
         else
         {
             this.PrefabSelecter = SkillControlIndicator.EEffectPrefabSelect.Normal;
         }
     }
 }
 public bool Linecast(VInt3 origin, VInt3 end, GraphNode hint, out GraphHitInfo hit, List <GraphNode> trace)
 {
     return(NavMeshGraph.Linecast(this, origin, end, hint, out hit, trace));
 }
        public static bool Linecast(INavmesh graph, VInt3 tmp_origin, VInt3 tmp_end, GraphNode hint, out GraphHitInfo hit, List <GraphNode> trace)
        {
            VInt3 vInt  = tmp_end;
            VInt3 vInt2 = tmp_origin;

            hit = default(GraphHitInfo);
            if (float.IsNaN((float)(tmp_origin.x + tmp_origin.y + tmp_origin.z)))
            {
                throw new ArgumentException("origin is NaN");
            }
            if (float.IsNaN((float)(tmp_end.x + tmp_end.y + tmp_end.z)))
            {
                throw new ArgumentException("end is NaN");
            }
            TriangleMeshNode triangleMeshNode = hint as TriangleMeshNode;

            if (triangleMeshNode == null)
            {
                triangleMeshNode = ((graph as NavGraph).GetNearest(tmp_origin, NNConstraint.None).node as TriangleMeshNode);
                if (triangleMeshNode == null)
                {
                    Debug.LogError("Could not find a valid node to start from");
                    hit.point = tmp_origin;
                    return(true);
                }
            }
            if (vInt2 == vInt)
            {
                hit.node = triangleMeshNode;
                return(false);
            }
            vInt2      = (VInt3)triangleMeshNode.ClosestPointOnNode((Vector3)vInt2);
            hit.origin = vInt2;
            if (!triangleMeshNode.Walkable)
            {
                hit.point         = vInt2;
                hit.tangentOrigin = vInt2;
                return(true);
            }
            List <VInt3> list = ListPool <VInt3> .Claim();

            List <VInt3> list2 = ListPool <VInt3> .Claim();

            int num = 0;

            while (true)
            {
                num++;
                if (num > 2000)
                {
                    break;
                }
                TriangleMeshNode triangleMeshNode2 = null;
                if (trace != null)
                {
                    trace.Add(triangleMeshNode);
                }
                if (triangleMeshNode.ContainsPoint(vInt))
                {
                    goto Block_9;
                }
                for (int i = 0; i < triangleMeshNode.connections.Length; i++)
                {
                    if (triangleMeshNode.connections[i].GraphIndex == triangleMeshNode.GraphIndex)
                    {
                        list.Clear();
                        list2.Clear();
                        if (triangleMeshNode.GetPortal(triangleMeshNode.connections[i], list, list2, false))
                        {
                            VInt3 vInt3 = list.get_Item(0);
                            VInt3 vInt4 = list2.get_Item(0);
                            float num2;
                            float num3;
                            if ((Polygon.LeftNotColinear(vInt3, vInt4, hit.origin) || !Polygon.LeftNotColinear(vInt3, vInt4, tmp_end)) && Polygon.IntersectionFactor(vInt3, vInt4, hit.origin, tmp_end, out num2, out num3) && num3 >= 0f && num2 >= 0f && num2 <= 1f)
                            {
                                triangleMeshNode2 = (triangleMeshNode.connections[i] as TriangleMeshNode);
                                break;
                            }
                        }
                    }
                }
                if (triangleMeshNode2 == null)
                {
                    goto Block_17;
                }
                triangleMeshNode = triangleMeshNode2;
            }
            Debug.LogError("Linecast was stuck in infinite loop. Breaking.");
            ListPool <VInt3> .Release(list);

            ListPool <VInt3> .Release(list2);

            return(true);

Block_9:
            ListPool <VInt3> .Release(list);

            ListPool <VInt3> .Release(list2);

            return(false);

Block_17:
            int vertexCount = triangleMeshNode.GetVertexCount();

            for (int j = 0; j < vertexCount; j++)
            {
                VInt3   vertex  = triangleMeshNode.GetVertex(j);
                VInt3   vertex2 = triangleMeshNode.GetVertex((j + 1) % vertexCount);
                VFactor vFactor;
                VFactor vFactor2;
                if ((Polygon.LeftNotColinear(vertex, vertex2, hit.origin) || !Polygon.LeftNotColinear(vertex, vertex2, tmp_end)) && Polygon.IntersectionFactor(vertex, vertex2, hit.origin, tmp_end, out vFactor, out vFactor2) && !vFactor2.IsNegative && !vFactor.IsNegative && vFactor.nom / vFactor.den <= 1L)
                {
                    VInt3 vInt5 = (vertex2 - vertex) * (float)vFactor.nom;
                    vInt5             = IntMath.Divide(vInt5, vFactor.den);
                    vInt5            += vertex;
                    hit.point         = vInt5;
                    hit.node          = triangleMeshNode;
                    hit.tangent       = vertex2 - vertex;
                    hit.tangentOrigin = vertex;
                    ListPool <VInt3> .Release(list);

                    ListPool <VInt3> .Release(list2);

                    return(true);
                }
            }
            Debug.LogWarning("Linecast failing because point not inside node, and line does not hit any edges of it");
            ListPool <VInt3> .Release(list);

            ListPool <VInt3> .Release(list2);

            return(false);
        }
Beispiel #8
0
        public void OnPathComplete(Path _p)
        {
            //Good Game

            /*if(!_p.error)
             * {
             *  for (int i = 0; i < _p.vectorPath.Count; i++)
             *  {
             *      Debug.Log(gameObject.name + "--first--" + i + "--" + IntMath.Int3s2Vector3s(_p.vectorPath)[i]);
             *  }
             * }*/
            ABPath p = _p as ABPath;

            canSearchAgain = true;

            if (path != null)
            {
                path.Release(this);
            }
            path = p;
            p.Claim(this);

            if (p.error)
            {
                wp         = 0;
                vectorPath = null;
                return;
            }


            //Good Game

            /*Vector3 p1 = (Vector3)p.originalStartPoint;
             *          Vector3 p2 = transform.position;*/
            VInt3 p1 = p.originalStartPoint;
            VInt3 p2 = (VInt3)transform.position;

            p1.y = p2.y;
            //GG
            //float d = (p2 - p1).magnitude;
            float d = ((Vector3)(p2 - p1)).magnitude;

            wp = 0;

            //Good Game
            vectorPath = p.vectorPath;
            //vectorPath = IntMath.Int3s2Vector3s(p.vectorPath);
            for (int i = 0; i < vectorPath.Count; i++)
            {
                Debug.Log(gameObject.name + "--path count--" + i + "--" + vectorPath[i]);
            }
            //Good Game
            //Vector3 waypoint;
            VInt3 waypoint;

            if (moveNextDist > 0)
            {
                for (float t = 0; t <= d; t += moveNextDist * 0.6f)
                {
                    wp--;
                    //Good Game
                    //Vector3 pos = p1 + (p2-p1)*t;
                    VInt3 pos = p1 + (p2 - p1) * t;

                    do
                    {
                        wp++;
                        waypoint = vectorPath[wp];
                        //Debug.Log($"--waypoint--{gameObject.name}--{((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude}--{moveNextDist * moveNextDist}");
                    }
                    //Good Game
                    //while (controller.To2D(pos - waypoint).sqrMagnitude < moveNextDist*moveNextDist && wp != vectorPath.Count-1);
                    //while (((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                    while (controller.To2D((pos - waypoint)).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1);
                }
                //Debug.Log($"--waypoint index--{gameObject.name}--{wp}");
            }
            //GG Test
            //wp = 2;
        }
Beispiel #9
0
        public void Update()
        {
            if (Time.time >= nextRepath && canSearchAgain)
            {
                RecalculatePath();
            }

            Vector3 pos = transform.position;

            if (vectorPath != null && vectorPath.Count != 0)
            {
                //Good Game
                //while ((controller.To2D(pos - vectorPath[wp]).sqrMagnitude < moveNextDist*moveNextDist && wp != vectorPath.Count-1) || wp == 0)
                //while ((controller.To2D((VInt3)pos - vectorPath[wp]).sqrMagnitude < moveNextDist*moveNextDist && wp != vectorPath.Count-1) || wp == 0)
                //Debug.Log($"--waypoint--{gameObject.name}--{(controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude / 1000000f}--{moveNextDist * moveNextDist}");
                while ((((Vector2)controller.To2D((VInt3)pos - vectorPath[wp])).sqrMagnitude < moveNextDist * moveNextDist && wp != vectorPath.Count - 1) || wp == 0)
                {
                    wp++;
                    //Debug.Log($"--agent{transform.GetSiblingIndex()}--wp--{wp}");
                }

                // Current path segment goes from vectorPath[wp-1] to vectorPath[wp]
                // We want to find the point on that segment that is 'moveNextDist' from our current position.
                // This can be visualized as finding the intersection of a circle with radius 'moveNextDist'
                // centered at our current position with that segment.
                var p1 = vectorPath[wp - 1];
                var p2 = vectorPath[wp];

                // Calculate the intersection with the circle. This involves some math.
                //Good Game
                //var t = VectorMath.LineCircleIntersectionFactor(controller.To2D(transform.position), controller.To2D(p1), controller.To2D(p2), moveNextDist);
                var t = VectorMath.LineCircleIntersectionFactor((Vector2)controller.To2D((VInt3)transform.position), (Vector2)controller.To2D(p1), (Vector2)controller.To2D(p2), moveNextDist);
                // Clamp to a point on the segment
                t = Mathf.Clamp01(t);
                //Good Game
                //Vector3 waypoint = Vector3.Lerp(p1, p2, t);
                VInt3 waypoint = VInt3.Lerp(p1, p2, t);

                // Calculate distance to the end of the path
                //Good Game

                /*float remainingDistance = controller.To2D(waypoint - pos).magnitude + controller.To2D(waypoint - p2).magnitude;
                 *              for (int i = wp; i < vectorPath.Count - 1; i++)
                 *                  remainingDistance += controller.To2D(vectorPath[i+1] - vectorPath[i]).magnitude;*/
                float remainingDistance = controller.To2D(waypoint - (VInt3)pos).magnitude + controller.To2D(waypoint - p2).magnitude;
                for (int i = wp; i < vectorPath.Count - 1; i++)
                {
                    remainingDistance += controller.To2D(vectorPath[i + 1] - vectorPath[i]).magnitude;
                }

                // Set the target to a point in the direction of the current waypoint at a distance
                // equal to the remaining distance along the path. Since the rvo agent assumes that
                // it should stop when it reaches the target point, this will produce good avoidance
                // behavior near the end of the path. When not close to the end point it will act just
                // as being commanded to move in a particular direction, not toward a particular point
                //GG
                remainingDistance /= 1000000;
                //Debug.Log("--remian--" + remainingDistance.ToString("f2"));
                //var rvoTarget = (waypoint - pos).normalized * remainingDistance + pos;
                var rvoTarget = ((Vector3)waypoint - pos).normalized * remainingDistance + pos;
                // When within [slowdownDistance] units from the target, use a progressively lower speed
                var desiredSpeed = Mathf.Clamp01(remainingDistance / slowdownDistance) * maxSpeed;
                Debug.DrawLine(transform.position, waypoint, Color.red);
                //GG
                //controller.SetTarget(rvoTarget, desiredSpeed, maxSpeed);
                //Debug.Log($"--target--{rvoTarget}--de speed--{desiredSpeed}--maxSpeed--{maxSpeed}");
                controller.SetTarget((VInt3)rvoTarget, (int)(desiredSpeed * 1000), (int)(maxSpeed * 1000));
                //controller.SetTarget((VInt3)rvoTarget, 50, (int)(maxSpeed* 1000));
            }
            else
            {
                // Stand still
                //GG
                //controller.SetTarget(pos, maxSpeed, maxSpeed);
                controller.SetTarget((VInt3)pos, (int)(maxSpeed * 1000), (int)(maxSpeed * 1000));
            }

            // Get a processed movement delta from the rvo controller and move the character.
            // This is based on information from earlier frames.
            //GG
            //var movementDelta = controller.CalculateMovementDelta(Time.deltaTime);
            //var movementDelta = controller.CalculateMovementDelta((int)(Time.deltaTime * 1000));
            var movementDelta = controller.CalculateMovementDelta(50);

            //GG
            //pos += movementDelta;
            pos += (Vector3)movementDelta;
            //Debug.Log("--" + movementDelta.ToString());

            //Rotate the character if the velocity is not extremely small
            //GG
            //if (Time.deltaTime > 0 && movementDelta.magnitude / Time.deltaTime > 0.01f)
            if (Time.deltaTime > 0 && ((Vector3)movementDelta).magnitude / Time.deltaTime > 0.01f)
            {
                var rot = transform.rotation;
                //GG
                //var targetRot = Quaternion.LookRotation((Vector3)movementDelta, (Vector3)controller.To3D(Vector2.zero, 1));
                var         targetRot     = Quaternion.LookRotation((Vector3)movementDelta, (Vector3)controller.To3D(VInt2.zero, 1000));
                const float RotationSpeed = 5;
                if (controller.movementPlane == MovementPlane.XY)
                {
                    targetRot = targetRot * Quaternion.Euler(-90, 180, 0);
                }
                transform.rotation = Quaternion.Slerp(rot, targetRot, Time.deltaTime * RotationSpeed);
            }

            if (controller.movementPlane == MovementPlane.XZ)
            {
                RaycastHit hit;
                if (Physics.Raycast(pos + Vector3.up, Vector3.down, out hit, 2, groundMask))
                {
                    pos.y = hit.point.y;
                }
            }

            transform.position = pos;
            //Good Game

            /*if(pos.x > 200 || pos.y > 200 || pos.z > 200 || pos.x > -200 || pos.z < -200)
             *  Debug.LogError("--" + gameObject.name + "--" + pos);*/
        }
Beispiel #10
0
        private void DelaunayRefinement(VInt3[] verts, int[] tris, ref int vCount, ref int tCount, bool delaunay, bool colinear, VInt3 worldOffset)
        {
            if (tCount % 3 != 0)
            {
                throw new Exception("Triangle array length must be a multiple of 3");
            }
            Dictionary <VInt2, int> dictionary = this.cached_Int2_int_dict;

            dictionary.Clear();
            for (int i = 0; i < tCount; i += 3)
            {
                if (!Polygon.IsClockwise(verts[tris[i]], verts[tris[i + 1]], verts[tris[i + 2]]))
                {
                    int num = tris[i];
                    tris[i]     = tris[i + 2];
                    tris[i + 2] = num;
                }
                dictionary.set_Item(new VInt2(tris[i], tris[i + 1]), i + 2);
                dictionary.set_Item(new VInt2(tris[i + 1], tris[i + 2]), i);
                dictionary.set_Item(new VInt2(tris[i + 2], tris[i]), i + 1);
            }
            int num2 = 9;

            for (int j = 0; j < tCount; j += 3)
            {
                for (int k = 0; k < 3; k++)
                {
                    int num3;
                    if (dictionary.TryGetValue(new VInt2(tris[j + (k + 1) % 3], tris[j + k % 3]), ref num3))
                    {
                        VInt3 vInt  = verts[tris[j + (k + 2) % 3]];
                        VInt3 vInt2 = verts[tris[j + (k + 1) % 3]];
                        VInt3 vInt3 = verts[tris[j + (k + 3) % 3]];
                        VInt3 vInt4 = verts[tris[num3]];
                        vInt.y  = 0;
                        vInt2.y = 0;
                        vInt3.y = 0;
                        vInt4.y = 0;
                        bool flag = false;
                        if (!Polygon.Left(vInt, vInt3, vInt4) || Polygon.LeftNotColinear(vInt, vInt2, vInt4))
                        {
                            if (!colinear)
                            {
                                goto IL_439;
                            }
                            flag = true;
                        }
                        if (colinear && AstarMath.DistancePointSegment(vInt, vInt4, vInt2) < (float)num2 && !dictionary.ContainsKey(new VInt2(tris[j + (k + 2) % 3], tris[j + (k + 1) % 3])) && !dictionary.ContainsKey(new VInt2(tris[j + (k + 1) % 3], tris[num3])))
                        {
                            tCount -= 3;
                            int num4 = num3 / 3 * 3;
                            tris[j + (k + 1) % 3] = tris[num3];
                            if (num4 != tCount)
                            {
                                tris[num4]     = tris[tCount];
                                tris[num4 + 1] = tris[tCount + 1];
                                tris[num4 + 2] = tris[tCount + 2];
                                dictionary.set_Item(new VInt2(tris[num4], tris[num4 + 1]), num4 + 2);
                                dictionary.set_Item(new VInt2(tris[num4 + 1], tris[num4 + 2]), num4);
                                dictionary.set_Item(new VInt2(tris[num4 + 2], tris[num4]), num4 + 1);
                                tris[tCount]     = 0;
                                tris[tCount + 1] = 0;
                                tris[tCount + 2] = 0;
                            }
                            else
                            {
                                tCount += 3;
                            }
                            dictionary.set_Item(new VInt2(tris[j], tris[j + 1]), j + 2);
                            dictionary.set_Item(new VInt2(tris[j + 1], tris[j + 2]), j);
                            dictionary.set_Item(new VInt2(tris[j + 2], tris[j]), j + 1);
                        }
                        else if (delaunay && !flag)
                        {
                            float num5 = VInt3.Angle(vInt2 - vInt, vInt3 - vInt);
                            float num6 = VInt3.Angle(vInt2 - vInt4, vInt3 - vInt4);
                            if (num6 > 6.28318548f - 2f * num5)
                            {
                                tris[j + (k + 1) % 3] = tris[num3];
                                int num7 = num3 / 3 * 3;
                                int num8 = num3 - num7;
                                tris[num7 + (num8 - 1 + 3) % 3] = tris[j + (k + 2) % 3];
                                dictionary.set_Item(new VInt2(tris[j], tris[j + 1]), j + 2);
                                dictionary.set_Item(new VInt2(tris[j + 1], tris[j + 2]), j);
                                dictionary.set_Item(new VInt2(tris[j + 2], tris[j]), j + 1);
                                dictionary.set_Item(new VInt2(tris[num7], tris[num7 + 1]), num7 + 2);
                                dictionary.set_Item(new VInt2(tris[num7 + 1], tris[num7 + 2]), num7);
                                dictionary.set_Item(new VInt2(tris[num7 + 2], tris[num7]), num7 + 1);
                            }
                        }
                    }
                    IL_439 :;
                }
            }
        }
Beispiel #11
0
 protected void Setup(ref VInt3 start, ref VInt3 end, OnPathDelegate callbackDelegate)
 {
     this.callback = callbackDelegate;
     this.UpdateStartEnd(ref start, ref end);
 }
Beispiel #12
0
        private void CutPoly(VInt3[] verts, int[] tris, ref VInt3[] outVertsArr, ref int[] outTrisArr, out int outVCount, out int outTCount, VInt3[] extraShape, VInt3 cuttingOffset, Bounds realBounds, TileHandler.CutMode mode = (TileHandler.CutMode) 3, int perturbate = 0)
        {
            if (verts.Length == 0 || tris.Length == 0)
            {
                outVCount   = 0;
                outTCount   = 0;
                outTrisArr  = new int[0];
                outVertsArr = new VInt3[0];
                return;
            }
            List <IntPoint> list = null;

            if (extraShape == null && (mode & TileHandler.CutMode.CutExtra) != (TileHandler.CutMode) 0)
            {
                throw new Exception("extraShape is null and the CutMode specifies that it should be used. Cannot use null shape.");
            }
            if ((mode & TileHandler.CutMode.CutExtra) != (TileHandler.CutMode) 0)
            {
                list = new List <IntPoint>(extraShape.Length);
                for (int i = 0; i < extraShape.Length; i++)
                {
                    list.Add(new IntPoint((long)(extraShape[i].x + cuttingOffset.x), (long)(extraShape[i].z + cuttingOffset.z)));
                }
            }
            List <IntPoint> list2 = new List <IntPoint>(5);
            Dictionary <TriangulationPoint, int> dictionary = new Dictionary <TriangulationPoint, int>();
            List <PolygonPoint> list3 = new List <PolygonPoint>();
            IntRect             b     = new IntRect(verts[0].x, verts[0].z, verts[0].x, verts[0].z);

            for (int j = 0; j < verts.Length; j++)
            {
                b = b.ExpandToContain(verts[j].x, verts[j].z);
            }
            List <VInt3> list4 = ListPool <VInt3> .Claim(verts.Length * 2);

            List <int> list5 = ListPool <int> .Claim(tris.Length);

            PolyTree polyTree             = new PolyTree();
            List <List <IntPoint> > list6 = new List <List <IntPoint> >();
            Stack <Polygon>         stack = new Stack <Polygon>();

            if (this.clipper == null)
            {
                this.clipper = new Clipper(0);
            }
            this.clipper.set_ReverseSolution(true);
            this.clipper.set_StrictlySimple(true);
            ListView <NavmeshCut> listView;

            if (mode == TileHandler.CutMode.CutExtra)
            {
                listView = new ListView <NavmeshCut>();
            }
            else
            {
                listView = NavmeshCut.GetAllInRange(realBounds);
            }
            List <int> list7 = ListPool <int> .Claim();

            List <IntRect> list8 = ListPool <IntRect> .Claim();

            List <VInt2> list9 = ListPool <VInt2> .Claim();

            List <List <IntPoint> > list10 = new List <List <IntPoint> >();
            List <bool>             list11 = ListPool <bool> .Claim();

            List <bool> list12 = ListPool <bool> .Claim();

            if (perturbate > 10)
            {
                Debug.LogError("Too many perturbations aborting : " + mode);
                Debug.Break();
                outVCount   = verts.Length;
                outTCount   = tris.Length;
                outTrisArr  = tris;
                outVertsArr = verts;
                return;
            }
            Random random = null;

            if (perturbate > 0)
            {
                random = new Random();
            }
            for (int k = 0; k < listView.Count; k++)
            {
                Bounds  bounds = listView[k].GetBounds();
                VInt3   vInt   = (VInt3)bounds.min + cuttingOffset;
                VInt3   vInt2  = (VInt3)bounds.max + cuttingOffset;
                IntRect a      = new IntRect(vInt.x, vInt.z, vInt2.x, vInt2.z);
                if (IntRect.Intersects(a, b))
                {
                    VInt2 vInt3 = new VInt2(0, 0);
                    if (perturbate > 0)
                    {
                        vInt3.x = random.Next() % 6 * perturbate - 3 * perturbate;
                        if (vInt3.x >= 0)
                        {
                            vInt3.x++;
                        }
                        vInt3.y = random.Next() % 6 * perturbate - 3 * perturbate;
                        if (vInt3.y >= 0)
                        {
                            vInt3.y++;
                        }
                    }
                    int count = list10.get_Count();
                    listView[k].GetContour(list10);
                    for (int l = count; l < list10.get_Count(); l++)
                    {
                        List <IntPoint> list13 = list10.get_Item(l);
                        if (list13.get_Count() == 0)
                        {
                            Debug.LogError("Zero Length Contour");
                            list8.Add(default(IntRect));
                            list9.Add(new VInt2(0, 0));
                        }
                        else
                        {
                            IntRect intRect = new IntRect((int)list13.get_Item(0).X + cuttingOffset.x, (int)list13.get_Item(0).Y + cuttingOffset.y, (int)list13.get_Item(0).X + cuttingOffset.x, (int)list13.get_Item(0).Y + cuttingOffset.y);
                            for (int m = 0; m < list13.get_Count(); m++)
                            {
                                IntPoint intPoint = list13.get_Item(m);
                                intPoint.X += (long)cuttingOffset.x;
                                intPoint.Y += (long)cuttingOffset.z;
                                if (perturbate > 0)
                                {
                                    intPoint.X += (long)vInt3.x;
                                    intPoint.Y += (long)vInt3.y;
                                }
                                list13.set_Item(m, intPoint);
                                intRect = intRect.ExpandToContain((int)intPoint.X, (int)intPoint.Y);
                            }
                            list9.Add(new VInt2(vInt.y, vInt2.y));
                            list8.Add(intRect);
                            list11.Add(listView[k].isDual);
                            list12.Add(listView[k].cutsAddedGeom);
                        }
                    }
                }
            }
            List <NavmeshAdd> allInRange = NavmeshAdd.GetAllInRange(realBounds);

            VInt3[] array  = verts;
            int[]   array2 = tris;
            int     num    = -1;
            int     n      = -3;

            VInt3[] array3 = null;
            VInt3[] array4 = null;
            VInt3   vInt4  = VInt3.zero;

            if (allInRange.get_Count() > 0)
            {
                array3 = new VInt3[7];
                array4 = new VInt3[7];
                vInt4  = (VInt3)realBounds.extents;
            }
            while (true)
            {
                n += 3;
                while (n >= array2.Length)
                {
                    num++;
                    n = 0;
                    if (num >= allInRange.get_Count())
                    {
                        array = null;
                        break;
                    }
                    if (array == verts)
                    {
                        array = null;
                    }
                    allInRange.get_Item(num).GetMesh(cuttingOffset, ref array, out array2);
                }
                if (array == null)
                {
                    break;
                }
                VInt3   vInt5 = array[array2[n]];
                VInt3   vInt6 = array[array2[n + 1]];
                VInt3   vInt7 = array[array2[n + 2]];
                IntRect a2    = new IntRect(vInt5.x, vInt5.z, vInt5.x, vInt5.z);
                a2 = a2.ExpandToContain(vInt6.x, vInt6.z);
                a2 = a2.ExpandToContain(vInt7.x, vInt7.z);
                int num2 = Math.Min(vInt5.y, Math.Min(vInt6.y, vInt7.y));
                int num3 = Math.Max(vInt5.y, Math.Max(vInt6.y, vInt7.y));
                list7.Clear();
                bool flag = false;
                for (int num4 = 0; num4 < list10.get_Count(); num4++)
                {
                    int x = list9.get_Item(num4).x;
                    int y = list9.get_Item(num4).y;
                    if (IntRect.Intersects(a2, list8.get_Item(num4)) && y >= num2 && x <= num3 && (list12.get_Item(num4) || num == -1))
                    {
                        VInt3 vInt8 = vInt5;
                        vInt8.y = x;
                        VInt3 vInt9 = vInt5;
                        vInt9.y = y;
                        list7.Add(num4);
                        flag |= list11.get_Item(num4);
                    }
                }
                if (list7.get_Count() == 0 && (mode & TileHandler.CutMode.CutExtra) == (TileHandler.CutMode) 0 && (mode & TileHandler.CutMode.CutAll) != (TileHandler.CutMode) 0 && num == -1)
                {
                    list5.Add(list4.get_Count());
                    list5.Add(list4.get_Count() + 1);
                    list5.Add(list4.get_Count() + 2);
                    list4.Add(vInt5);
                    list4.Add(vInt6);
                    list4.Add(vInt7);
                }
                else
                {
                    list2.Clear();
                    if (num == -1)
                    {
                        list2.Add(new IntPoint((long)vInt5.x, (long)vInt5.z));
                        list2.Add(new IntPoint((long)vInt6.x, (long)vInt6.z));
                        list2.Add(new IntPoint((long)vInt7.x, (long)vInt7.z));
                    }
                    else
                    {
                        array3[0] = vInt5;
                        array3[1] = vInt6;
                        array3[2] = vInt7;
                        int num5 = Utility.ClipPolygon(array3, 3, array4, 1, 0, 0);
                        if (num5 == 0)
                        {
                            continue;
                        }
                        num5 = Utility.ClipPolygon(array4, num5, array3, -1, 2 * vInt4.x, 0);
                        if (num5 == 0)
                        {
                            continue;
                        }
                        num5 = Utility.ClipPolygon(array3, num5, array4, 1, 0, 2);
                        if (num5 == 0)
                        {
                            continue;
                        }
                        num5 = Utility.ClipPolygon(array4, num5, array3, -1, 2 * vInt4.z, 2);
                        if (num5 == 0)
                        {
                            continue;
                        }
                        for (int num6 = 0; num6 < num5; num6++)
                        {
                            list2.Add(new IntPoint((long)array3[num6].x, (long)array3[num6].z));
                        }
                    }
                    dictionary.Clear();
                    VInt3 vInt10 = vInt6 - vInt5;
                    VInt3 vInt11 = vInt7 - vInt5;
                    VInt3 vInt12 = vInt10;
                    VInt3 vInt13 = vInt11;
                    vInt12.y = 0;
                    vInt13.y = 0;
                    for (int num7 = 0; num7 < 16; num7++)
                    {
                        if ((mode >> (num7 & 31) & TileHandler.CutMode.CutAll) != (TileHandler.CutMode) 0)
                        {
                            if (1 << num7 == 1)
                            {
                                this.clipper.Clear();
                                this.clipper.AddPolygon(list2, 0);
                                for (int num8 = 0; num8 < list7.get_Count(); num8++)
                                {
                                    this.clipper.AddPolygon(list10.get_Item(list7.get_Item(num8)), 1);
                                }
                                polyTree.Clear();
                                this.clipper.Execute(2, polyTree, 0, 1);
                            }
                            else if (1 << num7 == 2)
                            {
                                if (!flag)
                                {
                                    goto IL_1172;
                                }
                                this.clipper.Clear();
                                this.clipper.AddPolygon(list2, 0);
                                for (int num9 = 0; num9 < list7.get_Count(); num9++)
                                {
                                    if (list11.get_Item(list7.get_Item(num9)))
                                    {
                                        this.clipper.AddPolygon(list10.get_Item(list7.get_Item(num9)), 1);
                                    }
                                }
                                list6.Clear();
                                this.clipper.Execute(0, list6, 0, 1);
                                this.clipper.Clear();
                                for (int num10 = 0; num10 < list6.get_Count(); num10++)
                                {
                                    this.clipper.AddPolygon(list6.get_Item(num10), (!Clipper.Orientation(list6.get_Item(num10))) ? 0 : 1);
                                }
                                for (int num11 = 0; num11 < list7.get_Count(); num11++)
                                {
                                    if (!list11.get_Item(list7.get_Item(num11)))
                                    {
                                        this.clipper.AddPolygon(list10.get_Item(list7.get_Item(num11)), 1);
                                    }
                                }
                                polyTree.Clear();
                                this.clipper.Execute(2, polyTree, 0, 1);
                            }
                            else if (1 << num7 == 4)
                            {
                                this.clipper.Clear();
                                this.clipper.AddPolygon(list2, 0);
                                this.clipper.AddPolygon(list, 1);
                                polyTree.Clear();
                                this.clipper.Execute(0, polyTree, 0, 1);
                            }
                            for (int num12 = 0; num12 < polyTree.get_ChildCount(); num12++)
                            {
                                PolyNode        polyNode = polyTree.get_Childs().get_Item(num12);
                                List <IntPoint> contour  = polyNode.get_Contour();
                                List <PolyNode> childs   = polyNode.get_Childs();
                                if (childs.get_Count() == 0 && contour.get_Count() == 3 && num == -1)
                                {
                                    for (int num13 = 0; num13 < contour.get_Count(); num13++)
                                    {
                                        VInt3  vInt14 = new VInt3((int)contour.get_Item(num13).X, 0, (int)contour.get_Item(num13).Y);
                                        double num14  = (double)(vInt6.z - vInt7.z) * (double)(vInt5.x - vInt7.x) + (double)(vInt7.x - vInt6.x) * (double)(vInt5.z - vInt7.z);
                                        if (num14 == 0.0)
                                        {
                                            Debug.LogWarning("Degenerate triangle");
                                        }
                                        else
                                        {
                                            double num15 = ((double)(vInt6.z - vInt7.z) * (double)(vInt14.x - vInt7.x) + (double)(vInt7.x - vInt6.x) * (double)(vInt14.z - vInt7.z)) / num14;
                                            double num16 = ((double)(vInt7.z - vInt5.z) * (double)(vInt14.x - vInt7.x) + (double)(vInt5.x - vInt7.x) * (double)(vInt14.z - vInt7.z)) / num14;
                                            vInt14.y = (int)Math.Round(num15 * (double)vInt5.y + num16 * (double)vInt6.y + (1.0 - num15 - num16) * (double)vInt7.y);
                                            list5.Add(list4.get_Count());
                                            list4.Add(vInt14);
                                        }
                                    }
                                }
                                else
                                {
                                    Polygon polygon = null;
                                    int     num17   = -1;
                                    for (List <IntPoint> list14 = contour; list14 != null; list14 = ((num17 >= childs.get_Count()) ? null : childs.get_Item(num17).get_Contour()))
                                    {
                                        list3.Clear();
                                        for (int num18 = 0; num18 < list14.get_Count(); num18++)
                                        {
                                            PolygonPoint polygonPoint = new PolygonPoint((double)list14.get_Item(num18).X, (double)list14.get_Item(num18).Y);
                                            list3.Add(polygonPoint);
                                            VInt3  vInt15 = new VInt3((int)list14.get_Item(num18).X, 0, (int)list14.get_Item(num18).Y);
                                            double num19  = (double)(vInt6.z - vInt7.z) * (double)(vInt5.x - vInt7.x) + (double)(vInt7.x - vInt6.x) * (double)(vInt5.z - vInt7.z);
                                            if (num19 == 0.0)
                                            {
                                                Debug.LogWarning("Degenerate triangle");
                                            }
                                            else
                                            {
                                                double num20 = ((double)(vInt6.z - vInt7.z) * (double)(vInt15.x - vInt7.x) + (double)(vInt7.x - vInt6.x) * (double)(vInt15.z - vInt7.z)) / num19;
                                                double num21 = ((double)(vInt7.z - vInt5.z) * (double)(vInt15.x - vInt7.x) + (double)(vInt5.x - vInt7.x) * (double)(vInt15.z - vInt7.z)) / num19;
                                                vInt15.y = (int)Math.Round(num20 * (double)vInt5.y + num21 * (double)vInt6.y + (1.0 - num20 - num21) * (double)vInt7.y);
                                                dictionary.set_Item(polygonPoint, list4.get_Count());
                                                list4.Add(vInt15);
                                            }
                                        }
                                        Polygon polygon2;
                                        if (stack.get_Count() > 0)
                                        {
                                            polygon2 = stack.Pop();
                                            polygon2.AddPoints(list3);
                                        }
                                        else
                                        {
                                            polygon2 = new Polygon(list3);
                                        }
                                        if (polygon == null)
                                        {
                                            polygon = polygon2;
                                        }
                                        else
                                        {
                                            polygon.AddHole(polygon2);
                                        }
                                        num17++;
                                    }
                                    try
                                    {
                                        P2T.Triangulate(polygon);
                                    }
                                    catch (PointOnEdgeException)
                                    {
                                        Debug.LogWarning(string.Concat(new object[]
                                        {
                                            "PointOnEdgeException, perturbating vertices slightly ( at ",
                                            num7,
                                            " in ",
                                            mode,
                                            ")"
                                        }));
                                        this.CutPoly(verts, tris, ref outVertsArr, ref outTrisArr, out outVCount, out outTCount, extraShape, cuttingOffset, realBounds, mode, perturbate + 1);
                                        return;
                                    }
                                    for (int num22 = 0; num22 < polygon.get_Triangles().get_Count(); num22++)
                                    {
                                        DelaunayTriangle delaunayTriangle = polygon.get_Triangles().get_Item(num22);
                                        list5.Add(dictionary.get_Item(delaunayTriangle.Points._0));
                                        list5.Add(dictionary.get_Item(delaunayTriangle.Points._1));
                                        list5.Add(dictionary.get_Item(delaunayTriangle.Points._2));
                                    }
                                    if (polygon.get_Holes() != null)
                                    {
                                        for (int num23 = 0; num23 < polygon.get_Holes().get_Count(); num23++)
                                        {
                                            polygon.get_Holes().get_Item(num23).get_Points().Clear();
                                            polygon.get_Holes().get_Item(num23).ClearTriangles();
                                            if (polygon.get_Holes().get_Item(num23).get_Holes() != null)
                                            {
                                                polygon.get_Holes().get_Item(num23).get_Holes().Clear();
                                            }
                                            stack.Push(polygon.get_Holes().get_Item(num23));
                                        }
                                    }
                                    polygon.ClearTriangles();
                                    if (polygon.get_Holes() != null)
                                    {
                                        polygon.get_Holes().Clear();
                                    }
                                    polygon.get_Points().Clear();
                                    stack.Push(polygon);
                                }
                            }
                        }
                        IL_1172 :;
                    }
                }
            }
            Dictionary <VInt3, int> dictionary2 = this.cached_Int3_int_dict;

            dictionary2.Clear();
            if (this.cached_int_array.Length < list4.get_Count())
            {
                this.cached_int_array = new int[Math.Max(this.cached_int_array.Length * 2, list4.get_Count())];
            }
            int[] array5 = this.cached_int_array;
            int   num24  = 0;

            for (int num25 = 0; num25 < list4.get_Count(); num25++)
            {
                int num26;
                if (!dictionary2.TryGetValue(list4.get_Item(num25), ref num26))
                {
                    dictionary2.Add(list4.get_Item(num25), num24);
                    array5[num25] = num24;
                    list4.set_Item(num24, list4.get_Item(num25));
                    num24++;
                }
                else
                {
                    array5[num25] = num26;
                }
            }
            outTCount = list5.get_Count();
            if (outTrisArr == null || outTrisArr.Length < outTCount)
            {
                outTrisArr = new int[outTCount];
            }
            for (int num27 = 0; num27 < outTCount; num27++)
            {
                outTrisArr[num27] = array5[list5.get_Item(num27)];
            }
            outVCount = num24;
            if (outVertsArr == null || outVertsArr.Length < outVCount)
            {
                outVertsArr = new VInt3[outVCount];
            }
            for (int num28 = 0; num28 < outVCount; num28++)
            {
                outVertsArr[num28] = list4.get_Item(num28);
            }
            for (int num29 = 0; num29 < listView.Count; num29++)
            {
                listView[num29].UsedForCut();
            }
            ListPool <VInt3> .Release(list4);

            ListPool <int> .Release(list5);

            ListPool <int> .Release(list7);

            ListPool <VInt2> .Release(list9);

            ListPool <bool> .Release(list11);

            ListPool <bool> .Release(list12);

            ListPool <IntRect> .Release(list8);
        }
Beispiel #13
0
 public TileHandler.TileType RegisterTileType(Mesh source, VInt3 centerOffset, int width = 1, int depth = 1)
 {
     TileHandler.TileType tileType = new TileHandler.TileType(source, new VInt3(this.graph.tileSizeX, 1, this.graph.tileSizeZ) * (1000f * this.graph.cellSize), centerOffset, width, depth);
     this.tileTypes.Add(tileType);
     return(tileType);
 }
Beispiel #14
0
        public override void Apply(Path _p, ModifierData source)
        {
            ABPath aBPath = _p as ABPath;

            if (aBPath == null)
            {
                return;
            }
            if (aBPath.vectorPath.get_Count() == 0)
            {
                return;
            }
            if (aBPath.vectorPath.get_Count() < 2 && !this.addPoints)
            {
                aBPath.vectorPath.Add(aBPath.vectorPath.get_Item(0));
            }
            VInt3 vInt  = VInt3.zero;
            VInt3 vInt2 = VInt3.zero;

            if (this.exactStartPoint == StartEndModifier.Exactness.Original)
            {
                vInt = this.GetClampedPoint(aBPath.path.get_Item(0).position, aBPath.originalStartPoint, aBPath.path.get_Item(0));
            }
            else if (this.exactStartPoint == StartEndModifier.Exactness.ClosestOnNode)
            {
                vInt = this.GetClampedPoint(aBPath.path.get_Item(0).position, aBPath.startPoint, aBPath.path.get_Item(0));
            }
            else if (this.exactStartPoint == StartEndModifier.Exactness.Interpolate)
            {
                vInt = this.GetClampedPoint(aBPath.path.get_Item(0).position, aBPath.originalStartPoint, aBPath.path.get_Item(0));
                VInt3 position  = aBPath.path.get_Item(0).position;
                VInt3 position2 = aBPath.path.get_Item((1 >= aBPath.path.get_Count()) ? 0 : 1).position;
                vInt = AstarMath.NearestPointStrict(ref position, ref position2, ref vInt);
            }
            else
            {
                vInt = aBPath.path.get_Item(0).position;
            }
            if (this.exactEndPoint == StartEndModifier.Exactness.Original)
            {
                vInt2 = this.GetClampedPoint(aBPath.path.get_Item(aBPath.path.get_Count() - 1).position, aBPath.originalEndPoint, aBPath.path.get_Item(aBPath.path.get_Count() - 1));
            }
            else if (this.exactEndPoint == StartEndModifier.Exactness.ClosestOnNode)
            {
                vInt2 = this.GetClampedPoint(aBPath.path.get_Item(aBPath.path.get_Count() - 1).position, aBPath.endPoint, aBPath.path.get_Item(aBPath.path.get_Count() - 1));
            }
            else if (this.exactEndPoint == StartEndModifier.Exactness.Interpolate)
            {
                vInt2 = this.GetClampedPoint(aBPath.path.get_Item(aBPath.path.get_Count() - 1).position, aBPath.originalEndPoint, aBPath.path.get_Item(aBPath.path.get_Count() - 1));
                VInt3 position3 = aBPath.path.get_Item(aBPath.path.get_Count() - 1).position;
                VInt3 position4 = aBPath.path.get_Item((aBPath.path.get_Count() - 2 < 0) ? 0 : (aBPath.path.get_Count() - 2)).position;
                vInt2 = AstarMath.NearestPointStrict(ref position3, ref position4, ref vInt2);
            }
            else
            {
                vInt2 = aBPath.path.get_Item(aBPath.path.get_Count() - 1).position;
            }
            if (!this.addPoints)
            {
                aBPath.vectorPath.set_Item(0, vInt);
                aBPath.vectorPath.set_Item(aBPath.vectorPath.get_Count() - 1, vInt2);
            }
            else
            {
                if (this.exactStartPoint != StartEndModifier.Exactness.SnapToNode)
                {
                    aBPath.vectorPath.Insert(0, vInt);
                }
                if (this.exactEndPoint != StartEndModifier.Exactness.SnapToNode)
                {
                    aBPath.vectorPath.Add(vInt2);
                }
            }
        }
 public bool Linecast(VInt3 origin, VInt3 end, GraphNode hint, out GraphHitInfo hit)
 {
     return(NavMeshGraph.Linecast(this, origin, end, hint, out hit, null));
 }
Beispiel #16
0
        private bool UseImpl(PoolObjHandle <ActorRoot> user)
        {
            bool  flag    = false;
            bool  flag2   = false;
            bool  flag3   = false;
            VInt3 forward = VInt3.forward;

            switch (this.skillContext.AppointType)
            {
            case SkillRangeAppointType.Auto:
            case SkillRangeAppointType.Target:
                flag = true;
                break;

            case SkillRangeAppointType.Pos:
                flag2 = true;
                break;

            case SkillRangeAppointType.Directional:
                flag3   = true;
                forward = this.skillContext.UseVector;
                break;

            case SkillRangeAppointType.Track:
                flag2   = true;
                flag3   = true;
                forward = this.skillContext.EndVector - this.skillContext.UseVector;
                if (forward.sqrMagnitudeLong < 1L)
                {
                    forward = VInt3.forward;
                }
                break;
            }
            if (flag && (this.skillContext.TargetActor == 0))
            {
                return(false);
            }
            if (flag)
            {
                GameObject[] objArray1 = new GameObject[] { user.handle.gameObject, this.skillContext.TargetActor.handle.gameObject };
                this.curAction = new PoolObjHandle <AGE.Action>(ActionManager.Instance.PlayAction(this.ActionName, true, false, objArray1));
            }
            else
            {
                GameObject[] objArray2 = new GameObject[] { user.handle.gameObject };
                this.curAction = new PoolObjHandle <AGE.Action>(ActionManager.Instance.PlayAction(this.ActionName, true, false, objArray2));
            }
            if (this.curAction == 0)
            {
                return(false);
            }
            this.curAction.handle.onActionStop += new ActionStopDelegate(this.OnActionStoped);
            this.curAction.handle.refParams.AddRefParam("SkillObj", this);
            this.curAction.handle.refParams.AddRefParam("SkillContext", this.skillContext);
            if (flag)
            {
                this.curAction.handle.refParams.AddRefParam("TargetActor", this.skillContext.TargetActor);
            }
            if (flag2)
            {
                this.curAction.handle.refParams.SetRefParam("_TargetPos", this.skillContext.UseVector);
            }
            if (flag3)
            {
                this.curAction.handle.refParams.SetRefParam("_TargetDir", forward);
            }
            this.curAction.handle.refParams.SetRefParam("_BulletPos", this.skillContext.BulletPos);
            if (this.bAgeImmeExcute)
            {
                this.curAction.handle.UpdateLogic((int)Singleton <FrameSynchr> .GetInstance().FrameDelta);
            }
            return(true);
        }
        public bool Linecast(VInt3 origin, VInt3 end, GraphNode hint)
        {
            GraphHitInfo graphHitInfo;

            return(NavMeshGraph.Linecast(this, origin, end, hint, out graphHitInfo, null));
        }
Beispiel #18
0
 public static VInt3 Transform(VInt3 point, ref VInt3 axis_x, ref VInt3 axis_y, ref VInt3 axis_z, ref VInt3 trans)
 {
     return(new VInt3(IntMath.Divide(axis_x.x * point.x + axis_y.x * point.y + axis_z.x * point.z, 1000) + trans.x, IntMath.Divide(axis_x.y * point.x + axis_y.y * point.y + axis_z.y * point.z, 1000) + trans.y, IntMath.Divide(axis_x.z * point.x + axis_y.z * point.y + axis_z.z * point.z, 1000) + trans.z));
 }
 public static bool Linecast(INavmesh graph, VInt3 tmp_origin, VInt3 tmp_end, GraphNode hint, out GraphHitInfo hit)
 {
     return(NavMeshGraph.Linecast(graph, tmp_origin, tmp_end, hint, out hit, null));
 }
Beispiel #20
0
    public static VInt3 Transform(ref VInt3 point, ref VInt3 axis_x, ref VInt3 axis_y, ref VInt3 axis_z, ref VInt3 trans, ref VInt3 scale)
    {
        long num  = (long)point.x * (long)scale.x;
        long num2 = (long)point.y * (long)scale.x;
        long num3 = (long)point.z * (long)scale.x;

        return(new VInt3((int)IntMath.Divide((long)axis_x.x * num + (long)axis_y.x * num2 + (long)axis_z.x * num3, 1000000L) + trans.x, (int)IntMath.Divide((long)axis_x.y * num + (long)axis_y.y * num2 + (long)axis_z.y * num3, 1000000L) + trans.y, (int)IntMath.Divide((long)axis_x.z * num + (long)axis_y.z * num2 + (long)axis_z.z * num3, 1000000L) + trans.z));
    }
        public static void UpdateArea(GraphUpdateObject o, INavmesh graph)
        {
            Bounds  bounds = o.bounds;
            Rect    r      = Rect.MinMaxRect(bounds.min.x, bounds.min.z, bounds.max.x, bounds.max.z);
            IntRect r2     = new IntRect(Mathf.FloorToInt(bounds.min.x * 1000f), Mathf.FloorToInt(bounds.min.z * 1000f), Mathf.FloorToInt(bounds.max.x * 1000f), Mathf.FloorToInt(bounds.max.z * 1000f));
            VInt3   a      = new VInt3(r2.xmin, 0, r2.ymin);
            VInt3   b      = new VInt3(r2.xmin, 0, r2.ymax);
            VInt3   c      = new VInt3(r2.xmax, 0, r2.ymin);
            VInt3   d      = new VInt3(r2.xmax, 0, r2.ymax);
            VInt3   ia     = a;
            VInt3   ib     = b;
            VInt3   ic     = c;
            VInt3   id     = d;

            graph.GetNodes(delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode;
                bool flag = false;
                int num   = 0;
                int num2  = 0;
                int num3  = 0;
                int num4  = 0;
                for (int i = 0; i < 3; i++)
                {
                    VInt3 vertex   = triangleMeshNode.GetVertex(i);
                    Vector3 vector = (Vector3)vertex;
                    if (r2.Contains(vertex.x, vertex.z))
                    {
                        flag = true;
                        break;
                    }
                    if (vector.x < r.xMin)
                    {
                        num++;
                    }
                    if (vector.x > r.xMax)
                    {
                        num2++;
                    }
                    if (vector.z < r.yMin)
                    {
                        num3++;
                    }
                    if (vector.z > r.yMax)
                    {
                        num4++;
                    }
                }
                if (!flag && (num == 3 || num2 == 3 || num3 == 3 || num4 == 3))
                {
                    return(true);
                }
                for (int j = 0; j < 3; j++)
                {
                    int i2        = (j > 1) ? 0 : (j + 1);
                    VInt3 vertex2 = triangleMeshNode.GetVertex(j);
                    VInt3 vertex3 = triangleMeshNode.GetVertex(i2);
                    if (Polygon.Intersects(a, b, vertex2, vertex3))
                    {
                        flag = true;
                        break;
                    }
                    if (Polygon.Intersects(a, c, vertex2, vertex3))
                    {
                        flag = true;
                        break;
                    }
                    if (Polygon.Intersects(c, d, vertex2, vertex3))
                    {
                        flag = true;
                        break;
                    }
                    if (Polygon.Intersects(d, b, vertex2, vertex3))
                    {
                        flag = true;
                        break;
                    }
                }
                if (triangleMeshNode.ContainsPoint(ia) || triangleMeshNode.ContainsPoint(ib) || triangleMeshNode.ContainsPoint(ic) || triangleMeshNode.ContainsPoint(id))
                {
                    flag = true;
                }
                if (!flag)
                {
                    return(true);
                }
                o.WillUpdateNode(triangleMeshNode);
                o.Apply(triangleMeshNode);
                return(true);
            });
        }
Beispiel #22
0
        /** Finds all contours of a collection of nodes in a grid graph.
         * \param grid The grid to find the contours of
         * \param callback The callback will be called once for every contour that is found with the vertices of the contour. The contour always forms a cycle.
         * \param yMergeThreshold Contours will be simplified if the y coordinates for adjacent vertices differ by no more than this value.
         * \param nodes Only these nodes will be searched. If this parameter is null then all nodes in the grid graph will be searched.
         *
         * \snippet MiscSnippets.cs GraphUtilities.GetContours1
         *
         * In the image below you can see the contour of a graph.
         * \shadowimage{grid_contour.png}
         *
         * In the image below you can see the contour of just a part of a grid graph (when the \a nodes parameter is supplied)
         * \shadowimage{grid_contour_partial.png}
         *
         * Contour of a hexagon graph
         * \shadowimage{grid_contour_hexagon.png}
         *
         * \see #GetContours(NavGraph)
         */
        //GG
        //public static void GetContours(GridGraph grid, System.Action<Vector3[]> callback, float yMergeThreshold, GridNodeBase[] nodes = null)
        public static void GetContours(GridGraph grid, System.Action <VInt3[]> callback, int yMergeThreshold, GridNodeBase[] nodes = null)
        {
            // Set of all allowed nodes or null if all nodes are allowed
            HashSet <GridNodeBase> nodeSet = nodes != null ? new HashSet <GridNodeBase>(nodes) : null;

            // Use all nodes if the nodes parameter is null
            if (grid is LayerGridGraph)
            {
                nodes = nodes ?? (grid as LayerGridGraph).nodes;
            }
            nodes = nodes ?? grid.nodes;
            int[] neighbourXOffsets = grid.neighbourXOffsets;
            int[] neighbourZOffsets = grid.neighbourZOffsets;
            var   neighbourIndices  = grid.neighbours == NumNeighbours.Six ? GridGraph.hexagonNeighbourIndices : new[] { 0, 1, 2, 3 };
            //GG
            //var offsetMultiplier = grid.neighbours == NumNeighbours.Six ? 1 / 3f : 0.5f;
            var offsetMultiplier = grid.neighbours == NumNeighbours.Six ? new VFactor(1, 3) : new VFactor(1, 2);

            if (nodes != null)
            {
                //GG
                //var trace = ListPool<Vector3>.Claim();
                var trace = ListPool <VInt3> .Claim();

                var seenStates = new HashSet <int>();

                for (int i = 0; i < nodes.Length; i++)
                {
                    var startNode = nodes[i];
                    // The third check is a fast check for if the node has connections in all grid directions, if it has then we can skip processing it (unless the nodes parameter was used in which case we have to handle the edge cases)
                    if (startNode != null && startNode.Walkable && (!startNode.HasConnectionsToAllEightNeighbours || nodeSet != null))
                    {
                        for (int startDir = 0; startDir < neighbourIndices.Length; startDir++)
                        {
                            int startState = (startNode.NodeIndex << 4) | startDir;

                            // Check if there is an obstacle in that direction
                            var startNeighbour = startNode.GetNeighbourAlongDirection(neighbourIndices[startDir]);
                            if ((startNeighbour == null || (nodeSet != null && !nodeSet.Contains(startNeighbour))) && !seenStates.Contains(startState))
                            {
                                // Start tracing a contour here
                                trace.ClearFast();
                                int          dir  = startDir;
                                GridNodeBase node = startNode;

                                while (true)
                                {
                                    int state = (node.NodeIndex << 4) | dir;
                                    if (state == startState && trace.Count > 0)
                                    {
                                        break;
                                    }

                                    seenStates.Add(state);

                                    var neighbour = node.GetNeighbourAlongDirection(neighbourIndices[dir]);
                                    if (neighbour == null || (nodeSet != null && !nodeSet.Contains(neighbour)))
                                    {
                                        // Draw edge
                                        var d0 = neighbourIndices[dir];
                                        dir = (dir + 1) % neighbourIndices.Length;
                                        var d1 = neighbourIndices[dir];

                                        // Position in graph space of the vertex
                                        //GG
                                        //Vector3 graphSpacePos = new Vector3(node.XCoordinateInGrid + 0.5f, 0, node.ZCoordinateInGrid + 0.5f);
                                        VInt3 graphSpacePos = new VInt3(node.XCoordinateInGrid, 0, node.ZCoordinateInGrid);
                                        // Offset along diagonal to get the correct XZ coordinates
                                        graphSpacePos.x += (neighbourXOffsets[d0] + neighbourXOffsets[d1]) * offsetMultiplier;
                                        graphSpacePos.z += (neighbourZOffsets[d0] + neighbourZOffsets[d1]) * offsetMultiplier;
                                        //GG
                                        //graphSpacePos.y = grid.transform.InverseTransform((Vector3)node.position).y;
                                        graphSpacePos.y = grid.transform.InverseTransform(node.position).y;

                                        if (trace.Count >= 2)
                                        {
                                            var v0  = trace[trace.Count - 2];
                                            var v1  = trace[trace.Count - 1];
                                            var v1d = v1 - v0;
                                            var v2d = graphSpacePos - v0;
                                            // Replace the previous point if it is colinear with the point just before it and just after it (the current point), because that point wouldn't add much information, but it would add CPU overhead
                                            if (((Mathf.Abs(v1d.x) > 0.01f || Mathf.Abs(v2d.x) > 0.01f) && (Mathf.Abs(v1d.z) > 0.01f || Mathf.Abs(v2d.z) > 0.01f)) || (Mathf.Abs(v1d.y) > yMergeThreshold || Mathf.Abs(v2d.y) > yMergeThreshold))
                                            {
                                                trace.Add(graphSpacePos);
                                            }
                                            else
                                            {
                                                trace[trace.Count - 1] = graphSpacePos;
                                            }
                                        }
                                        else
                                        {
                                            trace.Add(graphSpacePos);
                                        }
                                    }
                                    else
                                    {
                                        // Move
                                        node = neighbour;
                                        dir  = (dir + neighbourIndices.Length / 2 + 1) % neighbourIndices.Length;
                                    }
                                }

                                var result = trace.ToArray();
                                grid.transform.Transform(result);
                                callback(result);
                            }
                        }
                    }
                }

                //GG
                //ListPool<Vector3>.Release(ref trace);
                ListPool <VInt3> .Release(ref trace);
            }
        }
Beispiel #23
0
        private void SpawnSoldier(uint SoldierID)
        {
            ResMonsterCfgInfo dataCfgInfoByCurLevelDiff = MonsterDataHelper.GetDataCfgInfoByCurLevelDiff((int)SoldierID);

            if (dataCfgInfoByCurLevelDiff != null)
            {
                if (CActorInfo.GetActorInfo(StringHelper.UTF8BytesToString(ref dataCfgInfoByCurLevelDiff.szCharacterInfo), enResourceType.BattleScene) != null)
                {
                    Transform      transform = this.Region.transform;
                    COM_PLAYERCAMP campType  = this.Region.CampType;
                    ActorMeta      actorMeta = new ActorMeta {
                        ConfigId  = (int)SoldierID,
                        ActorType = ActorTypeDef.Actor_Type_Monster,
                        ActorCamp = campType
                    };
                    VInt3 position = (VInt3)transform.position;
                    VInt3 forward  = (VInt3)transform.forward;
                    PoolObjHandle <ActorRoot> actor = new PoolObjHandle <ActorRoot>();
                    if (!Singleton <GameObjMgr> .GetInstance().TryGetFromCache(ref actor, ref actorMeta))
                    {
                        actor = Singleton <GameObjMgr> .GetInstance().SpawnActorEx(null, ref actorMeta, position, forward, false, true);

                        if (actor != 0)
                        {
                            actor.handle.InitActor();
                            actor.handle.PrepareFight();
                            Singleton <GameObjMgr> .instance.AddActor(actor);

                            actor.handle.StartFight();
                        }
                    }
                    else
                    {
                        ActorRoot handle = actor.handle;
                        handle.TheActorMeta.ActorCamp = actorMeta.ActorCamp;
                        handle.ReactiveActor(position, forward);
                    }
                    if (actor != 0)
                    {
                        if (this.Region.AttackRoute != null)
                        {
                            actor.handle.ActorControl.AttackAlongRoute(this.Region.AttackRoute.GetComponent <WaypointsHolder>());
                        }
                        else if (this.Region.finalTarget != null)
                        {
                            FrameCommand <AttackPositionCommand> cmd = FrameCommandFactory.CreateFrameCommand <AttackPositionCommand>();
                            cmd.cmdId            = 1;
                            cmd.cmdData.WorldPos = new VInt3(this.Region.finalTarget.transform.position);
                            actor.handle.ActorControl.CmdAttackMoveToDest(cmd, cmd.cmdData.WorldPos);
                        }
                        if (!this.isCannonNotified && (this.WaveInfo.bType == 1))
                        {
                            KillNotify theKillNotify = Singleton <CBattleSystem> .GetInstance().TheKillNotify;

                            Player hostPlayer = Singleton <GamePlayerCenter> .GetInstance().GetHostPlayer();

                            if ((theKillNotify != null) && (hostPlayer != null))
                            {
                                bool bSrcAllies = hostPlayer.PlayerCamp == actor.handle.TheActorMeta.ActorCamp;
                                if (bSrcAllies)
                                {
                                    KillInfo killInfo = new KillInfo((hostPlayer.PlayerCamp != COM_PLAYERCAMP.COM_PLAYERCAMP_1) ? KillNotify.red_cannon_icon : KillNotify.blue_cannon_icon, null, KillDetailInfoType.Info_Type_Cannon_Spawned, bSrcAllies, false, ActorTypeDef.Invalid);
                                    theKillNotify.AddKillInfo(killInfo);
                                    this.isCannonNotified = true;
                                }
                            }
                        }
                    }
                }
                if (this.Region.bTriggerEvent)
                {
                    SoldierWaveParam prm = new SoldierWaveParam(this.Index, this.repeatCount, this.Region.GetNextRepeatTime(false));
                    Singleton <GameEventSys> .instance.SendEvent <SoldierWaveParam>(GameEventDef.Event_SoldierWaveNextRepeat, ref prm);
                }
            }
        }
 public NNInfo GetNearest(VInt3 position, NNConstraint constraint, GraphNode hint)
 {
     return(NavMeshGraph.GetNearest(this, this.nodes, (Vector3)position, constraint, this.accurateNearestNode));
 }
Beispiel #25
0
 public abstract object DoSpawn(VInt3 inWorldPos, VInt3 inDir, GameObject inSpawnPoint);
        public static NNInfo GetNearestForceBoth(NavGraph graph, INavmeshHolder navmesh, Vector3 position, NNConstraint constraint, bool accurateNearestNode)
        {
            VInt3     pos                   = (VInt3)position;
            double    minDist               = -1.0;
            GraphNode minNode               = null;
            double    minConstDist          = -1.0;
            GraphNode minConstNode          = null;
            float     maxDistSqr            = constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;
            GraphNodeDelegateCancelable del = delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode3 = _node as TriangleMeshNode;
                if (accurateNearestNode)
                {
                    Vector3 b            = triangleMeshNode3.ClosestPointOnNode(position);
                    float   sqrMagnitude = ((Vector3)pos - b).sqrMagnitude;
                    if (minNode == null || (double)sqrMagnitude < minDist)
                    {
                        minDist = (double)sqrMagnitude;
                        minNode = triangleMeshNode3;
                    }
                    if (sqrMagnitude < maxDistSqr && constraint.Suitable(triangleMeshNode3) && (minConstNode == null || (double)sqrMagnitude < minConstDist))
                    {
                        minConstDist = (double)sqrMagnitude;
                        minConstNode = triangleMeshNode3;
                    }
                }
                else if (!triangleMeshNode3.ContainsPoint((VInt3)position))
                {
                    double sqrMagnitude2 = (triangleMeshNode3.position - pos).sqrMagnitude;
                    if (minNode == null || sqrMagnitude2 < minDist)
                    {
                        minDist = sqrMagnitude2;
                        minNode = triangleMeshNode3;
                    }
                    if (sqrMagnitude2 < (double)maxDistSqr && constraint.Suitable(triangleMeshNode3) && (minConstNode == null || sqrMagnitude2 < minConstDist))
                    {
                        minConstDist = sqrMagnitude2;
                        minConstNode = triangleMeshNode3;
                    }
                }
                else
                {
                    int num = AstarMath.Abs(triangleMeshNode3.position.y - pos.y);
                    if (minNode == null || (double)num < minDist)
                    {
                        minDist = (double)num;
                        minNode = triangleMeshNode3;
                    }
                    if ((float)num < maxDistSqr && constraint.Suitable(triangleMeshNode3) && (minConstNode == null || (double)num < minConstDist))
                    {
                        minConstDist = (double)num;
                        minConstNode = triangleMeshNode3;
                    }
                }
                return(true);
            };

            graph.GetNodes(del);
            NNInfo result = new NNInfo(minNode);

            if (result.node != null)
            {
                TriangleMeshNode triangleMeshNode = result.node as TriangleMeshNode;
                Vector3          clampedPosition  = triangleMeshNode.ClosestPointOnNode(position);
                result.clampedPosition = clampedPosition;
            }
            result.constrainedNode = minConstNode;
            if (result.constrainedNode != null)
            {
                TriangleMeshNode triangleMeshNode2    = result.constrainedNode as TriangleMeshNode;
                Vector3          constClampedPosition = triangleMeshNode2.ClosestPointOnNode(position);
                result.constClampedPosition = constClampedPosition;
            }
            return(result);
        }
        public bool GetRevivePosDir(ref ActorMeta actorMeta, bool bGiveBirth, out VInt3 outPosWorld, out VInt3 outDirWorld)
        {
            outPosWorld = VInt3.zero;
            outDirWorld = VInt3.forward;
            if (Singleton <GamePlayerCenter> .instance.GetPlayer(actorMeta.PlayerId) == null)
            {
                return(false);
            }
            ListView <ReviveRegion> .Enumerator enumerator = this.reviveAreas.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (!(enumerator.Current == null) && actorMeta.ActorCamp == enumerator.Current.CampType)
                {
                    IGameActorDataProvider actorDataProvider = Singleton <ActorDataCenter> .instance.GetActorDataProvider(GameActorDataProviderType.ServerDataProvider);

                    int       num       = actorDataProvider.Fast_GetActorServerDataBornIndex(ref actorMeta);
                    Transform transform = enumerator.Current.transform;
                    if (!bGiveBirth)
                    {
                        uint num2 = (uint)enumerator.Current.SubRevivePlaces.Length;
                        if (!enumerator.Current.OnlyBirth)
                        {
                            num2 += 1u;
                            int num3 = (int)FrameRandom.Random(num2);
                            if (0 < num3 && enumerator.Current.SubRevivePlaces[num3 - 1] != null)
                            {
                                transform = enumerator.Current.SubRevivePlaces[num3 - 1].transform;
                            }
                        }
                        else if (num2 >= 1u)
                        {
                            int num4 = (int)FrameRandom.Random(num2);
                            if (enumerator.Current.SubRevivePlaces[num4] != null)
                            {
                                transform = enumerator.Current.SubRevivePlaces[num4].transform;
                            }
                        }
                    }
                    Transform transform2 = null;
                    if (transform != null)
                    {
                        if (num < transform.childCount)
                        {
                            transform2 = transform.GetChild(num);
                        }
                        else
                        {
                            transform2 = transform;
                        }
                    }
                    if (transform2 != null)
                    {
                        outPosWorld = (VInt3)transform2.position;
                        outDirWorld = (VInt3)transform2.forward;
                        return(true);
                    }
                }
            }
            return(false);
        }
 public bool Linecast(VInt3 origin, VInt3 end)
 {
     return(this.Linecast(origin, end, base.GetNearest(origin, NNConstraint.None).node));
 }
Beispiel #29
0
 public ABPath(VInt3 start, VInt3 end, OnPathDelegate callbackDelegate)
 {
     this.Reset();
     this.Setup(ref start, ref end, callbackDelegate);
 }
Beispiel #30
0
 public abstract VInt3 ClosestPointOnNodeXZ(VInt3 p);