Beispiel #1
0
    public void PlayUIEffect(GameObject rootUI, string name, float elapsedTime, LuaFunction callback, bool isAbove, bool isForever, UIEffectAddType addType = UIEffectAddType.Keep)
    {
        switch (addType)
        {
        case UIEffectAddType.Keep:
        {
            Transform child = this.transform.FindChild(name + "(Clone)");
            if (child != null)
            {
                return;
            }
        } break;

        case UIEffectAddType.Replace:
        {
            StopUIEffect(name);
        } break;

        case UIEffectAddType.Overlying:
        {
        } break;

        default:
            return;
        }

        AssetLoader loader = AssetBundleManager.CreateLoader();

        loader.LoadAsync(GameResType.Effect, name, (asset) =>
        {
            GameObject effect = GameObject.Instantiate(asset) as GameObject;
            effect.transform.SetParent(this.transform);
            effect.transform.localPosition    = Vector3.zero;
            effect.transform.localEulerAngles = Vector3.zero;
            effect.transform.localScale       = Vector3.one;
            EffectController ec = effect.AddComponent <EffectController>();
            ec.elapsedTime      = elapsedTime;
            ec.forever          = isForever;
            UILayer layer       = effect.gameObject.AddComponent <UILayer>();
            layer.type          = UILayerType.UIEffect;
            layer.canvas        = rootUI.GetComponent <Canvas>();
            layer.AssetLoader   = loader;
            if (layer.canvas != null)
            {
                layer.sortingOrder = layer.canvas.sortingOrder + (isAbove ? 1 : -1);
                layer.AdjustCanvasSortingOrder();
            }

            if (callback != null)
            {
                callback.Call(effect);
                callback.Dispose();
            }
        });
    }
Beispiel #2
0
    public void PlayUIEffect(GameObject rootUI, GameObject effectPrefab, float elapsedTime, LuaFunction callback, bool isAbove, bool isForever, UIEffectAddType addType = UIEffectAddType.Keep)
    {
        if (effectPrefab == null)
        {
            return;
        }
        switch (addType)
        {
        case UIEffectAddType.Keep:
        {
            Transform child = this.transform.FindChild(effectPrefab.transform.name + "(Clone)");
            if (child)
            {
                return;
            }
        } break;

        case UIEffectAddType.Replace:
        {
            StopUIEffect(effectPrefab.transform.name);
        } break;

        case UIEffectAddType.Overlying:
        {
        } break;

        default:
            return;
        }
        GameObject effect = GameObject.Instantiate(effectPrefab) as GameObject;

        effect.transform.SetParent(this.transform);
        effect.transform.localPosition    = Vector3.zero;
        effect.transform.localEulerAngles = Vector3.zero;
        effect.transform.localScale       = Vector3.one;
        effect.SetActive(true);
        EffectController ec = effect.GetComponent <EffectController>();

        if (ec == null)
        {
            ec = effect.AddComponent <EffectController>();
        }
        ec.elapsedTime = elapsedTime;
        ec.forever     = isForever;
        UILayer layer = effect.gameObject.GetComponent <UILayer>();

        if (layer == null)
        {
            layer = effect.gameObject.AddComponent <UILayer>();
        }
        layer.type   = UILayerType.UIEffect;
        layer.canvas = rootUI.GetComponent <Canvas>();
        if (layer.canvas != null)
        {
            layer.sortingOrder = layer.canvas.sortingOrder + (isAbove ? 1 : -1);
            layer.AdjustCanvasSortingOrder();
        }

        if (callback != null)
        {
            callback.Call(effect);
            callback.Dispose();
        }
    }