Пример #1
0
        private void CreateEffectNodeDate()
        {
            m_EffectNodeMesh   = null;
            m_EffectNodePrefab = null;

            switch (m_EffectType)
            {
            case UEffectType.UET_EffectPrefab:
                m_EffectNodePrefab = new UEffectNodeData_Prefab(this);
                return;

            case UEffectType.UET_EffectMesh:
                m_EffectNodeMesh = new UEffectNodeData_Mesh(this);
                return;

            case UEffectType.UET_EffectMaterial:
                m_EffectNodeMaterial = new UEffectNodeData_Material(this);
                return;
            }
        }
        protected void InitEffectPrefabRefParam(UEffectPrefabParam _effectParam)
        {
            if (_effectParam.EffectRes == null)
            {
                Trace.LogWarning("实例化UI效果类型:" + _effectParam.AttachEffectType + " 失败,资源没加载");
                return;
            }
            //异步没加载完
            if (!_effectParam.EffectRes.isLoadFinish)
            {
                return;
            }

            //实例化失败,已报错
            if (_effectParam.EffectGameObject == null)
            {
                return;
            }

            GameObject _goEffect   = _effectParam.EffectGameObject;
            Transform  EffectTrans = _goEffect.transform;

            EffectTrans.SetParent(_effectParam.AttachParent, false);

            //初始化坐标
            if (_effectParam.AttachPosition != null)
            {
                EffectTrans.localPosition = (Vector3)_effectParam.AttachPosition;
            }
            //初始化角度
            if (_effectParam.AttachRotation != null)
            {
                EffectTrans.GetComponentsInChildren <ParticleSystem>().ToList()
                .ForEach(x =>
                {
                    x.startRotation = (float)_effectParam.AttachRotation * Mathf.Deg2Rad;
                });
            }
            //初始化延迟
            if (_effectParam.AttachDelay != null)
            {
                int timerID = (int)EEffectTimer.EET_Delay * MaxTimerIDCount + _goEffect.GetComponent <UEffectNode>().To <UEffectNodeData_Prefab>().EffectPrefabTypeID;
                TimerManager.SetTimer(this, timerID, (float)_effectParam.AttachDelay, 1);
                _goEffect.SetActive(false);
                m_dicTimerIDObject.Add(timerID, _goEffect);
            }
            ////////粒子相关
            UEffectNodeData_Prefab prefab = _goEffect.GetComponent <UEffectNode>().To <UEffectNodeData_Prefab>();

            prefab.InitParticles();

            //是否需要播放完后自动移除
            if (_effectParam.AutoDestroy)
            {
                //检测是否有循环播放的粒子系统,有的话不能自动移除
                if (prefab.IsLoopEffect())
                {
                    Trace.LogWarning("UI效果:" + EffectTrans.name + "不能用于自动移除,因为用到循环粒子系统");
                }
                else
                {
                    prefab = _goEffect.GetComponent <UEffectNode>().To <UEffectNodeData_Prefab>();
                    prefab.SetAutoDestroy();
                }
            }

            //if(_effectParam.AttachEffectType == UEffectPrefabType.UEPT_HeroPreviewFrame_GradeFrame4)
            //{
            //    Debug.Log("begin  InitEffectPrefabRefParam");
            //    UParticleMask mask = _goEffect.GetComponent<UParticleMask>();
            //    if (mask == null)
            //        mask = _goEffect.AddComponent<UParticleMask>();
            //    RectTransform rectTrans = (EffectTrans as RectTransform);
            //    rectTrans.sizeDelta = new Vector2(152f, 190f);
            //    Debug.Log(rectTrans.gameObject.name + "..InitEffectPrefabRefParam.." + rectTrans.position);
            //    Debug.Log("end    InitEffectPrefabRefParam");
            //}

            //最后播放粒子
            prefab.ReplayEffect();

            //异步资源回调
            if (_effectParam is UEffectPrefabAsyncParam)
            {
                if ((_effectParam as UEffectPrefabAsyncParam).onResLoadFinished != null)
                {
                    (_effectParam as UEffectPrefabAsyncParam).onResLoadFinished.Invoke(_effectParam as UEffectPrefabAsyncParam);
                }
            }
        }