116 lines
2.8 KiB
C#
116 lines
2.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class CamereModeButton : ImageToggle
|
|
{
|
|
private void Start()
|
|
{
|
|
if (ProcessInput.Instance != null)
|
|
ProcessInput.Instance.inputModule.onCameraModeChange += OnCameraModeChange;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (!GameManager.applicationQuit &&
|
|
ProcessInput.Instance != null)
|
|
ProcessInput.Instance.inputModule.onCameraModeChange -= OnCameraModeChange;
|
|
}
|
|
|
|
private void OnCameraModeChange(bool isOn)
|
|
{
|
|
SetImage(isOn);
|
|
}
|
|
|
|
public override bool GetValue()
|
|
{
|
|
return ProcessInput.Instance != null && ProcessInput.Instance.inputModule.isCameraMode;
|
|
}
|
|
|
|
public override void SetValue(bool isOn)
|
|
{
|
|
if (ProcessInput.Instance != null)
|
|
ProcessInput.Instance.inputModule.SetCameraModel(isOn);
|
|
}
|
|
}
|
|
|
|
[RequireComponent(typeof(Image))]
|
|
public abstract class ImageToggle : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
|
|
{
|
|
private int? _pointerId;
|
|
private Image _image;
|
|
public Sprite onSprite;
|
|
public Sprite offSprite;
|
|
|
|
private void Awake()
|
|
{
|
|
_image = GetComponent<Image>();
|
|
}
|
|
|
|
protected virtual void OnEnable()
|
|
{
|
|
SetImage(GetValue());
|
|
}
|
|
|
|
private void OnApplicationFocus(bool hasFocus)
|
|
{
|
|
if (!hasFocus)
|
|
CancelPointer();
|
|
}
|
|
|
|
public abstract bool GetValue();
|
|
|
|
public abstract void SetValue(bool isOn);
|
|
|
|
protected void SetImage(bool isOn)
|
|
{
|
|
_image.sprite = isOn ? onSprite : offSprite;
|
|
}
|
|
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
if (_pointerId == null)
|
|
{
|
|
_pointerId = eventData.pointerId;
|
|
SetImage(!GetValue());
|
|
}
|
|
}
|
|
|
|
//void WCCameraOperation()
|
|
//{
|
|
// if (GameManager.gameManager.PlayerDataPool.WCCamera)
|
|
// {
|
|
// GameManager.gameManager.PlayerDataPool.WCCamera.enabled = false;
|
|
// GameManager.gameManager.PlayerDataPool.WCCamera = null;
|
|
// }
|
|
|
|
// if (GameManager.gameManager.PlayerDataPool.IsInWeddingCar)
|
|
// if (Games.Scene.SceneLogic.CameraController != null)
|
|
// Games.Scene.SceneLogic.CameraController.OnWCMovie(false);
|
|
//}
|
|
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
if (_pointerId == eventData.pointerId)
|
|
{
|
|
_pointerId = null;
|
|
var value = GetValue();
|
|
SetValue(!value);
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (_pointerId == eventData.pointerId)
|
|
CancelPointer();
|
|
}
|
|
|
|
private void CancelPointer()
|
|
{
|
|
if (_pointerId != null)
|
|
{
|
|
_pointerId = null;
|
|
SetImage(GetValue());
|
|
}
|
|
}
|
|
} |