Пример #1
0
    public void Init()
    {
        TextAsset    act  = Resources.Load <TextAsset>(string.Format("{0}/characteract", Main.Ins.AppInfo.MeteorVersion));
        MemoryStream ms   = new MemoryStream(act.bytes);
        StreamReader text = new StreamReader(ms);

        //添加基本输入支持
        Root           = new ActionNode();
        Root.ActionIdx = 0;
        Root.KeyMap    = 0;//也就是什么都不输入,直接可以切换到Idle。
        Whole.Add(0, Root);

        //预备动作与IDLE类似

        //与IDLE并级别的.跑,左移,右移,后移,跳,左跳, 右跳, 后跳,(新增 怒气满 且防御时)
        //这些招式都可以往后接任意出招
        List <ActionNode> level0 = new List <ActionNode>();

        for (int i = 10; i < 11; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //准备动作
        for (int i = CommonAction.DartReady; i <= CommonAction.HammerReady; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //准备动作
        for (int i = CommonAction.GloveReady; i <= CommonAction.RendaoReady; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //受击动作
        for (int i = 40; i <= 88; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //倒地挣扎
        for (int i = 112; i <= 113; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        for (int i = 117; i < 118; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        for (int i = 140; i <= 148; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //跳跃
        for (int i = 150; i < CommonAction.DCForw; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //普通武器双击方向可以接任意招式
        for (int i = CommonAction.DForw4; i <= CommonAction.DBack6; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //远程武器双击方向滚动可以接任何招式-(处理远程武器大招-滚动完毕后再出招BUG)
        for (int i = CommonAction.DCForw; i <= CommonAction.DCBack; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        int    line = 1;
        string sV   = "";

        while (!text.EndOfStream)
        {
            string s = text.ReadLine();
            if (string.IsNullOrEmpty(s))
            {
                continue;
            }
            if (s.StartsWith("#"))
            {
                continue;
            }
            int subIndex = s.IndexOf('#');
            if (subIndex != -1)
            {
                s = s.Substring(0, subIndex);
            }
            sV += s.Trim().ToLower();
            //有的是会跨行的
            if (sV.EndsWith(","))
            {
                continue;
            }

            if (sV.StartsWith("group"))
            {
                string[] actArray = sV.Split(new char[] { '(', '-', ')' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (actArray.Length == 2)
                {
                    int Action = -1;
                    if (int.TryParse(actArray[1], out Action))
                    {
                        ActionNode no = new ActionNode();
                        no.ActionIdx = Action;
                        no.KeyMap    = line;
                        if (!Lines.ContainsKey(line))
                        {
                            Lines.Add(line, new List <int> {
                                Action
                            });
                        }
                        Whole.Add(no.ActionIdx, no);
                        //如果是第一个动作,那么可以从IDLE切换过去
                        Root.AddTargetAction(no);
                        //还可以从顶级非攻击动作进入
                        for (int j = 0; j < level0.Count; j++)
                        {
                            level0[j].AddTargetAction(no);
                        }
                    }
                }
                else if (actArray.Length == 3)
                {
                    int ActionStart = -1;
                    int ActionEnd   = -1;
                    if (int.TryParse(actArray[1], out ActionStart) && int.TryParse(actArray[2], out ActionEnd))
                    {
                        for (int i = 0; i <= ActionEnd - ActionStart; i++)
                        {
                            ActionNode no = new ActionNode();
                            no.ActionIdx = i + ActionStart;
                            no.KeyMap    = line;
                            if (!Lines.ContainsKey(line))
                            {
                                Lines.Add(line, new List <int> {
                                    no.ActionIdx
                                });
                            }
                            else
                            {
                                Lines[line].Add(no.ActionIdx);
                            }
                            Whole.Add(no.ActionIdx, no);
                            //如果是第一个动作,那么可以从IDLE切换过去
                            if (i == 0)
                            {
                                Root.AddTargetAction(no);
                                for (int j = 0; j < level0.Count; j++)
                                {
                                    level0[j].AddTargetAction(no);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Debug.LogError("!!!");
                }
                line++;
            }
            else
            {
                string[] actArray = sV.Split(new char[] { '(', ',', ')', '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (actArray.Length > 1)
                {
                    int        Action = -1;
                    ActionNode src    = null;
                    if (int.TryParse(actArray[0], out Action))
                    {
                        if (Whole.ContainsKey(Action))
                        {
                            src = Whole[Action];
                        }
                        else
                        {
                            //部分招式不接受任何输入。只能从上一个POSE自动切换,类似573 刀小绝2段,是没有任何招式可以后面接他的,而且他也不接受输入
                            //Debug.LogError("action:" + Action + " prev failed");
                            ActionNode no = new ActionNode();
                            no.ActionIdx = Action;
                            no.KeyMap    = -1;//不接受输入
                            Whole.Add(no.ActionIdx, no);
                            src = no;
                        }
                    }
                    if (src != null)
                    {
                        for (int i = 1; i < actArray.Length; i++)
                        {
                            ActionNode target = null;
                            Action = -1;
                            if (int.TryParse(actArray[i], out Action))
                            {
                                target = Whole[Action];
                            }
                            src.AddTargetAction(target);
                        }
                    }
                }
            }
            sV = "";
        }
        ms.Close();
        text.Close();

        //打印一下输入输出对应表
        //List<ActionNode> first = Whole.Values.ToList();
        //for (int i = 0; i < first.Count; i++)
        //{
        //    Log.Write(string.Format("Input:{0} targetAction ={1}", first[i].KeyMap, first[i].ActionIdx));
        //}
    }
    public Dictionary <int, List <int> > Lines = new Dictionary <int, List <int> >();//存储行 与 Pose的关系
    public void Init()
    {
        if (Root != null)
        {
            return;
        }
        //初始化基本输入表
        //基础动作,Idle->移动(前后左右)  Idle->防御(与武器有关系)  Idle->跳(前后左右各动作不同) Idle->双击移动(前后左右) Idle->蹲下
        //蹲下->滚动(前后左右)

        //一些循环的动作,可以退出 (注意是单个键的)
        //从上下左右走动到 空闲
        //    AddInterrupt(CommonAction.WalkLeft, VK_Pose.VK_Idle, (int)EKeyList.KL_KeyA, (int)EInputType.EIT_Release);
        //    AddInterrupt(CommonAction.WalkRight, VK_Pose.VK_Idle, (int)EKeyList.KL_KeyD, (int)EInputType.EIT_Release);
        //    AddInterrupt(CommonAction.Run, VK_Pose.VK_Idle, (int)EKeyList.KL_KeyW, (int)EInputType.EIT_Release);
        //   AddInterrupt(CommonAction.WalkBackward, VK_Pose.VK_Idle, (int)EKeyList.KL_KeyS, (int)EInputType.EIT_Release);
        //    AddInterrupt(CommonAction.RunOnDrug, VK_Pose.VK_Idle, (int)EKeyList.KL_KeyW, (int)EInputType.EIT_Release);

        //空闲->跳跃
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_Jump, (int)EKeyList.KL_Jump, (int)EInputType.EIT_Click);
        ////空闲->防御
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_Defence, (int)EKeyList.KL_Defence, (int)EInputType.EIT_Click);

        //防御姿态在松开防御后转为空闲
        //AddInterrupt(CommonAction.Defence, VK_Pose.VK_Idle, (int)EKeyList.KL_Defence, (int)EInputType.EIT_Releasing);
        //     AddInterrupt(CommonAction.Defence, VK_Pose.VK_Idle, (int)EKeyList.KL_Defence, (int)EInputType.EIT_Release);

        //普通切换武器
        //      AddInterrupt(CommonAction.Idle, VK_Pose.VK_ChangeWeapon1, (int)EKeyList.KL_ChangeWeapon1, (int)EInputType.EIT_Click);
        //      AddInterrupt(CommonAction.Idle, VK_Pose.VK_ChangeWeapon2, (int)EKeyList.KL_ChangeWeapon2, (int)EInputType.EIT_Click);

        //跳跃在空中或者落地过程切换武器1-2
        //AddInterrupt(CommonAction.LongJump, VK_Pose.VK_ChangeWeapon1, (int)EKeyList.KL_ChangeWeapon1, (int)EInputType.EIT_Click);
        //AddInterrupt(CommonAction.LongJump, VK_Pose.VK_ChangeWeapon2, (int)EKeyList.KL_ChangeWeapon2, (int)EInputType.EIT_Click);
        //落地切换武器1-2
        //      AddInterrupt(CommonAction.JumpFall, VK_Pose.VK_ChangeWeapon1, (int)EKeyList.KL_ChangeWeapon1, (int)EInputType.EIT_Click);
        //      AddInterrupt(CommonAction.JumpFall, VK_Pose.VK_ChangeWeapon2, (int)EKeyList.KL_ChangeWeapon2, (int)EInputType.EIT_Click);

        //普通走,中毒走,空闲->移动
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_Run, (int)EKeyList.KL_KeyW, (int)EInputType.EIT_Pressing);
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_WalkBackward, (int)EKeyList.KL_KeyS, (int)EInputType.EIT_Pressing);
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_WalkLeft, (int)EKeyList.KL_KeyA, (int)EInputType.EIT_Pressing);
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_WalkRight, (int)EKeyList.KL_KeyD, (int)EInputType.EIT_Pressing);

        //前后左右方向2连
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_DForw, new List<int> { (int)EKeyList.KL_KeyW, (int)EKeyList.KL_KeyW });
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_DBack, new List<int> { (int)EKeyList.KL_KeyS, (int)EKeyList.KL_KeyS });
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_DLeft, new List<int> { (int)EKeyList.KL_KeyA, (int)EKeyList.KL_KeyA });
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_DRight, new List<int> { (int)EKeyList.KL_KeyD, (int)EKeyList.KL_KeyD });

        //爆气
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_Break, (int)EKeyList.KL_BreakOut, (int)EInputType.EIT_Click);

        //爬墙落下
        //      AddInterrupt(CommonAction.ClimbUp, VK_Pose.VK_Fall, (int)EKeyList.KL_KeyW, (int)EInputType.EIT_Release);
        //      AddInterrupt(CommonAction.ClimbLeft, VK_Pose.VK_Fall, (int)EKeyList.KL_KeyW, (int)EInputType.EIT_Release);
        //      AddInterrupt(CommonAction.ClimbRight, VK_Pose.VK_Fall, (int)EKeyList.KL_KeyW, (int)EInputType.EIT_Release);

        //爬墙 蹬腿,单键判定,不需要方向,要用当前状态算方向
        //       AddInterrupt(CommonAction.ClimbUp, VK_Pose.VK_Jump, (int)EKeyList.KL_Jump, (int)EInputType.EIT_Click);
        //       AddInterrupt(CommonAction.ClimbLeft, VK_Pose.VK_Jump, (int)EKeyList.KL_Jump, (int)EInputType.EIT_Click);
        //       AddInterrupt(CommonAction.ClimbRight, VK_Pose.VK_Jump, (int)EKeyList.KL_Jump, (int)EInputType.EIT_Click);

        //蹲
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_Couch, (int)EKeyList.KL_Crouch, (int)EInputType.EIT_Pressing);
//        AddInterrupt(CommonAction.Crouch, VK_Pose.VK_Idle, (int)EKeyList.KL_Crouch, (int)EInputType.EIT_Release);

        //蹲->滚动
//        AddInterrupt(CommonAction.Crouch, VK_Pose.VK_DForw, new List<int> { (int)EKeyList.KL_KeyW, (int)EKeyList.KL_KeyW });
//       AddInterrupt(CommonAction.Crouch, VK_Pose.VK_DBack, new List<int> { (int)EKeyList.KL_KeyS, (int)EKeyList.KL_KeyS });
//        AddInterrupt(CommonAction.Crouch, VK_Pose.VK_DLeft, new List<int> { (int)EKeyList.KL_KeyA, (int)EKeyList.KL_KeyA });
//        AddInterrupt(CommonAction.Crouch, VK_Pose.VK_DRight, new List<int> { (int)EKeyList.KL_KeyD, (int)EKeyList.KL_KeyD });


        //IDle->上下左右跳
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_JumpForw, new List<int> { (int)EKeyList.KL_KeyW, (int)EKeyList.KL_Jump });
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_JumpBack, new List<int> { (int)EKeyList.KL_KeyS, (int)EKeyList.KL_Jump });
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_JumpLeft, new List<int> { (int)EKeyList.KL_KeyA, (int)EKeyList.KL_Jump });
        //AddInterrupt(CommonAction.Idle, VK_Pose.VK_JumpRight, new List<int> { (int)EKeyList.KL_KeyD, (int)EKeyList.KL_Jump });

        TextAsset    act  = Resources.Load <TextAsset>(Global.MeteorVersion + "/characteract");
        MemoryStream ms   = new MemoryStream(act.bytes);
        StreamReader text = new StreamReader(ms);

        //添加基本输入支持,上下左右,上上,下下,左左,右右,跳,上跳,左跳,右跳,后跳
        //Lines.Add()
        //IDLE是最顶级。
        Root           = new ActionNode();
        Root.ActionIdx = 0;
        Root.KeyMap    = 0;//也就是什么都不输入,直接可以切换到Idle。
        Whole.Add(0, Root);

        //预备动作与IDLE类似

        //与IDLE并级别的.跑,左移,右移,后移,跳,左跳, 右跳, 后跳,(新增 怒气满 且防御时)
        //这些招式都可以往后接任意出招
        List <ActionNode> level0 = new List <ActionNode>();

        for (int i = 10; i < 11; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //准备动作
        for (int i = CommonAction.DartReady; i <= CommonAction.HammerReady; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        //准备动作
        for (int i = CommonAction.ZhihuReady; i <= CommonAction.RendaoReady; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        for (int i = 40; i <= 88; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        for (int i = 140; i <= 148; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        for (int i = 150; i <= 180; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        for (int i = CommonAction.DForw4; i <= CommonAction.DBack6; i++)
        {
            ActionNode n = new ActionNode();
            n.ActionIdx = i;
            n.KeyMap    = 0;
            level0.Add(n);
            Whole.Add(i, n);
        }

        int    line = 1;
        string sV   = "";

        while (!text.EndOfStream)
        {
            string s = text.ReadLine();
            if (string.IsNullOrEmpty(s))
            {
                continue;
            }
            if (s.StartsWith("#"))
            {
                continue;
            }
            int subIndex = s.IndexOf('#');
            if (subIndex != -1)
            {
                s = s.Substring(0, subIndex);
            }
            sV += s.Trim().ToLower();
            //有的是会跨行的
            if (sV.EndsWith(","))
            {
                continue;
            }

            if (sV.StartsWith("group"))
            {
                string[] actArray = sV.Split(new char[] { '(', '-', ')' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (actArray.Length == 2)
                {
                    int Action = -1;
                    if (int.TryParse(actArray[1], out Action))
                    {
                        ActionNode no = new ActionNode();
                        no.ActionIdx = Action;
                        no.KeyMap    = line;
                        if (!Lines.ContainsKey(line))
                        {
                            Lines.Add(line, new List <int> {
                                Action
                            });
                        }
                        Whole.Add(no.ActionIdx, no);
                        //如果是第一个动作,那么可以从IDLE切换过去
                        Root.AddTargetAction(no);
                        //还可以从顶级非攻击动作进入
                        for (int j = 0; j < level0.Count; j++)
                        {
                            level0[j].AddTargetAction(no);
                        }
                    }
                }
                else if (actArray.Length == 3)
                {
                    int ActionStart = -1;
                    int ActionEnd   = -1;
                    if (int.TryParse(actArray[1], out ActionStart) && int.TryParse(actArray[2], out ActionEnd))
                    {
                        for (int i = 0; i <= ActionEnd - ActionStart; i++)
                        {
                            ActionNode no = new ActionNode();
                            no.ActionIdx = i + ActionStart;
                            no.KeyMap    = line;
                            if (!Lines.ContainsKey(line))
                            {
                                Lines.Add(line, new List <int> {
                                    no.ActionIdx
                                });
                            }
                            else
                            {
                                Lines[line].Add(no.ActionIdx);
                            }
                            Whole.Add(no.ActionIdx, no);
                            //如果是第一个动作,那么可以从IDLE切换过去
                            if (i == 0)
                            {
                                Root.AddTargetAction(no);
                                for (int j = 0; j < level0.Count; j++)
                                {
                                    level0[j].AddTargetAction(no);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Debug.LogError("!!!");
                }
                line++;
            }
            else
            {
                string[] actArray = sV.Split(new char[] { '(', ',', ')', '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (actArray.Length > 1)
                {
                    int        Action = -1;
                    ActionNode src    = null;
                    if (int.TryParse(actArray[0], out Action))
                    {
                        if (Whole.ContainsKey(Action))
                        {
                            src = Whole[Action];
                        }
                        else
                        {
                            //部分招式不接受任何输入。只能从上一个POSE自动切换,类似573 刀小绝2段,是没有任何招式可以后面接他的,而且他也不接受输入
                            //Debug.LogError("action:" + Action + " prev failed");
                            ActionNode no = new ActionNode();
                            no.ActionIdx = Action;
                            no.KeyMap    = -1;//不接受输入
                            Whole.Add(no.ActionIdx, no);
                            src = no;
                        }
                    }
                    if (src != null)
                    {
                        for (int i = 1; i < actArray.Length; i++)
                        {
                            ActionNode target = null;
                            Action = -1;
                            if (int.TryParse(actArray[i], out Action))
                            {
                                target = Whole[Action];
                            }
                            src.AddTargetAction(target);
                        }
                    }
                }
            }
            sV = "";
        }
        ms.Close();
        text.Close();

        //打印一下输入输出对应表
        List <ActionNode> first = Whole.Values.ToList();

        for (int i = 0; i < first.Count; i++)
        {
            Log.LogInfo("Input:" + first[i].KeyMap + "targetAction = " + first[i].ActionIdx);
        }
    }