关于unity3d播放flash动画,使用插件uniswf

主要就是代码了。

1.using UnityEngine;

using System.Collections;

using pumpkin.swf;

using System.Collections.Generic;

using pumpkin.events;

using pumpkin.display;



public class MovieClipX : MovieClip

{





    public delegate void FrameCallback();

    public Dictionary<int, FrameCallback> FrameEvents = null;



        public MovieClipX(SwfURI uri) : base(uri)

        {

            

        }



        public MovieClipX(string linkage)

            : base(linkage)

        {

            

        }

   

    public bool  addFrameScript(string label, FrameCallback onFrameCallback)

    {

        if (string.IsNullOrEmpty(label))

            return false;





        

         int index = this.getFrameLabel(label);

       //  Debug.Log("index " + getCurrentFrame());

         if (index <= 0)

             return false;





         if (FrameEvents == null)

         {

             FrameEvents = new Dictionary<int, FrameCallback>();

         }





         if (!FrameEvents.ContainsKey(index))

         {

             FrameEvents.Add(index, onFrameCallback);

         }

         else

         {

             FrameEvents.Remove(index);

             if (onFrameCallback != null)

             {

                 FrameEvents.Add(index, onFrameCallback);

             }  

         }



         return true;

       

    }



    public bool addFrameScript(int frame, FrameCallback onFrameCallback)

    {

       

       

       

        if (FrameEvents == null)

        {

            FrameEvents = new Dictionary<int, FrameCallback>();

        }



        if (!FrameEvents.ContainsKey(frame))

        {

            FrameEvents.Add(frame, onFrameCallback);

        }

        else

        {

            FrameEvents.Remove(frame);

            if (onFrameCallback != null)

            {

                FrameEvents.Add(frame, onFrameCallback);

            }

        }





        return true;





    }





    public bool  setEndScript(FrameCallback onFrameCallback)

    {

        int index = this.getTotalFrames();

        if (index <= 0)

         return false;

        

        return addFrameScript(index,   onFrameCallback);





    }



    public override void updateFrame(CEvent e)

    {

       

        if (FrameEvents != null)

        {

            int index = this.getCurrentFrame();

            if (FrameEvents.ContainsKey(index))

            {

                FrameCallback b = FrameEvents[index];

                if (b != null)

                {

                    b();

                }

            }

        }

      

        base.updateFrame(e);

    }

}

2.using UnityEngine;

using System.Collections;

using System.Collections.Generic;

using pumpkin.display;

using pumpkin.text;

using pumpkin.events;

using pumpkin.logging;

using pumpkin.tweener;





public class FlashUI : MovieClipOverlayCameraBehaviour {

public GameObject back;

protected MovieClipX movie = null;

public delegate void  OnStop();

void Start () {


stage.stageWidth = (float)Screen.width/1136f;

stage.stageHeight = (float)Screen.height/640f;

}

public void OnPlayToEnd(string path,Vector2 pos,OnStop stop = null)

{

MovieClipX overlay = new MovieClipX(path);

stage.addChild(overlay);

//位置

overlay.x = pos.x*stage.stageWidth;

overlay.y = pos.y*stage.stageHeight;

overlay.scaleX = stage.stageWidth;

overlay.scaleY = stage.stageHeight;

overlay.addFrameScript("end",delegate(){

stage.removeChild(overlay);

if(stop != null)stop();

});

overlay.gotoAndPlay(0);

}

public void OnPlayToFrame(string path,Vector2 pos,int endFrame,OnStop stop = null)

{

MovieClipX overlay = new MovieClipX(path);


stage.addChild(overlay);

//位置

overlay.x = pos.x*stage.stageWidth;

overlay.y = pos.y*stage.stageHeight;

overlay.scaleX = stage.stageWidth;

overlay.scaleY = stage.stageHeight;

overlay.addFrameScript(endFrame,delegate(){

stage.removeChild(overlay);

if(stop != null)stop();

});

overlay.gotoAndPlay(0);

}

public MovieClipX OnPlayNoEnd(string path,Vector2 pos)

{

MovieClipX overlay = new MovieClipX(path);


stage.addChild(overlay);

//位置

overlay.x = pos.x*stage.stageWidth;

overlay.y = pos.y*stage.stageHeight;

overlay.scaleX = stage.stageWidth;

overlay.scaleY = stage.stageHeight;

overlay.gotoAndPlay(0);

return overlay;

}

public void ClearFlash()

{

stage.clearChild();


}

上一篇:【Android Developers Training】 70. 使用ViewPager实现屏幕滑动


下一篇:使用Dictionary泛型集合封装业务逻辑判断 z