public static Sprite FromJsonElement(SpriteJson spriteBoxJson) { if (spriteBoxJson == null) { return(null); } Sprite sprBox = new Sprite(new Vector2((float)spriteBoxJson.posX, (float)spriteBoxJson.posY), spriteBoxJson.width, spriteBoxJson.height, spriteBoxJson.rotation, spriteBoxJson.textureKey, spriteBoxJson.layer, new Rectangle(spriteBoxJson.sourceX, spriteBoxJson.sourceY, spriteBoxJson.sourceWidth, spriteBoxJson.sourceHeight), null); sprBox.SetVisible(spriteBoxJson.visible); return(sprBox); }
public virtual void SetUpSheet() { Infos = new SpriteData(); Infos.List = new List <List <List <SpriteInfo> > >(); for (int i = 0; i < spriteList.Count; i++) { Infos.List.Add(new List <List <SpriteInfo> >()); var path = AssetDatabase.GetAssetPath(spriteList[i]) .Substring(17); //Substring(17) To remove the "Assets/Resources/" Sprite[] spriteSheetSprites = Resources.LoadAll <Sprite>(path.Remove(path.Length - 4)); if (spriteSheetSprites.Length > 1) { var p = AssetDatabase.GetAssetPath(spriteList[i]); int extensionIndex = p.LastIndexOf("."); p = p.Substring(0, extensionIndex) + ".json"; string json = System.IO.File.ReadAllText(p); Logger.Log(json.ToString()); spriteJson = JsonConvert.DeserializeObject <SpriteJson>(json); int c = 0; int cone = 0; for (int J = 0; J < spriteJson.Number_Of_Variants; J++) { Infos.List[i].Add(new List <SpriteInfo>()); } foreach (var SP in spriteSheetSprites) { var info = new SpriteInfo(); info.sprite = SP; if (spriteJson.Delays.Count > 0) { info.waitTime = spriteJson.Delays[c][cone]; } Infos.List[i][c].Add(info); if (c >= (spriteJson.Number_Of_Variants - 1)) { c = 0; cone++; } else { c++; } } } else { var info = new SpriteInfo() { sprite = spriteSheetSprites[0], waitTime = 0 }; Infos.List[i].Add(new List <SpriteInfo>()); Infos.List[i][0].Add(info); } } Infos.SerializeT(); var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { EditorSceneManager.MarkSceneDirty(prefabStage.scene); Logger.Log("Setup Complete", Category.SpriteHandler); } }