public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var animationBufferEntity = dstManager.CreateEntity(); #if UNITY_EDITOR dstManager.SetName(animationBufferEntity, $"{gameObject.name} - SpriteAnimationBuffer"); #endif var availableComponentTypes = TypeUtility.GetAvailableComponentTypes(typeof(IDynamicBufferProperty <>)); foreach (var propertyType in availableComponentTypes) { var baseType = typeof(SpriteAnimationClipConverter <,>); var genericType0 = propertyType; var genericType1 = TypeUtility.ExtractInterfaceGenericType(propertyType, typeof(IComponentValue <>), 0); var instance = TypeUtility.CreateInstance( baseType: baseType, genericType0: genericType0, genericType1: genericType1, constructorArgs: Array.Empty <object>()) as IAnimationClipConverter; instance.Convert(gameObject, dstManager, animationBufferEntity, Clips); } dstManager.AddSharedComponentData(entity, new SpriteAnimation { ClipSetEntity = animationBufferEntity, ClipIndex = ClipIndex, ClipCount = Clips.Length }); dstManager.AddComponentData(entity, new SpriteAnimationState { Speed = Speed, Time = StartTime }); }
protected override void OnCreate() { base.OnCreate(); var availableComponentTypes = TypeUtility.GetAvailableComponentTypes(typeof(IDynamicBufferProperty <>)); m_query = GetEntityQuery(new EntityQueryDesc { All = new ComponentType[] { ComponentType.ReadOnly <SpriteAnimation>(), ComponentType.ReadOnly <SpriteAnimationState>() }, Any = availableComponentTypes.Select(t => (ComponentType)t).ToArray() }); foreach (var propertyType in availableComponentTypes) { var baseType = typeof(SpritePropertyAnimator <,>); var genericType0 = propertyType; var genericType1 = TypeUtility.ExtractInterfaceGenericType(propertyType, typeof(IComponentValue <>), 0); m_spriteAnimators.Add( TypeUtility.CreateInstance( baseType: baseType, genericType0: genericType0, genericType1: genericType1, constructorArgs: new object[] { this, m_query }) as ISpritePropertyAnimator); } }
public static IEnumerable <IAnimationClipConverter> CreateConverters() { return(TypeUtility.GetTypes(typeof(IDynamicBufferProperty <>)) .Select(t => { return TypeUtility.CreateInstance( baseType: typeof(SpriteAnimationClipConverter <,>), genericType0: t, genericType1: TypeUtility.ExtractInterfaceGenericType(t, typeof(IComponentValue <>), 0), constructorArgs: Array.Empty <object>()) as IAnimationClipConverter; })); }