From 9a2bfe931ed406e98b716c71ebbfcd5db3ef332d Mon Sep 17 00:00:00 2001 From: kimura Date: Mon, 26 Sep 2022 11:24:19 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=A6=E7=90=86=E8=BF=BD=E5=8A=A0=20CityIcon?= =?UTF-8?q?.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorldMap/Prefabs/Country_icon.prefab | 19 ++++++++- .../Country_icon_b_SanFrancisco.prefab | 5 +++ .../Prefabs/Country_icon_c_Beijing.prefab | 5 +++ .../Scenes/WorldMap/Scripts/CityIcon.cs | 41 ++++++++++++++++++- 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon.prefab b/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon.prefab index 8f9b484b..f66155f1 100644 --- a/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon.prefab +++ b/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon.prefab @@ -130,7 +130,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 94d22fb4b30547a7a7d613555c1fd8da, type: 3} m_Name: m_EditorClassIdentifier: - icon: {fileID: 498716710821908371} + cityIcon: {fileID: 498716710821908371} + cityId: 1 + pin: {fileID: 498716709849429620} + lockIcon: {fileID: 498716710438122542} + notifyIcon: {fileID: 8888824836673155761} + animator: {fileID: 2247642576509783911} --- !u!1 &498716710438122542 GameObject: m_ObjectHideFlags: 0 @@ -571,6 +576,12 @@ RectTransform: type: 3} m_PrefabInstance: {fileID: 498716710500312605} m_PrefabAsset: {fileID: 0} +--- !u!1 &8888824836673155761 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 9056949049436837036, guid: f8587bb162250fa48947d648e934781e, + type: 3} + m_PrefabInstance: {fileID: 498716710500312605} + m_PrefabAsset: {fileID: 0} --- !u!1001 &1360594892428573506 PrefabInstance: m_ObjectHideFlags: 0 @@ -701,3 +712,9 @@ RectTransform: type: 3} m_PrefabInstance: {fileID: 1360594892428573506} m_PrefabAsset: {fileID: 0} +--- !u!95 &2247642576509783911 stripped +Animator: + m_CorrespondingSourceObject: {fileID: 995566939256566821, guid: 1dd4681cca844994eab02ced553ab174, + type: 3} + m_PrefabInstance: {fileID: 1360594892428573506} + m_PrefabAsset: {fileID: 0} diff --git a/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_b_SanFrancisco.prefab b/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_b_SanFrancisco.prefab index bb9c3edc..52f9d924 100644 --- a/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_b_SanFrancisco.prefab +++ b/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_b_SanFrancisco.prefab @@ -173,6 +173,11 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: -59.7 objectReference: {fileID: 0} + - target: {fileID: 2308183619134864621, guid: 68b944bf4894305448bb16375de74dbc, + type: 3} + propertyPath: cityId + value: 2 + objectReference: {fileID: 0} - target: {fileID: 8503390566567986980, guid: 68b944bf4894305448bb16375de74dbc, type: 3} propertyPath: m_AnchoredPosition.x diff --git a/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_c_Beijing.prefab b/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_c_Beijing.prefab index fc4ff558..959d665c 100644 --- a/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_c_Beijing.prefab +++ b/popcorn/Assets/MyGame/Scenes/WorldMap/Prefabs/Country_icon_c_Beijing.prefab @@ -143,6 +143,11 @@ PrefabInstance: propertyPath: m_AnchoredPosition.y value: -60.2 objectReference: {fileID: 0} + - target: {fileID: 2308183619134864621, guid: 68b944bf4894305448bb16375de74dbc, + type: 3} + propertyPath: cityId + value: 3 + objectReference: {fileID: 0} - target: {fileID: 8888824836673155761, guid: 68b944bf4894305448bb16375de74dbc, type: 3} propertyPath: m_IsActive diff --git a/popcorn/Assets/MyGame/Scenes/WorldMap/Scripts/CityIcon.cs b/popcorn/Assets/MyGame/Scenes/WorldMap/Scripts/CityIcon.cs index 4a0e1051..8084d148 100644 --- a/popcorn/Assets/MyGame/Scenes/WorldMap/Scripts/CityIcon.cs +++ b/popcorn/Assets/MyGame/Scenes/WorldMap/Scripts/CityIcon.cs @@ -5,18 +5,55 @@ using UnityEngine; namespace MyGame.Scenes.WorldMap.Scripts { + public enum CityState + { + UnRelease, + Lock, + Release + } public class CityIcon : MonoBehaviour { - [SerializeField] private Transform icon; + [SerializeField] private Transform cityIcon; [SerializeField] private int cityId; + private readonly ReactiveProperty cityState = new(); public int CityId => cityId; public IObservable OnClick => - (icon.GetComponent() ?? icon.gameObject.AddComponent()) + (cityIcon.GetComponent() ?? cityIcon.gameObject.AddComponent()) .OnPointerClickAsObservable() .AsUnitObservable(); + [SerializeField] private GameObject pin; + [SerializeField] private GameObject lockIcon; + [SerializeField] private GameObject notifyIcon; + [SerializeField] private Animator animator; + private void Start() { + cityState.AddTo(this); + cityState.Subscribe(x => + { + pin.SetActive(cityState.Value == Scripts.CityState.UnRelease); + lockIcon.SetActive(cityState.Value == Scripts.CityState.Lock); + cityIcon.gameObject.SetActive(cityState.Value is Scripts.CityState.Lock or Scripts.CityState.Release); + }).AddTo(this); + } + + public void SetState(CityState state) => cityState.Value = state; + + public void SetNotify(bool active) => notifyIcon.SetActive(active); + + public void PlayAnimation(Action onComplete = null) + { + animator.gameObject.SetActive(true); + animator.Play("WorldMap_staging", 0, 0f); + Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(.3f)) + .Select(_ => animator.GetCurrentAnimatorStateInfo(0)) + .Where(state => state.normalizedTime >= 1f && state.IsName("WorldMap_staging")) + .Take(1) + .Subscribe(_ => + { + onComplete?.Invoke(); + }).AddTo(this); } } } \ No newline at end of file