1
Support / Re: Create Sprite Animation With Code
« on: April 30, 2014, 02:35:52 am »
OK, I understand ,thanks you !
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
[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,