Merge branch 'main' of http://220.90.135.190:3000/uvcxr/Simulation
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
using Assets.WorkSpace.R;
|
using Octopus.Simulator.Camera;
|
||||||
using Octopus.Simulator.Networks;
|
using Octopus.Simulator.Networks;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public class StatusLED : ActionAnimator
|
|||||||
|
|
||||||
Material currentOnMaterial;
|
Material currentOnMaterial;
|
||||||
|
|
||||||
private string prevStatus;
|
|
||||||
public override void AnimationEnd()
|
public override void AnimationEnd()
|
||||||
{
|
{
|
||||||
SetColor("End");
|
SetColor("End");
|
||||||
@@ -84,6 +83,6 @@ public class StatusLED : ActionAnimator
|
|||||||
currentOnMaterial = LED_O.sharedMaterial;
|
currentOnMaterial = LED_O.sharedMaterial;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//prevStatus = progStatus;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
Assets/Scripts/Data.meta
Normal file
8
Assets/Scripts/Data.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b7e51d07cc1270142aecee4dabf80814
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Assets.WorkSpace.R
|
namespace Octopus.Simulator.Camera
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class CameraEntity
|
public class CameraEntity
|
||||||
8
Assets/Scripts/UI/PopUp.meta
Normal file
8
Assets/Scripts/UI/PopUp.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 59183c92e1a4ef74bb442d38c298e859
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
72
Assets/Scripts/UI/PopUp/AlertManager.cs
Normal file
72
Assets/Scripts/UI/PopUp/AlertManager.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Octopus.Simulator.UI.Popup
|
||||||
|
{
|
||||||
|
public class AlertManager : UnitySingleton<AlertManager>
|
||||||
|
{
|
||||||
|
private GameObject prefab;
|
||||||
|
private UIAlert alert;
|
||||||
|
|
||||||
|
|
||||||
|
private void Create()
|
||||||
|
{
|
||||||
|
if (alert == null)
|
||||||
|
{
|
||||||
|
if (prefab == null)
|
||||||
|
{
|
||||||
|
prefab = Resources.Load("UIPrefab/UIAlert", typeof(GameObject)) as GameObject;
|
||||||
|
}
|
||||||
|
GameObject go = UnityEngine.Object.Instantiate(prefab);
|
||||||
|
alert = go.GetComponent<UIAlert>();
|
||||||
|
}
|
||||||
|
var canvas = FindAnyObjectByType<Canvas_Main>();
|
||||||
|
alert.transform.SetParent(canvas.transform, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async UniTask ShowAlert(string title, string message, string okButtonTitle = "OK")
|
||||||
|
{
|
||||||
|
Create();
|
||||||
|
|
||||||
|
bool isClosed = false;
|
||||||
|
|
||||||
|
alert.Init(title: title, message: message, okButtonText: okButtonTitle, showCancelButton: false);
|
||||||
|
alert.OnOk.AddListener(() =>
|
||||||
|
{
|
||||||
|
isClosed = true;
|
||||||
|
});
|
||||||
|
alert.Open();
|
||||||
|
await UniTask.WaitUntil(() => isClosed == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async UniTask<bool> ShowConfirm(string title, string message, string okButtonTitle = "OK", string cancelButtonTitle = "CANCEL")
|
||||||
|
{
|
||||||
|
Create();
|
||||||
|
|
||||||
|
bool isClosed = false;
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
alert.Init(title, message, okButtonTitle, cancelButtonTitle, true);
|
||||||
|
|
||||||
|
alert.OnOk.AddListener(() =>
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
isClosed = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.OnCancel.AddListener(() =>
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
isClosed = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
alert.Open();
|
||||||
|
|
||||||
|
|
||||||
|
await UniTask.WaitUntil(() => isClosed == true);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
200
Assets/Scripts/UI/PopUp/UIAlert.cs
Normal file
200
Assets/Scripts/UI/PopUp/UIAlert.cs
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Octopus.Simulator.UI.Popup
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(CanvasGroup))]
|
||||||
|
public class UIAlert : MonoBehaviour
|
||||||
|
{
|
||||||
|
private string title;
|
||||||
|
private string message;
|
||||||
|
|
||||||
|
private string okButtonText = "확인";
|
||||||
|
private string cancelButtonText = "취소";
|
||||||
|
|
||||||
|
private bool showCancelButton = false;
|
||||||
|
|
||||||
|
public UnityEvent OnOk;
|
||||||
|
public UnityEvent OnCancel;
|
||||||
|
|
||||||
|
private Button okButton;
|
||||||
|
private Button cancelButton;
|
||||||
|
private TextMeshProUGUI titleText;
|
||||||
|
private TextMeshProUGUI messageText;
|
||||||
|
private CanvasGroup canvasGroup;
|
||||||
|
|
||||||
|
private bool animatting = false;
|
||||||
|
|
||||||
|
private float target = 0;
|
||||||
|
private float duration = 0.25f;
|
||||||
|
private float alpha = 1;
|
||||||
|
|
||||||
|
private bool useKeyboard = false;
|
||||||
|
|
||||||
|
public void Init(string title, string message, string okButtonText = "확인", string cancelButtonText = "취소", bool showCancelButton = true)
|
||||||
|
{
|
||||||
|
|
||||||
|
this.title = title;
|
||||||
|
this.message = message;
|
||||||
|
this.okButtonText = okButtonText;
|
||||||
|
this.cancelButtonText = cancelButtonText;
|
||||||
|
this.showCancelButton = showCancelButton;
|
||||||
|
|
||||||
|
canvasGroup = GetComponent<CanvasGroup>();
|
||||||
|
|
||||||
|
var okBtn = GetComponentInChildren<UIPopupButtonOk>();
|
||||||
|
var cancelBtn = GetComponentInChildren<UIPopupButtonCancel>();
|
||||||
|
var titleTxt = GetComponentInChildren<UIPopupTitle>();
|
||||||
|
var messageTxt = GetComponentInChildren<UIPopupMessage>();
|
||||||
|
|
||||||
|
|
||||||
|
if (okButton == null) okButton = okBtn.GetComponent<Button>();
|
||||||
|
|
||||||
|
if (okButton != null)
|
||||||
|
{
|
||||||
|
if (useKeyboard) okButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||||
|
okButton.GetComponentInChildren<TextMeshProUGUI>().text = okButtonText;
|
||||||
|
okButton.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
if (OnOk != null) OnOk.Invoke();
|
||||||
|
Close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancelButton == null) cancelButton = cancelBtn.GetComponent<Button>();
|
||||||
|
|
||||||
|
if (cancelButton != null)
|
||||||
|
{
|
||||||
|
if (useKeyboard) cancelButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
||||||
|
if (showCancelButton)
|
||||||
|
{
|
||||||
|
cancelButton.gameObject.SetActive(true);
|
||||||
|
cancelButton.GetComponentInChildren<TextMeshProUGUI>().text = cancelButtonText;
|
||||||
|
cancelButton.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
if (OnCancel != null) OnCancel.Invoke();
|
||||||
|
Close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cancelButton.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (titleTxt != null)
|
||||||
|
{
|
||||||
|
titleText = titleTxt.GetComponent<TextMeshProUGUI>();
|
||||||
|
titleText.text = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (messageTxt != null)
|
||||||
|
{
|
||||||
|
messageText = messageTxt.GetComponent<TextMeshProUGUI>();
|
||||||
|
messageText.text = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
canvasGroup.alpha = 0;
|
||||||
|
canvasGroup.interactable = false;
|
||||||
|
canvasGroup.blocksRaycasts = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open()
|
||||||
|
{
|
||||||
|
canvasGroup.interactable = true;
|
||||||
|
canvasGroup.blocksRaycasts = true;
|
||||||
|
target = 1;
|
||||||
|
alpha = canvasGroup.alpha;
|
||||||
|
animatting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
target = 0;
|
||||||
|
alpha = canvasGroup.alpha;
|
||||||
|
animatting = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LateUpdate()
|
||||||
|
{
|
||||||
|
if (animatting)
|
||||||
|
{
|
||||||
|
if (duration < 0)
|
||||||
|
{
|
||||||
|
duration = 0.001f;
|
||||||
|
}
|
||||||
|
|
||||||
|
alpha = Mathf.MoveTowards(alpha, target, (1 / duration) * Time.deltaTime);
|
||||||
|
canvasGroup.alpha = alpha;
|
||||||
|
if (alpha == target)
|
||||||
|
{
|
||||||
|
if (target == 0)
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
animatting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (alpha == 1 && target == 1 && useKeyboard)
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.Escape))
|
||||||
|
{
|
||||||
|
if (showCancelButton)
|
||||||
|
{
|
||||||
|
cancelButton.OnPointerDown(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Input.GetKeyUp(KeyCode.Escape))
|
||||||
|
{
|
||||||
|
if (showCancelButton)
|
||||||
|
{
|
||||||
|
cancelButton.OnPointerUp(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
||||||
|
}
|
||||||
|
if (OnCancel != null) OnCancel.Invoke();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
else if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
okButton.OnPointerDown(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
||||||
|
}
|
||||||
|
else if (Input.GetKeyUp(KeyCode.Space))
|
||||||
|
{
|
||||||
|
okButton.OnPointerUp(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
||||||
|
if (OnOk != null) OnOk.Invoke();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (okButton != null)
|
||||||
|
{
|
||||||
|
okButton.onClick.RemoveAllListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancelButton != null)
|
||||||
|
{
|
||||||
|
cancelButton.onClick.RemoveAllListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OnOk != null)
|
||||||
|
{
|
||||||
|
OnOk.RemoveAllListeners();
|
||||||
|
OnOk = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OnCancel != null)
|
||||||
|
{
|
||||||
|
OnCancel.RemoveAllListeners();
|
||||||
|
OnCancel = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Assets/Scripts/UI/PopUp/UIPopupButtonCancel.cs
Normal file
9
Assets/Scripts/UI/PopUp/UIPopupButtonCancel.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Octopus.Simulator.UI.Popup
|
||||||
|
{
|
||||||
|
public class UIPopupButtonCancel : MonoBehaviour
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
Assets/Scripts/UI/PopUp/UIPopupButtonOk.cs
Normal file
9
Assets/Scripts/UI/PopUp/UIPopupButtonOk.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Octopus.Simulator.UI.Popup
|
||||||
|
{
|
||||||
|
public class UIPopupButtonOk : MonoBehaviour
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
9
Assets/Scripts/UI/PopUp/UIPopupMessage.cs
Normal file
9
Assets/Scripts/UI/PopUp/UIPopupMessage.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Octopus.Simulator.UI.Popup
|
||||||
|
{
|
||||||
|
public class UIPopupMessage : MonoBehaviour
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
Assets/Scripts/UI/PopUp/UIPopupTitle.cs
Normal file
9
Assets/Scripts/UI/PopUp/UIPopupTitle.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Octopus.Simulator.UI.Popup
|
||||||
|
{
|
||||||
|
public class UIPopupTitle : MonoBehaviour
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using Newtonsoft.Json;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Octopus.Simulator.Networks;
|
using Octopus.Simulator.Networks;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Octopus.Simulator.UI.Popup;
|
||||||
|
|
||||||
#pragma warning disable CS8618
|
#pragma warning disable CS8618
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using UnityEngine;
|
using Best.MQTT;
|
||||||
using Best.MQTT;
|
|
||||||
using Best.MQTT.Packets;
|
using Best.MQTT.Packets;
|
||||||
using Best.MQTT.Packets.Builders;
|
using Best.MQTT.Packets.Builders;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Octopus.Simulator.UI.Popup;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Octopus.Simulator.Networks
|
namespace Octopus.Simulator.Networks
|
||||||
{
|
{
|
||||||
@@ -26,7 +26,7 @@ namespace Octopus.Simulator.Networks
|
|||||||
public event Action onLogicUpdated;
|
public event Action onLogicUpdated;
|
||||||
bool flag = true;
|
bool flag = true;
|
||||||
|
|
||||||
string protocol="wss";
|
string protocol = "wss";
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@@ -164,7 +164,7 @@ namespace Octopus.Simulator.Networks
|
|||||||
|
|
||||||
private async void OnDisconnected(MQTTClient client, DisconnectReasonCodes reasonCode, string reasonMessage)
|
private async void OnDisconnected(MQTTClient client, DisconnectReasonCodes reasonCode, string reasonMessage)
|
||||||
{
|
{
|
||||||
if(isSceneReroad)
|
if (isSceneReroad)
|
||||||
{
|
{
|
||||||
isSceneReroad = false;
|
isSceneReroad = false;
|
||||||
return;
|
return;
|
||||||
@@ -173,7 +173,7 @@ namespace Octopus.Simulator.Networks
|
|||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
{
|
{
|
||||||
var reconnect = await AlertManager.I.ShowConfirm("MQTT 연결 실패", "네트워크 재연결 하시겠습니까?");
|
var reconnect = await AlertManager.I.ShowConfirm("MQTT 연결 실패", "네트워크 재연결 하시겠습니까?");
|
||||||
if(reconnect)
|
if (reconnect)
|
||||||
SetMqttConfig();
|
SetMqttConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using UVC.Networks;
|
|||||||
using Best.MQTT;
|
using Best.MQTT;
|
||||||
using Best.MQTT.Packets;
|
using Best.MQTT.Packets;
|
||||||
using RTG;
|
using RTG;
|
||||||
using Assets.WorkSpace.R;
|
|
||||||
|
|
||||||
namespace Octopus.Simulator
|
namespace Octopus.Simulator
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -190,11 +190,6 @@ public class SimulationModelProcess : SimulationModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
protected override IEnumerator RunSimulationCoroutine()
|
protected override IEnumerator RunSimulationCoroutine()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using UnityEngine.Networking;
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Octopus.Simulator;
|
using Octopus.Simulator;
|
||||||
|
using Octopus.Simulator.UI.Popup;
|
||||||
|
|
||||||
#pragma warning disable CS8632
|
#pragma warning disable CS8632
|
||||||
|
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
using Cysharp.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class AlertManager : UnitySingleton<AlertManager>
|
|
||||||
{
|
|
||||||
private GameObject prefab;
|
|
||||||
private UIAlert alert;
|
|
||||||
|
|
||||||
|
|
||||||
private void Create()
|
|
||||||
{
|
|
||||||
if (alert == null)
|
|
||||||
{
|
|
||||||
if (prefab == null)
|
|
||||||
{
|
|
||||||
prefab = Resources.Load("UIPrefab/UIAlert", typeof(GameObject)) as GameObject;
|
|
||||||
}
|
|
||||||
GameObject go = UnityEngine.Object.Instantiate(prefab);
|
|
||||||
alert = go.GetComponent<UIAlert>();
|
|
||||||
}
|
|
||||||
var canvas = FindAnyObjectByType<Canvas_Main>();
|
|
||||||
alert.transform.SetParent(canvas.transform, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async UniTask ShowAlert(string title, string message, string okButtonTitle = "OK")
|
|
||||||
{
|
|
||||||
Create();
|
|
||||||
|
|
||||||
bool isClosed = false;
|
|
||||||
|
|
||||||
alert.Init(title: title, message: message, okButtonText: okButtonTitle, showCancelButton: false);
|
|
||||||
alert.OnOk.AddListener(() =>
|
|
||||||
{
|
|
||||||
isClosed = true;
|
|
||||||
});
|
|
||||||
alert.Open();
|
|
||||||
await UniTask.WaitUntil(() => isClosed == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async UniTask<bool> ShowConfirm(string title, string message, string okButtonTitle = "OK", string cancelButtonTitle = "CANCEL")
|
|
||||||
{
|
|
||||||
Create();
|
|
||||||
|
|
||||||
bool isClosed = false;
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
alert.Init(title, message, okButtonTitle, cancelButtonTitle, true);
|
|
||||||
|
|
||||||
alert.OnOk.AddListener(() =>
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
isClosed = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
alert.OnCancel.AddListener(() =>
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
isClosed = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
alert.Open();
|
|
||||||
|
|
||||||
|
|
||||||
await UniTask.WaitUntil(() => isClosed == true);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
using TMPro;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(CanvasGroup))]
|
|
||||||
public class UIAlert : MonoBehaviour
|
|
||||||
{
|
|
||||||
private string title;
|
|
||||||
private string message;
|
|
||||||
|
|
||||||
private string okButtonText = "확인";
|
|
||||||
private string cancelButtonText = "취소";
|
|
||||||
|
|
||||||
private bool showCancelButton = false;
|
|
||||||
|
|
||||||
public UnityEvent OnOk;
|
|
||||||
public UnityEvent OnCancel;
|
|
||||||
|
|
||||||
private Button okButton;
|
|
||||||
private Button cancelButton;
|
|
||||||
private TextMeshProUGUI titleText;
|
|
||||||
private TextMeshProUGUI messageText;
|
|
||||||
private CanvasGroup canvasGroup;
|
|
||||||
|
|
||||||
private bool animatting = false;
|
|
||||||
|
|
||||||
private float target = 0;
|
|
||||||
private float duration = 0.25f;
|
|
||||||
private float alpha = 1;
|
|
||||||
|
|
||||||
private bool useKeyboard = false;
|
|
||||||
|
|
||||||
public void Init(string title, string message, string okButtonText = "확인", string cancelButtonText = "취소", bool showCancelButton = true)
|
|
||||||
{
|
|
||||||
|
|
||||||
this.title = title;
|
|
||||||
this.message = message;
|
|
||||||
this.okButtonText = okButtonText;
|
|
||||||
this.cancelButtonText = cancelButtonText;
|
|
||||||
this.showCancelButton = showCancelButton;
|
|
||||||
|
|
||||||
canvasGroup = GetComponent<CanvasGroup>();
|
|
||||||
|
|
||||||
var okBtn = GetComponentInChildren<UIPopupButtonOk>();
|
|
||||||
var cancelBtn = GetComponentInChildren<UIPopupButtonCancel>();
|
|
||||||
var titleTxt = GetComponentInChildren<UIPopupTitle>();
|
|
||||||
var messageTxt = GetComponentInChildren<UIPopupMessage>();
|
|
||||||
|
|
||||||
|
|
||||||
if (okButton == null) okButton = okBtn.GetComponent<Button>();
|
|
||||||
|
|
||||||
if (okButton != null)
|
|
||||||
{
|
|
||||||
if (useKeyboard) okButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
|
||||||
okButton.GetComponentInChildren<TextMeshProUGUI>().text = okButtonText;
|
|
||||||
okButton.onClick.AddListener(() =>
|
|
||||||
{
|
|
||||||
if (OnOk != null) OnOk.Invoke();
|
|
||||||
Close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cancelButton == null) cancelButton = cancelBtn.GetComponent<Button>();
|
|
||||||
|
|
||||||
if (cancelButton != null)
|
|
||||||
{
|
|
||||||
if (useKeyboard) cancelButton.navigation = new Navigation() { mode = Navigation.Mode.None };
|
|
||||||
if (showCancelButton)
|
|
||||||
{
|
|
||||||
cancelButton.gameObject.SetActive(true);
|
|
||||||
cancelButton.GetComponentInChildren<TextMeshProUGUI>().text = cancelButtonText;
|
|
||||||
cancelButton.onClick.AddListener(() =>
|
|
||||||
{
|
|
||||||
if (OnCancel != null) OnCancel.Invoke();
|
|
||||||
Close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cancelButton.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (titleTxt != null)
|
|
||||||
{
|
|
||||||
titleText = titleTxt.GetComponent<TextMeshProUGUI>();
|
|
||||||
titleText.text = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (messageTxt != null)
|
|
||||||
{
|
|
||||||
messageText = messageTxt.GetComponent<TextMeshProUGUI>();
|
|
||||||
messageText.text = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvasGroup.alpha = 0;
|
|
||||||
canvasGroup.interactable = false;
|
|
||||||
canvasGroup.blocksRaycasts = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Open()
|
|
||||||
{
|
|
||||||
canvasGroup.interactable = true;
|
|
||||||
canvasGroup.blocksRaycasts = true;
|
|
||||||
target = 1;
|
|
||||||
alpha = canvasGroup.alpha;
|
|
||||||
animatting = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close()
|
|
||||||
{
|
|
||||||
target = 0;
|
|
||||||
alpha = canvasGroup.alpha;
|
|
||||||
animatting = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LateUpdate()
|
|
||||||
{
|
|
||||||
if (animatting)
|
|
||||||
{
|
|
||||||
if (duration < 0)
|
|
||||||
{
|
|
||||||
duration = 0.001f;
|
|
||||||
}
|
|
||||||
|
|
||||||
alpha = Mathf.MoveTowards(alpha, target, (1 / duration) * Time.deltaTime);
|
|
||||||
canvasGroup.alpha = alpha;
|
|
||||||
if (alpha == target)
|
|
||||||
{
|
|
||||||
if (target == 0)
|
|
||||||
{
|
|
||||||
Destroy(gameObject);
|
|
||||||
}
|
|
||||||
animatting = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (alpha == 1 && target == 1 && useKeyboard)
|
|
||||||
{
|
|
||||||
if (Input.GetKeyDown(KeyCode.Escape))
|
|
||||||
{
|
|
||||||
if (showCancelButton)
|
|
||||||
{
|
|
||||||
cancelButton.OnPointerDown(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Input.GetKeyUp(KeyCode.Escape))
|
|
||||||
{
|
|
||||||
if (showCancelButton)
|
|
||||||
{
|
|
||||||
cancelButton.OnPointerUp(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
|
||||||
}
|
|
||||||
if (OnCancel != null) OnCancel.Invoke();
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
else if (Input.GetKeyDown(KeyCode.Space))
|
|
||||||
{
|
|
||||||
okButton.OnPointerDown(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
|
||||||
}
|
|
||||||
else if (Input.GetKeyUp(KeyCode.Space))
|
|
||||||
{
|
|
||||||
okButton.OnPointerUp(new UnityEngine.EventSystems.PointerEventData(EventSystem.current));
|
|
||||||
if (OnOk != null) OnOk.Invoke();
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void OnDestroy()
|
|
||||||
{
|
|
||||||
if (okButton != null)
|
|
||||||
{
|
|
||||||
okButton.onClick.RemoveAllListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cancelButton != null)
|
|
||||||
{
|
|
||||||
cancelButton.onClick.RemoveAllListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OnOk != null)
|
|
||||||
{
|
|
||||||
OnOk.RemoveAllListeners();
|
|
||||||
OnOk = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OnCancel != null)
|
|
||||||
{
|
|
||||||
OnCancel.RemoveAllListeners();
|
|
||||||
OnCancel = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class UIPopupButtonCancel : MonoBehaviour
|
|
||||||
{
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class UIPopupButtonOk : MonoBehaviour
|
|
||||||
{
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class UIPopupMessage : MonoBehaviour
|
|
||||||
{
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class UIPopupTitle : MonoBehaviour
|
|
||||||
{
|
|
||||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user