-
-
Save Gucchi0512/1f49a0d5939517a6fe2b29323bc6661a to your computer and use it in GitHub Desktop.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System.Linq; | |
namespace app | |
{ | |
[System.Serializable] | |
public class EnumDataUnit | |
{ | |
#region Property | |
/// <summary> | |
/// 表示名 | |
/// </summary> | |
public string DisplayName => _DisplayName; | |
/// <summary> | |
/// 変数名 | |
/// </summary> | |
public string VariableName => _VariableName; | |
#endregion | |
#region Field | |
/// <summary> | |
/// 表示名 | |
/// </summary> | |
[SerializeField] | |
[Header("表示名")] | |
private string _DisplayName = ""; | |
/// <summary> | |
/// 変数名 | |
/// </summary> | |
[SerializeField] | |
[Header("変数名")] | |
private string _VariableName = ""; | |
#endregion | |
#region Method | |
/// <summary> | |
/// デフォルトコンストラクタ | |
/// </summary> | |
public EnumDataUnit() | |
{ | |
} | |
/// <summary> | |
/// コンストラクタ | |
/// </summary> | |
/// <param name="displayName"></param> | |
/// <param name="variableName"></param> | |
public EnumDataUnit(string displayName, string variableName) | |
{ | |
_DisplayName = displayName; | |
_VariableName = variableName; | |
} | |
/// <summary> | |
/// データのコピー | |
/// </summary> | |
/// <param name="src">元データ</param> | |
public void CopyTo(EnumDataUnit src) | |
{ | |
_DisplayName = src.DisplayName; | |
_VariableName = src.VariableName; | |
} | |
#endregion | |
} | |
[CreateAssetMenu(fileName = "EnumData", menuName = "EnumData/DataAsset")] | |
public class EnumData : ScriptableObject | |
{ | |
#region Definition | |
#endregion | |
#region Property | |
/// <summary> | |
/// データクラス名 | |
/// </summary> | |
public string DataClassName { get { return _DataClassName; } set { _DataClassName = value; } } | |
/// <summary> | |
/// データ群 | |
/// </summary> | |
public EnumDataUnit[] Units | |
{ | |
get | |
{ | |
return _Units.ToArray(); | |
} | |
} | |
#endregion | |
#region Field | |
/// <summary> | |
/// データクラス名 | |
/// </summary> | |
[SerializeField] | |
private string _DataClassName = ""; | |
/// <summary> | |
/// データ群 | |
/// </summary> | |
[SerializeField] | |
private List<EnumDataUnit> _Units = new List<EnumDataUnit>(); | |
#endregion | |
#region Method | |
/// <summary> | |
/// データの追加 | |
/// 同一の変数名を持つUnitがあるなら更新する | |
/// </summary> | |
/// <param name="newUnit"></param> | |
public void RegisterDataUnit(EnumDataUnit newUnit) | |
{ | |
//変数名が重複しているなら更新する | |
var unit = _Units.FirstOrDefault(_ => _.VariableName == newUnit.VariableName); | |
if (unit != null) | |
{ | |
unit.CopyTo(newUnit); | |
} | |
else | |
{ | |
_Units.Add(newUnit); | |
} | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment