void OnGUI() { #region Example /* string mConfigPath = "Hello World"; bool groupEnabled; bool myBool = true; float myFloat = 1.23f; GUILayout.Label("Base Settings", EditorStyles.boldLabel); mConfigPath = EditorGUILayout.TextField("ConfigPath", mConfigPath); groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled); myBool = EditorGUILayout.Toggle("Toggle", myBool); myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3); EditorGUILayout.EndToggleGroup();*/ #endregion EditorGUILayout.LabelField("功能描述", "按照配置自动生成NpcPrefab"); EditorGUILayout.LabelField("配置路径", "Assets/Resources/Table/Editor/AutoGenMecanim.tab.txt"); string mProcessString = ""; switch(mProcessingState) { case PrecessingState.Ready: mProcessString = "准备就绪"; break; case PrecessingState.Doing: mProcessString = "正在生成..."; break; case PrecessingState.Finished: mProcessString = "生成完毕"; break; } EditorGUILayout.LabelField("进度状态", mProcessString); if (GUILayout.Button("开始生成", GUILayout.Width(255))) { mProcessingState = PrecessingState.Doing; StartGenerate(); } }
void StartGenerate() { string configFilePath = "Table/Editor/AutoGenMecanim.tab"; Dictionary<int, BaseConfig> configDic = ConfigLoader.LoadConfig(configFilePath, typeof(AutoGenMecanim_Tbl)); foreach(BaseConfig cfg in configDic.Values) { AutoGenMecanim_Tbl agmTbl = cfg as AutoGenMecanim_Tbl; string srcPath = agmTbl.sourcePath; string destPath = agmTbl.destPath; List<AnimationClip> clips = FindAnimationClips(srcPath.Substring(0, srcPath.LastIndexOf("/"))); if (clips.Count == 0) { Debug.LogError("no clips at path : " + srcPath); continue; } string name = srcPath.Substring(srcPath.LastIndexOf("/") + 1).Replace(".fbx", ""); UnityEditor.Animations.AnimatorController controller = null; controller = GenerateController(name, "Assets/" + destPath, clips); GameObject prefab = GeneratePrefab("Assets/" + srcPath, "Assets/" + destPath, controller, agmTbl); AssetDatabase.SaveAssets(); } mProcessingState = PrecessingState.Finished; }