Implement input config dialog.
This commit is contained in:
49
Assets/Cryville/Crtr/InputConfig.cs
Normal file
49
Assets/Cryville/Crtr/InputConfig.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Cryville.Common.Unity;
|
||||
using Cryville.Common.Unity.Input;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class InputConfig : MonoBehaviour {
|
||||
[SerializeField]
|
||||
GameObject m_inputDialog;
|
||||
|
||||
[SerializeField]
|
||||
Transform m_deviceList;
|
||||
|
||||
[SerializeField]
|
||||
GameObject m_prefabListItem;
|
||||
|
||||
public void OpenDialog() {
|
||||
m_inputDialog.SetActive(true);
|
||||
Game.InputManager.Activate();
|
||||
CallHelper.Purge(m_deviceList);
|
||||
_recvsrcs.Clear();
|
||||
}
|
||||
|
||||
public void CloseDialog() {
|
||||
CloseDialog(null);
|
||||
}
|
||||
|
||||
public void CloseDialog(InputSource? src) {
|
||||
m_inputDialog.SetActive(false);
|
||||
Game.InputManager.Deactivate();
|
||||
}
|
||||
|
||||
List<InputSource> _recvsrcs = new List<InputSource>();
|
||||
void Update() {
|
||||
if (m_inputDialog.activeSelf) {
|
||||
Game.InputManager.EnumerateEvents(ev => {
|
||||
var src = ev.Id.Source;
|
||||
if (!_recvsrcs.Contains(src)) {
|
||||
_recvsrcs.Add(src);
|
||||
var obj = Instantiate(m_prefabListItem);
|
||||
obj.transform.SetParent(m_deviceList);
|
||||
obj.transform.Find("Text").GetComponent<Text>().text = src.Handler.GetTypeName(src.Type);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/InputConfig.cs.meta
Normal file
11
Assets/Cryville/Crtr/InputConfig.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d27589834da67984d98c6147c8b6b5bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user