public static void Import(DefaultAsset defaultAsset, ImportSettings settings) { var path = AssetDatabase.GetAssetPath(defaultAsset); var context = new ImportContext { // file = file, settings = settings, fileDirectory = Path.GetDirectoryName(path), fileName = Path.GetFileName(path), fileNameNoExt = Path.GetFileNameWithoutExtension(path) }; ImportStage(context, Stage.LoadFile); context.file = ASEParser.Parse(File.ReadAllBytes(path)); context.atlasPath = Path.Combine(settings.atlasOutputDirectory, context.fileNameNoExt + ".png"); if (settings.controllerPolicy == AnimControllerOutputPolicy.CreateOrOverride) { context.animControllerPath = settings.animControllerOutputPath + "/" + settings.baseName + ".controller"; } context.animClipDirectory = settings.clipOutputDirectory; // Create paths in advance Directory.CreateDirectory(settings.atlasOutputDirectory); Directory.CreateDirectory(context.animClipDirectory); if (context.animControllerPath != null) { Directory.CreateDirectory(Path.GetDirectoryName(context.animControllerPath)); } // ImportStage(context, Stage.GenerateAtlas); AtlasGenerator.GenerateAtlas(context); ImportStage(context, Stage.GenerateClips); GenerateAnimClips(context); ImportStage(context, Stage.GenerateController); GenerateAnimController(context); ImportStage(context, Stage.InvokeMetaLayerProcessor); context.file.layers .Where(layer => layer.type == LayerType.Meta) .ToList() .ForEach(layer => { MetaLayerProcessor processor; layerProcessors.TryGetValue(layer.actionName, out processor); if (processor == null) { Debug.LogWarning(string.Format("No processor for meta layer {0}", layer.layerName)); } else { processor.Process(context, layer); } }); ImportEnd(context); }
public ResourceManager(GraphicsDevice graphics, IStorageSystem storageSystem, IOptionsProvider options) { Storage = storageSystem; Graphics = graphics; Atlas = new AtlasGenerator(Graphics); Options = options; }
public ResourceManager(IServiceProvider serviceProvider) { Atlas = new AtlasGenerator(); Storage = serviceProvider.GetService <IStorageSystem>(); Options = serviceProvider.GetService <IOptionsProvider>(); RegistryManager = serviceProvider.GetService <IRegistryManager>(); Alex = serviceProvider.GetService <Alex>(); ContentManager = serviceProvider.GetService <ContentManager>(); AssetsUtil = new MCJavaAssetsUtil(Storage); //ContentManager.Load<byte[]>(); }
static void CreateTextureAtlas() { var srcFolder = EditorUtility.OpenFolderPanel("Select Source Images Folder", "", ""); var destFolder = EditorUtility.SaveFolderPanel("Select Location for Atlas", "", ""); if(srcFolder.Contains("Assets") != true && destFolder.Contains ("Assets") != true) { Debug.LogError("Both source and destination folders must be in the project hierarchy"); return; } var generator = new AtlasGenerator(srcFolder, destFolder); generator.ProcessAndSave(); }
public override void Process(ImportContext context, Layer layer) { string subImageName = layer.GetParamString(0); string targetChildObject = layer.GetParamString(1); List<Layer> layers; context.subImageLayers.TryGetValue(subImageName, out layers); var sprites = AtlasGenerator.GenerateAtlas(context, layers, Path.GetDirectoryName(context.atlasPath) + "/" + context.fileNameNoExt + "_" + subImageName + ".png"); ASEImporter.GenerateClipImageLayer(context, targetChildObject, sprites); }
public static Texture2D[] SetupTextures(Object[] objects) { //converte a lista de objetos e configura List <Texture2D> textures = new List <Texture2D>(); for (int i = 0; i < objects.Length; i++) { Texture2D tex = objects[i] as Texture2D; if (!tex.name.Contains("atlas")) { textures.Add(AtlasGenerator.SetupTexture(tex)); } } return(textures.ToArray()); }
static void OnPostprocessAllAssets(string[] imported, string[] deleted, string[] moved, string[] movedFrom) { List<string> changed = new List<string>(); changed.AddRange(imported); changed.AddRange(deleted); changed.AddRange(moved); changed.AddRange(movedFrom); TextureAtlasInfo[] atlases = GameObject.FindObjectsOfTypeIncludingAssets(typeof(TextureAtlasInfo)) as TextureAtlasInfo[]; foreach(TextureAtlasInfo tai in atlases) { if(tai.Overlaps(changed)) { Debug.Log("Updating atlas for: " + tai.srcDirectory); AtlasGenerator ag = new AtlasGenerator(); ag.Regenerate(tai); ag.RefreshDependentObjects(tai); } } }
public static void Import(DefaultAsset defaultAsset, ImportSettings settings) { var path = AssetDatabase.GetAssetPath(defaultAsset); var context = new ImportContext { // file = file, settings = settings, fileDirectory = Path.GetDirectoryName(path), fileName = Path.GetFileName(path), fileNameNoExt = Path.GetFileNameWithoutExtension(path) }; try { ImportStage(context, Stage.LoadFile); context.file = ASEParser.Parse(File.ReadAllBytes(path)); if (settings.controllerPolicy != AnimControllerOutputPolicy.Skip) { context.animControllerPath = settings.animControllerOutputPath + "/" + context.fileNameNoExt + ".controller"; } context.animClipDirectory = settings.clipOutputDirectory; context.prefabDirectory = Path.Combine(settings.prefabsDirectory, context.fileNameNoExt + "_Origin.prefab"); // Create paths in advance Directory.CreateDirectory(settings.atlasOutputDirectory); Directory.CreateDirectory(context.animClipDirectory); if (context.animControllerPath != null) { Directory.CreateDirectory(Path.GetDirectoryName(context.animControllerPath)); } if (settings.generatePrefab) { Directory.CreateDirectory(settings.prefabsDirectory); } ImportStage(context, Stage.GenerateAtlas); foreach (var group in context.file.name2Group.Values) { if (group.contentLayers.Count == 0) { continue; } string atlasPath = Path.Combine(settings.atlasOutputDirectory, context.fileNameNoExt + "_" + group.name + ".png"); var sprites = AtlasGenerator.GenerateAtlas(context, group.contentLayers, atlasPath); context.mapSprite.Add(group.name, sprites); } ImportStage(context, Stage.GenerateClips); GenerateAnimClips(context); ImportStage(context, Stage.GenerateController); GenerateAnimController(context); ImportStage(context, Stage.GeneratePrefab); GeneratePrefab(context); ImportStage(context, Stage.InvokeMetaLayerProcessor); MetaProcess(context); } catch (Exception e) { Debug.LogException(e); EditorUtility.ClearProgressBar(); } ImportEnd(context); }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="initTagName">null for random tag</param> /// <returns></returns> public static AsepriteAnimation Import(string path, string initTagName) { var context = new ImportContext { // file = file, fileDirectory = Path.GetDirectoryName(path), fileName = Path.GetFileName(path), fileNameNoExt = Path.GetFileNameWithoutExtension(path) }; // parse file context.file = ASEParser.Parse(System.IO.File.ReadAllBytes(path)); // gen default tag for no tag file GenerateFrameTagForNoTagFile(context); // generate sprite context.generatedSprites = AtlasGenerator.GenerateAtlas(context, context.file.layers.Where(it => it.type == LayerType.Content).ToList()); // generate animation clips GenerateAnimClips(context); // process other ... context.file.layers .Where(layer => layer.type == LayerType.Meta) .Select(layer => { MetaLayerProcessor processor; layerProcessors.TryGetValue(layer.actionName, out processor); return(new LayerAndProcessor { layer = layer, processor = processor }); }) .OrderBy(it => it.processor != null ? it.processor.executionOrder : 0) .ToList() .ForEach(it => { var layer = it.layer; var processor = it.processor; if (processor != null) { processor.Process(context, layer); } else { Log.Warnning($"No processor for meta layer {layer.layerName} \t {path}"); } }); Dictionary <string, AnimationClip> dict = new Dictionary <string, AnimationClip>(); foreach (var kv in context.generatedClips) { dict[kv.Key.name] = kv.Value; } Dictionary <string, AnimationClip> revsrse_dict = new Dictionary <string, AnimationClip>(); foreach (var kv in context.generatedReversedClips) { revsrse_dict[kv.Key.name] = kv.Value; } if (initTagName == null) { initTagName = dict.Keys.FirstOrDefault(); } return(new AsepriteAnimation(dict, revsrse_dict, context.file.width, context.file.height, initTagName)); }
//生成动画 static void GenerateAnimation(string name, GifFile gif, string path, ref AnimationInfo info) { AnimationClip clip = new AnimationClip(); clip.name = name; clip.frameRate = 25; //创建动画文件 string asset = string.Format("{0}/{1}.anim", path, name); AssetDatabase.CreateAsset(clip, asset); SpriteImportData[] spriteImportData = new SpriteImportData[0]; Texture2D atlas = AtlasGenerator.GenerateAtlas(gif, out spriteImportData); atlas.filterMode = FilterMode.Point; atlas.name = name; //AssetDatabase.AddObjectToAsset(atlas, clip); byte[] pngBytes = atlas.EncodeToPNG(); string atlasPath = string.Format("{0}/{1}.png", path, name); File.WriteAllBytes(atlasPath, pngBytes); AssetDatabase.Refresh(); //生成的贴图 Texture2D atlasObject = (Texture2D)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(Texture2D)); atlasObject.filterMode = FilterMode.Point; //生成贴图 List <Sprite> sprites = GenerateSprites(atlasObject, spriteImportData, clip); //帧数 int length = sprites.Count; EditorCurveBinding spriteBinding = new EditorCurveBinding(); spriteBinding.type = typeof(SpriteRenderer); spriteBinding.path = ""; spriteBinding.propertyName = "m_Sprite"; //设置帧信息 ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[length + 1]; float time = 0; for (int i = 0; i < length; i++) { ObjectReferenceKeyframe frame = new ObjectReferenceKeyframe(); frame.time = time; frame.value = sprites[i]; time += gif.textureList[i].m_delaySec; spriteKeyFrames[i] = frame; } //单独设置最后一帧 float frameTime = 1f / clip.frameRate; ObjectReferenceKeyframe lastFrame = new ObjectReferenceKeyframe(); lastFrame.time = time - frameTime; lastFrame.value = sprites[length - 1]; spriteKeyFrames[spriteKeyFrames.Length - 1] = lastFrame; AnimationUtility.SetObjectReferenceCurve(clip, spriteBinding, spriteKeyFrames); //循环设置 AnimationClipSettings settings = AnimationUtility.GetAnimationClipSettings(clip); //循环设置 //if (animationSetting.loop) { // settings.loopTime = true; // clip.wrapMode = WrapMode.Loop; //} else { // settings.loopTime = false; // clip.wrapMode = WrapMode.Once; //} AnimationUtility.SetAnimationClipSettings(clip, settings); info.animationClip = clip; info.texture = atlasObject; }
public static void Import(string path, ImportSettings settings) { // var path = AssetDatabase.GetAssetPath(defaultAsset); var context = new ImportContext { // file = file, settings = settings, fileDirectory = Path.GetDirectoryName(path), fileName = Path.GetFileName(path), fileNameNoExt = Path.GetFileNameWithoutExtension(path) }; try { ImportStage(context, Stage.LoadFile); context.file = ASEParser.Parse(File.ReadAllBytes(path)); context.atlasPath = Path.Combine(settings.atlasOutputDirectory, context.fileNameNoExt + ".png"); if (settings.controllerPolicy == AnimControllerOutputPolicy.CreateOrOverride) { context.animControllerPath = settings.animControllerOutputPath + "/" + settings.baseName + ".controller"; } context.animClipDirectory = settings.clipOutputDirectory; // Create paths in advance Directory.CreateDirectory(settings.atlasOutputDirectory); Directory.CreateDirectory(context.animClipDirectory); if (context.animControllerPath != null) { Directory.CreateDirectory(Path.GetDirectoryName(context.animControllerPath)); } // ImportStage(context, Stage.GenerateAtlas); context.generatedSprites = AtlasGenerator.GenerateAtlas(context, context.file.layers.Where(it => it.type == LayerType.Content).ToList(), context.atlasPath); ImportStage(context, Stage.GenerateClips); GenerateAnimClips(context); ImportStage(context, Stage.GenerateController); GenerateAnimController(context); ImportStage(context, Stage.InvokeMetaLayerProcessor); context.file.layers .Where(layer => layer.type == LayerType.Meta) .Select(layer => { MetaLayerProcessor processor; layerProcessors.TryGetValue(layer.actionName, out processor); return(new LayerAndProcessor { layer = layer, processor = processor }); }) .OrderBy(it => it.processor != null ? it.processor.executionOrder : 0) .ToList() .ForEach(it => { var layer = it.layer; var processor = it.processor; if (processor != null) { processor.Process(context, layer); } else { Debug.LogWarning(string.Format("No processor for meta layer {0}", layer.layerName)); } }); } catch (Exception e) { Debug.LogException(e); } ImportEnd(context); }
public static void Import(DefaultAsset defaultAsset, ImportSettings settings) { var path = AssetDatabase.GetAssetPath(defaultAsset); var context = new ImportContext { // file = file, settings = settings, fileDirectory = Path.GetDirectoryName(path), fileName = Path.GetFileName(path), fileNameNoExt = Path.GetFileNameWithoutExtension(path), animData = ScriptableObject.CreateInstance <AnimData>(), }; try { // context.animData.data = new Dictionary<string, Dictionary<string, List<FrameData>>>(); ImportStage(context, Stage.LoadFile); context.file = ASEParser.Parse(File.ReadAllBytes(path)); context.atlasPath = Path.Combine(settings.atlasOutputDirectory, context.fileNameNoExt + ".png"); if (settings.controllerPolicy == AnimControllerOutputPolicy.CreateOrOverride) { context.animControllerPath = settings.animControllerOutputPath + "/" + settings.baseName + ".controller"; } context.animClipDirectory = settings.clipOutputDirectory; context.animDataDirectory = settings.dataOutputDirectory; // Create paths in advance Directory.CreateDirectory(settings.atlasOutputDirectory); Directory.CreateDirectory(context.animClipDirectory); Directory.CreateDirectory(context.animDataDirectory); if (context.animControllerPath != null) { Directory.CreateDirectory(Path.GetDirectoryName(context.animControllerPath)); } ImportStage(context, Stage.GenerateAtlas); context.generatedSprites = AtlasGenerator.GenerateAtlas(context, context.file.layers.Where(it => it.type == LayerType.Content).ToList(), context.atlasPath); ImportStage(context, Stage.GenerateClips); GenerateAnimClips(context); ImportStage(context, Stage.GenerateController); GenerateAnimController(context); ImportStage(context, Stage.InvokeMetaLayerProcessor); context.file.layers .Where(layer => layer.type == LayerType.Meta) .Select(layer => { MetaLayerProcessor processor; layerProcessors.TryGetValue(layer.actionName, out processor); return(new LayerAndProcessor { layer = layer, processor = processor }); }) .OrderBy(it => it.processor != null ? it.processor.executionOrder : 0) .ToList() .ForEach(it => { var layer = it.layer; var processor = it.processor; if (processor != null) { processor.Process(context, layer); } else { Debug.LogWarning(string.Format("No processor for meta layer {0}", layer.layerName)); } }); // calc num frames for each animation, save to animData foreach (var tag in context.file.frameTags) { string animName = tag.name; int numFrames = tag.to - tag.from + 1; if (context.animData.animDict.ContainsKey(animName)) { context.animData.animDict[animName].numFrames = numFrames; } else { context.animData.animDict.Add(animName, new AnimList { numFrames = numFrames, frameDict = new FrameDictionary(), }); } } // save each frame's pivot and dimensions in animData foreach (var tag in context.file.frameTags) { string animName = tag.name; var pivotDataList = new FrameDataList { frames = new List <FrameData>() }; var dimsDataList = new FrameDataList { frames = new List <FrameData>() }; for (int i = tag.from, j = 0; i <= tag.to; i++, j++) { pivotDataList.frames.Add(new FrameData { frame = j, coords = new List <Vector2> { context.spritePivots[i] } }); dimsDataList.frames.Add(new FrameData { frame = j, coords = new List <Vector2> { context.spriteDimensions[i] } }); } context.animData.animDict[animName].frameDict.Add("pivot", pivotDataList); context.animData.animDict[animName].frameDict.Add("dims", dimsDataList); } /* * var importer = AssetImporter.GetAtPath(context.atlasPath) as TextureImporter; * var spriteSheet = importer.spritesheet; * Debug.Log("== SPRITESHEET =="); * Debug.Log($"{spriteSheet[0].rect}"); * Debug.Log($"{spriteSheet[0].pivot}"); * Debug.Log(ObjectDumper.Dump(context.spriteDimensions)); * Debug.Log(ObjectDumper.Dump(context.spritePivots)); */ ImportStage(context, Stage.SaveAnimData); var filePath = context.animDataDirectory + "/" + context.settings.baseName + " data.asset"; AnimData asset = (AnimData)AssetDatabase.LoadAssetAtPath(filePath, typeof(AnimData)); if (!asset) { asset = ScriptableObject.CreateInstance <AnimData>(); asset = context.animData; asset.ppu = context.settings.ppu; asset.pixelOrigin = context.settings.pixelOrigin.ToString(); AssetDatabase.CreateAsset(asset, filePath); } else { asset.ppu = context.settings.ppu; asset.pixelOrigin = context.settings.pixelOrigin.ToString(); // merge any new animations with old (and overwrite matching old) foreach (KeyValuePair <string, AnimList> item in context.animData.animDict) { asset.animDict[item.Key] = item.Value; } EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); } } catch (Exception e) { Debug.LogException(e); } ImportEnd(context); }
private void AseShow() { EditorGUI.BeginChangeCheck(); using (new GUILayout.HorizontalScope(EditorStyles.toolbar)) { GUILayout.Label("Options"); } _settings.baseName = EditorGUILayout.TextField("Base Name", _settings.baseName); _settings.spriteTarget = EditorGUILayout.TextField("Target Child Object", _settings.spriteTarget); EditorGUILayout.Space(); _settings.ppu = EditorGUILayout.IntField("Pixel Per Unit", _settings.ppu); _settings.alignment = (SpriteAlignment)EditorGUILayout.EnumPopup("Default Align", _settings.alignment); if (_settings.alignment == SpriteAlignment.Custom) { _settings.customPivot = EditorGUILayout.Vector2Field("Custom Pivot", _settings.customPivot); } _settings.densePacked = EditorGUILayout.Toggle("Dense Pack", _settings.densePacked); _settings.border = EditorGUILayout.IntField("Border", _settings.border); EditorGUILayout.Space(); using (new GUILayout.HorizontalScope(EditorStyles.toolbar)) { GUILayout.Label("Output"); } _settings.atlasOutputDirectory = PathSelection("Atlas Directory", _settings.atlasOutputDirectory); _settings.clipOutputDirectory = PathSelection("Anim Clip Directory", _settings.clipOutputDirectory); _settings.controllerPolicy = (AnimControllerOutputPolicy)EditorGUILayout.EnumPopup("Anim Controller Policy", _settings.controllerPolicy); if (_settings.controllerPolicy == AnimControllerOutputPolicy.CreateOrOverride) { _settings.animControllerOutputPath = PathSelection("Anim Controller Directory", _settings.animControllerOutputPath); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(_settings); } if (GUILayout.Button("Gen")) { var path = AssetDatabase.GetAssetPath(Selection.activeObject); // ASEImporter.Import(path, _settings); var context = new ImportContext { settings = _settings, fileDirectory = Path.GetDirectoryName(path), fileName = Path.GetFileName(path), fileNameNoExt = Path.GetFileNameWithoutExtension(path) }; context.file = ASEParser.Parse(File.ReadAllBytes(path)); context.atlasPath = Path.Combine(_settings.atlasOutputDirectory, context.fileNameNoExt + ".png"); context.animClipDirectory = _settings.clipOutputDirectory; if (_settings.controllerPolicy == AnimControllerOutputPolicy.CreateOrOverride) { context.animControllerPath = _settings.animControllerOutputPath + "/" + _settings.baseName + ".controller"; } Directory.CreateDirectory(_settings.atlasOutputDirectory); Directory.CreateDirectory(_settings.clipOutputDirectory); if (context.animControllerPath != null) { Directory.CreateDirectory(_settings.animControllerOutputPath); } context.generatedSprites = AtlasGenerator.GenerateAtlas(context, context.file.layers.Where(it => it.type == LayerType.Content).ToList(), context.atlasPath); CreateClips(context); } }