Search Unity

Question Extending Unity.Collections with Partial?

Discussion in 'Entity Component System' started by jGate99, Apr 8, 2021.

  1. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Hi there,

    I have seemingly odd request, I want to extend Unity.Collection Classes such as NativeList, NativeHashMap using partial. However as they live in their own package/assembly, and just adding a partial keyword there doesnt connect it to the cs file in unity folder.

    Can please assist here? How can i achieve this usecase?

    Thanks
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I don't think you can really use partial for this.

    Is there any reason you can't just write extension methods?
     
    jGate99 likes this.
  3. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Actually as i have lots of native collections of different types (List, HashMaps etc) and i want to use loops to represent all with one interface and clear, dispose and remove keys easily.

    Currently i have to do this

    Code (CSharp):
    1.  
    2.  
    3.             SharedRemovables = new Func<int, bool>[]
    4.             {
    5.                 GridState.Remove,
    6.                 GridBonuses.Remove,
    7.  
    8.             };
    9.  
    10.             SharedClears = new Action[]
    11.             {
    12.                 GridState.Clear,
    13.  
    14.  
    15.                 WordsHorizontalRange.Clear,
    16.                 WordsVerticalRange.Clear,
    17.                
    18.                 GridBonuses.Clear,
    19.                
    20.                
    21.                 VisitedCells.Clear,
    22.                
    23.  
    24.                
    25.             };
    26.  
    27.  
    28.             SharedDisposables = new IDisposable[]
    29.             {
    30.                 GridState,
    31.  
    32.  
    33.                 WordsHorizontalRange,
    34.                 WordsVerticalRange,
    35.                
    36.                 GridBonuses,
    37.                
    38.                 VisitedCells,
    39.                
    40.                 JobsResults,
    41.             };