//保存动作信息
 private void SaveData()
 {
     foreach (AnimationState item in Anim.transform.GetComponent <Animation>())
     {
         AnimationEvent[] Events = AnimationUtility.GetAnimationEvents(item.clip);
         if (Events.Length != 0)
         {
             Debug.Log(item.clip.name);
             AnimationDataObj AnimData = ScriptableObject.CreateInstance <AnimationDataObj>();
             AnimData.HeroID   = Anim.HeroID;
             AnimData.AnimMame = item.clip.name;
             AnimData.AnimationFuntionDataList = new System.Collections.Generic.List <AnimationFuntionData>();
             Anim.AnimationFuntiondata         = new AnimationFuntionData[Events.Length];
             for (int i = 0; i < Events.Length; i++)
             {
                 Anim.AnimationFuntiondata[i]                  = new AnimationFuntionData();
                 Anim.AnimationFuntiondata[i].FuntionTime      = Events[i].time;
                 Anim.AnimationFuntiondata[i].FuntionName      = Events[i].functionName;
                 Anim.AnimationFuntiondata[i].FuntionParameter = Events[i].stringParameter;
                 AnimData.AnimationFuntionDataList.Add(Anim.AnimationFuntiondata[i]);
             }
             string name = "Assets/Art/Characters/AnimationEvnents/" + Anim.transform.name + item.clip.name;
             AssetDatabase.CreateAsset(AnimData, name + ".asset");
         }
         else
         {
             string name = "Assets/Art/Characters/AllAnimationEventFile/" + Anim.transform.name + item.clip.name;
             AssetDatabase.DeleteAsset(name + ".asset");
         }
     }
 }
Exemplo n.º 2
0
 private void SaveData()
 {
     GameObject[] TagObjs = Selection.gameObjects as GameObject[];
     foreach (GameObject item in TagObjs)
     {
         if (item.transform.GetComponent <Animation>() == null)
         {
             EditorUtility.DisplayDialog("", item.name + "无动画组件", "确定");
             continue;
         }
         foreach (AnimationState state in item.transform.GetComponent <Animation>())
         {
             AnimationEvent[] Events  = AnimationUtility.GetAnimationEvents(state.clip);
             string           saveurl = "Assets/Art/Characters/AnimationEvnents/";
             if (Directory.Exists(saveurl) == false)
             {
                 Directory.CreateDirectory(saveurl);
             }
             if (Events.Length != 0)
             {
                 Debug.Log(state.clip.name);
                 AnimationDataObj AnimData = ScriptableObject.CreateInstance <AnimationDataObj>();
                 AnimData.HeroID   = HeroID;
                 AnimData.AnimMame = state.clip.name;
                 AnimData.AnimationFuntionDataList = new System.Collections.Generic.List <AnimationFuntionData>();
                 AnimationFuntiondata = new AnimationFuntionData[Events.Length];
                 for (int i = 0; i < Events.Length; i++)
                 {
                     AnimationFuntiondata[i]                  = new AnimationFuntionData();
                     AnimationFuntiondata[i].FuntionTime      = Events[i].time;
                     AnimationFuntiondata[i].FuntionName      = Events[i].functionName;
                     AnimationFuntiondata[i].FuntionParameter = Events[i].stringParameter;
                     AnimData.AnimationFuntionDataList.Add(AnimationFuntiondata[i]);
                 }
                 string name = saveurl + item.name + state.clip.name;
                 AssetDatabase.CreateAsset(AnimData, name + ".asset");
             }
             else
             {
                 string name = saveurl + item.transform.name + state.clip.name;
                 AssetDatabase.DeleteAsset(name + ".asset");
             }
         }
     }
     AssetDatabase.Refresh();
     EditorUtility.DisplayDialog("", "保存完成", "OK");
 }
        //读取动作信息
        private void LoadData()
        {
            AnimationDataObj o = AssetDatabase.LoadAssetAtPath("Assets/Art/Characters/AnimationEvnents/" + Anim.transform.name + Anim.LoadAnimName + ".asset", typeof(AnimationDataObj)) as AnimationDataObj;

            AnimationEvent[] e = new AnimationEvent[o.AnimationFuntionDataList.Count];
            for (int i = 0; i < o.AnimationFuntionDataList.Count; i++)
            {
                AnimationEvent even = new AnimationEvent();
                even.time         = o.AnimationFuntionDataList[i].FuntionTime;
                even.functionName = o.AnimationFuntionDataList[i].FuntionName;
                if (o.AnimationFuntionDataList[i].FuntionParameter == string.Empty)
                {
                    Debug.Log("无参数");
                }
                else
                {
                    even.stringParameter = o.AnimationFuntionDataList[i].FuntionParameter;
                }
                e[i] = even;
            }
            AnimationUtility.SetAnimationEvents(Anim.transform.GetComponent <Animation>().GetClip(Anim.LoadAnimName), e);
        }
