static void DoImport(DefaultAsset[] assets) { foreach (var asset in assets) { var settings = ImportSettingsReference.LoadImportSettings(asset); if (!settings) { CreateSettingsThenImport(assets); return; } } foreach (var asset in assets) { var reference = ImportSettingsReference.LoadImportSettings(asset); if (reference) { ASEImporter.Import(asset, reference.settings); } else { Debug.LogWarning("File " + asset.name + " has empty import settings, it is ignored."); } } }
static void DoImport(DefaultAsset[] assets) { foreach (var asset in assets) { var settingsPath = GetImportSettingsPath(asset); var reference = (ImportSettingsReference)AssetDatabase.LoadAssetAtPath(settingsPath, typeof(ImportSettingsReference)); if (!reference) { CreateSettingsThenImport(assets); return; } } foreach (var asset in assets) { var settingsPath = GetImportSettingsPath(asset); var reference = (ImportSettingsReference)AssetDatabase.LoadAssetAtPath(settingsPath, typeof(ImportSettingsReference)); if (reference.settings) { ASEImporter.Import(asset, reference.settings); } else { Debug.LogWarning("File " + asset.name + " has empty import settings, it is ignored."); } } }
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); }
static void CreateSettingsThenImport(DefaultAsset[] assets) { var size = new Vector2(Screen.width, Screen.height); var rect = new Rect(size.x / 2, size.y / 2, 250, 200); var window = (CreateSettingsWindow) EditorWindow.CreateInstance(typeof(CreateSettingsWindow)); window.position = rect; var paths = assets.Select(it => GetImportSettingsPath(it)).ToList(); window._Init(paths, settings => { foreach (var asset in assets) { ASEImporter.Import(asset, settings); } }); window.ShowPopup(); }
private static void CompleteAutoImports() { EditorApplication.update = Delegate.Remove(EditorApplication.update, _importDelegate as EditorApplication.CallbackFunction) as EditorApplication.CallbackFunction; AssetDatabase.Refresh(); ASEImporter.Refresh(); foreach (var path in _autoImports) { var asset = AssetDatabase.LoadAssetAtPath <DefaultAsset>(path); var reference = ImportSettingsReference.LoadImportSettings(asset); if (reference?.settings && reference.settings.automaticReimport) { ASEImporter.Import(asset, reference.settings); } } _autoImports.Clear(); }
private static void CreateMetaDataThenImport(DefaultAsset[] assets) { var size = new Vector2(Screen.width, Screen.height); var rect = new Rect(size.x / 2, size.y / 2, 250, 200); var window = ScriptableObject.CreateInstance <CreateSettingsWindow>(); window.position = rect; var paths = assets.Select(AssetDatabase.GetAssetPath).ToList(); window._Init(paths, settings => { foreach (var asset in assets) { ASEImporter.Import(asset, settings); } }); window.ShowPopup(); }
private static void DoImport(DefaultAsset[] assets) { foreach (var asset in assets) { var metaData = GetMetaData(asset); if (metaData == null) { CreateMetaDataThenImport(assets); return; } var guid = metaData.metaSpriteSettingsGuid; var settings = AssetDatabase.LoadAssetAtPath <ImportSettings>(AssetDatabase.GUIDToAssetPath(guid)); if (settings != null) { ASEImporter.Import(asset, settings); return; } Debug.LogWarning("File " + asset.name + " has empty import metaSpriteImporterSettings, it is ignored."); } }
static void MenuClicked() { ASEImporter.Refresh(); DoImport(GetSelectedAseprites()); }
public static AsepriteAnimation New(string path, string initTag) { return(ASEImporter.Import(path, initTag)); }
public override void Process(ImportContext ctx, Layer layer) { var animPath = layer.group.path; var frames = new Dictionary <int, Vector2>(); var file = ctx.file; //Change this layer sprites pivot var processor = ASEImporter.getProcessor("pivot"); processor?.Process(ctx, layer); //Read data from cel for (var i = 0; i < file.frames.Count; ++i) { var center = Vector2.zero; var pixelCount = 0; file.frames[i].cels.TryGetValue(layer.layerIndex, out var cel); if (cel == null) { continue; } for (var y = 0; y < cel.height; ++y) { for (var x = 0; x < cel.width; ++x) { var texX = cel.x + x; var texY = -(cel.y + y) + file.height - 1; var col = cel.GetPixelRaw(x, y); if (col.a > 0.1f) { center += new Vector2(texX, texY); pixelCount++; } } } if (pixelCount > 0) { center /= pixelCount; var pivot = Vector2.Scale(ctx.settings.pivotRelativePos, new Vector2(file.width, file.height)); var posWorld = (center - pivot) / ctx.settings.ppu; frames.Add(i, posWorld); } } //Change animation clips foreach (var frameTag in file.frameTags) { var clip = ctx.generatedClips[frameTag]; AnimationCurve curveX = new AnimationCurve(), curveY = new AnimationCurve(); float t = 0; var firstFramePos = frames[frameTag.from]; for (var f = frameTag.from; f <= frameTag.to; ++f) { if (frames.ContainsKey(f)) { var pos = frames[f]; var currentGroup = layer.group.parent; while (currentGroup != null) { var path = currentGroup.path; var bindings = AnimationUtility.GetCurveBindings(clip); var xb = bindings.Where(it => it.path == path && it.propertyName == "m_LocalPosition.x") .ToList(); var yb = bindings.Where(it => it.path == path && it.propertyName == "m_LocalPosition.y") .ToList(); if (!(xb.IsNullOrEmpty() || yb.IsNullOrEmpty())) { var x = AnimationUtility.GetEditorCurve(clip, xb[0]).keys .First(it => Mathf.Approximately(it.time, t)).value; var y = AnimationUtility.GetEditorCurve(clip, yb[0]).keys .First(it => Mathf.Approximately(it.time, t)).value; pos -= new Vector2(x, y); } currentGroup = currentGroup.parent; } if (f == frameTag.from) { firstFramePos = pos; } curveX.AddKey(t, pos.x); curveY.AddKey(t, pos.y); } t += file.frames[f].duration * 1e-3f; } //Completing the end frame for the loop //t -= 1.0f / clip.frameRate; curveX.AddKey(t, firstFramePos.x); curveY.AddKey(t, firstFramePos.y); if (curveX.length <= 0) { continue; } MakeConstant(curveX); MakeConstant(curveY); EditorCurveBinding bindingX = new EditorCurveBinding { path = animPath, type = typeof(Transform), propertyName = "m_LocalPosition.x" }, bindingY = new EditorCurveBinding { path = animPath, type = typeof(Transform), propertyName = "m_LocalPosition.y" }; AnimationUtility.SetEditorCurve(clip, bindingX, curveX); AnimationUtility.SetEditorCurve(clip, bindingY, curveY); EditorUtility.SetDirty(clip); } if (ctx.settings.generatePrefab) { var layerTransform = ctx.name2GameObject[layer.group.name].transform; var position = frames[0]; var transform = layerTransform.parent; while (transform.gameObject != ctx.rootGameObject) { position -= (Vector2)transform.localPosition; transform = transform.parent; } layerTransform.transform.localPosition = position; } }