Beispiel #1
0
        public void Execute(Entity entity, int index, ref AgentComponent c0, ref LocalToWorld c2)
        {
            //c2 = new LocalToWorld { Value = new float4x4(quaternion.identity, c2.Position + new float3(0, c0.moveSpeed * 0.01f, 0))};
            var navQuery         = new NavMeshQuery(navWorld, Allocator.TempJob, 20);
            var startPos         = navQuery.MapLocation(c0.position, new float3(10), 0);
            var endPos           = navQuery.MapLocation(setting.position1, new float3(10), 0);
            var status           = navQuery.BeginFindPath(startPos, endPos);
            int pathFindingInter = 0;

            if (status == PathQueryStatus.InProgress)
            {
                bool end       = false;
                bool err       = false;
                int  nodeCount = 0;
                while (!end)
                {
                    var upStatus = navQuery.UpdateFindPath(10, out pathFindingInter);
                    if (upStatus != PathQueryStatus.InProgress)
                    {
                        end = true;
                        err = upStatus == PathQueryStatus.Success;
                    }
                }
                if (!err)
                {
                    var endStatus = navQuery.EndFindPath(out nodeCount);
                    if (endStatus == PathQueryStatus.Failure)
                    {
                        err = true;
                    }
                }
                if (!err)
                {
                    NativeSlice <PolygonId> path = new NativeSlice <PolygonId>();
                    var count = navQuery.GetPathResult(path);
                    Debug.Log(count);
                }
            }
        }
Beispiel #2
0
        public static Vector2 GetCentralSymmetry(this NativeSlice <Vector2> self)
        {
            float x = 0;
            float y = 0;
            int   n = self.Length;
            var   b = self[n - 1];

            for (int i = 0; i < n; ++i)
            {
                var a = self[i];

                float d = a.x * b.y - b.x * a.y;
                x += (a.x + b.x) * d;
                y += (a.y + b.y) * d;

                b = a;
            }

            float k = 1f / (6f * Area(self));

            return(new Vector2(k * x, k * y));
        }
        public static unsafe void CopyToFast <T>(
            this NativeSlice <T> nativeSlice,
            T[] array)
            where T : struct
        {
            if (array == null)
            {
                throw new NullReferenceException(nameof(array) + " is null");
            }
            int nativeArrayLength = nativeSlice.Length;

            if (array.Length < nativeArrayLength)
            {
                throw new IndexOutOfRangeException(
                          nameof(array) + " is shorter than " + nameof(nativeSlice));
            }
            int   byteLength    = nativeSlice.Length * UnsafeUtility.SizeOf <T>();
            void *managedBuffer = UnsafeUtility.AddressOf(ref array[0]);
            void *nativeBuffer  = nativeSlice.GetUnsafePtr();

            UnsafeUtility.MemCpy(managedBuffer, nativeBuffer, byteLength);
        }
    // Retrace portals between corners and register if type of polygon changes
    public static int RetracePortals(NavMeshQuery query, int startIndex, int endIndex
                                     , NativeSlice <PolygonId> path, int n, Vector3 termPos
                                     , NativeSlice <PathPoint> straightPath
                                     , int maxStraightPath)
    {
        PathPoint point;

        for (var k = startIndex; k < endIndex - 1; ++k)
        {
            var type1 = query.GetPolygonType(path[k]);
            var type2 = query.GetPolygonType(path[k + 1]);

            if (type1 != type2)
            {
                Vector3 l, r;
                var     status = query.GetPortalPoints(path[k], path[k + 1], out l, out r);

                float3 cpa1, cpa2;
                SegmentSegmentCPA(out cpa1, out cpa2, l, r, straightPath[n - 1].location.position, termPos);

                point = straightPath[n];

                point.location = query.CreateLocation(cpa1, path[k + 1]);

                point.flag = (type2 == NavMeshPolyTypes.OffMeshConnection) ? StraightPathFlags.OffMeshConnection : 0;
                if (++n == maxStraightPath)
                {
                    return(maxStraightPath);
                }
                straightPath[n] = point;
            }
        }
        point           = straightPath[n];
        point.location  = query.CreateLocation(termPos, path[endIndex]);
        point.flag      = query.GetPolygonType(path[endIndex]) == NavMeshPolyTypes.OffMeshConnection ? StraightPathFlags.OffMeshConnection : 0;
        straightPath[n] = point;
        return(++n);
    }
    public static unsafe void DumpReliabilityStatistics(UdpNetworkDriver driver, NetworkPipeline pipeline, NetworkConnection con)
    {
        NativeSlice <byte> receiveBuffer = default;
        NativeSlice <byte> sendBuffer    = default;
        NativeSlice <byte> sharedBuffer  = default;

        driver.GetPipelineBuffers(pipeline, 4, con, ref receiveBuffer, ref sendBuffer, ref sharedBuffer);

        /*var relCtx = (ReliableUtility.SharedContext*)sharedBuffer.GetUnsafeReadOnlyPtr();
        *  var sendCtx = (ReliableUtility.Context*)sendBuffer.GetUnsafeReadOnlyPtr();
        *  UnityEngine.Debug.Log("Reliability stats\nPacketsDropped: " + relCtx->stats.PacketsDropped + "\n" +
        *         "PacketsDuplicated: " + relCtx->stats.PacketsDuplicated + "\n" +
        *         "PacketsOutOfOrder: " + relCtx->stats.PacketsOutOfOrder + "\n" +
        *         "PacketsReceived: " + relCtx->stats.PacketsReceived + "\n" +
        *         "PacketsResent: " + relCtx->stats.PacketsResent + "\n" +
        *         "PacketsSent: " + relCtx->stats.PacketsSent + "\n" +
        *         "PacketsStale: " + relCtx->stats.PacketsStale + "\n" +
        *         "Last received remote seqId: " + relCtx->ReceivedPackets.Sequence + "\n" +
        *         "Last received remote ackMask: " + SequenceHelpers.BitMaskToString(relCtx->ReceivedPackets.AckMask) + "\n" +
        *         "Last sent seqId: " + (relCtx->SentPackets.Sequence - 1)+ "\n" +
        *         "Last acked seqId: " + relCtx->SentPackets.Acked + "\n" +
        *         "Last ackmask: " + SequenceHelpers.BitMaskToString(relCtx->SentPackets.AckMask));*/
    }
Beispiel #6
0
        public unsafe void Update(float dt, int nodeIndex, TreeDef treeDef, NativeSlice <NodeState> state, NativeSlice <byte> data)
        {
            Profiler.BeginSample("TNode::Update");
            var arr = data.SliceConvert <T>();

            for (int i = 0; i < arr.Length; ++i)
            {
                var h = new NodeStateHandle(nodeIndex, state.Slice(i * treeDef.Nodes.Length, treeDef.Nodes.Length), treeDef);
                var v = arr[i];

                if (h.State == NodeState.Activating)
                {
                    h.State = Activate(h, ref v);
                }

                if (h.State == NodeState.Running)
                {
                    h.State = Update(dt, h, ref v);
                    arr[i]  = v;
                }
            }
            Profiler.EndSample();
        }