示例#1
0
        /// <summary>
        /// 対象フォルダ確認ページを表示
        /// </summary>
        static void ShowFolderConfirmPage()
        {
            EditorGUILayout.LabelField("対象フォルダ確認");
            EditorGUILayout.HelpBox("抽出元FBXフォルダ:" + CurrentFolderPath, MessageType.None);
            EditorGUILayout.HelpBox("Clip保存先フォルダ:" + ExtractFolderPath, MessageType.None);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("MotionType");
            _motionType = (ExtractAnimationClipEnum.MotionType)System.Enum.Parse(typeof(ExtractAnimationClipEnum.MotionType), EditorGUILayout.EnumPopup(_motionType).ToString());
            EditorGUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("やめる", GUILayout.Width(ButtonWidth)))
            {
                _window.Close();
                GUIUtility.ExitGUI();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("進む", GUILayout.Width(ButtonWidth)))
            {
                ExtractAnimationClipEnum.Page nextPage = ExtractAnimationClipEnum.Page.Alert;
                SwitchPage(nextPage);
            }
            EditorGUILayout.EndHorizontal();
        }
示例#2
0
        /// <summary>
        /// 指定されたMotionTypeにおけるループモーション名のListを返す
        /// </summary>
        public static List <string> GetLoopMotionNames(ExtractAnimationClipSettings settings,
                                                       ExtractAnimationClipEnum.MotionType type)
        {
            switch (type)
            {
            case ExtractAnimationClipEnum.MotionType.InGame:
                return(settings.InGameLoopMotionNameList);

            case ExtractAnimationClipEnum.MotionType.OutGame:
                return(settings.OutGameLoopMotionNameList);

            default:
                return(null);
            }
        }
        /// <summary>
        /// 指定された種類のモーションクリップを検索して返す
        /// </summary>
        public static List <MotionSearchResult> SearchAnimationClipSources(ExtractAnimationClipEnum.MotionType type)
        {
            // ソースとなるファイルの検索
            string[] lookFor  = { ExtractAnimationClipWindow.CurrentFolderPath };
            string[] fbxGuids = AssetDatabase.FindAssets(ExtractAnimationClipConst.FbxFilter, lookFor);

            var resultList = new List <MotionSearchResult>();

            foreach (string guid in fbxGuids)
            {
                string path = AssetDatabase.GUIDToAssetPath(guid);

                // 正規の拡張子だけを対象とする
                if (!Path.GetExtension(path).Equals(ExtractAnimationClipConst.FbxExtension))
                {
                    continue;
                }
                string fbxFileName = Path.GetFileNameWithoutExtension(path);

                var      result = new MotionSearchResult(path, fbxFileName);
                Object[] files  = AssetDatabase.LoadAllAssetsAtPath(path);

                List <Object> animationClips = files.Where(x => x is AnimationClip && !x.name.Contains(ExtractAnimationClipConst.PreviewClipPrefix)).ToList();
                if (animationClips == null || animationClips.Count <= 0)
                {
                    continue;
                }

                // 1クリップに関するデータを作る
                var castList = animationClips.Cast <AnimationClip>().ToList();
                foreach (AnimationClip clip in castList)
                {
                    ClipSearchResult clipResult = new ClipSearchResult();
                    clipResult.SourceFbxPath = result.SourceFbxPath;
                    clipResult.Clip          = clip;
                    clipResult.IsNew         = false == File.Exists(ExtractAnimationClipWindow.ExtractFolderPath + ExtractAnimationClipConst.DirectorySeparator + clip.name + ExtractAnimationClipConst.AnimationClipExtension);
                    clipResult.IsTarget      = clipResult.IsNew;
                    result.ClipDataList.Add(clipResult);
                }

                // すべて新しいものならtrue
                result.IsTarget = result.ClipDataList.All(clipData => clipData.IsNew);
                resultList.Add(result);
            }
            return(resultList);
        }
示例#4
0
        /// <summary>
        /// 指定されたソースをもとにアニメーションクリップの抽出、パラメータ設定を行う
        /// </summary>
        public static bool ExtractAnimationClip(ExtractAnimationClipEnum.MotionType motionType,
                                                List <MotionSearchResult> sourceList)
        {
            bool isProgressDisplayed = false;

            try
            {
                List <string> loopMotionNames = GetLoopMotionNames(GetSettings(), motionType);

                int counter = 1;
                int total   = sourceList.Sum(result => result.ClipDataList.Where(clipData => clipData.IsTarget).Count());
                foreach (MotionSearchResult source in sourceList)
                {
                    foreach (ClipSearchResult clipData in source.ClipDataList)
                    {
                        if (false == clipData.IsTarget)
                        {
                            continue;
                        }
                        EditorUtility.DisplayProgressBar("AnimationClip抽出中", clipData.Clip.name, (float)counter / (float)total);
                        isProgressDisplayed = true;

                        AnimationClip copyClip = Object.Instantiate(clipData.Clip);

                        if (loopMotionNames.Contains(clipData.Clip.name))
                        {
                            var tmpSerialized = new SerializedObject(copyClip);
                            tmpSerialized.FindProperty("m_AnimationClipSettings.m_LoopTime").boolValue = true;
                            tmpSerialized.ApplyModifiedProperties();
                        }

                        AssetDatabase.CreateAsset(copyClip, ExtractAnimationClipConst.TmpClipFilePath);
                        string destPath = GetClipPath(clipData.Clip.name, motionType);
                        File.Copy(ExtractAnimationClipConst.TmpClipFilePath, destPath, true);
                        File.Delete(ExtractAnimationClipConst.TmpClipFilePath);
                        File.Delete(ExtractAnimationClipConst.TmpClipFilePath + ".meta");
                        AssetDatabase.Refresh();
                        AnimationClip    saved      = AssetDatabase.LoadAssetAtPath <AnimationClip>(destPath);
                        SerializedObject serialized = new SerializedObject(saved);
                        serialized.FindProperty("m_Name").stringValue = clipData.Clip.name;
                        serialized.ApplyModifiedProperties();
                        serialized.UpdateIfRequiredOrScript();
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                        counter++;
                    }
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
                return(false);
            }
            finally
            {
                if (isProgressDisplayed)
                {
                    EditorUtility.ClearProgressBar();
                }
            }
            return(true);
        }
示例#5
0
        /// <summary>
        /// 指定されたクリップ名、MotionTypeのクリップのパスを返す
        /// </summary>
        public static string GetClipPath(string clipName, ExtractAnimationClipEnum.MotionType motionType)
        {
            string clipPath = ExtractAnimationClipWindow.ExtractFolderPath;

            return(clipPath + ExtractAnimationClipConst.DirectorySeparator + clipName + ExtractAnimationClipConst.AnimationClipExtension);
        }