Exemplo n.º 1
0
    public override IEnumerator onInit(LChatacterRecourceInterface loader, LChatacterInterface character, AddCoroutineFun fun)
    {
        Debug.Log("skill on init " + SkillId);
        hasLoaded = false;
        CharactorLoadHandle handle0 = loader.LoadSkillDataFile(SkillId, fun);

        while (!handle0.isFinish)
        {
            yield return(null);
        }
        skillData = (LCHSkillData)handle0.asset;
        //Debug.LogError("LoadSkillDataFile");
        role.type        = 1;
        role.objId       = -1;
        objs[role.objId] = role;
        objList          = new ObjectContain[skillData.objs.Length];
        for (int i = 0, l = skillData.objs.Length; i < l; i++)
        {
            var           o  = skillData.objs[i];
            ObjectContain oc = new ObjectContain();
            oc.SetInformation(o);
            objs[o.id] = oc;
            objList[i] = oc;
            if (o.id == -1)//不加载主模型。
            {
                continue;
            }
            else if (o.type == 1)//对象(特效,模型...)。
            {
                Debug.LogError("load " + oc.mod);
                var handle = loader.loadResource(oc.mod_name, oc.mod, fun);
                while (!handle.isFinish)
                {
                    yield return(1);
                }
                if (null != handle.asset)
                {
                    if (handle.asset == null)
                    {
                        Debug.LogError("找不到资源,是否没打包 ? " + oc.mod);
                    }
                    else
                    {
                        oc.baseGameObject = (GameObject)handle.asset;
                        if (null != oc.baseGameObject)
                        {
                            oc.gameobject = GameObject.Instantiate(oc.baseGameObject);
                            oc.gameobject.SetActive(false);
                            oc.gameobject.name      = o.name;
                            oc.gameobject.hideFlags = HideFlags.None;
                            oc.systems = oc.gameobject.GetComponentsInChildren <ParticleSystem>();
                        }
                    }
                }
            }
            else if (o.type == 2)//(碰撞体)。
            {
                GameObject g = new GameObject();
                g.layer = character.GetAttackLayer();
                g.SetActive(false);
                g.AddComponent <BoxCollider>();
                g.hideFlags   = HideFlags.DontSave;
                oc.gameobject = g;
                g.name        = o.name;
            }
            else if (o.type == 3)//模型本身碰撞体。暂不连接。
            {
                continue;
            }
            else if (o.type == 4)//加载声音
            {
                GameObject g = new GameObject();
                g.name        = o.name;
                oc.gameobject = g;
                loader.loadResource(oc.mod_name, oc.mod, fun);
            }
        }
        for (int i = 0, c0 = skillData.events.Count; i < c0; i++)
        {
            var _e      = skillData.events[i];
            var contain = objs[_e.objId];
            contain.events.Add(_e);
        }

        for (int i = 0, c0 = skillData.channels.Count; i < c0; i++)
        {
            var _c      = skillData.channels[i];
            var contain = objs[_c.objId];
            contain.channels.Add(_c);
        }

        hasLoaded = true;
        Debug.Log("skill on init finish " + SkillId);
    }
