Пример #1
0
    private void LoadTextures()
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
        stopWatch.Reset();

        stopWatch.Start();

        Unity.Collections.NativeArray <byte> data = new Unity.Collections.NativeArray <byte>(System.IO.File.ReadAllBytes($"Texture_PNG.png"), Unity.Collections.Allocator.Temp);

        PNGTexture = new Texture2D(912, 513, TextureFormat.ARGB32, true);
        PNGTexture.LoadImage(data.ToArray());
        PNGTexture.Apply();



        data.Dispose();

        stopWatch.Stop();
        Debug.Log($"<color=red>Time taken for PNG :</color> {stopWatch.ElapsedMilliseconds} ms");

        stopWatch.Reset();
        stopWatch.Start();

        DDSTexture = TextureUtils.LoadTexture_DDS(System.IO.File.ReadAllBytes($"Texture_DDS.DDS"), TextureFormat.DXT5);
        stopWatch.Stop();
        Debug.Log($"<color=red>Time taken for DDS :</color> {stopWatch.ElapsedMilliseconds} ms");
    }
Пример #2
0
    public static void CreatEntity5()
    {
        //method4
        var a4 = w.EntityManager.CreateArchetype(typeof(Transform));

        Unity.Collections.NativeArray <Entity> e4_array = new Unity.Collections.NativeArray <Entity>(10, Unity.Collections.Allocator.Temp);
        w.EntityManager.CreateEntity(a4, e4_array);
        e4_array.Dispose();
    }
Пример #3
0
    public static void CreatEntity4()
    {
        //method3
        //CreateEntity(EntityArchetype, Int32, Allocator), 通过原型创建
        var a3 = w.EntityManager.CreateArchetype(typeof(Transform), typeof(EmptyData));

        Unity.Collections.NativeArray <Entity> e3_array = w.EntityManager.CreateEntity(a3, 10, Unity.Collections.Allocator.Temp);
        e3_array.Dispose();
    }
Пример #4
0
    void AddCube(int amount)
    {
        Unity.Collections.NativeArray <Unity.Entities.Entity> entities = new Unity.Collections.NativeArray <Unity.Entities.Entity>(amount, Unity.Collections.Allocator.Temp);
        manager.Instantiate(GameObjectEntity, entities);
        for (int i = 0; i < amount; i++)
        {
            manager.SetComponentData(entities[i], new Unity.Transforms.Position {
                Value = new Unity.Mathematics.float3(Random.Range(1, 400), 0, Random.Range(1, 400))
            });

            manager.SetComponentData(entities[i], new Speed {
                Value = 10f
            });
        }
        entities.Dispose();
    }
            public void Execute()
            {
                var bestCost = new Unity.Collections.NativeArray <int>(this.arr.Length, Unity.Collections.Allocator.Temp);

                for (int i = 0; i < this.arr.Length; ++i)
                {
                    bestCost[i] = int.MaxValue;
                }

                bestCost[this.endNodeIndex] = 0;

                // Creating cost field
                //var visited = new Unity.Collections.NativeList<int>(this.arr.Length, Unity.Collections.Allocator.Temp);
                this.queue.Enqueue(this.endNodeIndex);
                while (this.queue.Count > 0)
                {
                    ++this.results[0];
                    var curNodeIndex = this.queue.Dequeue();
                    //visited.Add(curNodeIndex);
                    var nodeData = this.arr[curNodeIndex];
                    // TODO: add custom connections support
                    var connections = nodeData.connections;
                    for (int i = 0; i < connections.Length; ++i)
                    {
                        var conn = connections.Get(i);
                        if (conn.index < 0)
                        {
                            continue;
                        }

                        var neighbor = this.arr[conn.index];
                        if (neighbor.IsSuitable(this.constraint, this.arr, this.graphSize, this.graphCenter) == false)
                        {
                            continue;
                        }

                        if (this.pathCustomWalkableField.IsTraversable(conn.index, this.constraint) == false)
                        {
                            continue;
                        }

                        int customCost = 0;
                        if (this.pathCustomWalkableField.IsWalkable(conn.index, this.constraint) == false)
                        {
                            customCost = this.pathCustomWalkableField.GetCustomCost(conn.index, this.constraint);
                        }

                        var cost        = neighbor.penalty + customCost;
                        var endNodeCost = cost + bestCost[nodeData.index];
                        if (endNodeCost < bestCost[neighbor.index])
                        {
                            bestCost[neighbor.index] = endNodeCost;
                            this.queue.Enqueue(neighbor.index);
                        }
                    }
                }

                // Creating direction field
                for (int i = 0, cnt = this.arr.Length; i < cnt; ++i)
                {
                    var nodeIdx = this.arr[i].index;
                    var ffCost  = bestCost[nodeIdx];
                    var node    = this.arr[nodeIdx];
                    var minCost = ffCost;
                    if (this.endNodeIndex == node.index)
                    {
                        minCost = 0;
                    }

                    // TODO: add custom connections support
                    var connections = node.connections;
                    var dir         = 0;
                    var iterDir     = 2;
                    for (int j = 2; j < 10; ++j)
                    {
                        ++iterDir;

                        var conn = connections.Get(j);
                        if (conn.index < 0)
                        {
                            continue;
                        }

                        var cost = bestCost[conn.index];
                        if (cost < minCost)
                        {
                            minCost = cost;
                            dir     = iterDir - 1;
                        }
                    }

                    this.flowField[nodeIdx] = (byte)dir;
                }

                bestCost.Dispose();
            }