Files
MinFt/Client/Assets/Scripts/InfiniteBuilding/InfiniteBuildingData.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

87 lines
3.0 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System.Collections.Generic;
using UnityEngine;
public class InfiniteBuildingData
{
public int Lvl, Step, StepLvl = 1, LastHangingBlock = -1;
public List<BlockRecord> Record = new List<BlockRecord>();
// private readonly TbConstructionUnits BlocksTable = GContext.container.Resolve<Tables>().TbConstructionUnits;
public int ConstructPrice => (int)
(GContext.container.Resolve<Tables>().TbMapData.DataList[^1].ConstrutionCost
* GContext.container.Resolve<Tables>().TbConstructionInfiniteConfig.CashMagList[Step]);
public struct BlockRecord
{
public readonly int ID;
public Vector2 Pos;
public readonly float Height => GContext.container.Resolve<Tables>().TbConstructionUnits[ID].Height;
public readonly string PrefabID => GContext.container.Resolve<Tables>().TbConstructionUnits[ID].Prefab;
public BlockRecord(int id = 0, Vector2 pos = default)
{
this.ID = id;
this.Pos = pos;
}
public BlockRecord(int id = 0, float x = 0, float y = 0)
{
this.ID = id;
Pos = new Vector2(x, y);
}
public readonly override string ToString() => $"{ID},{Pos.x},{Pos.y}";
}
private string Serialize()
{
var sb = new System.Text.StringBuilder();
sb.Append($"{Lvl},{Step},{StepLvl},{LastHangingBlock},");
foreach (BlockRecord node in Record)
sb.Append($"{node.ToString()},");
return sb.ToString().Trim(',');
}
public void Deserialize(string s)
{
string[] tokens = s.Split(',');
if (tokens == null || tokens.Length < 4 || tokens.Length % 3 != 1)
{
Debug.LogWarning($"string \"{s}\" cannot be deserialized.");
return;
}
Lvl = int.Parse(tokens[0]);
Step = int.Parse(tokens[1]);
StepLvl = int.Parse(tokens[2]);
LastHangingBlock = int.Parse(tokens[3]);
Record = new List<BlockRecord>();
for (int i = 4; i < tokens.Length; i+=3)
{
Record.Add(new BlockRecord(int.Parse(tokens[i]),
float.Parse(tokens[i + 1]), float.Parse(tokens[i + 2])));
//Debug.Log($"{int.Parse(tokens[i])}, {float.Parse(tokens[i + 1])}, {float.Parse(tokens[i + 2])}");
}
}
public void UploadData()
{
string s = Serialize();
//Debug.Log("Upload!!!!!!!!!!!!!!");
//Debug.Log(s);
GContext.container.Resolve<PlayerData>().InfiniteBuildingData = s;
PlayFabMgr.Instance.UpdateUserDataValue("InfiniteBuildingData", s);
}
public void DownloadData(string s)
{
Deserialize(s);
}
#if UNITY_EDITOR
public void PrintSelf()
{
Debug.Log($"Lvl: {Lvl}");
Debug.Log($"Step: {Step}");
Debug.Log($"StepLvl: {StepLvl}");
foreach (BlockRecord node in Record)
{
Debug.Log($"node: {node.PrefabID}, {node.Pos}");
}
}
#endif
}