private void InitFBXFilesData(XmlDataList list)
 {
     m_xmlSetting        = new AnimatorXmlSetting();
     m_xmlDataList       = new List <AnimatorXmlData>();
     m_LayerDefaultState = new Dictionary <int, AnimatorState>();
     foreach (var item in list)
     {
         if (item.sLogicName.Equals("AnimatorXmlSetting"))
         {
             SetLogicFieldInfo(m_xmlSetting, item);
         }
         if (item.sLogicName.Equals("AnimatorXmlData"))
         {
             AnimatorXmlData data = new AnimatorXmlData();
             SetLogicFieldInfo(data, item);
             m_xmlDataList.Add(data);
         }
     }
 }
Example #2
0
        public void AddNewClassData()
        {
            AnimatorXmlData data = new AnimatorXmlData();

            System.Reflection.FieldInfo[] m_DataFields = data.GetType().GetFields();
            XmlClassData list = new XmlClassData();

            list.sLogicName = "AnimatorXmlData";
            foreach (var field in m_DataFields)
            {
                XmlParamItem item = new XmlParamItem();
                item.sName  = field.Name;
                item.sType  = field.FieldType.ToString();
                item.sValue = "";
                list.Add(item);
            }
            m_data.SafeAdd(list);

            Reload();
            Repaint();
        }
        private void ReadFBXFiles(string strFBXPath, AnimatorXmlData data, int nGroupID)
        {
            if (!Directory.Exists(strFBXPath))
            {
                return;
            }

            AnimationClipAndInfo clipAndinfo = new AnimationClipAndInfo(data);

            m_dictFBXFiles.Add(nGroupID, clipAndinfo);

            DirectoryInfo direction = new DirectoryInfo(strFBXPath);

            FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name.EndsWith(".anim"))
                {
                    string strAnimName = files[i].Name.Remove(files[i].Name.LastIndexOf('.'));
                    if (clipAndinfo.m_Animations.ContainsKey(strAnimName))
                    {
                        Debug.LogError("有重复的文件名称:" + strAnimName);
                        continue;
                    }

                    string strFilePath = files[i].ToString().Replace("\\", "/");
                    strFilePath = strFilePath.Substring(strFilePath.IndexOf("Assets"));
                    AnimationClip clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(strFilePath);
                    if (clip != null)
                    {
                        clipAndinfo.m_Animations.Add(strAnimName, clip);
                        ++m_FBXFilesCount;
                    }
                }
                else if (files[i].Name.EndsWith(".FBX"))
                {
                    string strFilePath = files[i].ToString().Replace("\\", "/");
                    strFilePath = strFilePath.Substring(strFilePath.IndexOf("Assets"));
                    UnityEngine.Object[] datas = AssetDatabase.LoadAllAssetsAtPath(strFilePath);
                    if (datas.Length == 0)
                    {
                        Debug.Log(string.Format("Can't find clip in {0}", strFBXPath));
                        return;
                    }
                    foreach (var item in datas)
                    {
                        if (!(item is AnimationClip))
                        {
                            continue;
                        }
                        var clip = item as AnimationClip;
                        // 取出动画名字,添加到state里面
                        if (clip != null)
                        {
                            clipAndinfo.m_Animations.Add(clip.name, clip);
                            ++m_FBXFilesCount;
                        }
                    }
                }
            }
        }
 public AnimationClipAndInfo(AnimatorXmlData _Xmldata)
 {
     m_Xmldata    = _Xmldata;
     m_Animations = new Dictionary <string, AnimationClip>();
 }