Created
November 14, 2017 04:16
-
-
Save HituziANDO/c51a7a3a5035f4df6d0cbb839af77e39 to your computer and use it in GitHub Desktop.
Unity JsonUtilityでルートが配列なデータを扱いやすくするクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System; | |
using System.Collections.Generic; | |
namespace MyApplication | |
{ | |
/// <summary> | |
/// JsonUtilityはルートが配列の場合は扱えないため、オブジェクトでラップするクラスです。 | |
/// | |
/// { "array": [ 指定した配列要素 ] } | |
/// | |
/// </summary> | |
[Serializable] | |
public class JsonArray<T> | |
{ | |
[SerializeField] | |
private T[] array; | |
public JsonArray(T[] array) | |
{ | |
this.array = array; | |
} | |
public JsonArray(List<T> list) | |
{ | |
this.array = list.ToArray(); | |
} | |
public List<T> ToList() | |
{ | |
return new List<T>(array); | |
} | |
public T[] Array | |
{ | |
get | |
{ | |
return this.array; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment