script追加

This commit is contained in:
kimura 2022-09-15 12:42:23 +09:00
parent be7f96ff59
commit eb113dfc73
5 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3b97fdce2b414051ab1dfb02023f448a
timeCreated: 1663136175

View File

@ -0,0 +1,20 @@
using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
namespace MyGame.Scenes.WorldMap.Scripts
{
public class CityIcon : MonoBehaviour
{
[SerializeField] private Transform icon;
public IObservable<Unit> OnClick =>
(icon.GetComponent<ObservableEventTrigger>() ?? icon.gameObject.AddComponent<ObservableEventTrigger>())
.OnPointerClickAsObservable()
.AsUnitObservable();
private void Start()
{
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 94d22fb4b30547a7a7d613555c1fd8da
timeCreated: 1663139984

View File

@ -0,0 +1,84 @@
using System;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.UI;
namespace MyGame.Scenes.WorldMap.Scripts
{
public class WorldMap : MonoBehaviour
{
[SerializeField] private Transform selectedCityTarget;
[SerializeField] private CityIcon[] cityIcons;
[SerializeField] private ScrollRect scrollRect;
[SerializeField] private GameObject cancelWall;
[SerializeField] private GameObject investmentPopup;
[SerializeField] private GameObject earningPopup;
[SerializeField] private float selectDuration = 1f;
[SerializeField] private float zoomScale = 1f;
private void Start()
{
#if UNITY_EDITOR
this.UpdateAsObservable()
.Where(_ => Input.GetKeyDown(KeyCode.R))
.Subscribe(_ => TransitionManager.Instance.LoadScene(GameScenes.WorldMap));
#endif
var content = scrollRect.content;
var contentOffset = content.localPosition;
var selectedPos = selectedCityTarget.localPosition;
var shareGate = true;
cancelWall.AddComponent<ObservableEventTrigger>().OnPointerClickAsObservable()
.Where(_ => shareGate)
.ThrottleFirst(TimeSpan.FromSeconds(1f))
.Subscribe(_ =>
{
shareGate = false;
investmentPopup.SetActive(false);
var beginPos = content.localPosition;
var endPos = new Vector3(contentOffset.y, contentOffset.x + (beginPos - contentOffset).x / zoomScale);
this.CallLerp(selectDuration, f =>
{
var scale = Mathf.Lerp(zoomScale, 1f, f);
content.localPosition = Vector3.Lerp(beginPos, endPos, f);
content.SetLocalScale(scale);
}, () =>
{
content.localPosition = endPos;
cancelWall.SetActive(false);
shareGate = true;
});
}).AddTo(this);
foreach (var cityIcon in cityIcons)
{
cityIcon.OnClick
.Where(_ => shareGate)
.ThrottleFirst(TimeSpan.FromSeconds(1f))
.Subscribe(_ =>
{
shareGate = false;
var beginPos = content.localPosition;
var endPos = contentOffset + (selectedPos - cityIcon.transform.localPosition) * zoomScale;
this.CallLerp(selectDuration, f =>
{
var scale = Mathf.Lerp(1f, zoomScale, f);
content.localPosition = Vector3.Lerp(beginPos, endPos, f);
content.SetLocalScale(scale);
}, () =>
{
// popup表示
investmentPopup.SetActive(true);
cancelWall.SetActive(true);
shareGate = true;
});
}).AddTo(cityIcon);
}
investmentPopup.SetActive(false);
cancelWall.SetActive(false);
// 選択中の店舗を中央に持ってくる
content.localPosition = contentOffset.AddX(-cityIcons[0].transform.localPosition.x);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4319073427524c249da746ff7c2fca42
timeCreated: 1663136189