2D Toolkit Forum
2D Toolkit => Support => Topic started by: zhaoqingqing on April 29, 2014, 09:52:59 am
-
Hello Unikron,Our team is doing packed images and Use scripts to automate generate sprite Animation script but not success
Here is my script
[MenuItem("Game/AutoCreate Sprite Animation")]
public static void CreateSpriteAnimaTest()
{
//sprite animation
string animaSpPath = "Assets/Actor/ActorAnimation.prefab";
tk2dSpriteAnimation newSpriteAnimation = null;//
if (animaSpPath.Length != 0)
{
GameObject go = new GameObject();
newSpriteAnimation = go.AddComponent<tk2dSpriteAnimation>();
tk2dEditorUtility.SetGameObjectActive(go, false);
UnityEngine.Object p = PrefabUtility.CreateEmptyPrefab(animaSpPath);
PrefabUtility.ReplacePrefab(go, p, ReplacePrefabOptions.ConnectToPrefab);
//GameObject.DestroyImmediate(go);
tk2dEditorUtility.GetOrCreateIndex().AddSpriteAnimation(AssetDatabase.LoadAssetAtPath(animaSpPath, typeof(tk2dSpriteAnimation)) as tk2dSpriteAnimation);
tk2dEditorUtility.CommitIndex();
//AnimationEditorPopup
tk2dSpriteAnimationEditorPopup editor = EditorWindow.GetWindow(typeof(tk2dSpriteAnimationEditorPopup), false, "Sprite Animation") as tk2dSpriteAnimationEditorPopup;
editor.CreateNewClip();
CBase.Log("new clip");
editor.SetSpriteAnimation(newSpriteAnimation);
//AutoFillFrames.
editor.Commit();
editor.Close();
}
}
However, the script did not like my expectations, it also creates SpriteAnimation, but SpriteAnimation is empty, Does not contain any NewClip,
ask for help
-
Hi you shouldn't use the editor to create animations - once you create the newSpriteAnimation object, you can simply fill in the contents directly. I've attached an example to this thread - you will need to register your copy of 2D Toolkit (http://2dtoolkit.com/forum/index.php?index.php/topic,34.0.html) to download attachments.
-
OK, I understand ,thanks you !