Example #1
0
    // returns the index of the component version of the data in the cache
    public static int GetOrAddMovementIdx(BulletMovementData moveData)
    {
        if (!movementStatsCache.IsCreated)
        {
            movementStatsCache = new NativeList <BulletMovement>(Allocator.Persistent);
        }

        if (!movementIdx.ContainsKey(moveData))
        {
            movementStatsCache.Add(moveData.ToBulletMovement());
            movementIdx.Add(moveData, movementStatsCache.Length - 1);
        }

        return(movementIdx[moveData]);
    }
    // copies monobehavior data into component data
    public void Convert(Entity entity, EntityManager dstManager,
                        GameObjectConversionSystem conversionSystem)
    {
        BulletMovement data;

        // stats exist, prefill
        if (stats != null)
        {
            data = stats.ToBulletMovement();
        }
        // no stats, make default
        else
        {
            data = new BulletMovement {
                moveType    = BulletMovementSystem.MoveType.LINEAR,
                moveSpeed   = 0,
                rotateSpeed = 0
            };
        }
        dstManager.AddComponentData(entity, data);
    }