Пример #1
0
    public long GetNextMagicPosAndTime_2D(long nowTime, ref SkillVector3 nextPos)
    {
        if (Speed <= 0 || (Dir.x == 0 && Dir.z == 0) || Dir.x * Dir.z != 0)
        {
            nextPos.x = Pos.x;
            nextPos.z = Pos.z;
            return(nowTime);
        }
        long         time   = -1;
        SkillVector3 nowPos = new SkillVector3();

        GetNextPos_2D(nowTime, ref nowPos);
        if (Dir.x != 0)
        {
            nextPos.x = Clamp(UnifyRound(nowPos.x + f05MinusCenterPoint) + 0.5f * Dir.x - f05MinusCenterPoint, MinX, MaxX);
            nextPos.z = nowPos.z;
            float dis = Mathf.Abs(nextPos.x - nowPos.x);
            time = nowTime + UnifyRound(dis / Speed);
        }
        else if (Dir.z != 0)
        {
            nextPos.z = Clamp(UnifyRound(nowPos.z + f05MinusCenterPoint) + 0.5f * Dir.z - f05MinusCenterPoint, MinX, MaxX);
            nextPos.x = nowPos.x;
            float dis = Mathf.Abs(nextPos.z - nowPos.z);
            time = nowTime + UnifyRound(dis / Speed);
        }
        else
        {
            throw new Exception("");
        }
        return(time);
    }
Пример #2
0
    private MagicMoveRecord CalcNextMMR(MagicMoveRecord last, float dirX, float dirZ, SpeedChangeType speedType, long time, int index, MagicMoveRecord newRecord = null)
    {
        //MagicMoveRecord newRecord = null;
        SkillVector3 curDir   = last.GetDir();
        float        curSpeed = last.GetSpeed();

        if (newRecord == null)
        {
            newRecord = GetNewRecord();
        }
        if (speedType != SpeedChangeType.None)
        {
            SkillVector3 beginPos = new SkillVector3();
            last.GetNextPos_2D(time, ref beginPos);
            //newRecord = GetNewRecord();
            newRecord.SetInitPos(beginPos.x, beginPos.z, time, curDir.x, curDir.z, CalcSpeed(speedType, curSpeed), time, MinX, MaxX, MinZ, MaxZ, speedType, index);

            //FixMMRs(newRecord);
            Log(index + " Speed Changed : " + curSpeed + "---->>>----" + newRecord.GetSpeed() + " BeginPos:" + beginPos.ToString() + " NowPos:" + NextPos.ToString() + " Time:" + newRecord.GetTime());
        }
        else
        {
            SkillVector3 beginPos = new SkillVector3();
            if (last.GetTime() == newRecord.GetTime())
            {
                return(null);
            }
            long nextTime = last.GetNextMagicPosAndTime_2D(time, ref beginPos);
            //newRecord = GetNewRecord();
            newRecord.SetInitPos(beginPos.x, beginPos.z, nextTime, dirX, dirZ, last.GetSpeed(), time, MinX, MaxX, MinZ, MaxZ, speedType, index);
            Log(index + " Dir Changed : " + "(" + curDir.x + "," + curDir.z + ")" + "---->>>----" + "(" + dirX + "," + dirZ + ")" + " BeginPos:" + beginPos.ToString() + " NowPos:" + NextPos.ToString() + " Time:" + newRecord.GetTime());
        }
        return(newRecord);
    }
Пример #3
0
 public SkillVector3 SpecialNormalize(SkillVector3 input)
 {
     input.x = input.x == 0 ? 0 : input.x / Mathf.Abs(input.x);
     input.y = input.y == 0 ? 0 : input.y / Mathf.Abs(input.y);
     input.z = input.z == 0 ? 0 : input.z / Mathf.Abs(input.z);
     return(input);
 }
Пример #4
0
 public static SkillVector3 FsmVector3Popup(GUIContent label, Skill fsm, SkillVector3 fsmVector3)
 {
     EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
     fsmVector3 = VariableEditor.DoFsmVector3Popup(label, fsm, fsmVector3);
     VariableEditor.EndVariableEditor(fsmVector3);
     return(fsmVector3);
 }
Пример #5
0
 public void InitShadow(long time, SkillVector3 pos, SkillVector3 dir, float shadowSpeed)
 {
     LastTime  = time;
     LastPos   = pos;
     LastDir   = dir;
     LastSpeed = shadowSpeed;
     FollowList.Clear();
 }
Пример #6
0
    public void Clear()
    {
        MMRs.Clear();
        NextPos     = NextPos * 0;
        NextPosTime = -1;

        BacktrackingPoints.Clear();
        TrackingPoints.Clear();

        MinX = -1;
        MaxX = -1;
        MinZ = -1;
        MaxZ = -1;
    }
