Exemple #1
0
 /// <summary>
 /// 绑定动作
 /// </summary>
 /// <param name="onEnd"></param>
 public void BindAnimator(UIFXListener.OnFXEnd onEnd)
 {
     var timer = gameObject.GetComponentInChildren<DestroyTimer>();
     if (timer != null)
     {
         timer.gameObject.AddComponent<UIFXListener>().onFXEnd = onEnd;
     }
 }
    /// <summary>
    /// 播放特效
    /// </summary>
    /// <param name="go">挂载点</param>
    /// <param name="name">特效名</param>
    /// <param name="mode">播放模式</param>
    /// <param name="onEnd">特效播放完事件</param>
    public static void PlayFX(GameObject go, string name, GameObject VV, EFX_PLAY_MODE mode, UIFXListener.OnFXEnd onEnd = null)
    {
        if (go == null)
        {
            return;
        }

        GameObject uiFxGO = null;

        UIFXController fxc = go.GetComponent<UIFXController>();
        if (fxc == null)
        {
            fxc = go.AddComponent<UIFXController>();
            fxc.mode = mode;
            fxc.fxName = name;
        }
        else if (fxc.fxList.Count > 0)
        {
            switch (fxc.mode)
            {
                case EFX_PLAY_MODE.LOOP:
                    {
                        //如果是循环特效则返回 (仅存在一个)
                        return;
                    }
                    break;
                case EFX_PLAY_MODE.ONCE_EXCLUSIVE:
                    {
                        StopFX(go);
                    }
                    break;
                case EFX_PLAY_MODE.ONCE_NONEXCLUSIVE:
                    {
                        foreach (UIFX fx in fxc.fxList)
                        {
                            GameObject goUIFx = fx.gameObject;
                            if (goUIFx.transform.childCount == 0)
                            {
                                uiFxGO = goUIFx;
                                break;
                            }
                        }
                    }
                    break;
            }
        }

        if (uiFxGO == null)
        {
            uiFxGO = new GameObject("UIFxGO");
            uiFxGO.transform.parent = go.transform;

            uiFxGO.transform.localPosition = new Vector3(0, 0, -15);

            if (go.GetComponent<UISprite>() != null
                || go.GetComponent<UITexture>() != null)
            {
                uiFxGO.transform.parent = go.transform.parent;
            }
            uiFxGO.transform.localScale = new Vector3(107, 107, 107);

            UIFX uiFx = uiFxGO.AddComponent<UIFX>();
            fxc.fxList.Add(uiFx);
        }

        OnFXLoaded(uiFxGO, VV);

        if (onEnd != null)
        {
            UIFX fx = uiFxGO.GetComponent<UIFX>();
            if (fx == null)
            {
                Debug.LogError("fx 为空!!!");
            }
            else
            {
                fx.BindAnimator(onEnd);
            }
        }
    }