145 lines
3.5 KiB
C#
145 lines
3.5 KiB
C#
using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Assets.MyGame.Scripts.Net.WebResponses
|
|
{
|
|
|
|
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());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
public enum FrameDataType
|
|
{
|
|
none = 0,
|
|
rotateTurrect=1,
|
|
fireBullet=2,
|
|
createFish=3,
|
|
changeAutoTarget=4,
|
|
randomDieFish=5,
|
|
changeTurretState=6,
|
|
changeTurret=7,
|
|
freezeFish=8,
|
|
changeCannonMultiple=9
|
|
|
|
}
|
|
[Serializable]
|
|
public class FireCannonSendData
|
|
{
|
|
public string userId;
|
|
public List<string> bulletIds;
|
|
public long gold;
|
|
public int count;
|
|
public SyncGameData extra;
|
|
}
|
|
/// <summary>
|
|
/// 同步游戏数据
|
|
/// </summary>
|
|
[Serializable]
|
|
public class SyncGameData
|
|
{
|
|
public int sitPos;
|
|
public FrameDataType frameType;
|
|
public long time;
|
|
public object frameData;
|
|
|
|
}
|
|
[Serializable]
|
|
public class FrameData
|
|
{
|
|
|
|
}
|
|
[Serializable]
|
|
public class FrameData_Rotate : FrameData
|
|
{
|
|
public float angle;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_FireBullet : FrameData
|
|
{
|
|
public float angle;
|
|
public long gold;
|
|
public bool isSanShe;
|
|
public bool isSuoDing;
|
|
public bool auto;
|
|
public bool twoRTruuect;
|
|
public string monsterID;
|
|
public bool isZuanTou;
|
|
/// <summary>三发锁定时每个子弹对应的鱼 GUID(3个),按优先级排序</summary>
|
|
public List<string> monsterIDs;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_CreateFish : FrameData
|
|
{
|
|
public string fishNumber;
|
|
public string guid;
|
|
public string moveLineId;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_ChangeAutoTarget : FrameData
|
|
{
|
|
public List< string> targetGuid;
|
|
public int colliderIndex;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_RandomDieFish : FrameData
|
|
{
|
|
public float x;
|
|
public float y;
|
|
public float z;
|
|
public List<string> guids=new List<string>();
|
|
public List<RedPacketRecord> coinNum=new List<RedPacketRecord>();
|
|
public int count;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_TurretState : FrameData
|
|
{
|
|
public TurretState state;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_ChangeTurret : FrameData
|
|
{
|
|
public int turretIndex;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_FreezeFish : FrameData
|
|
{
|
|
public bool isFreeze;
|
|
}
|
|
[Serializable]
|
|
public class FrameData_ChangeCannonMultiple : FrameData
|
|
{
|
|
public int cannonMultiple;
|
|
}
|
|
}
|