Пример #7
0
 public static SkillVector3 FsmVector3Field(GUIContent label, Skill fsm, SkillVector3 fsmVector3)
 {
     EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
     if (fsmVector3.get_UseVariable())
     {
         fsmVector3 = VariableEditor.DoFsmVector3Popup(label, fsm, fsmVector3);
     }
     else
     {
         fsmVector3.set_Value(EditorGUILayout.Vector3Field(label.get_text(), fsmVector3.get_Value(), new GUILayoutOption[0]));
     }
     fsmVector3 = (SkillVector3)VariableEditor.VariableToggle(fsmVector3, label.get_text());
     VariableEditor.EndVariableEditor(fsmVector3);
     return(fsmVector3);
 }
Пример #8
0
    public bool AddMoveCtrlCommand(long time, float dirX, float dirZ, SpeedChangeType speedType, int index)
    {
        Log("Enter AddMoveCtrlCommand:" + time);
        if (dirX == 0 && dirZ == 0 && speedType == SpeedChangeType.None)
        {
            Log("dirX == 0 && dirZ == 0 && speedType == SpeedChangeType.None");
            Log("Leave AddMoveCtrlCommand:" + time);
            return(false);
        }

        var previous = FindPreviousMMR(time);

        Log("previous:" + previous.ToString());

        SkillVector3 curDir = previous.GetDir();

        if (curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None)
        {
            Log("curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None");
            Log("Leave AddMoveCtrlCommand:" + time);
            return(false);
        }

        MagicMoveRecord newRecord = CalcNextMMR(previous, dirX, dirZ, speedType, time, index);

        var realPrevious = AddRecord(newRecord);

        if (realPrevious == null)
        {
            Log(" AddRecord(newRecord) failed:");
            Log("Leave AddMoveCtrlCommand:" + time);
            return(false);
        }
        Log("RealPrevious:" + realPrevious.ToString());

        var beforeTime = newRecord.GetTime();

        FixMMRs(realPrevious);

        if (beforeTime != newRecord.GetTime())
        {
            Log("Lesdfsdfave sfaf:" + newRecord);
        }
        Log("Leave AddMoveCtrlCommand:" + time);
        return(true);
    }
Пример #9
0
    public void Clear()
    {
        NextPos     = NextPos * 0;
        NextPosTime = -1;
        CurMagicRecord.Clear();
        foreach (MagicMoveRecord tmp in HistoryRecords)
        {
            tmp.Clear();
            recordsCache.Add(tmp);
        }
        HistoryRecords.Clear();

        FutureExeMoves.Clear();
        CurNeedExeMoves.Clear();
        BacktrackingPoints.Clear();
        TrackingPoints.Clear();
        NeedFixRecords.Clear();
    }
Пример #10
0
    public void GetNextPos_2D(long NowTime_Ms_Long, ref SkillVector3 pos)
    {
        long diffTime = Compare(NowTime_Ms_Long);

        if (diffTime > 0)
        {
            double r   = Mathf.Sqrt(Mathf.Pow(Dir.x, 2) + Mathf.Pow(Dir.z, 2));
            double sin = r == 0 ? 0 : Dir.z / r;
            double cos = r == 0 ? 0 : Dir.x / r;
            pos.x = Clamp((float)(Pos.x + cos * Speed * diffTime), MinX, MaxX);
            pos.z = Clamp((float)(Pos.z + sin * Speed * diffTime), MinZ, MaxZ);
        }
        else if (diffTime <= 0)
        {
            pos.x = Pos.x;
            pos.z = Pos.z;
            //throw new Exception("else if(diffTime < 0)");
        }
        //      else
        //      {
        //          throw new Exception("需要辅助参数来确定顺序,否则会出现客户端服务器不一致 3333333333333333333");
        //      }
    }
Пример #11
0
 public void GetNextPos_2D(long NowTime_Ms_Long, ref SkillVector3 pos)
 {
     CurMagicRecord.GetNextPos_2D(NowTime_Ms_Long, ref pos);
 }
