Esempio n. 1
0
    //private void TryInitEffAttachPoint()
    //{
    //    this.effAttachPoint = body.GetComponentInChildren<tk2dSpriteAttachPoint>();
    //    if (aps != null)
    //    {
    //        foreach (var ap in aps.attachPoints)
    //        {
    //            //  REMARK:效果挂掉名字(EffPoint) 考虑移动到 Constant 。
    //            if (!string.IsNullOrEmpty(ap.gameObject.name) && ap.gameObject.name.Contains("EffPoint"))
    //            {
    //                if (this.effAttachPoint == null)
    //                    this.effAttachPoint = new List<Vector3>();
    //                //Vector3 p = ap.position;
    //                //effAttachPoint.Add(new Vector2(p.x, p.z));
    //                this.effAttachPoint.Add(ap.position);
    //            }
    //        }
    //    }
    //}

    //private void RegisterSpriteChangeEvent()
    //{
    //    if (this.sprite != null)
    //    {
    //        sprite.SpriteChanged -= sprite_SpriteChanged;
    //    }
    //    this.sprite = body.GetComponentInChildren<tk2dBaseSprite>();
    //    if (this.sprite != null)
    //    {
    //        this.sprite.SpriteChanged += sprite_SpriteChanged;
    //        //sprite_SpriteChanged(this.sprite);   //  初始化的时候处理一下???
    //    }
    //}

    //private void sprite_SpriteChanged(tk2dBaseSprite obj)
    //{
    //    //  是否是攻击动画判断
    //    if (animator == null)
    //        return;
    //    var clip = animator.CurrentClip;
    //    if (clip == null || string.IsNullOrEmpty(clip.name))
    //        return;
    //    if (!clip.name.Contains("Attack"))  //  TODO:这里暂时直接根据动画名的Attack判断
    //        return;


    //}

    /// <summary>
    /// 切换显示状态
    /// </summary>
    /// <param name="bodyIndex"></param>
    public void SwitchBody(int bodyIndex)
    {
        var toBody = transform.FindChild("body" + bodyIndex);

        if (toBody != null)
        {
            body = toBody;
            foreach (Transform child in transform)
            {
                if (child == body)
                {
                    child.gameObject.SetActive(true);
                }
                else if (child.name.StartsWith("body"))
                {
                    child.gameObject.SetActive(false);
                }
            }
            animator = body.GetComponentInChildren <tk2dSpriteAnimator>();
            //attachPoint = body.GetComponentInChildren<tk2dSpriteAttachPoint>();
            this.effAttachPoint = body.GetComponentInChildren <tk2dSpriteAttachPoint>();
            //RegisterSpriteChangeEvent();

            if (animator != null)
            {
                animator.enabled = false;   //  REMARK:禁用掉然后手动更新
            }
        }
    }
 static void DoRemoveAnimator()
 {
     PerformActionOnGlobalSelection("Add AttachPoint", delegate(GameObject go) {
         tk2dSpriteAttachPoint ap = go.GetComponent <tk2dSpriteAttachPoint>();
         if (ap == null)
         {
             go.AddComponent <tk2dSpriteAttachPoint>();
         }
     });
 }
Esempio n. 3
0
    virtual public void Init(bool faceToMainCamera = true)
    {
        _animationFinishCallbacks = null;

        if (faceToMainCamera)
        {
            foreach (Transform child in transform)
            {
                if (child.GetComponent <tk2dSprite>() != null)
                {
                    IsoHelper.FaceToWorldCamera(child);
                    if (child.name.IndexOf("Shadow") != -1)
                    {
                        shadow = child;
                        IsoHelper.MoveAlongCamera(child, Constants.SHADOW_Z_ORDER);
                    }
                }
            }
        }
        body = transform.FindChild("body");
        if (body == null)//多状态的
        {
            SwitchBody(1);
        }
        else
        {
            animator = body.GetComponentInChildren <tk2dSpriteAnimator>();
            //attachPoint = body.GetComponentInChildren<tk2dSpriteAttachPoint>();
            this.effAttachPoint = body.GetComponentInChildren <tk2dSpriteAttachPoint>();
            //RegisterSpriteChangeEvent();
        }
        if (animator != null)
        {
            animator.AnimationCompleted      = ontk2dSpriteAnimatorCallback_Completed;
            animator.AnimationEventTriggered = OnAnimationEventTriggered;

            animator.enabled = false;   //  REMARK:禁用掉然后手动更新
        }
    }