public static ObservableList <string> GetActionList() { if (actionList.Count > 0) { return(actionList); } List <string> aList = AnimationType.GetActionList(); foreach (string action in aList) { actionList.Add(action); } return(actionList); }
public string ToXMLString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<table n='CharacterConfigInfo'>\n"); PushToStringBuilder(stringBuilder, "ModelName", ModelName); PushToStringBuilder(stringBuilder, "WalkSpeed", WalkSpeed.ToString()); PushToStringBuilder(stringBuilder, "RunSpeed", RunSpeed.ToString()); PushToStringBuilder(stringBuilder, "LeftWeaponName", LeftWeaponName); PushToStringBuilder(stringBuilder, "RightWeaponName", RightWeaponName); foreach (string actionn in AnimationType.GetActionList()) { ActionInfo actionInfo = GetActionInfo(actionn); stringBuilder.Append(actionInfo.ToXMLString()); } stringBuilder.Append("</table>"); return(stringBuilder.ToString()); }
public static void DoCreateAnimationAssets() { List <UnityEditor.Animations.AnimatorState> states = new List <UnityEditor.Animations.AnimatorState>(); List <string> actions = AnimationType.GetActionList(); UnityEngine.Object select = Selection.activeObject; string p = AssetDatabase.GetAssetPath(select); if (!Directory.Exists(p)) { return; } string dirName = Path.GetFileName(p); string fp = p + "/" + dirName.ToLower() + AnimatorControllerExtName; if (File.Exists(fp)) { File.Delete(fp); } //创建animationController文件,保存在选择的目录下 UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(fp); //得到它的Layer, 默认layer为base UnityEditor.Animations.AnimatorControllerLayer layer = animatorController.layers[0]; string[] files = Directory.GetFiles(p); //List<float> ePrecent = new List<float>(); //ePrecent.Add(0.95f); //List<string> events = new List<string>(); //events.Add("endevent"); //List<string> eventPs = new List<string>(); //eventPs.Add(""); for (int i = 0; i < actions.Count; i++) { string action = actions[i]; string file = p + "/" + action + AssetsExtName; //if (action == AnimationType.Hit || action == AnimationType.Dead || action == AnimationType.Dodge) //{ // AddEventToAction(file, ePrecent, events, eventPs); //} //else if (AnimationType.IsAttackAction(action)) //{ // ePrecent.Add(0.55f); // events.Add("hitevent"); // eventPs.Add(""); // AddEventToAction(file, ePrecent, events, eventPs); //} if (File.Exists(file)) { UnityEditor.Animations.AnimatorState state = AddStateTransition(animatorController, file, layer); states.Add(state); } } foreach (UnityEditor.Animations.AnimatorState fState in states) { if (fState.name == AnimationType.Idle) { layer.stateMachine.defaultState = fState; } foreach (UnityEditor.Animations.AnimatorState tState in states) { if (fState != tState) { UnityEditor.Animations.AnimatorStateTransition at = fState.AddTransition(tState); at.hasExitTime = false; at.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 1f, tState.name); } } } }