Пример #12
0
    public void TestAddMoveCtrlCommand(long time, float dirX, float dirZ, SpeedChangeType speedType, int index)
    {
        DebugSkillUpDown("Before ADD");
        //检查是否是合法参数
        //如果这个时间点比服务器时间更早
        //if(time <= CurMagicRecord.GetTime())
        //{
        // throw new Exception("这个时间点比服务器时间更早:" + time + "@" + NowTime_Ms_Long );
        //}
        //先找到该时间点前一个MagicMoveRecord是哪个,可能是当前的MagicMoveRecord,也可能是缓存队列里某一个,所以遍历一下
        //上边已经排除了一个不可能的情况,现在看其他情况
        {
            NeedFixRecords.Clear();

            MagicMoveRecord cmdLastRecord = null;
            FindCMDType     find          = FindCMDType.None;
            int             findIdx       = -1;
            if (HistoryRecords.Count > 0)
            {
                for (int i = HistoryRecords.Count - 1; i >= 0; i--)
                {
                    MagicMoveRecord tmp = HistoryRecords[i];
                    if (tmp.GetTime() <= time && tmp.GetCMDTime() <= time)
                    {
                        cmdLastRecord = tmp;
                        break;
                    }
                    else
                    {
                        findIdx = i;
                        find    = FindCMDType.History;
                    }
                }
            }

            {
                if (find == FindCMDType.None)
                {
                    if (CurMagicRecord != null && CurMagicRecord.GetTime() <= time && CurMagicRecord.GetCMDTime() <= time)
                    {
                        cmdLastRecord = CurMagicRecord;
                        //Log("CurMagicRecord:" + CurMagicRecord.ToString());
                    }
                    else
                    {
                        find = FindCMDType.Now;
                    }
                }
                if (find == FindCMDType.None)
                {
                    if (FutureExeMoves.Count > 0)
                    {
                        foreach (var tmp in FutureExeMoves)
                        {
                            //Log("FutureExeMoves:" + tmp.ToString());
                            if (tmp.GetTime() <= time && tmp.GetCMDTime() <= time)
                            {
                                cmdLastRecord = tmp;
                            }
                            else
                            {
                                findIdx = FutureExeMoves.IndexOf(tmp);
                                find    = FindCMDType.Future;
                                //这是个优先权队列,所以一旦发现不满足了就都不用检查了
                                break;
                            }
                        }
                    }
                }
            }

            Log("LastMoveCmd:" + cmdLastRecord.ToString());
            //根据上一个关键节点计算这个关键节点
            if (dirX == 0 && dirZ == 0 && speedType == SpeedChangeType.None)
            {
                Log("dirX == 0 && dirZ == 0");
                return;
            }
            SkillVector3 curDir   = cmdLastRecord.GetDir();
            float        curSpeed = cmdLastRecord.GetSpeed();
            if (curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None)
            {
                Log("curDir.x == dirX && curDir.z == dirZ && speedType == SpeedChangeType.None");
                return;
            }
            MagicMoveRecord newRecord = CalcNextMMR(cmdLastRecord, dirX, dirZ, speedType, time, index);
            Log(" find ret :" + find);
            //速度改变的情况
            //if (speedType != SpeedChangeType.None)
            {
                switch (find)
                {
                case FindCMDType.Future:
                {
                    if (FutureExeMoves.Count > findIdx)
                    {
                        NeedFixRecords.AddRange(FutureExeMoves.GetRange(findIdx, FutureExeMoves.Count - findIdx));
                        FutureExeMoves.RemoveRange(findIdx, FutureExeMoves.Count - findIdx);
                    }
                }
                break;

                case FindCMDType.History:
                {
                    if (HistoryRecords.Count > findIdx)
                    {
                        NeedFixRecords.AddRange(HistoryRecords.GetRange(findIdx, HistoryRecords.Count - findIdx));
                        HistoryRecords.RemoveRange(findIdx, HistoryRecords.Count - findIdx);
                    }

                    if (findIdx == 0)
                    {
                        throw new Exception("findIdx == 0");
                    }

                    NeedFixRecords.Add(CurMagicRecord);
                    CurMagicRecord = HistoryRecords[findIdx - 1];
                    HistoryRecords.RemoveAt(findIdx - 1);

                    if (FutureExeMoves.Count > 0)
                    {
                        NeedFixRecords.AddRange(FutureExeMoves);
                        FutureExeMoves.Clear();
                    }
                }
                break;

                case FindCMDType.Now:
                {
                    NeedFixRecords.Add(CurMagicRecord);
                    if (HistoryRecords.Count == 0)
                    {
                        throw new Exception("HistoryRecords.Count() == 0");
                    }
                    CurMagicRecord = HistoryRecords[HistoryRecords.Count - 1];
                    HistoryRecords.RemoveAt(HistoryRecords.Count - 1);
                    if (FutureExeMoves.Count > 0)
                    {
                        NeedFixRecords.AddRange(FutureExeMoves);
                        FutureExeMoves.Clear();
                    }
                }
                break;
                }

                newRecord = FixMMRs(newRecord);
                //Log(index + " Speed Changed : " + curSpeed + "---->>>----" + speed + " BeginPos:" + beginPos.ToString() + " NowPos:" + NextPos.ToString());
            }
            if (newRecord.GetTime() > cmdLastRecord.GetTime() || (newRecord.GetTime() == cmdLastRecord.GetTime() && newRecord.GetSpeedType() != SpeedChangeType.None))
            {
                bool bAdd = true;
                foreach (var tmp in FutureExeMoves)
                {
                    if (tmp.GetTime() == newRecord.GetTime() && tmp.GetSpeedType() == SpeedChangeType.None && newRecord.GetSpeedType() == SpeedChangeType.None)
                    {
                        bAdd = false;
                    }
                }
                if (CurMagicRecord != null && CurMagicRecord.GetTime() == newRecord.GetTime() && CurMagicRecord.GetSpeedType() == SpeedChangeType.None && newRecord.GetSpeedType() == SpeedChangeType.None)
                {
                    bAdd = false;
                }
                if (bAdd)
                {
                    AddFutureExeMoves(newRecord);
                    if (newRecord.GetSpeedType() == SpeedChangeType.SkillUp)
                    {
                        skillupcount++;
                    }
                    else if (newRecord.GetSpeedType() == SpeedChangeType.SkillDown)
                    {
                        skilldowncount++;
                    }
                }
                else
                {
                    Log("abandon 222 " + newRecord.ToString());
                }
            }
            else
            {
                Log("abandon " + newRecord.ToString());
                if (newRecord.GetSpeedType() != SpeedChangeType.None)
                {
                    DebugConsole.LogError("SDFEARYTHRTHGFHGDSFSDFSDFSDAF");
                }
            }
        }
        {
            FixToFuture();
        }
        DebugSkillUpDown("After ADD");
    }
