void SelfInit(FB.PosePlus.AniPlayer ani, string tag) { this.ani = ani; this.tag = tag; //if (GUILayout.Button("Update Clips")) //{ }
public static void Show(FB.PosePlus.AniPlayer ani, string tag) { // Get existing open window or if none, make a new one: //获取现有的打开窗口或如果没有,创建一个新的 var window = EditorWindow.GetWindow <EditorWindow_AniPick>(true, "Window_AniPick", true); window.SelfInit(ani, tag); }
void FillAniBoneInfo(Transform root, FB.PosePlus.AniPlayer controller, FB.PosePlus.AniClip ani) { string path = getPath(root, controller.transform); if (ani.boneinfo == null) { ani.boneinfo = new List <string>(); } ani.boneinfo.Add(path); foreach (Transform t in root) { FillAniBoneInfo(t, controller, ani); } }
public static void Show(FB.PosePlus.AniPlayer aniPlayer = null, AniClip clip = null, int curfunc = -1, int curframe = -1) { var window = EditorWindow.GetWindow <Window_StateBlockFuncs>(false, "Block详细编辑"); window.Init(); if (clip != null) { _clip = Window_StateTable.aniPlayer.GetClip(Window_StateTable.selectBlock.playani); _subclip = clip.GetSubClip(Window_StateTable.selectBlock.playsubani); Debug.Log(Window_StateTable.selectBlock.playani); } else { _clip = clip; _subclip = clip.GetSubClip(Window_StateTable.selectBlock.playsubani); } if (curframe >= 0) { selectFrame = curframe; } if (curfunc >= 0) { SelectSelectFunc(Window_StateTable.selectBlock.funcs[curfunc]); } else { SelectSelectFunc(null); } clip = Window_StateTable.aniPlayer.GetClip(Window_StateTable.selectBlock.playani); if (clip != null) { _subclip = clip.GetSubClip(Window_StateTable.selectBlock.playsubani); } if (curfunc >= 0 && curfunc <= Window_StateTable.selectBlock.funcs.Count - 1) { SelectSelectFunc(Window_StateTable.selectBlock.funcs[curfunc]); } if (aniPlayer != null) { _aniPlayer = aniPlayer; } pickfunc = null; }
public Frame(AniClip clip, AniPlayer player, Frame last, int _fid, Transform root, IList <Transform> trans) { //Debug.LogWarning("bones=" + trans.Length); this.fid = _fid; this.key = true; this.boneinfo = clip.boneinfo; //bonesinfo = new PoseBoneMatrix[trans.Count]; for (int i = 0; i < trans.Count; i++) { PoseBoneMatrix b = new PoseBoneMatrix(); bonesinfo.Add(b); string bone = this.boneinfo[i]; var tbone = player.getbone(bone); bonesinfo[i].Record(root, trans[i], tbone == null?Matrix4x4.identity:tbone.tpose, last == null ? null : last.bonesinfo[i]); } }
public static void preAnimation(Animation animation) { GameObject curObj = animation.gameObject; FB.PosePlus.AniPlayer player = curObj.GetComponent <FB.PosePlus.AniPlayer>(); if (player == null) { player = curObj.AddComponent <FB.PosePlus.AniPlayer>(); } player.InitBone(); List <AnimationClip> clips = new List <AnimationClip>(); foreach (AnimationState state in animation) { clips.Add(state.clip); } foreach (var c in clips) { AddClip(c, c.frameRate, animation); } }
public static void AddClip(AnimationClip clip, float fps, Animation ani) { FB.PosePlus.AniClip _clip = ScriptableObject.CreateInstance <FB.PosePlus.AniClip>(); _clip.boneinfo = new List <string>();//也增加了每个动画中的boneinfo信息. //这里重新检查动画曲线,找出动画中涉及的Transform部分,更精确 List <Transform> cdpath = new List <Transform>(); var curveDatas = AnimationUtility.GetCurveBindings(clip); FB.PosePlus.AniPlayer con = ani.GetComponent <FB.PosePlus.AniPlayer>(); UpdateCdpath(ani, curveDatas, _clip, con, cdpath); string path = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip.GetInstanceID())); _clip.name = clip.name; _clip.frames = new List <FB.PosePlus.Frame>(); _clip.fps = fps; _clip.loop = clip.isLooping; float flen = (clip.length * fps); int framecount = (int)flen; if (flen - framecount > 0.0001) { framecount++; } for (int i = 0, l = clip.events.Length; i < l; i++) { var aniEvent = clip.events[i]; FrameEvent evt = new FrameEvent(); evt.name = aniEvent.functionName; evt.position = aniEvent.time; evt.intVariable = aniEvent.intParameter; evt.floatVariable = aniEvent.floatParameter; evt.stringVariable = aniEvent.stringParameter; _clip.events.Add(evt); } framecount += 1; FB.PosePlus.Frame last = null; for (int i = 0; i < framecount; i++) { ani[_clip.name].time = (i * 1.0f / fps) / clip.length; ani[_clip.name].enabled = true; ani[_clip.name].weight = 1; ani.Sample(); ani[_clip.name].enabled = false; last = new FB.PosePlus.Frame(_clip, con, last, i, ani.transform, cdpath); _clip.frames.Add(last); } Dictionary <string, int> clipcache = new Dictionary <string, int>(); if (con.clips != null) { for (int i = 0, l = con.clips.Count; i < l; i++) { if (con.clips[i]) { clipcache[con.clips[i].name] = i; Debug.Log(con.clips[i].name); } else { con.clips.RemoveAt(i); i--; l--; } } } con.clipcache = clipcache; string outpath = path + "/" + clip.name + ".FBAni.asset"; FB.PosePlus.AniClip src = null; /*if (Pretreatment.AnimatorCache.ContainsKey(outpath)) * { * src = Pretreatment.AnimatorCache[outpath]; * } * else * { * AssetDatabase.CreateAsset(_clip, outpath); * src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip; * Pretreatment.AnimatorCache[outpath] = src; * }*/ AssetDatabase.CreateAsset(_clip, outpath); src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip; Pretreatment.AnimatorCache[outpath] = src; con.AddAni(src); }
public static void UpdateCdpath(Animation ani, EditorCurveBinding[] curveDatas, FB.PosePlus.AniClip _clip, FB.PosePlus.AniPlayer con, List <Transform> cdpath) { foreach (var dd in curveDatas) { Transform tran = ani.transform.Find(dd.path); if (tran == null) { Debug.LogWarning("trans not found:" + dd.path); //丢弃无法被找到的动画通道 } else { if (cdpath.Contains(tran) == false) { _clip.boneinfo.Add(tran.name); cdpath.Add(tran); } } } foreach (var b in con.bones) { //if (b.bone.GetComponent<asbone>() != null) { //特别关注的骨骼 if (_clip.boneinfo.Contains(b.bone.name) == false) { _clip.boneinfo.Add(b.bone.name); cdpath.Add(b.bone); } } } Debug.LogWarning("curve got path =" + cdpath.Count); }
void CloneAni(AnimationClip clip, float fps) { var ani = target as Animator; //创建CleanData.Ani FB.PosePlus.AniClip _clip = ScriptableObject.CreateInstance <FB.PosePlus.AniClip>(); _clip.boneinfo = new List <string>();//也增加了每个动画中的boneinfo信息. //这里重新检查动画曲线,找出动画中涉及的Transform部分,更精确 List <Transform> cdpath = new List <Transform>(); var curveDatas = AnimationUtility.GetCurveBindings(clip); //AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true); foreach (var dd in curveDatas) { Transform tran = ani.transform.Find(dd.path); if (cdpath.Contains(tran) == false) { _clip.boneinfo.Add(dd.path); cdpath.Add(tran); } } Debug.LogWarning("curve got path =" + cdpath.Count); string path = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip.GetInstanceID())); _clip.name = clip.name; _clip.frames = new List <FB.PosePlus.Frame>(); _clip.fps = fps; _clip.loop = clip.isLooping; float flen = (clip.length * fps); int framecount = (int)flen; if (flen - framecount > 0.0001) { framecount++; } //if (framecount < 1) framecount = 1; framecount += 1; FB.PosePlus.Frame last = null; //ani.StartPlayback(); //逐帧复制 //ani.Play(_clip.name, 0, 0); for (int i = 0; i < framecount; i++) { ani.Play(_clip.name, 0, (i * 1.0f / fps) / clip.length); ani.Update(0); last = new FB.PosePlus.Frame(last, i, cdpath); _clip.frames.Add(last); } if (_clip.loop) { _clip.frames[0].LinkLoop(last); } Debug.Log("FrameCount." + framecount); FB.PosePlus.AniPlayer con = ani.GetComponent <FB.PosePlus.AniPlayer>(); List <FB.PosePlus.AniClip> clips = null; if (con.clips != null) { clips = new List <FB.PosePlus.AniClip>(con.clips); } else { clips = new List <FB.PosePlus.AniClip>(); } foreach (var c in clips) { if (c.name == _clip.name + ".FBAni") { clips.Remove(c); break; } } //ani.StopPlayback(); string outpath = path + "/" + clip.name + ".FBAni.asset"; AssetDatabase.CreateAsset(_clip, outpath); var src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip; //设置clip //FB.CleanData.AniController con = ani.GetComponent<FB.CleanData.AniController>(); clips.Add(src); con.clips = clips; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (con == null) { EditorApplication.update += this._OnUpdate; } con = target as FB.PosePlus.AniPlayer; if (con == null) { return; } if (con.Clips == null) { con.Clips = new List <FB.PosePlus.AniClip>(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("向左")) { con.SetDir(-1); } GUILayout.Space(10); if (GUILayout.Button("向右")) { con.SetDir(1); } GUILayout.EndHorizontal(); { foreach (var c in con.Clips) { if (c == null) { continue; } GUILayout.BeginHorizontal(); if (c.frames == null) { continue; } GUILayout.Label(c.name + "(" + (c.loop ? "loop" : "") + c.frames.Count + ")"); if (GUILayout.Button("play", GUILayout.Width(150))) { con.Play(c.name); //con.Play(); bPlay = true; //return; //CloneAni(c); } if (GUILayout.Button("cross 0.2", GUILayout.Width(150))) { con.Play(c.name); bPlay = true; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(40); GUILayout.BeginVertical(); foreach (var sub in c.subclips) { GUILayout.BeginHorizontal(); GUILayout.Label(sub.name + (sub.loop ? "[Loop]" : "") + "(" + (sub.endframe - sub.startframe + 1) + ")"); if (GUILayout.Button("play", GUILayout.Width(100))) { con.Play(c.name, sub.name); bPlay = true; } if (GUILayout.Button("cross 0.2", GUILayout.Width(100))) { con.Play(c.name, sub.name); bPlay = true; } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } { //动画控制 GUILayout.BeginHorizontal(); if (GUILayout.Button("stopAni", GUILayout.Width(150))) { bPlay = false; //con.Stop(); } if (GUILayout.Button("AddTime", GUILayout.Width(150))) { con._OnUpdate(0.04f); } GUILayout.EndHorizontal(); } { if (GUILayout.Button("显示/隐藏Box")) { var ani = target as FB.PosePlus.AniPlayer; ani.isShowBoxLine = !ani.isShowBoxLine; var trans = con.transform.Find("_boxes"); if (trans == null) { Debug.LogError("没有找到_boxes"); } foreach (Transform t in trans) { var o = t.gameObject; if (ani.isShowBoxLine) { if (!o.GetComponent <Collider_Vis>()) { o.AddComponent <Collider_Vis>(); } if (!o.GetComponent <LineRenderer>()) { o.AddComponent <LineRenderer>(); } if (!o.GetComponent <MeshRenderer>()) { o.AddComponent <MeshRenderer>(); } ani.SetBoxColor(o); //o.GetComponent<Collider_Vis>().updateColl(); } else { if (o.GetComponent <Collider_Vis>()) { DestroyImmediate(o.GetComponent <Collider_Vis>()); } if (o.GetComponent <LineRenderer>()) { DestroyImmediate(o.GetComponent <LineRenderer>()); } if (o.GetComponent <MeshRenderer>()) { DestroyImmediate(o.GetComponent <MeshRenderer>()); } } } var _trans = con.transform.Find("_dotes"); if (trans == null) { Debug.LogError("没有找到_dotes"); } foreach (Transform t in _trans) { var o = t.gameObject; if (ani.isShowBoxLine) { /* if (!o.GetComponent<LineRenderer>())*/ o.GetComponent <LineRenderer>().enabled = true; } else { /* if (o.GetComponent<LineRenderer>())*/ o.GetComponent <LineRenderer>().enabled = false; } } } if (GUILayout.Button("匹配所有动画的骨骼")) { var win = EditorWindow.GetWindow <EditorWindow_FBAniCheck>("动作检测"); win.Show(target as AniPlayer); } GUI.color = Color.red; if (GUILayout.Button("寻找丢失动画")) { FindLoseAni(); } GUI.color = GUI.contentColor; } }
/// <summary> /// 1、人物控制器更新 /// 2、里面控制这人物状态机的更新 /// 3、摇杆更新 /// </summary> /// <param name="delta"></param> public void OnUpdate(float delta) { if (fightFSM != null) { fightFSM.Update(); if (Death) { //怪物死亡之后,三秒钟销毁怪物 deathTimer += delta; if (deathTimer >= 15f) { (battleField as BattleField).Cmd_Char_Death(idCare); fightFSM = null; aniplayer = null; graphchar = null; logicchar = null; } return; } } else { return; //死亡了直接return; } if (iLife > -1) { iLife--; if (iLife == -1) { Death = true; } } timer += Time.deltaTime; if (hitcount > lastcount) { lastcount = hitcount; timer = 0; } if (timer > intervaltime) { hitcount = lastcount = 0; } var ap = (battleField as BattleField).GetRealChar(idCare); if (ap == null) { return; } var cc = ap.transform.GetComponent <FB.FFSM.com_FightFSM>(); cc.Hp = this.logicchar.GetParam("hp"); //更新方向 if (attackDir != aniplayer.dir) { attackDir = aniplayer.dir; } if (cc.Hp <= 0) { if (fightFSM.isCanDeath) { Death = true; } else { Debug.Log("该状态下不能死亡!"); } } if (joy != null) { joy.SetCharDir(aniplayer.chardir); joy.Update(); } }
public override void OnInspectorGUI() { if (this.target == null) { return; } base.OnInspectorGUI(); if (Application.isPlaying) { return; } EditorGUILayout.HelpBox("这里增加一个Inspector,用来检查动画和产生CleanData.Ani", MessageType.Info); //GUILayout.Label("1:" + this.serializedObject); //GUILayout.Label("2:" + this.target); //return; var ani = target as Animator; FB.PosePlus.AniPlayer con = ani.GetComponent <FB.PosePlus.AniPlayer>(); if (con == null) { if (GUILayout.Button("添加CleanData.Ani组件")) { con = ani.gameObject.AddComponent <FB.PosePlus.AniPlayer>(); ani.enabled = false; } } else { GUILayout.Label("已经有CleanData.Ani"); List <AnimationClip> clips = new List <AnimationClip>(); //if (GUILayout.Button("Update Clips")) //{ UnityEditor.Animations.AnimatorController cc = ani.runtimeAnimatorController as UnityEditor.Animations.AnimatorController; if (cc != null) { FindAllAniInControl(cc, clips); GUILayout.Label("拥有动画:" + clips.Count); if (GUILayout.Button("重新生成所有 FBAaniClip")) {//用最粗暴的方式清理 con.Clips = null; foreach (var c in clips) { CloneAni(c, c.frameRate); } return; } //} foreach (var c in clips) { if (c == null) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(c.name + "(" + c.length * c.frameRate + ")"); if (GUILayout.Button("Create FBAniClip", GUILayout.Width(150))) { CloneAni(c, c.frameRate); } //if (GUILayout.Button("clone fps=16", GUILayout.Width(150))) //{ // CloneAni(c, 16); //} GUILayout.EndHorizontal(); if (anipos.ContainsKey(c.name) == false) { anipos[c.name] = 0; } float v = anipos[c.name]; v = GUILayout.HorizontalSlider(v, 0, c.length); if (v != anipos[c.name]) { anipos[c.name] = v; ani.Play(c.name, 0, v / c.length); ani.updateMode = AnimatorUpdateMode.UnscaledTime; ani.Update(0); } } } } }
void SelfInit(FB.PosePlus.AniPlayer ani, string tag) { this.ani = ani; this.tag = tag; }
//从一个Animator中获取所有的Animation public static void CloneAni(UnityEngine.AnimationClip clip, float fps, Animator ani) { //创建CleanData.Ani FB.PosePlus.AniClip _clip = ScriptableObject.CreateInstance <FB.PosePlus.AniClip>(); _clip.boneinfo = new List <string>();//也增加了每个动画中的boneinfo信息. //这里重新检查动画曲线,找出动画中涉及的Transform部分,更精确 List <Transform> cdpath = new List <Transform>(); var curveDatas = AnimationUtility.GetCurveBindings(clip); //AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true); foreach (var dd in curveDatas) { Transform tran = ani.transform.Find(dd.path); if (tran == null) { Debug.LogWarning("trans not found:" + dd.path); //丢弃无法被找到的动画通道 } else { if (cdpath.Contains(tran) == false) { _clip.boneinfo.Add(tran.name); cdpath.Add(tran); } } } FB.PosePlus.AniPlayer con = ani.gameObject.GetComponent <FB.PosePlus.AniPlayer>(); foreach (var b in con.bones) { //if (b.bone.GetComponent<asbone>() != null) { //特别关注的骨骼 if (_clip.boneinfo.Contains(b.bone.name) == false) { _clip.boneinfo.Add(b.bone.name); cdpath.Add(b.bone); } } } Debug.LogWarning("curve got path =" + cdpath.Count); string path = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(clip.GetInstanceID())); _clip.name = clip.name; _clip.frames = new List <FB.PosePlus.Frame>(); _clip.fps = fps; _clip.loop = clip.isLooping; float flen = (clip.length * fps); int framecount = (int)flen; if (flen - framecount > 0.0001) { framecount++; } //if (framecount < 1) framecount = 1; for (int i = 0, l = clip.events.Length; i < l; i++) { var aniEvent = clip.events[i]; FrameEvent evt = new FrameEvent(); evt.name = aniEvent.functionName; evt.position = aniEvent.time; evt.intVariable = aniEvent.intParameter; evt.floatVariable = aniEvent.floatParameter; evt.stringVariable = aniEvent.stringParameter; _clip.events.Add(evt); } framecount += 1; FB.PosePlus.Frame last = null; //ani.StartPlayback(); //逐帧复制 //ani.Play(_clip.name, 0, 0); for (int i = 0; i < framecount; i++) { ani.Play(mapClip2State[_clip.name], 0, (i * 1.0f / fps) / clip.length); ani.Update(0); last = new FB.PosePlus.Frame(_clip, con, last, i, ani.transform, cdpath); _clip.frames.Add(last); } //特殊处理:写文件后,clips中的内容会丢失 //这里用clipcache保存clips的内容 //Debug.Log(con.clips[0].name); Dictionary <string, int> clipcache = new Dictionary <string, int>(); if (con.clips != null) { for (int i = 0; i < con.clips.Count; i++) { if (con.clips[i]) { clipcache[con.clips[i].name] = i; } else { con.clips.RemoveAt(i); } } } con.clipcache = clipcache; string outpath = PathHelper.CheckFileName(path + "/" + ani.gameObject.name + "_" + clip.name + ".FBAni.asset"); /*FB.PosePlus.AniClip src = null; * if (Pretreatment.AnimatorCache.ContainsKey(outpath)) * { * src = Pretreatment.AnimatorCache[outpath]; * } * else * { * AssetDatabase.CreateAsset(_clip, outpath); * src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip; * Pretreatment.AnimatorCache[outpath] = src; * }*/ AssetDatabase.CreateAsset(_clip, outpath); var src = AssetDatabase.LoadAssetAtPath(outpath, typeof(FB.PosePlus.AniClip)) as FB.PosePlus.AniClip; Pretreatment.AnimatorCache[outpath] = src; src.clipName = PathHelper.CheckFileName(clip.name); con.AddAni(src); }