Exemplo n.º 2
0
    public static void CmpObjectEvent(float curTime, float lastTime, LCHEventChannelData _e, ObjectContain contain, LChatacterInterface character, LChatacterInformationInterface information,
                                      Dictionary <int, ObjectContain> objs
                                      , CdState cdState
                                      , string cdName
                                      , int skillState

                                      )
    {
        LCHChannelType t = (LCHChannelType)_e.type;
        ObjDictionary  value;
        float          _time;

        if (t == LCHChannelType.Object)
        {
            int res = _e.TryGetKeyFrameRunTime(curTime, lastTime, out value, out _time);
            if (res == 1)
            {
                if (null != contain.gameobject)
                {
                    bool enable = value.GetValue <bool>("enable", true);
                    if (_e.objId == -1)
                    {
                        //因為主對象直接設置 gameObject的Enable,所有腳本都不工作了.
                        if (null != contain.roleRenders)
                        {
                            for (int n = 0; n < contain.roleRenders.Length; n++)
                            {
                                contain.roleRenders[n].enabled = enable;
                            }
                        }
                    }
                    else
                    {
                        if (enable)
                        {
                            contain.gameobject.SetActive(false);
                            contain.gameobject.SetActive(true);

                            /*contain.gameobject.SetActive(enable);
                             * for (int i = 0, l = contain.systems.Length; i < l; i++)
                             * {
                             *  //Debug.Log(contain.systems[i].isStopped);
                             *  contain.systems[i].gameObject.SetActive(false);
                             *  contain.systems[i].gameObject.SetActive(true);
                             *  contain.systems[i].Play(true);
                             * }*/
                        }
                        else
                        {
                            contain.gameobject.SetActive(enable);
                        }

                        //Debug.LogError("_e.objId  " + _e.objId + " " + enable);
                        //contain.gameobject.SetActive(enable);
                    }

                    if (enable)
                    {
                        if (contain.type == 1)
                        {
                            string anim_name = value.GetValue <string>("anim", "");
                            if (anim_name.Length > 0)
                            {
                                if (null == contain.animaction)
                                {
                                    contain.animaction = contain.gameobject.GetComponent <Animation>();
                                }
                                if (null != contain.animaction)
                                {
                                    bool cf = value.GetValue <bool>("crossFade", true);
                                    //crossFade
                                    contain.animaction[anim_name].time = _time;
                                    if (cf)
                                    {
                                        contain.animaction.CrossFade(anim_name, 0.05f);
                                    }
                                    else
                                    {
                                        contain.animaction[anim_name].time = 0f;//特么受击不这么干不重置。。。
                                        contain.animaction.Play(anim_name);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (res == 0)
            {
                if (_e.objId != -1)//非主模型,一开始隐藏
                {
                    if (null != contain.gameobject)
                    {
                        if (contain.objId != -1)
                        {
                            contain.gameobject.SetActive(false);
                        }
                    }
                }
            }
        }
        if (t == LCHChannelType.Event)
        {
            int res = _e.TryGetKeyFrameRunTime(curTime, lastTime, out value, out _time);
            if (res == 1)
            {
                if (contain.type == 2 || contain.type == 3)
                {
                    if (null == contain.collider)
                    {
                        if (null != contain.gameobject)
                        {
                            contain.collider         = contain.gameobject.GetComponent <Collider>();
                            contain.gameobject.layer = character.GetAttackLayer();
                            if (null != contain.collider)
                            {
                                contain.collider.isTrigger = true;
                            }
                        }
                    }
                }
                if (null != contain.gameobject)
                {
                    bool enable = value.GetValue <bool>("enable", true);
                    contain.gameobject.SetActive(enable);
                    if (contain.collider)
                    {
                        contain.collider.enabled = enable;
                        if (enable)
                        {
                            if (null == contain.hitData)
                            {
                                LCharacterHitDataCmp hdc = contain.gameobject.GetComponent <LCharacterHitDataCmp>();
                                if (null == hdc)
                                {
                                    hdc = contain.gameobject.AddComponent <LCharacterHitDataCmp>();
                                }
                                contain.hitData = hdc.data;
                            }

                            contain.hitData.type = "hit";
                            LCharacterHitData hitData = new LCharacterHitData();

                            hitData.hittedObject.Clear();
                            hitData.value       = value;
                            hitData.characterId = character.GetId();
                            hitData.firstHit    = true;

                            hitData.cdName     = cdName;
                            hitData.skillState = skillState;
                            hitData.cdState    = cdState;

                            int effectId = value.GetValueInt("hit_effect", -2);
                            if (effectId != -2 && objs.ContainsKey(effectId))
                            {
                                var ct = objs[effectId];
                                hitData.effect     = ct.mod;
                                hitData.effect_obj = ct.baseGameObject;
                            }
                            else
                            {
                                hitData.effect     = null;
                                hitData.effect_obj = null;
                            }
                            contain.hitData.data = hitData;
                        }
                    }
                }
            }
            else if (res == 0)
            {
                if (null != contain.gameobject)
                {
                    contain.gameobject.SetActive(false);
                }
            }
        }
    }