Пример #13
0
 private static SkillVector3 DoFsmVector3Popup(GUIContent label, Skill fsm, SkillVector3 fsmVector3)
 {
     ActionEditor.DoVariableSelector(label, fsm, 6, fsmVector3, -1, null);
     fsmVector3.set_UseVariable(true);
     return(fsmVector3);
 }
Пример #14
0
 private static void NetworkSyncVariables(BitStream stream, SkillVariables variables)
 {
     SkillInt[]        intVariables;
     SkillQuaternion[] quaternionVariables;
     SkillVector3[]    vector3Variables;
     SkillColor[]      colorVariables;
     SkillVector2[]    vector2Variables;
     if (stream.get_isWriting())
     {
         SkillString[] stringVariables = variables.StringVariables;
         for (int i = 0; i < stringVariables.Length; i++)
         {
             SkillString fsmString = stringVariables[i];
             if (fsmString.NetworkSync)
             {
                 char[] array = fsmString.Value.ToCharArray();
                 int    num   = array.Length;
                 stream.Serialize(ref num);
                 for (int j = 0; j < num; j++)
                 {
                     stream.Serialize(ref array[j]);
                 }
             }
         }
         SkillBool[] boolVariables = variables.BoolVariables;
         for (int k = 0; k < boolVariables.Length; k++)
         {
             SkillBool fsmBool = boolVariables[k];
             if (fsmBool.NetworkSync)
             {
                 bool value = fsmBool.Value;
                 stream.Serialize(ref value);
             }
         }
         SkillFloat[] floatVariables = variables.FloatVariables;
         for (int l = 0; l < floatVariables.Length; l++)
         {
             SkillFloat fsmFloat = floatVariables[l];
             if (fsmFloat.NetworkSync)
             {
                 float value2 = fsmFloat.Value;
                 stream.Serialize(ref value2);
             }
         }
         intVariables = variables.IntVariables;
         for (int m = 0; m < intVariables.Length; m++)
         {
             SkillInt fsmInt = intVariables[m];
             if (fsmInt.NetworkSync)
             {
                 int value3 = fsmInt.Value;
                 stream.Serialize(ref value3);
             }
         }
         quaternionVariables = variables.QuaternionVariables;
         for (int n = 0; n < quaternionVariables.Length; n++)
         {
             SkillQuaternion fsmQuaternion = quaternionVariables[n];
             if (fsmQuaternion.NetworkSync)
             {
                 Quaternion value4 = fsmQuaternion.Value;
                 stream.Serialize(ref value4);
             }
         }
         vector3Variables = variables.Vector3Variables;
         for (int num2 = 0; num2 < vector3Variables.Length; num2++)
         {
             SkillVector3 fsmVector = vector3Variables[num2];
             if (fsmVector.NetworkSync)
             {
                 Vector3 value5 = fsmVector.Value;
                 stream.Serialize(ref value5);
             }
         }
         colorVariables = variables.ColorVariables;
         for (int num3 = 0; num3 < colorVariables.Length; num3++)
         {
             SkillColor fsmColor = colorVariables[num3];
             if (fsmColor.NetworkSync)
             {
                 Color value6 = fsmColor.Value;
                 stream.Serialize(ref value6.r);
                 stream.Serialize(ref value6.g);
                 stream.Serialize(ref value6.b);
                 stream.Serialize(ref value6.a);
             }
         }
         vector2Variables = variables.Vector2Variables;
         for (int num4 = 0; num4 < vector2Variables.Length; num4++)
         {
             SkillVector2 fsmVector2 = vector2Variables[num4];
             if (fsmVector2.NetworkSync)
             {
                 Vector2 value7 = fsmVector2.Value;
                 stream.Serialize(ref value7.x);
                 stream.Serialize(ref value7.y);
             }
         }
         return;
     }
     SkillString[] stringVariables2 = variables.StringVariables;
     for (int num5 = 0; num5 < stringVariables2.Length; num5++)
     {
         SkillString fsmString2 = stringVariables2[num5];
         if (fsmString2.NetworkSync)
         {
             int num6 = 0;
             stream.Serialize(ref num6);
             char[] array2 = new char[num6];
             for (int num7 = 0; num7 < num6; num7++)
             {
                 stream.Serialize(ref array2[num7]);
             }
             fsmString2.Value = new string(array2);
         }
     }
     SkillBool[] boolVariables2 = variables.BoolVariables;
     for (int num8 = 0; num8 < boolVariables2.Length; num8++)
     {
         SkillBool fsmBool2 = boolVariables2[num8];
         if (fsmBool2.NetworkSync)
         {
             bool value8 = false;
             stream.Serialize(ref value8);
             fsmBool2.Value = value8;
         }
     }
     SkillFloat[] floatVariables2 = variables.FloatVariables;
     for (int i = 0; i < floatVariables2.Length; i++)
     {
         SkillFloat fsmFloat2 = floatVariables2[i];
         if (fsmFloat2.NetworkSync)
         {
             float value9 = 0f;
             stream.Serialize(ref value9);
             fsmFloat2.Value = value9;
         }
     }
     intVariables = variables.IntVariables;
     for (int i = 0; i < intVariables.Length; i++)
     {
         SkillInt fsmInt2 = intVariables[i];
         if (fsmInt2.NetworkSync)
         {
             int value10 = 0;
             stream.Serialize(ref value10);
             fsmInt2.Value = value10;
         }
     }
     quaternionVariables = variables.QuaternionVariables;
     for (int i = 0; i < quaternionVariables.Length; i++)
     {
         SkillQuaternion fsmQuaternion2 = quaternionVariables[i];
         if (fsmQuaternion2.NetworkSync)
         {
             Quaternion identity = Quaternion.get_identity();
             stream.Serialize(ref identity);
             fsmQuaternion2.Value = identity;
         }
     }
     vector3Variables = variables.Vector3Variables;
     for (int i = 0; i < vector3Variables.Length; i++)
     {
         SkillVector3 fsmVector3 = vector3Variables[i];
         if (fsmVector3.NetworkSync)
         {
             Vector3 zero = Vector3.get_zero();
             stream.Serialize(ref zero);
             fsmVector3.Value = zero;
         }
     }
     colorVariables = variables.ColorVariables;
     for (int i = 0; i < colorVariables.Length; i++)
     {
         SkillColor fsmColor2 = colorVariables[i];
         if (fsmColor2.NetworkSync)
         {
             float num9 = 0f;
             stream.Serialize(ref num9);
             float num10 = 0f;
             stream.Serialize(ref num10);
             float num11 = 0f;
             stream.Serialize(ref num11);
             float num12 = 0f;
             stream.Serialize(ref num12);
             fsmColor2.Value = new Color(num9, num10, num11, num12);
         }
     }
     vector2Variables = variables.Vector2Variables;
     for (int i = 0; i < vector2Variables.Length; i++)
     {
         SkillVector2 fsmVector4 = vector2Variables[i];
         if (fsmVector4.NetworkSync)
         {
             float num13 = 0f;
             stream.Serialize(ref num13);
             float num14 = 0f;
             stream.Serialize(ref num14);
             fsmVector4.Value = new Vector2(num13, num14);
         }
     }
 }
