Ejemplo n.º 1
0
 public LinkAnimate(cca.Animation animation, Animate.Function onSpecial, UnitNode from, UnitNode to)
     : base(animation, onSpecial)
 {
     m_fromToType = Projectile.FromToType.kUnitToUnit;
     m_from.Set(from.GetComponent <Unit>());
     m_to.Set(to.GetComponent <Unit>());
 }
Ejemplo n.º 2
0
    public override Action reverse()
    {
        Sprite[] frames = _animation.Frames.Clone() as Sprite[];
        System.Array.Reverse(frames);

        cca.Animation newAnim = new cca.Animation(frames, _animation.DelayPerUnit);
        newAnim.RestoreOriginalFrame = _animation.RestoreOriginalFrame;
        return(new LinkAnimate(newAnim, _onSpecial, m_from.Node, m_to.Node));
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 加载Unit或Projectile模型资源(动画和帧)
    /// 因为模型下info结构不同,所以需要用TYPE来区分(UnitModelInfo或ProjectileModelInfo)
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    TYPE LoadModel <TYPE>(string path)
        where TYPE : ModelBaseInfo
    {
        ModelBaseInfo baseInfo;

        if (m_modelInfos.TryGetValue(path, out baseInfo))
        {
            return(baseInfo as TYPE);
        }

        TextAsset res       = Resources.Load <TextAsset>(string.Format("{0}/info", path));
        TYPE      modelInfo = JsonMapper.ToObject <TYPE>(res.text);

        Resources.UnloadAsset(res);
        m_modelInfos.Add(path, modelInfo);

        Vector2 pivot = new Vector2((float)modelInfo.pivot.x, (float)modelInfo.pivot.y);

        foreach (KeyValuePair <string, ModelBaseInfo.Action> action in modelInfo.actions)
        {
            string actName = action.Key;
            ModelBaseInfo.Action actData = action.Value;
            int   aframes  = actData.frames;
            float adelay   = (float)actData.delay;
            int   aspecial = actData.special;

            Sprite[] sprites = new Sprite[aframes];
            for (int i = 0; i < aframes; ++i)
            {
                Texture2D texture = Resources.Load <Texture2D>(string.Format("{0}/{1}/{2:00}", path, actName, i));
                sprites[i] = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), pivot);
                Resources.UnloadAsset(texture);
                //sprites[i] = Resources.Load<Sprite>(string.Format("{0}/{1}/{2:00}", path, actName, i));
            }

            cca.Animation animation = new cca.Animation(sprites, adelay);
            if (aspecial >= 0)
            {
                animation.setFrameData(aspecial, "onSpecial");
            }
            m_modelAnimations.Add(string.Format("{0}/{1}", path, actName), animation);
        }

        foreach (string frame in modelInfo.frames)
        {
            Texture2D texture = Resources.Load <Texture2D>(string.Format("{0}/{1}", path, frame));
            Sprite    sprite  = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), pivot);
            Resources.UnloadAsset(texture);
            m_modelFrames.Add(string.Format("{0}/{1}", path, frame), sprite);
        }

        return(modelInfo);
    }
Ejemplo n.º 4
0
 // like PrepareAnimation(kActionMove, "Malik/move")
 public void AssignAnimation(int id, cca.Animation animation)
 {
     m_animations.Add(id, animation);
 }