public static IDictionary <string, FrameData[]> GetData(SpriterEntity entity, int interval) { IDictionary <string, FrameData[]> data = new Dictionary <string, FrameData[]>(); foreach (SpriterAnimation anim in entity.Animations) { int length = (int)Math.Ceiling(anim.Length / interval); FrameData[] animData = new FrameData[length]; for (int i = 0; i < animData.Length; ++i) { float time = i * interval; if (time > anim.Length) { time = anim.Length; } FrameData fd = new FrameData(); SpriterProcessor.UpdateFrameData(fd, anim, time); animData[i] = fd; } data[anim.Name] = animData; } return(data); }
/// <summary> /// Calculates the FrameData for the given entity with the given interval. /// </summary> public static Dictionary <string, FrameData[]> Calculate(SpriterEntity entity, int interval, Config config) { Dictionary <string, FrameData[]> results = new Dictionary <string, FrameData[]>(); foreach (SpriterAnimation anim in entity.Animations) { int length = (int)Math.Ceiling(anim.Length / interval); FrameData[] animData = new FrameData[length]; for (int i = 0; i < animData.Length; ++i) { float time = i * interval; if (time > anim.Length) { time = anim.Length; } ObjectPool pool = new ObjectPool(config); FrameData data = new FrameDataCalculator(config, pool).GetFrameData(anim, time, interval); animData[i] = data; } results[anim.Name] = animData; } return(results); }
private static Dictionary <string, T[]> Calculate <T>(SpriterEntity entity, int interval, Action <T, SpriterAnimation, float, float> filler) where T : new() { Dictionary <string, T[]> results = new Dictionary <string, T[]>(); foreach (SpriterAnimation anim in entity.Animations) { int length = (int)Math.Ceiling(anim.Length / interval); T[] animData = new T[length]; for (int i = 0; i < animData.Length; ++i) { float time = i * interval; if (time > anim.Length) { time = anim.Length; } T data = new T(); filler(data, anim, time, interval); animData[i] = data; } results[anim.Name] = animData; } return(results); }
private static SpriterEntity FetchOrCacheSpriterEntityDataFromFile(string path, string entityName, SpriterDotNetBehaviour spriterDotNetBehaviour) { if (SpriterEntityDatas.TryGetValue(new PathToEntity(path, entityName), out SpriterEntityData cachedEntityData)) { spriterDotNetBehaviour.SpriterData = cachedEntityData.data; return(cachedEntityData.entity); } string data = File.ReadAllText(path); Spriter spriter = SpriterReader.Default.Read(data); string rootFolder = Path.GetDirectoryName(path); SpriterEntity requestedEntity = null; foreach (SpriterEntity entity in spriter.Entities) { bool isRequestedEntity = entity.Name == entityName; SpriterData spriterData = CreateSpriterData(spriter, rootFolder, spriterDotNetBehaviour, isRequestedEntity); SpriterEntityData entityData = new SpriterEntityData(entity, spriterData); SpriterEntityDatas[new PathToEntity(path, entity.Name)] = entityData; if (isRequestedEntity) { requestedEntity = entity; spriterDotNetBehaviour.SpriterData = spriterData; } } return(requestedEntity); }
private static void CreateCollisionRectangles(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent) { if (entity.ObjectInfos == null) { return; } var boxes = entity.ObjectInfos.Where(o => o.ObjectType == SpriterObjectType.Box).ToList(); if (boxes.Count == 0) { return; } GameObject boxRoot = new GameObject("Boxes"); boxRoot.SetParent(parent); cd.BoxPivots = new GameObject[boxes.Count]; cd.Boxes = new GameObject[boxes.Count]; for (int i = 0; i < boxes.Count; ++i) { GameObject pivot = new GameObject("Pivot " + i); GameObject child = new GameObject("Box " + i); pivot.SetParent(boxRoot); child.SetParent(pivot); cd.BoxPivots[i] = pivot; cd.Boxes[i] = child; child.AddComponent <BoxCollider2D>(); } }
public CustomSpriterAnimator( XmasHell game, SpriterEntity entity, IProviderFactory <ISprite, SoundEffect> providerFactory = null, Stack <SpriteDrawInfo> drawInfoPool = null ) : base(entity, providerFactory, drawInfoPool) { _game = game; _providerFactory = providerFactory; _drawInfoPool = drawInfoPool; _hiddenTextures = new List <string>(); _textureSwapMap = new Dictionary <string, Texture2D>(); _pointTexture = new TextureSprite(TextureUtil.CreateCircle(_game.GraphicsDevice, 1, Color.Cyan)); if (entity.ObjectInfos != null) { foreach (SpriterObjectInfo objInfo in entity.ObjectInfos) { if (objInfo.ObjectType != SpriterObjectType.Box) { continue; } _boxTextures[objInfo.Name] = new TextureSprite(TextureUtil.CreateRectangle(_game.GraphicsDevice, (int)objInfo.Width, (int)objInfo.Height, Color.Cyan)); } } }
private static bool HasSound(SpriterEntity entity) { foreach (SpriterAnimation animation in entity.Animations) { if (animation.Soundlines != null && animation.Soundlines.Length > 0) { return(true); } if (animation.Timelines == null) { continue; } foreach (SpriterTimeline timeline in animation.Timelines) { if (timeline.ObjectType != SpriterObjectType.Entity || timeline.Keys == null) { continue; } foreach (SpriterTimelineKey key in timeline.Keys) { if (key.ObjectInfo == null) { continue; } bool hasSound = HasSound(entity.Spriter.Entities[key.ObjectInfo.EntityId]); if (hasSound) { return(true); } } } } return(false); }
private static void CreateSprites(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent) { int maxObjects = GetDrawablesCount(entity); cd.Sprites = new GameObject[maxObjects]; cd.SpritePivots = new GameObject[maxObjects]; cd.SpriteTransforms = new Transform[maxObjects]; cd.SpritePivotTransforms = new Transform[maxObjects]; for (int i = 0; i < maxObjects; ++i) { GameObject pivot = new GameObject("Pivot " + i); GameObject child = new GameObject("Sprite " + i); pivot.SetParent(parent); child.SetParent(pivot); cd.SpritePivots[i] = pivot; cd.Sprites[i] = child; cd.SpritePivotTransforms[i] = pivot.transform; cd.SpriteTransforms[i] = child.transform; child.transform.localPosition = Vector3.zero; child.AddComponent <SpriteRenderer>(); } }
public GameAnimator(SpriterEntity entity, int width, int height, GraphicsDevice graphicsDevice, IProviderFactory <ISprite, SoundEffect> providerFactory = null) : base(entity, providerFactory) { whiteDot = TextureUtil.CreateRectangle(graphicsDevice, 1, 1, Color.White); this.width = width; this.height = height; cox = 0; coy = 0; }
public MonoGameAnimator(SpriterEntity entity, IProviderFactory <Sprite, SoundEffect> providerFactory = null) : base(entity, providerFactory) { DrawInfoPool = new Stack <DrawInfo>(); DrawInfos = new List <DrawInfo>(); Scale = Vector2.One; DeltaDepth = DefaultDeltaDepth; Depth = DefaultDepth; }
public MonoGameDebugAnimator ( SpriterEntity entity, GraphicsDevice graphicsDevice, IProviderFactory <ISprite, SoundEffect> providerFactory = null, Stack <SpriteDrawInfo> drawInfoPool = null ) : base(entity, providerFactory, drawInfoPool) { whiteDot = CreateTexture(graphicsDevice, 1, 1, Color.White); }
public UltravioletAnimator ( SpriterEntity entity, IProviderFactory <ISprite, SoundEffect> providerFactory = null, Stack <SpriteDrawInfo> drawInfoPool = null ) : base(entity, providerFactory) { Scale = Vector2.One; Rotation = 0; DrawInfoPool = drawInfoPool ?? new Stack <SpriteDrawInfo>(); }
private static void Process(SpriterEntity entity, GameObject prefab) { GetAssistant(prefab); var controller = GetController(prefab); ProcessAnimations(entity.Animations, controller); if (MecanimDone != null) { MecanimDone(entity, prefab, controller); } }
private static bool HasSound(SpriterEntity entity) { foreach (SpriterAnimation animation in entity.Animations) { if (animation.Soundlines != null && animation.Soundlines.Length > 0) { return(true); } } return(false); }
public UnityAnimator(SpriterEntity entity, ChildData childData, AudioSource audioSource) : base(entity) { this.childData = childData; this.audioSource = audioSource; renderers = new SpriteRenderer[childData.Sprites.Length]; for (int i = 0; i < childData.Sprites.Length; ++i) { renderers[i] = childData.Sprites[i].GetComponent <SpriteRenderer>(); } }
private static int GetPointsCount(SpriterEntity entity) { int count = 0; foreach (SpriterAnimation animation in entity.Animations) { int countForAnim = animation.Timelines.Where(t => t.ObjectType == SpriterObjectType.Point).Count(); count = Math.Max(count, countForAnim); } return(count); }
private static int GetDrawablesCount(SpriterEntity entity) { int drawablesCount = 0; foreach (SpriterAnimation animation in entity.Animations) { int count = GetDrawablesCount(animation); drawablesCount = Math.Max(drawablesCount, count); } return(drawablesCount); }
private void Start() { SpriterEntity entity = SpriterData.Spriter.Entities[EntityIndex]; AudioSource audioSource = gameObject.GetComponent <AudioSource>(); Animator = new UnityAnimator(entity, ChildData, audioSource, Ppu); RegisterSpritesAndSounds(); if (UseNativeTags) { defaultTag = gameObject.tag; } Animator.Update(0); }
public void Start() { SpriterEntity entity = SpriterData.Spriter.Entities[EntityIndex]; AudioSource audioSource = gameObject.GetComponent <AudioSource>(); Animator = new UnityAnimator(entity, ChildData, audioSource); //Debug.Log("Animator: " + Animator); //Animator.CurrentAnimation = ; RegisterSpritesAndSounds(); if (UseNativeTags) { defaultTag = gameObject.tag; } Animator.Update(0); }
internal static int GetDrawablesCount(SpriterEntity entity) { if (entity.Animations == null) { return(0); } int drawablesCount = 0; foreach (SpriterAnimation animation in entity.Animations) { int count = GetDrawablesCount(animation); drawablesCount = Math.Max(drawablesCount, count); } return(drawablesCount); }
private static void CreatePoints(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent) { GameObject pointRoot = new GameObject("Points"); pointRoot.SetParent(parent); int count = GetPointsCount(entity); cd.Points = new GameObject[count]; for (int i = 0; i < count; ++i) { GameObject point = new GameObject("Point " + i); point.SetParent(pointRoot); cd.Points[i] = point; } }
public MonogameSpriterAnimator(SpriterEntity entity, Vector2 charLocation, SpriteBatch spriteBatch, GraphicsDevice graphics) : base(entity) { this.charLocation = charLocation; this.spriteBatch = spriteBatch; pointTexture = TextureUtil.CreateCircle(graphics, 5, Color.Cyan); if (entity.ObjectInfos != null) { foreach (SpriterObjectInfo objInfo in entity.ObjectInfos) { if (objInfo.ObjectType != SpriterObjectType.Box) { continue; } boxTextures[objInfo.Name] = TextureUtil.CreateRectangle(graphics, (int)objInfo.Width, (int)objInfo.Height, Color.Cyan); } } }
public virtual IFrameDataProvider GetDataProvider(SpriterEntity entity) { if (!CacheAnimations) { return(new DefaultFrameDataProvider(Config, Pool)); } AnimProviders.TryGetValue(entity, out var provider); if (provider == null) { var data = SnapshotFrameDataProvider.Calculate(entity, Interval, Config); provider = new SnapshotFrameDataProvider(Config, Pool, data); AnimProviders[entity] = provider; } return(provider); }
private static bool HasSound(SpriterEntity entity, HashSet <int> processedIds = null) { if (processedIds == null) { processedIds = new HashSet <int>(); } if (processedIds.Contains(entity.Id)) { return(false); } processedIds.Add(entity.Id); foreach (SpriterAnimation animation in entity.Animations) { if (animation.Soundlines != null && animation.Soundlines.Length > 0) { return(true); } if (animation.Timelines == null) { continue; } foreach (SpriterTimeline timeline in animation.Timelines) { if (timeline.ObjectType != SpriterObjectType.Entity || timeline.Keys == null) { continue; } foreach (SpriterTimelineKey key in timeline.Keys) { if (key.ObjectInfo == null) { continue; } bool hasSound = HasSound(entity.Spriter.Entities[key.ObjectInfo.EntityId], processedIds); if (hasSound) { return(true); } } } } return(false); }
internal static void CreatePoints(SpriterEntity entity, ChildData cd, GameObject parent) { GameObject pointRoot = new GameObject("Points"); pointRoot.SetParent(parent); int count = GetPointsCount(entity); cd.Points = new GameObject[count]; cd.PointTransforms = new Transform[count]; for (int i = 0; i < count; ++i) { GameObject point = new GameObject("Point " + i); point.SetParent(pointRoot); cd.Points[i] = point; cd.PointTransforms[i] = point.transform; } }
public MonoGameDebugAnimator(SpriterEntity entity, GraphicsDevice graphicsDevice, IProviderFactory <Sprite, SoundEffect> providerFactory = null) : base(entity, providerFactory) { pointTexture = new Sprite { Texture = TextureUtil.CreateCircle(graphicsDevice, 5, Color.Cyan) }; if (entity.ObjectInfos != null) { foreach (SpriterObjectInfo objInfo in entity.ObjectInfos) { if (objInfo.ObjectType != SpriterObjectType.Box) { continue; } boxTextures[objInfo.Name] = new Sprite { Texture = TextureUtil.CreateRectangle(graphicsDevice, (int)objInfo.Width, (int)objInfo.Height, Color.Cyan) }; } } }
public static SpriterDotNetBehaviour CreateSpriter(string path, string entityName, Transform parent = null) { GameObject go = new GameObject(entityName); SpriterDotNetBehaviour behaviour = go.AddComponent <SpriterDotNetBehaviour>(); SpriterEntity entity = FetchOrCacheSpriterEntityDataFromFile(path, entityName, behaviour); if (entity == null) { UnityEngine.Object.Destroy(go); return(null); } GameObject sprites = new GameObject(ObjectNameSprites); GameObject metadata = new GameObject(ObjectNameMetadata); behaviour.UseNativeTags = false; if (SpriterImporterUtil.HasSound(entity)) { go.AddComponent <AudioSource>(); } sprites.SetParent(go); metadata.SetParent(go); ChildData cd = new ChildData(); SpriterImporterUtil.CreateSprites(entity, cd, sprites); SpriterImporterUtil.CreateCollisionRectangles(entity, cd, metadata); SpriterImporterUtil.CreatePoints(entity, cd, metadata); cd.Verify(); behaviour.EntityIndex = entity.Id; behaviour.enabled = true; behaviour.ChildData = cd; go.transform.parent = parent; return(behaviour); }
/// Initialize the animatior private void InitAnimator() { SpriterEntity entity = SpriterData.Spriter.Entities[EntityIndex]; AudioSource audioSource = gameObject.GetComponent <AudioSource>(); SpriterAnimator = new UnitySpriterAnimator(entity, ChildData, audioSource); RegisterSpritesAndSounds(); if (UseNativeTags) { defaultTag = gameObject.tag; } if (!String.IsNullOrEmpty(DefaultAnimation)) { N.Console.Log("Trying to set animation {0}", DefaultAnimation); foreach (var i in SpriterAnimator.GetAnimations()) { N.Console.Log(i); } SpriterAnimator.Transition(DefaultAnimation, 0); } SpriterAnimator.Step(0); }
public static IDictionary<string, FrameData[]> GetData(SpriterEntity entity, int interval) { IDictionary<string, FrameData[]> data = new Dictionary<string, FrameData[]>(); foreach (SpriterAnimation anim in entity.Animations) { int length = (int)Math.Ceiling(anim.Length / interval); FrameData[] animData = new FrameData[length]; for (int i = 0; i < animData.Length; ++i) { float time = i * interval; if (time > anim.Length) time = anim.Length; FrameData fd = new FrameData(); SpriterProcessor.UpdateFrameData(fd, anim, time); animData[i] = fd; } data[anim.Name] = animData; } return data; }
private static void SpriterImporter_EntityImported(SpriterEntity entity, GameObject go) { Debug.Log("Imported Entity: " + entity.Name); }
public SpriteWrapper(SpriterEntity ent, IProviderFactory <ISprite, SoundEffect> prov) { Entity = ent; AssetProvider = prov; }