Пример #15
0
    public SkillVector3 GetNextPos(long time, SkillVector3 shadowPos, SkillVector3 shadowDir, float shadowSpeed, List <SkillVector3> bkps, List <SkillVector3> tps)
    {
        long DeltaTime = time - LastTime;

        if (DeltaTime <= 0 || LastPos.Distance_Horizontal_Vertical(shadowPos) <= shadowSpeed * (time - LastTime))
        {
            InitShadow(time, shadowPos, shadowDir, shadowSpeed);
        }
        else
        {
            //这里说明位置距离比较大,需要加速追上影子,离影子越远速度就越大

            if (bkps.Count > 0)
            {
                FollowList.AddRange(bkps.Reverse <SkillVector3>());
            }
            if (tps.Count > 0)
            {
                FollowList.AddRange(tps);
            }
            if (FollowList.Count > 0)
            {
                //有的时候点比较多,中间还可能有重复经过的点,就把中间的部分直接干掉,省略一些路径
                FollowListSkip();

                //直接求位置,跳过求速度,但是会记录速度
                var dis = CalcAllDis();
                if (dis > shadowSpeed * DeltaTime)
                {
                    var moveDis = shadowSpeed * 2 * DeltaTime;
                    if (moveDis >= dis)
                    {
                        //Debug.LogError("if(moveDis >= dis) followed shadow :" + FollowList[FollowList.Count - 1]);
                        LastDir  *= 0;                       //需要计算一下
                        LastSpeed = 0;
                        LastPos   = FollowList[FollowList.Count - 1];
                        FollowList.Clear();
                    }
                    else
                    {
                        //Debug.LogError("move " + moveDis + " Alldis:" + dis + " DeltaTime:" + DeltaTime);
                        LastDir  *= 0;                       //需要计算一下
                        LastSpeed = 0;
                        LastPos   = Move(moveDis);
                    }
                }
                else
                {
                    //Debug.LogWarning("followed shadow :" + FollowList[FollowList.Count - 1]);
                    LastDir  *= 0;                   //需要计算一下
                    LastSpeed = 0;
                    LastPos   = FollowList[FollowList.Count - 1];
                    FollowList.Clear();
                }
            }
            else
            {
                Debug.LogError("! if (FollowList.Count > 0)");
            }


            LastTime = time;
        }
        return(LastPos);
    }
