Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ECS files Templates

Discussion in 'Entity Component System' started by Micz84, May 13, 2018.

  1. Micz84

    Micz84

    Joined:
    Jul 21, 2012
    Posts:
    447
    I am creating a small project with a hybrid ECS approach. I have created several systems and more than dozen components and there is a lot of repetition a specially in systems. So I have created templates for VS attached below.
    System Template
    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. namespace $rootnamespace$
    4. {
    5.     public class $itemname$ : ComponentSystem
    6.     {
    7.         public struct Data
    8.         {
    9.             public int Length;
    10.             public EntityArray EntityID;
    11.         }
    12.  
    13.         [Inject] Data m_Data;
    14.  
    15.         protected override void OnUpdate()
    16.         {
    17.             for(int i = 0;i < m_Data.Length;i++)
    18.             {
    19.  
    20.             }
    21.         }
    22.     }
    23. }
    JobComponentSystem template
    Code (CSharp):
    1. using System;
    2. using Unity.Entities;
    3. using Unity.Jobs;
    4.  
    5. namespace $rootnamespace$
    6. {
    7.    
    8.     public class $itemname$ : JobComponentSystem
    9.     {
    10.         public struct JobTmplate : IJobProcessComponentData<T1>
    11.         {
    12.             public float Value;
    13.            
    14.  
    15.             public void Execute(ref T1 value) //  example (ref T1 health, [ReadOnly] ref Position2D pos, [ReadOnly] ref Enemy enemyTag)
    16.             {
    17.                
    18.             }
    19.         }
    20.  
    21.         protected override JobHandle OnUpdate(JobHandle inputDeps)
    22.         {
    23.            
    24.             var boundaryKillJob = new JobTmplate
    25.             {
    26.                 Value = 0,
    27.                
    28.             };
    29.  
    30.             return boundaryKillJob.Schedule(this, 64, inputDeps);
    31.         }
    32.     }
    33. }
    34.  
    Component template
    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. namespace $rootnamespace$
    4. {
    5.     public struct $safeitemname$ : IComponentData
    6.     {
    7.     }
    8. }
     

    Attached Files:

    Last edited: May 14, 2018
    hensoup, Onigiri, zyzyx and 1 other person like this.