コード例 #1
0
    //打开
    void Open(bool isTest = false, int testID = 0, Info.ENTabelType testType = Info.ENTabelType.enNone)
    {
        Delete();
        Info.ENTabelType type = Info.ENTabelType.enNone;
        int        modelID = 0, weaponID = 0;
        List <int> allSkillIDList = new List <int>();
        int        id             = 0;

        if (isTest)
        {//测试用
            id = testID;
            if (testType == Info.ENTabelType.enHero)
            {
                type = Info.ENTabelType.enHero;
                HeroInfo heroInfo = m_heroTabel.Lookup(id);
                modelID        = heroInfo.ModelId;
                weaponID       = heroInfo.WeaponId;
                allSkillIDList = heroInfo.GetAllSkillIDList();
            }
            else
            {
                type = Info.ENTabelType.enNPC;
                NPCInfo npcInfo = m_npcTabel.Lookup(id);
                modelID  = npcInfo.ModelId;
                weaponID = npcInfo.WeaponID;
                allSkillIDList.AddRange(npcInfo.SkillList);
                allSkillIDList.Add(npcInfo.StaminaSkillID);
            }
        }
        else
        {
            id = m_idList[m_index];
            if (m_tableIndex == 0)
            {
                type = Info.ENTabelType.enHero;
                HeroInfo heroInfo = m_heroTabel.Lookup(id);
                modelID        = heroInfo.ModelId;
                weaponID       = heroInfo.WeaponId;
                allSkillIDList = heroInfo.GetAllSkillIDList();
            }
            else
            {
                type = Info.ENTabelType.enNPC;
                NPCInfo npcInfo = m_npcTabel.Lookup(id);
                modelID  = npcInfo.ModelId;
                weaponID = npcInfo.WeaponID;
                allSkillIDList.AddRange(npcInfo.SkillList);
                allSkillIDList.Add(npcInfo.StaminaSkillID);
            }
        }

        ModelInfo modelInfo = m_modelTable.Lookup(modelID);

        if (modelInfo == null)
        {
            Debug.LogError("model error,modelID:" + modelID + ",card id:" + id + ",type:" + type.ToString());
            return;
        }
        WeaponInfo weaponInfo = m_weaponTable.Lookup(weaponID);

        if (weaponInfo == null)
        {
            Debug.LogError("weapon error,weaponID:" + weaponID + ",card id:" + id + ",type:" + type.ToString());
            return;
        }

        m_currentInfo.m_tabelType  = type;
        m_currentInfo.m_tabelID    = id;
        m_currentInfo.m_modelType  = modelInfo.modelType;
        m_currentInfo.m_weaponType = (int)weaponInfo.WeaponType;
        List <int> skillIDList = new List <int>();

        foreach (var item in allSkillIDList)
        {//删除相同的技能id
            if (!skillIDList.Contains(item))
            {
                skillIDList.Add(item);
            }
        }
        GetAnimationList(skillIDList);

        //加载模型,并给模型加一个父
        GameObject parentObj = new GameObject();

        m_currentObj = parentObj;
        parentObj.transform.parent = ObjPanel.transform;
        GameObject modelObj = GameObject.Instantiate(GameData.LoadPrefab <GameObject>(modelInfo.ModelFile)) as GameObject;

        modelObj.name = "body";
        ObjEffect.GetComponent <EDSkillEventTrigger>().MainObj = modelObj;
        parentObj.name            = modelObj.name + "_parent";
        modelObj.transform.parent = parentObj.transform;

        parentObj.AddComponent <AnimationCameraCallback>();
        parentObj.AddComponent <AnimationEffectCallback>();
        parentObj.AddComponent <AnimationEndCallback>();
        parentObj.AddComponent <AnimationShaderParamCallback>();
        parentObj.AddComponent <AnimationSoundCallback>();
        parentObj.AddComponent <BreakPointCallback>();
        parentObj.AddComponent <AttackActionCallback>();
        #region//加载模型的父的animation
        Animation parentAnim = parentObj.AddComponent <Animation>();
        string    path       = "Assets/Resources/SkillAnim/";
        foreach (var item in m_skillAnimList)
        {
            Info.AnimInfo info = null;
            m_currentInfo.m_animMap.TryGetValue(item, out info);

            string filename = m_currentInfo.m_modelType.ToString() + "-" +
                              m_currentInfo.m_weaponType.ToString() + "-" +
                              info.m_skillID.ToString() + "-" + ((int)info.m_skillStepType).ToString() + "-" + info.m_animName + ".anim";
            string        assetPath = path + filename;
            AnimationClip clip      = AssetDatabase.LoadMainAssetAtPath(assetPath) as AnimationClip;
            if (clip != null)
            {
                parentAnim.AddClip(clip, item);
            }
            else
            {
                Debug.Log("load clip failed, path:" + assetPath);
            }
        }
        #endregion
        #region//加载模型的脚本和animation
        if (modelObj.GetComponent <AnimationCameraCallback>() == null)
        {
            modelObj.AddComponent <AnimationCameraCallback>();
        }
        if (modelObj.GetComponent <AnimationEffectCallback>() == null)
        {
            modelObj.AddComponent <AnimationEffectCallback>();
        }
        if (modelObj.GetComponent <AnimationEndCallback>() == null)
        {
            modelObj.AddComponent <AnimationEndCallback>();
        }
        if (modelObj.GetComponent <AnimationShaderParamCallback>() == null)
        {
            modelObj.AddComponent <AnimationShaderParamCallback>();
        }
        if (modelObj.GetComponent <AnimationSoundCallback>() == null)
        {
            modelObj.AddComponent <AnimationSoundCallback>();
        }
        if (modelObj.GetComponent <BreakPointCallback>() == null)
        {
            modelObj.AddComponent <BreakPointCallback>();
        }
        if (modelObj.GetComponent <AttackActionCallback>() == null)
        {
            modelObj.AddComponent <AttackActionCallback>();
        }
        if (LoadAnimationClip(modelObj, modelInfo.modelType, (int)weaponInfo.WeaponType))
        {
            Animation modelAnim = modelObj.GetComponent <Animation>();
            //加载模型的事件
            foreach (var item in m_skillAnimList)
            {
                Info.AnimInfo info = null;
                m_currentInfo.m_animMap.TryGetValue(item, out info);
                AnimationClip copyClip = modelAnim.GetClip(GetFullAnimName(info.m_animName, m_currentInfo.m_modelType, m_currentInfo.m_weaponType));
                if (copyClip == null)
                {
                    Debug.LogError("body get animation failed, anim:" + info.m_animName);
                }
                modelAnim.AddClip(copyClip, item);
                AnimationClip modelClip = modelAnim.GetClip(item);

                AnimationClip parentClip = parentAnim.GetClip(item);
                if (parentClip != null)
                {//从parentObj中获取事件信息
                    AnimationClipCurveData[] array = AnimationUtility.GetAllCurves(parentClip);
                    foreach (var data in array)
                    {
                        if (!m_typeList.Contains(data.type.BaseType))
                        {
                            continue;
                        }
                        string dataPath = "";
                        if (data.path.Contains("body"))
                        {
                            dataPath = data.path.Substring(4);
                        }
                        else if (data.path.Contains("body/"))
                        {
                            dataPath = data.path.Substring(5);
                        }
                        modelClip.SetCurve(dataPath, data.type, data.propertyName, data.curve);
                    }
                    AnimationUtility.SetAnimationEvents(modelClip, AnimationUtility.GetAnimationEvents(parentClip));
                }
                else
                {//获取原来的事件信息,存储在resources/skillanim目录下
                    string dir      = "assets/resources/skillanim/";
                    string animName = "a-" + m_currentInfo.m_modelType.ToString() + "-w" +
                                      m_currentInfo.m_weaponType.ToString() + "-" + info.m_animName + ".anim";
                    UnityEngine.Object tempObj = AssetDatabase.LoadMainAssetAtPath(dir + animName);
                    if (tempObj == null)
                    {
                        //Debug.LogWarning("animation name:" + animName);
                        //resources/skillanim目录下不存在
                        //从原动作中获取
                        AnimationClip bodyClip = modelAnim.GetClip(info.m_animName);
                        if (bodyClip == null)
                        {
                            Debug.LogError("animation is null, name:" + info.m_animName);
                        }
                        else
                        {
                            AnimationClipCurveData[] array = AnimationUtility.GetAllCurves(bodyClip);
                            foreach (var data in array)
                            {
                                if (!m_typeList.Contains(data.type.BaseType))
                                {
                                    continue;
                                }
                                //if (!string.IsNullOrEmpty(data.path))
                                //{//不是body下的
                                //    continue;
                                //}
                                modelClip.SetCurve(data.path, data.type, data.propertyName, data.curve);
                            }
                            AnimationUtility.SetAnimationEvents(modelClip, AnimationUtility.GetAnimationEvents(bodyClip));
                        }
                    }
                    else
                    {
                        AnimationClip            clip  = GameObject.Instantiate(tempObj) as AnimationClip;
                        AnimationClipCurveData[] array = AnimationUtility.GetAllCurves(clip);
                        foreach (var data in array)
                        {
                            if (!m_typeList.Contains(data.type.BaseType))
                            {
                                continue;
                            }
                            //if (!string.IsNullOrEmpty(data.path))
                            //{//不是body下的
                            //    continue;
                            //}
                            modelClip.SetCurve(data.path, data.type, data.propertyName, data.curve);
                        }
                        AnimationUtility.SetAnimationEvents(modelClip, AnimationUtility.GetAnimationEvents(clip));

                        GameObject.DestroyImmediate(clip);
                    }
                }
            }
        }
        else
        {
            Debug.LogError("LoadAnimationClip failed");
        }
        #endregion
        #region//加载武器
        if (weaponInfo.LeftModelID != 0)
        {
            Transform leftArmParentTrans = Actor.S_LookupBone2(modelObj.transform, weaponInfo.LeftPoint);
            ArmLoad(leftArmParentTrans, weaponInfo.LeftModelID, weaponInfo.IsHideLeftModel);
        }
        if (weaponInfo.RightModelID != 0)
        {
            Transform rightArmParentTrans = Actor.S_LookupBone2(modelObj.transform, weaponInfo.RightPoint);
            ArmLoad(rightArmParentTrans, weaponInfo.RightModelID, weaponInfo.IsHideRightModel);
        }
        #endregion
        #region//刷新动画列表
        Animation AniList = modelObj.GetComponent <Animation>();
        m_loadedAnimationList.Clear();
        foreach (AnimationState state in AniList)
        {
            m_loadedAnimationList.Add(state.name);
        }
        m_loadedAnimationList.AddRange(m_skillAnimList);
        m_playingAniIndex = m_loadedAnimationList.Count - 1;
        ED_SimActorManager.Instance.Clear();
        ED_SimActorManager.Instance.AddActor(m_currentObj);
        #endregion

        Selection.activeObject = modelObj;
    }