Пример #16
0
        public override void Update(SkillObjMoveController ctrl, SkillBulletMove move, float deltaTime, float timeMS)
        {
            base.Update(ctrl, move, deltaTime, timeMS);
            var tarPos = ctrl.GetVecParam();

            if (move.SpeedDirection.x == 0 && move.SpeedDirection.y == 0)
            {
                SkillVector3 lastPos = move.GetMoveStruct().position;
                var          disX    = tarPos.x - lastPos.x;
                var          disZ    = tarPos.y - lastPos.y;
                if (disX * disX + disZ * disZ <= 0.3 * 0.3)
                {
                    move.SpeedValue = 0;
                    var action = ctrl.GetMoveCallBackAction();
                    if (action != null)
                    {
                        action(ctrl);
                    }
                }
            }
            else
            {
                //                      P(tarPos)
                //                     /|
                //                    / |
                //                   /  |
                //         (lastPos)A————*————————————B(p)
                //                      C(AP在AB上的投影点)
                SkillVector3?lastPos = null;
                foreach (var p in move.GetMovingTrajectory())
                {
                    if (lastPos != null)
                    {
                        SkillVector3 AP          = tarPos - lastPos.Value;
                        SkillVector3 AB          = p - lastPos.Value;;
                        var          dot_AB_AP   = AB.Dot2D(AP);
                        var          disAB_Pow_2 = AB.DisPow2();
                        double       min_P2AB    = 0;
                        if (dot_AB_AP <= 0)
                        {
                            //AP
                            min_P2AB = AP.DisPow2();
                        }
                        else if (dot_AB_AP >= disAB_Pow_2)
                        {
                            //BP
                            min_P2AB = (p - tarPos).DisPow2();
                        }
                        else
                        {
                            //PC = -AP + AC
                            min_P2AB = (-AP + (dot_AB_AP / disAB_Pow_2) * AB).DisPow2();
                        }
                        if (min_P2AB <= 0.3 * 0.3)
                        {
                            move.SpeedValue = 0;
                            var action = ctrl.GetMoveCallBackAction();
                            if (action != null)
                            {
                                action(ctrl);
                            }
                            break;
                        }
                    }
                    lastPos = p;
                }
            }

            return;
        }
