我一直在努力想弄清楚如何在不使用playerprefs的情况下保存我的球员在统一中的位置,并且它必须是某种浮动,因为你无法在Serializeable类中保存Vector,甚至某种类型的将向量(Vector3)转换为浮点数的方法会很有帮助。
任何帮助都将不胜感激。
答案 0 :(得分:0)
你应该像这样实现ISerializable接口:
using UnityEngine;
using System;
using System.Runtime.Serialization;
[Serializable]
public class BasePrefabSaveData : ISerializable
{
public Vector3 _Position;
public BasePrefabSaveData()
{
}
public BasePrefabSaveData(SerializationInfo info, StreamingContext context)
{
_Position.x = (float)info.GetValue( "Position.x", typeof( float ) );
_Position.y = (float)info.GetValue( "Position.y", typeof( float ) );
_Position.z = (float)info.GetValue( "Position.z", typeof( float ) );
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue( "Position.x", _Position.x, typeof( float ) );
info.AddValue( "Position.y", _Position.y, typeof( float ) );
info.AddValue( "Position.z", _Position.z, typeof( float ) );
}
}