public static void CreateAnimation() { SpriteAnimation asset = SpriteAnimation.CreateInstance <SpriteAnimation>(); AssetDatabase.CreateAsset(asset, "Assets/Animations/New Animation.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
static void CreateAnimationAsset() { SpriteAnimation a = SpriteAnimation.CreateInstance <SpriteAnimation>(); string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (path == "") { path = "Assets"; } else if (System.IO.Path.GetExtension(path) != "") { path = path.Replace(System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); } AssetDatabase.CreateAsset(a, AssetDatabase.GenerateUniqueAssetPath(path + "/SpriteAnimation.asset")); }
//-------------------------- public void AddAnimation(string p_name, int[] p_frames, float time = 1.0f, bool p_looping = true) { if (_animations.ContainsKey(p_name)) { return; } SpriteAnimation anim = SpriteAnimation.CreateInstance <SpriteAnimation>(); anim.wrapMode = WrapMode.Loop; anim.name = p_name; anim.duration = time; anim.startFrame = p_frames[0]; anim.endFrame = p_frames[p_frames.Length - 1]; _animations.Add(anim.name, anim); _animationsInternals.Add(anim); }