Пример #17
0
        public static void OnGUI()
        {
            EditorGUI.BeginChangeCheck();
            Skill fsm = SkillEditor.SelectedFsm;

            if (fsm == null)
            {
                GUILayout.FlexibleSpace();
                return;
            }
            if (!FsmInspector.isInitialized)
            {
                FsmInspector.isInitialized = true;
                FsmInspector.Init();
            }
            FsmInspector.scrollViewPosition = GUILayout.BeginScrollView(FsmInspector.scrollViewPosition, new GUILayoutOption[0]);
            EditorGUI.BeginChangeCheck();
            fsm.set_Name(EditorGUILayout.TextField(fsm.get_Name(), new GUILayoutOption[0]));
            if (EditorGUI.EndChangeCheck())
            {
                Labels.Update(fsm);
            }
            if (fsm.get_Owner() != null)
            {
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                SkillTemplate fsmTemplate = (SkillTemplate)EditorGUILayout.ObjectField(FsmInspector.SelectedTemplate, typeof(SkillTemplate), false, new GUILayoutOption[0]);
                if (fsmTemplate != FsmInspector.SelectedTemplate)
                {
                    FsmInspector.SelectTemplate(fsmTemplate);
                }
                if (GUILayout.Button(SkillEditorContent.BrowseTemplateButton, new GUILayoutOption[]
                {
                    GUILayout.MaxWidth(30f),
                    GUILayout.Height(16f)
                }))
                {
                    Templates.DoSelectTemplateMenu(FsmInspector.SelectedTemplate, new GenericMenu.MenuFunction(FsmInspector.ClearTemplate), new GenericMenu.MenuFunction2(FsmInspector.SelectTemplate));
                }
                GUILayout.EndHorizontal();
            }
            EditorGUI.BeginDisabledGroup(!Application.get_isPlaying() && SkillEditor.SelectedFsmUsesTemplate);
            if (fsm.get_Template() != null)
            {
                fsm = fsm.get_Template().fsm;
            }
            fsm.set_Description(SkillEditorGUILayout.TextAreaWithHint(fsm.get_Description(), Strings.get_Label_Description___(), new GUILayoutOption[]
            {
                GUILayout.MinHeight(80f)
            }));
            EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
            fsm.set_DocUrl(SkillEditorGUILayout.TextFieldWithHint(fsm.get_DocUrl(), Strings.get_Tooltip_Documentation_Url(), new GUILayoutOption[0]));
            EditorGUI.BeginDisabledGroup(!string.IsNullOrEmpty(fsm.get_DocUrl()));
            if (SkillEditorGUILayout.HelpButton("Online Help"))
            {
                Application.OpenURL(fsm.get_DocUrl());
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginDisabledGroup(!Application.get_isPlaying() && SkillEditor.SelectedFsmUsesTemplate);
            fsm.set_MaxLoopCountOverride(EditorGUILayout.IntField(SkillEditorContent.MaxLoopOverrideLabel, fsm.get_MaxLoopCountOverride(), new GUILayoutOption[0]));
            fsm.RestartOnEnable = GUILayout.Toggle(fsm.RestartOnEnable, SkillEditorContent.ResetOnDisableLabel, new GUILayoutOption[0]);
            EditorGUI.EndDisabledGroup();
            EditorGUI.EndDisabledGroup();
            fsm = SkillEditor.SelectedFsm;
            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
            GUILayout.Label(SkillEditorContent.FsmControlsLabel, EditorStyles.get_boldLabel(), new GUILayoutOption[0]);
            if (fsm.ExposedEvents.get_Count() + FsmInspector.fsmVariables.get_Count() == 0)
            {
                SkillEditorGUILayout.DisabledLabel(Strings.get_Label_None_In_Table());
            }
            else
            {
                SkillEditorGUILayout.LabelWidth(100f);
                int num = 0;
                for (int i = 0; i < FsmInspector.fsmVariables.get_Count(); i++)
                {
                    SkillVariable fsmVariable = FsmInspector.fsmVariables.get_Item(i);
                    if (fsmVariable.ShowInInspector)
                    {
                        int categoryID = fsmVariable.CategoryID;
                        if (categoryID > 0 && categoryID != num)
                        {
                            num = categoryID;
                            GUILayout.Label(SkillEditor.SelectedFsm.get_Variables().get_Categories()[categoryID], EditorStyles.get_boldLabel(), new GUILayoutOption[0]);
                            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
                        }
                        fsmVariable.DoInspectorGUI(SkillEditorContent.TempContent(fsmVariable.Name, fsmVariable.Name + ((!string.IsNullOrEmpty(fsmVariable.Tooltip)) ? (":\n" + fsmVariable.Tooltip) : "")), false);
                    }
                }
                using (List <SkillEvent> .Enumerator enumerator = fsm.ExposedEvents.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        SkillEvent current = enumerator.get_Current();
                        if (GUILayout.Button(current.get_Name(), new GUILayoutOption[0]))
                        {
                            fsm.Event(current);
                        }
                    }
                }
                if (GUI.get_changed())
                {
                    SkillEditor.RepaintAll();
                }
            }
            if (FsmEditorSettings.ShowHints)
            {
                GUILayout.Box(Strings.get_Hint_Expose_Events_and_Variables(), SkillEditorStyles.HintBox, new GUILayoutOption[0]);
            }
            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
            GUILayout.Label(SkillEditorContent.NetworkSyncLabel, EditorStyles.get_boldLabel(), new GUILayoutOption[0]);
            int num2 = 0;

            SkillBool[] boolVariables = fsm.get_Variables().get_BoolVariables();
            for (int j = 0; j < boolVariables.Length; j++)
            {
                SkillBool fsmBool = boolVariables[j];
                if (fsmBool.get_NetworkSync())
                {
                    GUILayout.Label(fsmBool.get_Name(), new GUILayoutOption[0]);
                    num2++;
                }
            }
            SkillFloat[] floatVariables = fsm.get_Variables().get_FloatVariables();
            for (int k = 0; k < floatVariables.Length; k++)
            {
                SkillFloat fsmFloat = floatVariables[k];
                if (fsmFloat.get_NetworkSync())
                {
                    GUILayout.Label(fsmFloat.get_Name(), new GUILayoutOption[0]);
                    num2++;
                }
            }
            SkillInt[] intVariables = fsm.get_Variables().get_IntVariables();
            for (int l = 0; l < intVariables.Length; l++)
            {
                SkillInt fsmInt = intVariables[l];
                if (fsmInt.get_NetworkSync())
                {
                    GUILayout.Label(fsmInt.get_Name(), new GUILayoutOption[0]);
                    num2++;
                }
            }
            SkillQuaternion[] quaternionVariables = fsm.get_Variables().get_QuaternionVariables();
            for (int m = 0; m < quaternionVariables.Length; m++)
            {
                SkillQuaternion fsmQuaternion = quaternionVariables[m];
                if (fsmQuaternion.get_NetworkSync())
                {
                    GUILayout.Label(fsmQuaternion.get_Name(), new GUILayoutOption[0]);
                    num2++;
                }
            }
            SkillVector3[] vector3Variables = fsm.get_Variables().get_Vector3Variables();
            for (int n = 0; n < vector3Variables.Length; n++)
            {
                SkillVector3 fsmVector = vector3Variables[n];
                if (fsmVector.get_NetworkSync())
                {
                    GUILayout.Label(fsmVector.get_Name(), new GUILayoutOption[0]);
                    num2++;
                }
            }
            if (num2 == 0)
            {
                SkillEditorGUILayout.DisabledLabel(Strings.get_Label_None_In_Table());
            }
            if (FsmEditorSettings.ShowHints)
            {
                GUILayout.Box(Strings.get_Hint_Network_Sync_Variables(), SkillEditorStyles.HintBox, new GUILayoutOption[0]);
            }
            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
            GUILayout.Label("Debug", EditorStyles.get_boldLabel(), new GUILayoutOption[0]);
            fsm.set_ShowStateLabel(GUILayout.Toggle(fsm.get_ShowStateLabel(), SkillEditorContent.ShowStateLabelsLabel, new GUILayoutOption[0]));
            fsm.EnableBreakpoints = GUILayout.Toggle(fsm.EnableBreakpoints, SkillEditorContent.EnableBreakpointsLabel, new GUILayoutOption[0]);
            fsm.EnableDebugFlow   = GUILayout.Toggle(fsm.EnableDebugFlow, SkillEditorContent.EnableDebugFlowLabel, new GUILayoutOption[0]);
            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
            GUILayout.Label("Experimental", EditorStyles.get_boldLabel(), new GUILayoutOption[0]);
            EditorGUILayout.HelpBox(Strings.get_Help_Experimental_Warning(), 0);
            fsm.set_KeepDelayedEventsOnStateExit(GUILayout.Toggle(fsm.get_KeepDelayedEventsOnStateExit(), SkillEditorContent.KeepDelayedEvents, new GUILayoutOption[0]));
            fsm.set_ManualUpdate(GUILayout.Toggle(fsm.get_ManualUpdate(), SkillEditorContent.ManualUpdate, new GUILayoutOption[0]));
            GUILayout.EndScrollView();
            EventType arg_641_0 = Event.get_current().get_type();

            if (EditorGUI.EndChangeCheck())
            {
                SkillEditor.SetFsmDirty(false, false);
            }
            if (Event.get_current().get_type() == null)
            {
                GUIUtility.set_keyboardControl(0);
            }
            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
            EditorGUI.BeginDisabledGroup(true);
            GUILayout.Label("Data Version: " + fsm.get_DataVersion(), EditorStyles.get_miniLabel(), new GUILayoutOption[0]);
            EditorGUI.EndDisabledGroup();
            SkillEditorGUILayout.LockFsmGUI(fsm);
        }