public virtual Spriter Read(string data) { if (data == null) { throw new ArgumentNullException("data"); } data = data.Trim(); if (string.IsNullOrEmpty(data)) { return(null); } Spriter spriter = null; foreach (ISpriterParser parser in Parsers) { if (!parser.CanParse(data)) { continue; } spriter = parser.Parse(data); break; } foreach (ISpriterPreprocessor preprocessor in Preprocessors) { preprocessor.Preprocess(spriter); } return(spriter); }
private static void CreateChildren(SpriterDotNetBehaviour sdnBehaviour, Spriter spriter, GameObject parent) { SpriterEntity entity = spriter.Entities[0]; int maxObjects = 0; foreach (SpriterAnimation animation in entity.Animations) { foreach (SpriterMainLineKey mainKey in animation.MainlineKeys) { maxObjects = Math.Max(maxObjects, mainKey.ObjectRefs.Length); } } sdnBehaviour.Children = new GameObject[maxObjects]; sdnBehaviour.Pivots = new GameObject[maxObjects]; for (int i = 0; i < maxObjects; ++i) { GameObject pivot = new GameObject(); GameObject child = new GameObject(); sdnBehaviour.Pivots[i] = pivot; sdnBehaviour.Children[i] = child; pivot.transform.SetParent(parent.transform); child.transform.SetParent(pivot.transform); child.transform.localPosition = new Vector3(0, 0, DeltaZ * i); pivot.name = "pivot " + i; child.name = "child " + i; child.AddComponent<SpriteRenderer>(); } }
public static Spriter Parse(string data) { if (data != null) { data = data.Trim(); } if (String.IsNullOrEmpty(data)) { return(null); } Spriter spriter = null; foreach (ISpriterParser parser in Parsers) { if (!parser.CanParse(data)) { continue; } spriter = parser.Parse(data); break; } if (spriter != null) { Init(spriter); } return(spriter); }
public static void Init(Spriter spriter) { foreach (SpriterEntity entity in spriter.Entities) { entity.Spriter = spriter; foreach (SpriterAnimation animation in entity.Animations) { animation.Entity = entity; InitInfos(animation); InitVarDefs(animation); } } }
public static void Init(Spriter spriter) { foreach (SpriterEntity entity in spriter.Entities) { entity.Spriter = spriter; if (entity.ObjectInfos == null) entity.ObjectInfos = new SpriterObjectInfo[0]; foreach (SpriterAnimation animation in entity.Animations) { animation.Entity = entity; InitInfos(animation); InitVarDefs(animation); } } }
/// <summary> /// Parses and processes the provided data and returns a <see cref="Spriter"/>. /// </summary> /// <param name="data">The data to parse. Intaken as a <see cref="string"/>.</param> /// <returns>Returns a <see cref="Spriter"/></returns> public virtual Spriter Read(string data) { // Throw a null argument if the data is null. if (data == null) { throw new ArgumentNullException(nameof(data)); } // Trim the data of any leading and trailing white space. data = data.Trim(); // Return null if the data is null or empty after being trimmed. if (string.IsNullOrEmpty(data)) { return(null); } // Setup return Spriter. Spriter spriter = null; // Parse the data with any loaded parsers to find a Spriter. foreach (ISpriterParser parser in Parsers) { // If the data cannot be parsed by the current parser then continue on to the next parser without continuing past the if statement. if (!parser.CanParse(data)) { continue; } // Assign the spriter after parsing the parseable data. spriter = parser.Parse(data); // Exit the foreach loop once a Spriter is found. break; } // Process the Spriter with any loaded preprocessors. foreach (ISpriterPreprocessor preprocessor in Preprocessors) { preprocessor.Preprocess(spriter); } // Return a Spriter or null based on the usability of the provided data. return(spriter); }
public static void Init(Spriter spriter) { foreach (SpriterEntity entity in spriter.Entities) { entity.Spriter = spriter; if (entity.ObjectInfos == null) { entity.ObjectInfos = new SpriterObjectInfo[0]; } foreach (SpriterAnimation animation in entity.Animations) { animation.Entity = entity; InitInfos(animation); InitVarDefs(animation); } } }
protected virtual void AddSpatialData(SpriterObject info, SpriterTimeline timeline, Spriter spriter, float deltaTime) { switch (timeline.ObjectType) { case SpriterObjectType.Sprite: FrameData.SpriteData.Add(info); break; case SpriterObjectType.Entity: SpriterAnimation newAnim = spriter.Entities[info.EntityId].Animations[info.AnimationId]; float newTargetTime = info.T * newAnim.Length; GetFrameData(newAnim, newTargetTime, deltaTime, info); break; case SpriterObjectType.Point: info.PivotX = 0.0f; info.PivotY = 1.0f; FrameData.PointData[timeline.Name] = info; break; case SpriterObjectType.Box: FrameData.BoxData[timeline.ObjectId] = info; break; } }
private static void LoadSprites(SpriterDotNetBehaviour sdnBehaviour, Spriter spriter, string rootFolder) { sdnBehaviour.Folders = new SdnFolder[spriter.Folders.Length]; for (int i = 0; i < spriter.Folders.Length; ++i) { SpriterFolder folder = spriter.Folders[i]; SdnFolder sdnFolder = new SdnFolder(); sdnFolder.Files = new Sprite[folder.Files.Length]; sdnBehaviour.Folders[i] = sdnFolder; for (int j = 0; j < folder.Files.Length; ++j) { SpriterFile file = folder.Files[j]; string spritePath = rootFolder; spritePath += "/"; spritePath += file.Name; Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(spritePath); if (sprite == null) { Debug.LogWarning("Unable to load sprite: " + spritePath); continue; } sdnFolder.Files[j] = sprite; } } }
private static void SetDefaultPivots(Spriter spriter) { var infos = from e in spriter.Entities from a in e.Animations from t in a.Timelines from k in t.Keys let o = k.ObjectInfo where o != null && (float.IsNaN(o.PivotX) || float.IsNaN(o.PivotY)) select o; foreach (SpriterObjectInfo info in infos) { SpriterFile file = spriter.Folders[info.FolderId].Files[info.FileId]; info.PivotX = file.PivotX; info.PivotY = file.PivotY; } }
private static void AddSpatialData(SpriterObject info, SpriterTimeline timeline, Spriter spriter, float targetTime, FrameData frameData) { switch (timeline.ObjectType) { case SpriterObjectType.Sprite: frameData.SpriteData.Add(info); break; case SpriterObjectType.Entity: SpriterAnimation newAnim = spriter.Entities[info.EntityId].Animations[info.AnimationId]; float newTargetTime = info.T * newAnim.Length; UpdateFrameData(frameData, newAnim, newTargetTime, info); break; case SpriterObjectType.Point: frameData.PointData[timeline.Name] = info; break; case SpriterObjectType.Box: frameData.BoxData[timeline.ObjectId] = info; break; } }