데이터 파싱 기능 추가
This commit is contained in:
parent
4dd450ea32
commit
061b39f035
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -9,6 +10,8 @@ public class DataSo<T> : ScriptableObject where T : IId
|
|||||||
{
|
{
|
||||||
[FormerlySerializedAs("Datas")] [SerializeField] protected List<T> _datas = new();
|
[FormerlySerializedAs("Datas")] [SerializeField] protected List<T> _datas = new();
|
||||||
|
|
||||||
|
private static readonly char[] _defaultSeparators = { ',', '|' };
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
@ -42,5 +45,51 @@ public List<T> GetDataList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int GetDataCount() => _datas.Count;
|
public int GetDataCount() => _datas.Count;
|
||||||
|
|
||||||
|
public static List<string> ParseDelimitedList(string input, List<string> buffer = null, char[] separators = null,
|
||||||
|
bool distinct = false, bool toLower = false)
|
||||||
|
{
|
||||||
|
separators ??= _defaultSeparators;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
if (buffer == null) return new List<string>(0);
|
||||||
|
buffer.Clear();
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerable<string> query = input
|
||||||
|
.Split(separators, StringSplitOptions.RemoveEmptyEntries)
|
||||||
|
.Select(s => s.Trim())
|
||||||
|
.Where(s => !string.IsNullOrWhiteSpace(s));
|
||||||
|
|
||||||
|
// 소문자 정규화가 필요하면 먼저 적용
|
||||||
|
if (toLower)
|
||||||
|
{
|
||||||
|
query = query.Select(s => s.ToLowerInvariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Distinct
|
||||||
|
if (distinct)
|
||||||
|
{
|
||||||
|
query = query.Distinct(StringComparer.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer == null) return query.ToList();
|
||||||
|
|
||||||
|
buffer.Clear();
|
||||||
|
buffer.AddRange(query);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 결과 리스트(target)에 직접 채워 넣습니다. (할당 최소화)
|
||||||
|
/// </summary>
|
||||||
|
public static void ParseDelimitedListInPlace(string input, List<string> target, char[] separators = null,
|
||||||
|
bool distinct = false, bool toLower = false)
|
||||||
|
{
|
||||||
|
ParseDelimitedList(input, target, separators, distinct, toLower);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
@ -31,5 +34,6 @@ public class CustomerData : IId
|
|||||||
[Tooltip("선호 맛들")]
|
[Tooltip("선호 맛들")]
|
||||||
public string FavoriteTastes;
|
public string FavoriteTastes;
|
||||||
|
|
||||||
|
[ReadOnly] public List<string> ValidFavoriteTastes = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,16 @@
|
|||||||
namespace DDD
|
namespace DDD
|
||||||
{
|
{
|
||||||
[CreateAssetMenu(fileName = "CustomerDataSo", menuName = "GoogleSheet/CustomerDataSo")]
|
[CreateAssetMenu(fileName = "CustomerDataSo", menuName = "GoogleSheet/CustomerDataSo")]
|
||||||
public class CustomerDataSo : DataSo<CustomerData> { }
|
public class CustomerDataSo : DataSo<CustomerData>
|
||||||
|
{
|
||||||
|
protected override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
foreach (var customerData in _datas)
|
||||||
|
{
|
||||||
|
ParseDelimitedListInPlace(customerData.FavoriteTastes, customerData.ValidFavoriteTastes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DDD
|
namespace DDD
|
||||||
@ -19,6 +21,7 @@ public class CustomerPoolData : IId
|
|||||||
/// <summary>등장 손님들</summary>
|
/// <summary>등장 손님들</summary>
|
||||||
[Tooltip("등장 손님들")]
|
[Tooltip("등장 손님들")]
|
||||||
public string Customers;
|
public string Customers;
|
||||||
|
|
||||||
|
[ReadOnly] public List<string> ValidCustomers = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,16 @@
|
|||||||
namespace DDD
|
namespace DDD
|
||||||
{
|
{
|
||||||
[CreateAssetMenu(fileName = "CustomerPoolDataSo", menuName = "GoogleSheet/CustomerPoolDataSo")]
|
[CreateAssetMenu(fileName = "CustomerPoolDataSo", menuName = "GoogleSheet/CustomerPoolDataSo")]
|
||||||
public class CustomerPoolDataSo : DataSo<CustomerPoolData> { }
|
public class CustomerPoolDataSo : DataSo<CustomerPoolData>
|
||||||
|
{
|
||||||
|
protected override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
foreach (var customerPoolData in _datas)
|
||||||
|
{
|
||||||
|
ParseDelimitedListInPlace(customerPoolData.Customers, customerPoolData.ValidCustomers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user