-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLottieAssetImporter.cs
62 lines (54 loc) · 1.88 KB
/
LottieAssetImporter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.AssetImporters;
#endif
/*
This imports anything with a .lottie extension as a custom asset type.
This isn't required by the UIToolkit element, but this does mean we can
treat this asset as a custom type, which then means we can do custom previews
in the inspector
*/
// gr: this MUST be named the same as the filename
#if UNITY_EDITOR
[ScriptedImporter(1, "lottie")]
public class LottieAssetImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
var Json = System.IO.File.ReadAllText(ctx.assetPath);
//var Animation = new PopLottie.Animation(Json);
var animationContainer = ScriptableObject.CreateInstance<LottieAsset>();
//animationContainer.Animation = Animation;
animationContainer.Json = Json;
// cache the parsed animation to the asset
ctx.AddObjectToAsset("PopLottie_Animation", animationContainer);
ctx.SetMainObject(animationContainer);
}
}
#endif
/*
#if UNITY_EDITOR
[CustomEditor(typeof(LottieImporter))]
public class ExampleEditor : UnityEditor.AssetImporters.ScriptedImporterEditor
{
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
{
Debug.Log($"RenderStaticPreview {assetPath}");
return Texture2D.redTexture;
}
}
#endif
*/
#if UNITY_EDITOR
[CustomEditor(typeof(LottieAssetImporter))]
//public class LottieAssetImporterEditor : Editor//UnityEditor.AssetImporters.ScriptedImporterEditor
public class LottieAssetImporterEditor : UnityEditor.AssetImporters.ScriptedImporterEditor
{
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
{
Debug.Log($"RenderStaticPreview {assetPath}");
return Texture2D.redTexture;
}
}
#endif