late goodbye
This commit is contained in:
@@ -21,6 +21,11 @@ public class GameSystem : MonoBehaviour
|
||||
public List<IGameComponent> gameComponents { get; private set; } = new List<IGameComponent>();
|
||||
|
||||
[SerializeField] UIMainMenu mainMenu;
|
||||
[SerializeField] UICanvas trainsMenu;
|
||||
[Space]
|
||||
public UICanvas trainEP2D;
|
||||
public UICanvas train2;
|
||||
public UICanvas train3;
|
||||
[Space]
|
||||
[SerializeField] GameObject[] sigletonComponents;
|
||||
|
||||
@@ -40,8 +45,12 @@ public class GameSystem : MonoBehaviour
|
||||
{
|
||||
mainMenu.UpdateLocationMenu(locationsName[sceneName]);
|
||||
|
||||
var qrReader = FindObjectOfType<QRCodeReader>();
|
||||
qrReader.camTexture.Stop();
|
||||
try
|
||||
{
|
||||
var qrReader = FindObjectOfType<QRCodeReader>();
|
||||
qrReader.camTexture.Stop();
|
||||
}
|
||||
catch {}
|
||||
|
||||
var sceneLoadingOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
|
||||
while(!sceneLoadingOperation.isDone) await Task.Yield();
|
||||
@@ -54,6 +63,51 @@ public class GameSystem : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
public void ShowAboutTrain()
|
||||
{
|
||||
switch(mainMenu.currentTrain.type)
|
||||
{
|
||||
case(TrainType.EP2D):
|
||||
ShowAboutEP2D();
|
||||
break;
|
||||
|
||||
case(TrainType.Ivolga2):
|
||||
ShowAboutIvolga2();
|
||||
break;
|
||||
|
||||
case(TrainType.Ivolga3):
|
||||
ShowAboutIvolga3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowAboutEP2D()
|
||||
{
|
||||
train2.gameObject.SetActive(false);
|
||||
train3.gameObject.SetActive(false);
|
||||
|
||||
trainsMenu.gameObject.SetActive(true);
|
||||
trainEP2D.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void ShowAboutIvolga2()
|
||||
{
|
||||
train3.gameObject.SetActive(false);
|
||||
trainEP2D.gameObject.SetActive(false);
|
||||
|
||||
trainsMenu.gameObject.SetActive(true);
|
||||
train2.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void ShowAboutIvolga3()
|
||||
{
|
||||
train2.gameObject.SetActive(false);
|
||||
trainEP2D.gameObject.SetActive(false);
|
||||
|
||||
trainsMenu.gameObject.SetActive(true);
|
||||
train3.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void LeaveScene()
|
||||
{
|
||||
var sceneLoadingOperation = SceneManager.LoadSceneAsync("MainMenu",
|
||||
|
||||
@@ -4,9 +4,11 @@ using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class InputHandler : MonoBehaviour, IGameComponent
|
||||
public class InputHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float speed = 2;
|
||||
private Transform cameraTransform;
|
||||
private Quaternion lastRotation;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
@@ -15,14 +17,14 @@ public class InputHandler : MonoBehaviour, IGameComponent
|
||||
|
||||
void Start()
|
||||
{
|
||||
GameSystem.Instance.AddGameComponent(this);
|
||||
// GameSystem.Instance.AddGameComponent(this);
|
||||
Input.gyro.enabled = true;
|
||||
}
|
||||
|
||||
public void OnUpdate()
|
||||
public void Update()
|
||||
{
|
||||
var phoneRotation = Input.gyro.attitude;
|
||||
cameraTransform.rotation = phoneRotation;
|
||||
cameraTransform.rotation = lastRotation;
|
||||
lastRotation = Quaternion.Lerp(transform.rotation, Input.gyro.attitude, speed * Time.deltaTime);
|
||||
|
||||
cameraTransform.Rotate(0, 0, 180, Space.Self);
|
||||
cameraTransform.Rotate(90, 180, 0, Space.World);
|
||||
@@ -33,6 +35,6 @@ public class InputHandler : MonoBehaviour, IGameComponent
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
GameSystem.Instance.RemoveGameComponent(this);
|
||||
// GameSystem.Instance.RemoveGameComponent(this);
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,17 @@ public class QRCodeReader : MonoBehaviour
|
||||
var ratio = (float)camTexture.width / (float)camTexture.height;
|
||||
aspectRatioFitter.aspectRatio = ratio;
|
||||
|
||||
float scaleY = camTexture.videoVerticallyMirrored ? -1f : 1f;
|
||||
rawImage.rectTransform.localScale = new Vector3(1f, scaleY, 1f);
|
||||
float scaleY = 1;
|
||||
if(Application.platform == RuntimePlatform.Android)
|
||||
{
|
||||
scaleY = camTexture.videoVerticallyMirrored ? -1f : 1f;
|
||||
rawImage.rectTransform.localScale = new Vector3(1f, scaleY, 1f);
|
||||
}
|
||||
else if(Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
{
|
||||
ratio = (float)camTexture.height / (float)camTexture.width;
|
||||
rawImage.rectTransform.localScale = new Vector3(1f, -1f, 1f);
|
||||
}
|
||||
|
||||
ScanningQRCode();
|
||||
}
|
||||
|
||||
+28
-9
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using DG.Tweening;
|
||||
@@ -10,16 +12,30 @@ public class Train : MonoBehaviour
|
||||
public bool useEffect;
|
||||
private LocomotionHandler locomotionHandler;
|
||||
private Coroutine c_effect;
|
||||
private Material[] materials;
|
||||
private List<Material> materials = new();
|
||||
private float effectDuration = .4f;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(materials == null)
|
||||
materials = GetComponent<MeshRenderer>().materials;
|
||||
var uiMenu = FindObjectOfType<UIMainMenu>();
|
||||
uiMenu.currentTrain = this;
|
||||
|
||||
if(materials.Count == 0)
|
||||
{
|
||||
materials = GetComponent<MeshRenderer>().materials.ToList();
|
||||
var materialsInChildren = gameObject.transform
|
||||
.GetChild(0)
|
||||
.GetComponent<MeshRenderer>()
|
||||
.materials.ToList();
|
||||
|
||||
foreach(var mat in materialsInChildren)
|
||||
materials.Add(mat);
|
||||
}
|
||||
|
||||
if(!useEffect)
|
||||
{
|
||||
SetEffect(true);
|
||||
|
||||
if(locomotionHandler == null)
|
||||
locomotionHandler = FindObjectOfType<LocomotionHandler>();
|
||||
|
||||
@@ -36,7 +52,7 @@ public class Train : MonoBehaviour
|
||||
else SetEffect(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
public async void Hide()
|
||||
{
|
||||
if(!useEffect)
|
||||
{
|
||||
@@ -46,6 +62,9 @@ public class Train : MonoBehaviour
|
||||
transform.DOLocalMoveZ(endPosition, speed)
|
||||
.SetEase(Ease.InSine)
|
||||
.OnComplete(() => gameObject.SetActive(false));
|
||||
|
||||
await Task.Delay(3000);
|
||||
SetEffect(false);
|
||||
}
|
||||
else SetEffect(false);
|
||||
}
|
||||
@@ -63,11 +82,11 @@ public class Train : MonoBehaviour
|
||||
|
||||
IEnumerator SetEffectRoutine(bool isShow)
|
||||
{
|
||||
float startPosition = isShow ? -5 : 2;
|
||||
float startPosition = isShow ? -5 : 3;
|
||||
float currentValue = startPosition;
|
||||
float endPosition = 0;
|
||||
|
||||
if(isShow) endPosition = 2;
|
||||
if(isShow) endPosition = 3;
|
||||
else endPosition = -5;
|
||||
|
||||
float progress = 0;
|
||||
@@ -77,7 +96,7 @@ public class Train : MonoBehaviour
|
||||
{
|
||||
currentValue = Mathf.Lerp(startPosition, endPosition, progress);
|
||||
|
||||
for(int i = 0; i < materials.Length; i++)
|
||||
for(int i = 0; i < materials.Count; i++)
|
||||
{
|
||||
materials[i]
|
||||
.SetFloat("_EffectPosition", currentValue);
|
||||
@@ -87,13 +106,13 @@ public class Train : MonoBehaviour
|
||||
yield return null;
|
||||
}
|
||||
|
||||
for(int i = 0; i < materials.Length; i++)
|
||||
for(int i = 0; i < materials.Count; i++)
|
||||
{
|
||||
materials[i]
|
||||
.SetFloat("_EffectPosition", endPosition);
|
||||
}
|
||||
|
||||
if(!isShow)
|
||||
if(!isShow && useEffect)
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIMainMenu : UICanvas
|
||||
{
|
||||
[SerializeField] private Text stationName;
|
||||
[SerializeField] UITrainButton[] trainButtons;
|
||||
|
||||
public Image aboutTrainButton;
|
||||
public Train currentTrain { get; set; }
|
||||
|
||||
public void ShowAboutTrainButton()
|
||||
{
|
||||
aboutTrainButton.gameObject.SetActive(true);
|
||||
aboutTrainButton.color = new Color(1, 1, 1, 0);
|
||||
aboutTrainButton.DOFade(.7f, 10f);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(aboutTrainButton.gameObject.activeSelf && currentTrain != null)
|
||||
aboutTrainButton.rectTransform
|
||||
.position = Camera.main.WorldToScreenPoint(currentTrain.transform.position + Vector3.up * 1.5f);
|
||||
}
|
||||
|
||||
public void UpdateLocationMenu(Location location)
|
||||
{
|
||||
@@ -37,4 +56,13 @@ public class UIMainMenu : UICanvas
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetButtons()
|
||||
{
|
||||
foreach(var button in trainButtons)
|
||||
button.Unselect();
|
||||
|
||||
aboutTrainButton.gameObject.SetActive(false);
|
||||
currentTrain = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ public class UITrainButton : MonoBehaviour, IPointerClickHandler
|
||||
item.Unselect();
|
||||
}
|
||||
|
||||
FindObjectOfType<UIMainMenu>()
|
||||
.ShowAboutTrainButton();
|
||||
|
||||
locomotionHandler.ShowTrain(trainType);
|
||||
buttonBase.DOColor(selectedColor, .2f);
|
||||
isSelected = true;
|
||||
|
||||
Reference in New Issue
Block a user