159 lines
5.5 KiB
C#
159 lines
5.5 KiB
C#
#nullable enable
|
|
using Cysharp.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UVC.Core;
|
|
using UVC.Studio.Config;
|
|
using UVC.UI.Tab;
|
|
|
|
namespace UVC.Studio.Modal.Settings
|
|
{
|
|
public class SettingGeneralTabContent : MonoBehaviour, ITabContent
|
|
{
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? autoSaveValueTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? gridValueTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? positionSnapValueTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? RotationSnapValueTxt;
|
|
|
|
[SerializeField]
|
|
private TMP_InputField? ScaleSnapValueTxt;
|
|
|
|
[Inject]
|
|
private Setting? setting;
|
|
|
|
private bool changedValue = false;
|
|
|
|
/// <summary>
|
|
/// 탭 콘텐츠에 데이터를 전달합니다.
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public async void SetContentData(object? data)
|
|
{
|
|
Debug.Log($"SettingGeneralTabContent SetContentData: {data}");
|
|
|
|
if (setting == null)
|
|
{
|
|
await InjectorAppContext.Instance.WaitForInitializationAsync();
|
|
setting = InjectorAppContext.Instance.Get<Setting>();
|
|
}
|
|
|
|
if (setting != null)
|
|
{
|
|
changedValue = false;
|
|
|
|
GeneralSetting general = setting.Data.general;
|
|
if (autoSaveValueTxt != null)
|
|
{
|
|
autoSaveValueTxt.text = general.autoSaveInterval.ToString();
|
|
autoSaveValueTxt.onEndEdit.AddListener(onChagedTextAutoSave);
|
|
}
|
|
if (gridValueTxt != null)
|
|
{
|
|
gridValueTxt.text = general.gridSize.ToString();
|
|
gridValueTxt.onEndEdit.AddListener(onChagedTextGrid);
|
|
}
|
|
if (positionSnapValueTxt != null)
|
|
{
|
|
positionSnapValueTxt.text = general.snapPosition.ToString();
|
|
positionSnapValueTxt.onEndEdit.AddListener(onChagedTextSnapPosition);
|
|
}
|
|
if (RotationSnapValueTxt != null)
|
|
{
|
|
RotationSnapValueTxt.text = general.snapRotation.ToString();
|
|
RotationSnapValueTxt.onEndEdit.AddListener(onChagedTextRotationSnap);
|
|
}
|
|
if (ScaleSnapValueTxt != null)
|
|
{
|
|
ScaleSnapValueTxt.text = general.snapScale.ToString();
|
|
ScaleSnapValueTxt.onEndEdit.AddListener(onChagedTextScaleSnap);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void onChagedTextAutoSave(string value)
|
|
{
|
|
if (setting != null && int.TryParse(value, out int intValue))
|
|
{
|
|
setting.Data.general.autoSaveInterval = intValue;
|
|
changedValue = true;
|
|
}
|
|
}
|
|
|
|
private void onChagedTextGrid(string value)
|
|
{
|
|
if (setting != null && float.TryParse(value, out float floatValue))
|
|
{
|
|
setting.Data.general.gridSize = floatValue;
|
|
changedValue = true;
|
|
}
|
|
}
|
|
|
|
private void onChagedTextSnapPosition(string value)
|
|
{
|
|
if (setting != null && float.TryParse(value, out float floatValue))
|
|
{
|
|
setting.Data.general.snapPosition = floatValue;
|
|
changedValue = true;
|
|
}
|
|
}
|
|
|
|
private void onChagedTextRotationSnap(string value)
|
|
{
|
|
if (setting != null && float.TryParse(value, out float floatValue))
|
|
{
|
|
setting.Data.general.snapRotation = floatValue;
|
|
changedValue = true;
|
|
}
|
|
}
|
|
|
|
private void onChagedTextScaleSnap(string value)
|
|
{
|
|
if (setting != null && float.TryParse(value, out float floatValue))
|
|
{
|
|
setting.Data.general.snapScale = floatValue;
|
|
changedValue = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 전환 시 데이터가 있는 경우 전달 되는 데이터. SetContentData 이후 호출 됨
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public void UpdateContentData(object? data)
|
|
{
|
|
if (data != null && data is string content)
|
|
{
|
|
Debug.Log($"UpdateContentData: {content}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 닫힐 때 실행되는 로직을 처리합니다.
|
|
/// </summary>
|
|
/// <returns>비동기 닫기 작업을 나타내는 <see cref="UniTask"/>입니다.</returns>
|
|
public async UniTask OnCloseAsync()
|
|
{
|
|
if (autoSaveValueTxt != null) autoSaveValueTxt.onEndEdit.RemoveListener(onChagedTextAutoSave);
|
|
if (gridValueTxt != null) gridValueTxt.onEndEdit.RemoveListener(onChagedTextGrid);
|
|
if (positionSnapValueTxt != null) positionSnapValueTxt.onEndEdit.RemoveListener(onChagedTextSnapPosition);
|
|
if (RotationSnapValueTxt != null) RotationSnapValueTxt.onEndEdit.RemoveListener(onChagedTextRotationSnap);
|
|
if (ScaleSnapValueTxt != null) ScaleSnapValueTxt.onEndEdit.RemoveListener(onChagedTextScaleSnap);
|
|
|
|
Debug.Log($"SettingGeneralTabContent OnCloseAsync: changedValue={changedValue} setting == null:{setting == null}");
|
|
|
|
if(changedValue && setting != null)
|
|
{
|
|
await setting.SaveAsync();
|
|
changedValue = false;
|
|
}
|
|
}
|
|
}
|
|
} |