Exemplo n.º 4
0
    private void LoadAnimData()
    {
        GameObject[] TagObjs = Selection.gameObjects as GameObject[];
        string       url     = Application.dataPath + "/Art/Characters/AnimationEvnents/";

        if (Directory.Exists(url) == false)
        {
            EditorUtility.DisplayDialog("", "无效目录", "确定");
            return;
        }
        string[] files = Directory.GetFiles(url);
        foreach (string item in files)
        {
            if (item.Contains("meta"))
            {
                continue;
            }
            else
            {
                foreach (GameObject itemobj in TagObjs)
                {
                    if (itemobj.transform.GetComponent <Animation>() == null)
                    {
                        continue;
                    }
                    if (item.Contains(itemobj.transform.name))
                    {
                        string[]         names = item.Split('/');
                        string           name  = item.Substring(item.LastIndexOf("/") + 1, item.LastIndexOf(".") - item.LastIndexOf("/") - 1);
                        string           name1 = name.Substring(itemobj.name.Length);
                        AnimationDataObj o     = AssetDatabase.LoadAssetAtPath("Assets/Art/Characters/AnimationEvnents/" + names[names.Length - 1], typeof(AnimationDataObj)) as AnimationDataObj;
                        AnimationEvent[] e     = new AnimationEvent[o.AnimationFuntionDataList.Count];
                        for (int i = 0; i < o.AnimationFuntionDataList.Count; i++)
                        {
                            AnimationEvent even = new AnimationEvent();
                            even.time         = o.AnimationFuntionDataList[i].FuntionTime;
                            even.functionName = o.AnimationFuntionDataList[i].FuntionName;
                            if (o.AnimationFuntionDataList[i].FuntionParameter == string.Empty)
                            {
                                Debug.Log("无参数");
                            }
                            else
                            {
                                even.stringParameter = o.AnimationFuntionDataList[i].FuntionParameter;
                            }
                            e[i] = even;
                        }
                        if (itemobj.transform.GetComponent <Animation>().GetClip(name1) != null)
                        {
                            AnimationUtility.SetAnimationEvents(itemobj.transform.GetComponent <Animation>().GetClip(name1), e);
                        }
                        else
                        {
                            EditorUtility.DisplayDialog("", "未找动作" + name1, "确定");
                        }
                    }
                }
            }
        }
        AssetDatabase.Refresh();
        EditorUtility.DisplayDialog("", "资源加密完成", "OK");
    }
Exemplo n.º 5
0
    private void GetNames()
    {
        string url = Application.dataPath + "/Art/Characters/AnimationEvnents/";

        if (Directory.Exists(url) == false)
        {
            EditorUtility.DisplayDialog("", "无效目录", "确定");
            return;
        }
        FileInfo t = new FileInfo(Application.dataPath + "/StreamingAssets/CSV/" + "48_animationevent" + ".txt");

        sw = t.CreateText();
        //写入表头
        WriteValue("id");
        WriteValue("playerID");
        WriteValue("AnimName");
        WriteValue("HitTime");
        WriteValue("FunctionName");
        WriteValue("Param1");
        WriteValue("Param2");
        WriteValue("Param3");
        WriteValue("Param4");
        WriteValue("Param5");
        sw.Write("\r");

        WriteValue("索引");
        WriteValue("英雄/怪物ID");
        WriteValue("动作名称");
        WriteValue("命中时间");
        WriteValue("回调函数");
        WriteValue("参数1");
        WriteValue("参数2");
        WriteValue("参数3");
        WriteValue("参数4");
        WriteValue("参数5");
        sw.Write("\r");

        WriteValue("int");
        WriteValue("int");
        WriteValue("string");
        WriteValue("float");
        WriteValue("string");
        WriteValue("string");
        WriteValue("string");
        WriteValue("string");
        WriteValue("string");
        WriteValue("string");
        sw.Write("\r");
        int count = 0;

        string[] files = Directory.GetFiles(url);
        foreach (string item in files)
        {
            if (item.Contains("meta"))
            {
                continue;
            }
            else
            {
                string[]         names = item.Split('/');
                AnimationDataObj o     = AssetDatabase.LoadAssetAtPath("Assets/Art/Characters/AnimationEvnents/" + names[names.Length - 1], typeof(AnimationDataObj)) as AnimationDataObj;
                for (int i = 0; i < o.AnimationFuntionDataList.Count; ++i)
                {
                    WriteValue(count);
                    count++;
                    WriteValue(o.HeroID);
                    WriteValue(o.AnimMame);
                    WriteValue(o.AnimationFuntionDataList[i].FuntionTime);
                    WriteValue(o.AnimationFuntionDataList[i].FuntionName);
                    if (o.AnimationFuntionDataList[i].FuntionParameter != string.Empty)
                    {
                        WriteValue(o.AnimationFuntionDataList[i].FuntionParameter);
                    }
                    else
                    {
                        WriteValue(-1);
                    }
                    WriteValue(-1);
                    WriteValue(-1);
                    WriteValue(-1);
                    WriteValue(-1);
                    sw.Write("\r");
                }
            }
        }
        //关闭流
        sw.Close();
        //销毁流
        sw.Dispose();
        AssetDatabase.Refresh();
        EditorUtility.DisplayDialog("", "生成完成", "OK");
    }