| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public interface ISceneCatalogView |
| | 8 | | { |
| | 9 | | CatalogAssetPackListView catalogAssetPackList { get; } |
| | 10 | | CatalogGroupListView catalogGroupList { get; } |
| | 11 | | Toggle category { get; } |
| | 12 | | Toggle favorites { get; } |
| | 13 | | Toggle assetPack { get; } |
| | 14 | | IBIWSearchBarView searchBarView { get; } |
| | 15 | |
|
| | 16 | | event Action OnHideCatalogClicked; |
| | 17 | | event Action OnSceneCatalogBack; |
| | 18 | |
|
| | 19 | | void Back(); |
| | 20 | | void CloseCatalog(); |
| | 21 | | bool IsCatalogOpen(); |
| | 22 | | bool IsCatalogExpanded(); |
| | 23 | | void OnHideCatalogClick(); |
| | 24 | | void SetCatalogTitle(string text); |
| | 25 | | void ToggleCatalogExpanse(); |
| | 26 | | void SetActive(bool isActive); |
| | 27 | | void ShowBackButton(bool isActive); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | public class SceneCatalogView : MonoBehaviour, ISceneCatalogView |
| | 31 | | { |
| 2 | 32 | | public CatalogAssetPackListView catalogAssetPackList => catalogAssetPackListView; |
| 6 | 33 | | public CatalogGroupListView catalogGroupList => catalogGroupListView; |
| 2 | 34 | | public Toggle category => categoryToggle; |
| 2 | 35 | | public Toggle favorites => favoritesToggle; |
| 2 | 36 | | public Toggle assetPack => assetPackToggle; |
| 1 | 37 | | public IBIWSearchBarView searchBarView => biwSearchBarView; |
| | 38 | |
|
| | 39 | | public event Action OnHideCatalogClicked; |
| | 40 | | public event Action OnSceneCatalogBack; |
| | 41 | |
|
| | 42 | | [Header("Prefab References")] |
| | 43 | | [SerializeField] internal TextMeshProUGUI catalogTitleTxt; |
| | 44 | |
|
| | 45 | | [SerializeField] internal CatalogAssetPackListView catalogAssetPackListView; |
| | 46 | | [SerializeField] internal CatalogGroupListView catalogGroupListView; |
| | 47 | | [SerializeField] internal TMP_InputField searchInputField; |
| | 48 | | [SerializeField] internal Toggle categoryToggle; |
| | 49 | | [SerializeField] internal Toggle favoritesToggle; |
| | 50 | | [SerializeField] internal Toggle assetPackToggle; |
| | 51 | | [SerializeField] internal Button hideCatalogBtn; |
| | 52 | | [SerializeField] internal Button backgBtn; |
| | 53 | | [SerializeField] internal Button toggleCatalogBtn; |
| | 54 | | [SerializeField] internal BIWSearchBarView biwSearchBarView; |
| | 55 | |
|
| | 56 | | [Header("Catalog RectTransforms")] |
| | 57 | | [SerializeField] internal RectTransform panelRT; |
| | 58 | |
|
| | 59 | | [SerializeField] internal RectTransform headerRT; |
| | 60 | | [SerializeField] internal RectTransform searchBarRT; |
| | 61 | | [SerializeField] internal RectTransform assetPackRT; |
| | 62 | | [SerializeField] internal RectTransform categoryRT; |
| | 63 | |
|
| | 64 | | [Header("MinSize Catalog RectTransforms")] |
| | 65 | | [SerializeField] internal RectTransform panelMinSizeRT; |
| | 66 | |
|
| | 67 | | [SerializeField] internal RectTransform headerMinSizeRT; |
| | 68 | | [SerializeField] internal RectTransform searchBarMinSizeRT; |
| | 69 | | [SerializeField] internal RectTransform assetPackMinSizeRT; |
| | 70 | |
|
| | 71 | | [Header("MaxSize Catalog RectTransforms")] |
| | 72 | | [SerializeField] internal RectTransform panelMaxSizeRT; |
| | 73 | |
|
| | 74 | | [SerializeField] internal RectTransform headerMaxSizeRT; |
| | 75 | | [SerializeField] internal RectTransform searchBarMaxSizeRT; |
| | 76 | | [SerializeField] internal RectTransform assetPackMaxSizeRT; |
| | 77 | |
|
| | 78 | | internal bool isCatalogExpanded = false; |
| | 79 | | internal bool isClosing = false; |
| | 80 | |
|
| | 81 | | private const string VIEW_PATH = "Common/SceneCatalogView"; |
| | 82 | |
|
| | 83 | | internal static SceneCatalogView Create() |
| | 84 | | { |
| 15 | 85 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<SceneCatalogView>(); |
| 15 | 86 | | view.gameObject.name = "_SceneCatalogView"; |
| | 87 | |
|
| 15 | 88 | | return view; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | private void Awake() |
| | 92 | | { |
| 15 | 93 | | hideCatalogBtn.onClick.AddListener(OnHideCatalogClick); |
| 15 | 94 | | backgBtn.onClick.AddListener(Back); |
| 15 | 95 | | toggleCatalogBtn.onClick.AddListener(ToggleCatalogExpanse); |
| 15 | 96 | | } |
| | 97 | |
|
| | 98 | | private void OnDestroy() |
| | 99 | | { |
| 15 | 100 | | hideCatalogBtn.onClick.RemoveListener(OnHideCatalogClick); |
| 15 | 101 | | backgBtn.onClick.RemoveListener(Back); |
| 15 | 102 | | toggleCatalogBtn.onClick.RemoveListener(ToggleCatalogExpanse); |
| 15 | 103 | | } |
| | 104 | |
|
| 34 | 105 | | private void OnEnable() { AudioScriptableObjects.dialogOpen.Play(); } |
| | 106 | |
|
| 34 | 107 | | private void OnDisable() { AudioScriptableObjects.dialogClose.Play(); } |
| | 108 | |
|
| | 109 | | public void ToggleCatalogExpanse() |
| | 110 | | { |
| 0 | 111 | | if (isCatalogExpanded) |
| | 112 | | { |
| 0 | 113 | | BIWUtils.CopyRectTransform(panelRT, panelMinSizeRT); |
| 0 | 114 | | BIWUtils.CopyRectTransform(headerRT, headerMinSizeRT); |
| 0 | 115 | | BIWUtils.CopyRectTransform(searchBarRT, searchBarMinSizeRT); |
| 0 | 116 | | BIWUtils.CopyRectTransform(assetPackRT, assetPackMinSizeRT); |
| 0 | 117 | | BIWUtils.CopyRectTransform(categoryRT, assetPackMinSizeRT); |
| 0 | 118 | | AudioScriptableObjects.dialogClose.Play(); |
| 0 | 119 | | } |
| | 120 | | else |
| | 121 | | { |
| 0 | 122 | | BIWUtils.CopyRectTransform(panelRT, panelMaxSizeRT); |
| 0 | 123 | | BIWUtils.CopyRectTransform(headerRT, headerMaxSizeRT); |
| 0 | 124 | | BIWUtils.CopyRectTransform(searchBarRT, searchBarMaxSizeRT); |
| 0 | 125 | | BIWUtils.CopyRectTransform(assetPackRT, assetPackMaxSizeRT); |
| 0 | 126 | | BIWUtils.CopyRectTransform(categoryRT, assetPackMaxSizeRT); |
| 0 | 127 | | AudioScriptableObjects.dialogOpen.Play(); |
| | 128 | | } |
| | 129 | |
|
| 0 | 130 | | isCatalogExpanded = !isCatalogExpanded; |
| 0 | 131 | | } |
| | 132 | |
|
| 2 | 133 | | public void OnHideCatalogClick() { OnHideCatalogClicked?.Invoke(); } |
| | 134 | |
|
| 4 | 135 | | public void ShowBackButton(bool isActive) { backgBtn.gameObject.SetActive(isActive); } |
| | 136 | |
|
| 2 | 137 | | public void Back() { OnSceneCatalogBack?.Invoke(); } |
| | 138 | |
|
| 2 | 139 | | public void SetCatalogTitle(string text) { catalogTitleTxt.text = text; } |
| | 140 | |
|
| 2 | 141 | | public bool IsCatalogOpen() { return gameObject.activeSelf; } |
| | 142 | |
|
| 0 | 143 | | public bool IsCatalogExpanded() { return isCatalogExpanded; } |
| | 144 | |
|
| | 145 | | public void CloseCatalog() |
| | 146 | | { |
| 1 | 147 | | if (gameObject.activeSelf) |
| 1 | 148 | | CoroutineStarter.Start(CloseCatalogAfterOneFrame()); |
| 1 | 149 | | } |
| | 150 | |
|
| | 151 | | internal IEnumerator CloseCatalogAfterOneFrame() |
| | 152 | | { |
| 1 | 153 | | isClosing = true; |
| 1 | 154 | | yield return null; |
| 1 | 155 | | gameObject.SetActive(false); |
| 1 | 156 | | isClosing = false; |
| 1 | 157 | | } |
| | 158 | |
|
| | 159 | | public void SetActive(bool isActive) |
| | 160 | | { |
| 4 | 161 | | if (isActive && isClosing) |
| 1 | 162 | | CoroutineStarter.Start(OpenCatalogWhenIsAlreadyClosed()); |
| | 163 | | else |
| 3 | 164 | | gameObject.SetActive(isActive); |
| 3 | 165 | | } |
| | 166 | |
|
| | 167 | | internal IEnumerator OpenCatalogWhenIsAlreadyClosed() |
| | 168 | | { |
| 3 | 169 | | yield return new WaitUntil(() => !isClosing); |
| 1 | 170 | | gameObject.SetActive(true); |
| 1 | 171 | | } |
| | 172 | | } |