2016-04-10 5 views
0

ファイル:は、私は私の保存オプションでのVector3をシリアライズすることができ、私はゲームのためのオプションの保存と読み込みに取り組んでいると私はのVector3をシリアライズしようとしていますが、私はこのエラーを受け取った

SerializationException: Type UnityEngine.Vector3 is not marked as Serializable. 

私はドキュメントを見てみると私はSerializableタイプのこのリストにするVector3を参照してください。

Serializable types are: 
- Some built-in types like Vector2, Vector3, Vector4, Quaternion, Matrix4x4, Color, Rect, LayerMask. 

私のコードは次のとおりです。

public Options_Settings GameOptions { get; private set; } 

public void SaveOptionSettings(){ 
    // Create the Binary Formatter. 
    BinaryFormatter bf = new BinaryFormatter(); 
    // Stream the file with a File Stream. (Note that File.Create() 'Creates' or 'Overwrites' a file.) 
    FileStream file = File.Create(Application.persistentDataPath + "/OptionsInfo.dat"); 
    // Serialize the file so the contents cannot be manipulated. 
    bf.Serialize(file, GameOptions); // <---- Error is here 
    // Close the file to prevent any corruptions 
    file.Close(); 
} 

私のOpti ons_Settings:ドキュメントが私と言うので、私は私が回避策を作り、ちょうど各ベクトルのための3台の山車を作り、その道の周りにそれらを渡すことができます知っているが、私は私が間違っているのかを理解したい

using UnityEngine; 
using System; 

[Serializable] 
public class Options_Settings { 

public bool MusicToggle { get; set; } 
public float MusicVolume { get; set; } 

public bool SFXToggle { get; set; } 
public float SFXVolume { get; set; } 

public Vector3 UIOneScaling { get; set; } 
public Vector3 UITwoScaling { get; set; } 
public Vector3 UIThreeScaling { get; set; } 


public void Default() { 

    MusicToggle = true; 
    MusicVolume = 0.5f; 

    SFXToggle = true; 
    SFXVolume = 0.5f; 

    UIOneScaling = Vector3.one; 
    UITwoScaling = Vector3.one; 
    UIThreeScaling = Vector3.one; 
} 

}

余分なコーディングを防ぎ、単調な動作をするVector3を行うことができます。

+1

[serialization surrogates](http://web.archive.org/web/20141231105711/http://msdn.microsoft.com/en-us/magazine/cc188950.aspx)を使用してください。 http://forum.unity3d.com/threads/vector3-not-serializable.7766/を参照してください。 – dbc

答えて

1

単一性は実際にVector3変数をシリアル化しますが、ACCESSORをVector3にシリアル化することはできません。

は、私はあなたのコード内でこのアクセサを参照してください。

public Vector3 UIOneScaling { get; set; } 

が、私は、実際のベクトル変数が格納されて表示されていない:アクセサだけの機能です。メンバーVARIABLE _UIOneScalingをシリアル化されるだろう。この場合、

[SerializeField] // needed to serialize private fields 
private Vector3 _UIOneScaling; //a member variable to hold the data 
public Vector3 UIOneScaling { 
    get return {_UIOneScaling;} 
    set {_UIOneScaling=value;} 
} 

は、私はのようなものを見ると期待しているでしょう。

関連する問題

 関連する問題