Ejemplo n.º 1
0
 void DrawGUIControls()
 {
     SwfEditorUtils.DoHorizontalGUI(() => {
         if (GUILayout.Button("Create prefab"))
         {
             CreateAllClipsPrefabs();
         }
         if (GUILayout.Button("Instance to scene"))
         {
             CreateAllClipsOnScene();
         }
     });
 }
Ejemplo n.º 2
0
        private void DrawGUICreateClips()
        {
            SwfEditorUtils.DoHorizontalGUI(() => {
                if (GUILayout.Button("Create/Update All AnimationClips from sequences"))
                {
                    SwfClipAsset clip;
                    List <SwfClipAsset.Sequence> allSequences;
                    SwfClipAsset.Sequence sequence;
                    List <AnimationClip> allAnimationClips = new List <AnimationClip>();
                    AnimationClip animationClip;
                    int frameCount;
                    string sequenceName;
                    float frameRate;
                    AnimationEvent animationEvent;
                    AnimationEvent[] allAnimationEvents;
                    float timePerSprite;
                    string animFolder;
                    string animPath;

                    for (int i = _clips.Count - 1; i > -1; i--)
                    {
                        clip         = _clips[i];
                        frameRate    = clip.FrameRate;
                        allSequences = clip.Sequences;
                        animFolder   = Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip)) + "/";

                        for (int j = allSequences.Count - 1; j > -1; j--)
                        {
                            sequence     = allSequences[j];
                            frameCount   = sequence.Frames.Count;
                            sequenceName = sequence.Name;

                            animPath = animFolder + sequenceName + ".anim";

                            allAnimationEvents = new AnimationEvent[frameCount];

                            animationClip = GetAnimationClipAt(animPath);

                            EditorUtility.SetDirty(animationClip);

                            animationClip.frameRate = frameRate;

                            timePerSprite = 1f / frameRate;

                            animationEvent = new AnimationEvent();
                            animationEvent.stringParameter = sequenceName;
                            animationEvent.time            = 0;
                            animationEvent.functionName    = "set_sequence";
                            allAnimationEvents[0]          = animationEvent;

                            for (int k = 1; k < frameCount; k++)
                            {
                                animationEvent = new AnimationEvent();
                                animationEvent.intParameter = k;
                                animationEvent.time         = timePerSprite * k;
                                animationEvent.functionName = "GotoAndStop";
                                allAnimationEvents[k]       = animationEvent;
                            }

                            AnimationUtility.SetAnimationEvents(animationClip, allAnimationEvents);
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                        }
                    }
                }
            });
        }