Files
5.24BuYu/Assets/MyGame/Scripts/Net/WebResponses/SyncGameData.cs
T

122 lines
2.8 KiB
C#
Raw Normal View History

2026-03-09 09:25:01 +08:00
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
2026-02-03 11:35:19 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2026-04-25 18:53:04 +08:00
using UnityEngine;
2026-02-03 11:35:19 +08:00
namespace Assets.MyGame.Scripts.Net.WebResponses
{
2026-05-01 06:26:50 +08:00
public static class FrameDataParser
{
public static T Parse<T>(object frameData) where T : class, new()
{
if (frameData == null) return null;
// 如果已经是目标类型,直接返回
if (frameData is T typed) return typed;
// 如果是字符串,直接反序列化
if (frameData is string str)
return JsonConvert.DeserializeObject<T>(str);
// 如果是 JObject,轻量解析
if (frameData is JObject jObj)
return jObj.ToObject<T>();
// 兜底:调用 ToString 再反序列化
return JsonConvert.DeserializeObject<T>(frameData.ToString());
}
}
2026-03-09 09:25:01 +08:00
[Serializable]
public enum FrameDataType
{
2026-04-22 16:22:28 +08:00
none = 0,
2026-04-24 22:51:34 +08:00
rotateTurrect=1,
fireBullet=2,
createFish=3,
changeAutoTarget=4,
randomDieFish=5,
2026-05-04 17:21:52 +08:00
changeTurretState=6,
changeTurret=7
2026-03-09 09:25:01 +08:00
}
2026-02-03 11:35:19 +08:00
/// <summary>
/// 同步游戏数据
/// </summary>
[Serializable]
public class SyncGameData
{
2026-04-22 16:22:28 +08:00
public int sitPos;
2026-03-09 09:25:01 +08:00
public FrameDataType frameType;
2026-03-18 17:26:14 +08:00
public long time;
2026-04-25 18:53:04 +08:00
public object frameData;
2026-02-03 11:35:19 +08:00
}
2026-03-09 09:25:01 +08:00
[Serializable]
2026-02-03 11:35:19 +08:00
public class FrameData
{
2026-04-22 16:22:28 +08:00
2026-03-09 09:25:01 +08:00
}
[Serializable]
public class FrameData_Rotate : FrameData
{
public float angle;
}
[Serializable]
public class FrameData_FireBullit : FrameData
{
public float angle;
public long gold;
public bool isSanShe;
public bool isSuoDing;
public bool auto;
public bool twoRTruuect;
public string monsterID;
2026-05-18 18:39:11 +08:00
public bool isZuanTou;
2026-03-09 09:25:01 +08:00
}
[Serializable]
public class FrameData_CreateFish : FrameData
{
2026-03-18 17:26:14 +08:00
public string fishNumber;
2026-03-10 15:36:10 +08:00
public string guid;
2026-03-18 17:26:14 +08:00
public string moveLineId;
2026-03-09 09:25:01 +08:00
}
[Serializable]
public class FrameData_ChangeAutoTarget : FrameData
{
public string targetGuid;
2026-05-01 06:26:50 +08:00
public string targetPostName;
2026-02-03 11:35:19 +08:00
}
2026-04-22 16:22:28 +08:00
[Serializable]
public class FrameData_RandomDieFish : FrameData
{
2026-04-25 18:53:04 +08:00
public float x;
public float y;
public float z;
2026-04-22 18:15:22 +08:00
public List<string> guids=new List<string>();
2026-04-25 00:12:55 +08:00
public List<RedPacketRecord> coinNum=new List<RedPacketRecord>();
2026-04-24 22:51:34 +08:00
public int count;
2026-04-22 16:22:28 +08:00
}
2026-05-04 17:21:52 +08:00
[Serializable]
public class FrameData_TurretState : FrameData
{
public TurretState state;
}
[Serializable]
public class FrameData_ChangeTurret : FrameData
{
public int turretIndex;
}
2026-02-03 11:35:19 +08:00
}