Files
XMen/Assets/Scripts/Data/FixedElementInfo.cs
2025-07-10 14:49:53 +08:00

58 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static XPlugin.Data.JsonLiteDB.JsonLiteDB;
public class FixedElementInfo
{
public int ItemId;
public string ItemName;
public Vector3[] Position;
public Vector3[] Angle;
public FixedElementInfo(TableReader table) {
ItemId = table["ItemId"].OptInt();
ItemName = table["ItemName"].OptString();
string position = table["Position"].OptString();
Position = ParseStringToVectorArray(position);
string angle = table["Angle"].OptString();
Angle = ParseStringToVectorArray(angle);
}
Vector3[] ParseStringToVectorArray(string input)
{
Debug.Log(input);
if (input == "")
{
return null;
}
string[] elements = input.Replace("(", "").Replace(")", "").Split(',');
List<Vector3> vectorList = new List<Vector3>();
for (int i = 0; i < elements.Length; i += 3)
{
// 将每三个元素解析为一个 Vector3并添加到列表中
float x = float.Parse(elements[i]);
float y = float.Parse(elements[i + 1]);
float z = float.Parse(elements[i + 2]);
vectorList.Add(new Vector3(x, y, z));
}
return vectorList.ToArray();
}
}