// static int dummyCnt = 0;

        public static Entity Instantiate(Entity prefab, float3 pos, quaternion rot, int replayIndex)
        {
            var em     = World.Active.EntityManager;
            var entity = em.Instantiate(prefab);

#if UNITY_EDITOR
            em.SetName(entity, "fighter");
#endif
            em.SetComponentData(entity, new Translation {
                Value = pos,
            });
            em.SetComponentData(entity, new Rotation {
                Value = rot,
            });
            em.SetComponentData(entity, new FighterComponent {
                Target           = new float3(0, 16, 0), // tmp
                LastBeamFired    = 0,
                ControllerReplay = new ControllerReplay {
                    ReplayIndex = replayIndex,
                },
            });
            var trailColor = new Color(172f / 255f, 255f / 255f, 237f / 255f);
            TrailSystem.Instantiate(entity, pos, 1f /* width */, trailColor,
                                    FighterConfig.BurnerLeft, 1f / 60f /* update_interval */);
            TrailSystem.Instantiate(entity, pos, 1f /* width */, trailColor,
                                    FighterConfig.BurnerRight, 1f / 60f /* update_interval */);
            return(entity);
        }
 public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
 {
     _prefabEntity = conversionSystem.GetPrimaryEntity(prefab);
     _random.InitState(12345678u);
     TrailSystem.Initialize(_prefabEntity);
     RenderTrailSystem.Initialize(materialTrail);
 }
        void Start()
        {
            var       em     = World.Active.EntityManager;
            var       random = new Random(12345);
            const int NUM    = 1023 * 2;
            var       coltbl = new Color[] {
                Color.HSVToRGB(0.0f, 1f, 1f),
                Color.HSVToRGB(0.1f, 1f, 1f),
                Color.HSVToRGB(0.2f, 1f, 1f),
                Color.HSVToRGB(0.3f, 1f, 1f),
                Color.HSVToRGB(0.4f, 1f, 1f),
                Color.HSVToRGB(0.5f, 1f, 1f),
                Color.HSVToRGB(0.6f, 1f, 1f),
                Color.HSVToRGB(0.7f, 1f, 1f),
                Color.HSVToRGB(0.8f, 1f, 1f),
                Color.HSVToRGB(0.9f, 1f, 1f),
            };

            for (var i = 0; i < NUM; ++i)
            {
                var entity = em.CreateEntity(typeof(Translation),
                                             typeof(Rotation),
                                             typeof(TestTrailRaycasterComponent));
#if UNITY_EDITOR
                em.SetName(entity, "trailRoot");
#endif
                em.SetComponentData(entity, new TestTrailRaycasterComponent {
                    Direction = random.NextFloat3Direction(),
                });
                var col = coltbl[(i / 1023) % coltbl.Length];
                TrailSystem.Instantiate(entity, float3.zero, 0.02f /* width */, col,
                                        float3.zero, 1f / 60f /* update_interval */);
            }
        }
Esempio n. 4
0
        protected override void OnUpdate()
        {
            if (group_.Length == 0)
            {
                return;
            }
            TrailSystem.Sync();

            var entity_manager = Unity.Entities.World.Active.GetOrCreateManager <EntityManager>();
            var trail_renderer = entity_manager.GetSharedComponentData <TrailRenderer>(group_.entity_list_[0]);

            Assert.IsTrue(group_.Length <= TrailConfig.BULK_NUM);
            mesh_.triangles = CV.IntArrayEmpty;
            mesh_.normals   = CV.Vector3ArrayEmpty;
            mesh_.uv        = CV.Vector2ArrayEmpty;
            mesh_.vertices  = CV.Vector3ArrayEmpty;
            mesh_.SetVertices(TrailSystem.GetVertices());
            mesh_.SetNormals(TrailSystem.GetNormals());
            mesh_.SetUVs(0 /* channel */, TrailSystem.GetUVs());

            mesh_.SetTriangles(TrailSystem.GetTriangles(), 0 /* submesh */, false /* calculateBounds */, 0 /* baseVertex */);

            var material = trail_renderer.material_;

            Graphics.DrawMesh(mesh_,
                              Matrix4x4.identity,
                              material,
                              0 /* layer */,
                              null /* camera */,
                              0 /* submeshIndex */,
                              null /* MaterialPropertyBlock */,
                              false /* castShadows */,
                              false /* receiveShadows */,
                              false /* lightprobe */);
        }
Esempio n. 5
0
 public void Execute()
 {
     TrailSystem.ClearUVs();
     for (var i = 0; i < trail_data_list_.Length; ++i)
     {
         var td = trail_data_list_[i];
         for (var j = 0; j < TrailConfig.NODE_NUM; ++j)
         {
             float alpha = (((float)j) / (float)TrailConfig.NODE_NUM);
             alpha = (1f - alpha * alpha) * 0.8f;
             var uv = new Vector2(td.color_type_, alpha);
             TrailSystem.AddUV(ref uv);
             TrailSystem.AddUV(ref uv);
         }
     }
 }
Esempio n. 6
0
 public void Execute()
 {
     TrailSystem.ClearTriangles();
     for (var i = 0; i < length; ++i)
     {
         for (var j = 0; j < TrailConfig.NODE_NUM; ++j)
         {
             if (j < TrailConfig.NODE_NUM - 1)
             {
                 TrailSystem.AddTriangle(i * TrailConfig.NODE_NUM * 2 + (j + 0) * 2 + 0,
                                         i * TrailConfig.NODE_NUM * 2 + (j + 0) * 2 + 1,
                                         i * TrailConfig.NODE_NUM * 2 + (j + 1) * 2 + 0);
                 TrailSystem.AddTriangle(i * TrailConfig.NODE_NUM * 2 + (j + 1) * 2 + 0,
                                         i * TrailConfig.NODE_NUM * 2 + (j + 0) * 2 + 1,
                                         i * TrailConfig.NODE_NUM * 2 + (j + 1) * 2 + 1);
             }
         }
     }
 }
