123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using System;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class FacilityUIPowerUpMaterialList : MonoBehaviour
- {
- private FacilityManager FacilityMgr
- {
- get
- {
- if (this.m_FacilityMgr == null)
- {
- this.m_FacilityMgr = GameMain.Instance.FacilityMgr;
- }
- return this.m_FacilityMgr;
- }
- }
- public void Show(int id, Facility facility, Action<int[]> callbackSelect)
- {
- this.m_CallbackSelect = callbackSelect;
- this.SetupFacilityPowerUpMaterialListDropDown(id, facility);
- }
- private void SetupFacilityPowerUpMaterialListDropDown(int id, Facility facility)
- {
- this.m_uGUIListViewer.parentItemArea.gameObject.SetActive(true);
- this.DeleteDropdown();
- Facility.PowerUpRecipe facilityPowerUpRecipe = FacilityDataTable.GetFacilityPowerUpRecipe(id);
- int[] materialCategoryIDArray = facilityPowerUpRecipe.materialCategoryIDArray;
- Facility.RecipeData recipeData = facility.GetRecipeData(id);
- this.m_uGUIListViewer.Show<Transform>(materialCategoryIDArray.Length, delegate(int i, Transform trans)
- {
- int num = materialCategoryIDArray[i];
- Dropdown componentInChildren = trans.GetComponentInChildren<Dropdown>();
- Text[] componentsInChildren = trans.GetComponentsInChildren<Text>();
- FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial dropdownPowerUpMaterial = trans.gameObject.AddComponent<FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial>();
- string facilityPowerUpMaterialCategoryName = FacilityDataTable.GetFacilityPowerUpMaterialCategoryName(num);
- componentsInChildren[0].text = facilityPowerUpMaterialCategoryName;
- componentsInChildren[1].text = string.Format("CATEGORY{0}", i + 1);
- componentInChildren.ClearOptions();
- Facility.PowerUpMaterial[] materialArray = this.FacilityMgr.GetFacilityPowerUpItemEnableArray(num);
- if (materialArray.Length > 0)
- {
- for (int j = 0; j < materialArray.Length; j++)
- {
- componentInChildren.options.Add(new Dropdown.OptionData(materialArray[j].name));
- if (recipeData.materialIDArray[i] == materialArray[j].id)
- {
- dropdownPowerUpMaterial.materialID = materialArray[j].id;
- componentInChildren.value = j;
- }
- }
- }
- else
- {
- componentInChildren.image.raycastTarget = false;
- dropdownPowerUpMaterial.materialID = 0;
- componentInChildren.options.Add(new Dropdown.OptionData("無し"));
- }
- if (dropdownPowerUpMaterial.materialID == 0)
- {
- if (materialArray.Length > 0)
- {
- dropdownPowerUpMaterial.materialID = materialArray[0].id;
- componentInChildren.value = 0;
- }
- else
- {
- dropdownPowerUpMaterial.materialID = -1;
- }
- }
- componentInChildren.RefreshShownValue();
- componentInChildren.onValueChanged.AddListener(delegate(int value)
- {
- dropdownPowerUpMaterial.materialID = materialArray[value].id;
- this.OnUpdateDropdownParams();
- });
- if (i == 0)
- {
- Transform transform = dropdownPowerUpMaterial.transform.Find("Image Plus Mark");
- if (transform)
- {
- transform.gameObject.SetActive(false);
- }
- else
- {
- Debug.LogError("[FacilityPowerUP]プラスマークのイメージが見つかりません\n「Image Plus Mark」という名前の子オブジェクトを追加してください");
- }
- }
- });
- this.OnUpdateDropdownParams();
- }
- public void HideAllDropdown()
- {
- Transform transform = this.m_uGUIListViewer.transform;
- Dropdown[] componentsInChildren = transform.GetComponentsInChildren<Dropdown>();
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- componentsInChildren[i].Hide();
- }
- }
- public void DeleteDropdown()
- {
- this.HideAllDropdown();
- this.m_uGUIListViewer.ResetList();
- }
- private void OnUpdateDropdownParams()
- {
- Transform transform = this.m_uGUIListViewer.transform;
- FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial[] componentsInChildren = transform.GetComponentsInChildren<FacilityUIPowerUpMaterialList.DropdownPowerUpMaterial>();
- int[] array = new int[componentsInChildren.Length];
- for (int i = 0; i < componentsInChildren.Length; i++)
- {
- array[i] = componentsInChildren[i].materialID;
- }
- if (this.m_CallbackSelect != null)
- {
- this.m_CallbackSelect(array);
- }
- }
- private FacilityManager m_FacilityMgr;
- [SerializeField]
- private uGUIListViewer m_uGUIListViewer;
- private Action<int[]> m_CallbackSelect;
- private class DropdownPowerUpMaterial : MonoBehaviour, IPointerClickHandler, ISubmitHandler, IEventSystemHandler
- {
- private void SetupTemplateCanvas()
- {
- Dropdown component = base.GetComponent<Dropdown>();
- Transform transform = component.transform.Find("Dropdown List");
- if (!transform)
- {
- return;
- }
- Canvas component2 = transform.GetComponent<Canvas>();
- Canvas componentInParent = component.GetComponentInParent<Canvas>();
- component2.sortingOrder = componentInParent.sortingOrder + 50;
- }
- private void SetupBlockerCanvas()
- {
- Dropdown component = base.GetComponent<Dropdown>();
- Canvas componentInParent = component.GetComponentInParent<Canvas>();
- Transform transform = componentInParent.transform.Find("Blocker");
- if (!transform)
- {
- return;
- }
- Canvas component2 = transform.GetComponent<Canvas>();
- component2.sortingOrder = componentInParent.sortingOrder + 1;
- CanvasGroup canvasGroup = transform.gameObject.GetComponent<CanvasGroup>();
- if (!canvasGroup)
- {
- canvasGroup = transform.gameObject.AddComponent<CanvasGroup>();
- }
- canvasGroup.ignoreParentGroups = true;
- canvasGroup.interactable = true;
- canvasGroup.blocksRaycasts = true;
- }
- public void OnPointerClick(PointerEventData data)
- {
- this.SetupTemplateCanvas();
- this.SetupBlockerCanvas();
- }
- public void OnSubmit(BaseEventData data)
- {
- this.SetupTemplateCanvas();
- this.SetupBlockerCanvas();
- }
- public int materialID;
- }
- }
|