コード例 #2
0
    static public byte[] Save()
    {
        m_hadResourceList.Clear();

        BinaryHelper helper = new BinaryHelper();

        TextAsset     asset         = GameData.LoadConfig <TextAsset>("HeroInfoTable");
        HeroInfoTable heroInfoTable = new HeroInfoTable();

        heroInfoTable.Load(asset.bytes);

        Debug.Log("扫描资源信息条为:" + (heroInfoTable.m_list.Count + m_npcInfoTable.m_list.Count));
        // 信息数量
        helper.Write(heroInfoTable.m_list.Count + m_npcInfoTable.m_list.Count);

        // HERO
        foreach (KeyValuePair <int, HeroInfo> item in heroInfoTable.m_list)
        {
            m_resourceList.Clear();

            ModelInfo modelInfo = m_modelInfoTable.Lookup(item.Value.ModelId);
            if (null == modelInfo)
            {
                helper.Write(0);
                continue;
            }

            GameObject preObj = GameData.LoadPrefab <GameObject>(modelInfo.ModelFile);

            if (null == preObj)
            {
                helper.Write(0);
                continue;
            }
            Animation AniList = preObj.GetComponent <Animation>();

            if (string.IsNullOrEmpty(modelInfo.ModelFile))
            {
                helper.Write(0);
                continue;
            }

            if (m_hadResourceList.Contains(modelInfo.ModelFile))
            {
                helper.Write(0);
                continue;
            }

            // 模型预设名称
            m_resourceList.Add(modelInfo.ModelFile, (int)Type.enPrefab);
            m_hadResourceList.Add(modelInfo.ModelFile);
            Debug.Log("modelInfo.ModelFile:" + modelInfo.ModelFile);

            foreach (AnimationState state in AniList)
            {
                AnimationClip clip = AniList.GetClip(state.name);
                if (null == clip)
                {
                    continue;
                }

                // 动画列表
                AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);

                foreach (AnimationEvent data in events)
                {
                    if (data.functionName == "ChangeResultID" || data.functionName == "ChangeInstantResultID")
                    {
                        LoadEffect(data.intParameter);
                    }
                    else if (data.functionName == "RemoteAttack")
                    {
                        LoadRemoteObj(data.intParameter);
                    }
                }
            }

            Debug.Log("m_resourceList.Count:" + m_resourceList.Count);

            helper.Write(m_resourceList.Count);

            foreach (KeyValuePair <string, int> resourceListItem in m_resourceList)
            {
                helper.Write(resourceListItem.Value);
                helper.Write(resourceListItem.Key);
                //Debug.Log("resourceListItem:" + resourceListItem);
            }
        }

        // NPC
        foreach (KeyValuePair <int, NPCInfo> item in m_npcInfoTable.m_list)
        {
            m_resourceList.Clear();

            ModelInfo modelInfo = m_modelInfoTable.Lookup(item.Value.ModelId);
            if (null == modelInfo)
            {
                helper.Write(0);
                continue;
            }

            GameObject preObj = GameData.LoadPrefab <GameObject>(modelInfo.ModelFile);

            if (null == preObj)
            {
                helper.Write(0);
                continue;
            }
            Animation AniList = preObj.GetComponent <Animation>();

            if (string.IsNullOrEmpty(modelInfo.ModelFile))
            {
                helper.Write(0);
                continue;
            }

            if (m_hadResourceList.Contains(modelInfo.ModelFile))
            {
                helper.Write(0);
                continue;
            }

            // 模型预设名称
            m_resourceList.Add(modelInfo.ModelFile, (int)Type.enPrefab);
            m_hadResourceList.Add(modelInfo.ModelFile);
            Debug.Log("NPC modelInfo.ModelFile:" + modelInfo.ModelFile);

            foreach (float buffId in item.Value.GiftBuffIDList)
            {
                BuffInfo buffInfo = m_buffTable.Lookup((int)buffId);

                if (null == buffInfo)
                {
                    continue;
                }

                BuffEffectInfo buffEffectInfo = m_buffEffectTable.Lookup(buffInfo.BuffEffectID);
                if (null == buffEffectInfo)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(buffEffectInfo.EffectName))
                {
                    continue;
                }

                if (!m_hadResourceList.Contains(buffEffectInfo.EffectName))
                {
                    m_resourceList.Add(buffEffectInfo.EffectName, (int)Type.enEffect);
                    m_hadResourceList.Add(buffEffectInfo.EffectName);
                    Debug.Log("NPC m_resourceList 添加  " + buffEffectInfo.EffectName);
                }
            }

            foreach (AnimationState state in AniList)
            {
                AnimationClip clip = AniList.GetClip(state.name);
                if (null == clip)
                {
                    continue;
                }

                // 动画列表
                AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);

                foreach (AnimationEvent data in events)
                {
                    if (data.functionName == "ChangeResultID" || data.functionName == "ChangeInstantResultID")
                    {
                        LoadEffect(data.intParameter);
                    }
                    else if (data.functionName == "RemoteAttack")
                    {
                        LoadRemoteObj(data.intParameter);
                    }
                }
            }

            Debug.Log(" NPC m_resourceList.Count:" + m_resourceList.Count);

            helper.Write(m_resourceList.Count);

            foreach (KeyValuePair <string, int> resourceListItem in m_resourceList)
            {
                helper.Write(resourceListItem.Value);
                helper.Write(resourceListItem.Key);
                //Debug.Log("resourceListItem:" + resourceListItem);
            }
        }


        return(helper.GetBytes());
    }