Esempio n. 7
0
 public void Execute()
 {
     TrailSystem.ClearNormals();
     for (var i = 0; i < trail_data_list_.Length; ++i)
     {
         var td           = trail_data_list_[i];
         var trail_points = trail_points_list_[i];
         for (var j = 0; j < TrailConfig.NODE_NUM; ++j)
         {
             int idx = td.trail_head_index_ - j;
             if (idx < 0)
             {
                 idx += TrailConfig.NODE_NUM;
             }
             Vector3 n = trail_points[idx].normal_;
             TrailSystem.AddNormal(ref n);
             TrailSystem.AddNormal(ref n);
         }
     }
 }
Esempio n. 8
0
 public void Execute()
 {
     TrailSystem.ClearVertices();
     for (var i = 0; i < trail_data_list_.Length; ++i)
     {
         var td           = trail_data_list_[i];
         var trail_points = trail_points_list_[i];
         for (var j = 0; j < TrailConfig.NODE_NUM; ++j)
         {
             int idx = td.trail_head_index_ - j;
             if (idx < 0)
             {
                 idx += TrailConfig.NODE_NUM;
             }
             Vector3 v = trail_points[idx].position_;
             TrailSystem.AddVertex(ref v);
             TrailSystem.AddVertex(ref v); // two by two
         }
     }
 }
Esempio n. 9
0
            public void Execute()
            {
                TrailSystem.ClearVertices();
                TrailSystem.ClearNormals();
                TrailSystem.ClearUVs();
                TrailSystem.ClearTriangles();
                for (var i = 0; i < trail_data_list_.Length; ++i)
                {
                    var td           = trail_data_list_[i];
                    var trail_points = trail_points_list_[i];
                    for (var j = 0; j < TrailConfig.NODE_NUM; ++j)
                    {
                        int idx = td.trail_head_index_ - j;
                        if (idx < 0)
                        {
                            idx += TrailConfig.NODE_NUM;
                        }
                        Vector3 v = trail_points[idx].position_;
                        Vector3 n = trail_points[idx].normal_;

                        TrailSystem.AddVertex(ref v);
                        TrailSystem.AddVertex(ref v); // two by two
                        TrailSystem.AddNormal(ref n);
                        TrailSystem.AddNormal(ref n);
                        float alpha = (((float)j) / (float)TrailConfig.NODE_NUM);
                        alpha = (1f - alpha * alpha) * 0.8f;
                        var uv = new Vector2(td.color_type_, alpha);
                        TrailSystem.AddUV(ref uv);
                        TrailSystem.AddUV(ref uv);
                        if (j < TrailConfig.NODE_NUM - 1)
                        {
                            TrailSystem.AddTriangle(i * TrailConfig.NODE_NUM * 2 + (j + 0) * 2 + 0,
                                                    i * TrailConfig.NODE_NUM * 2 + (j + 0) * 2 + 1,
                                                    i * TrailConfig.NODE_NUM * 2 + (j + 1) * 2 + 0);
                            TrailSystem.AddTriangle(i * TrailConfig.NODE_NUM * 2 + (j + 1) * 2 + 0,
                                                    i * TrailConfig.NODE_NUM * 2 + (j + 0) * 2 + 1,
                                                    i * TrailConfig.NODE_NUM * 2 + (j + 1) * 2 + 1);
                        }
                    }
                }
            }
Esempio n. 10
0
        void Start()
        {
            var       em     = World.DefaultGameObjectInjectionWorld.EntityManager;
            var       random = new Random(12345);
            const int NUM    = 1023 * 2;
            var       coltbl = new Color[] {
                Color.HSVToRGB(0.0f, 1f, 1f),
                Color.HSVToRGB(0.1f, 1f, 1f),
                Color.HSVToRGB(0.2f, 1f, 1f),
                Color.HSVToRGB(0.3f, 1f, 1f),
                Color.HSVToRGB(0.4f, 1f, 1f),
                Color.HSVToRGB(0.5f, 1f, 1f),
                Color.HSVToRGB(0.6f, 1f, 1f),
                Color.HSVToRGB(0.7f, 1f, 1f),
                Color.HSVToRGB(0.8f, 1f, 1f),
                Color.HSVToRGB(0.9f, 1f, 1f),
            };

            for (var i = 0; i < NUM; ++i)
            {
                var entity = em.CreateEntity(ComponentType.ReadWrite <Translation>(),
                                             ComponentType.ReadWrite <Rotation>(),
                                             ComponentType.ReadWrite <TestTrailComponent>());
            #if UNITY_EDITOR
                em.SetName(entity, "testTrail");
            #endif
                em.SetComponentData(entity, new TestTrailComponent {
                    LocalVector = random.NextFloat3Direction(),
                });
                //var col = coltbl[(i/1023)%coltbl.Length];
                var col = i < 1024 ? Color.red : Color.white;
                col.a = 0.1f;
                TrailSystem.Instantiate(entity, float3.zero, 0.2f /* width */, col,
                                        float3.zero, 1f / 60f /* update_interval */);
            }
        }