123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- using SC.XR.Unity;
- using ShadowStudio.Model;
- using Studio.Scripts;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- namespace ShadowStudio.UI
- {
- [RequireComponent(typeof(WorldDlg))]
- public class ZiYuanKuDlg : UnitySingleton<ZiYuanKuDlg>
- {
- private Transform fenleiAllTogglesTran;
- private ToggleGroup fenleiAllTogglesGroup;
- private ZiYuanFileList ziYuanFileList;
- private Transform wuwenjian;
- private Button closeBtn;
- private Button loadBtn;
- private Button canelBtn;
- private SCInputField searchInputField;
- private Button searchBtn;
- private Button clearBtn;
- public List<ArtInfo> NeedLoadartInfos;
- public Action<int> ShowOrHideGrayImage;
- public Action CanelLoadAction;
- protected override void Awake()
- {
- base.Awake();
- HomeProxy.Instance.SearchArtListAction += SearchArtList;
- HomeProxy.Instance.NoArtReturnAction += ShowNoArt;
- NeedLoadartInfos = new List<ArtInfo>();
- }
- void Start()
- {
- WorldDlg dlg = GetComponent<WorldDlg>();
- ziYuanFileList = dlg.GetBreadthChild<ZiYuanFileList>("ItemFileList");
- wuwenjian = dlg.GetBreadthChild<Transform>("Wuwenjian");
- fenleiAllTogglesTran = dlg.GetBreadthChild<Transform>("FenleiAllToggles");
- fenleiAllTogglesGroup = dlg.GetBreadthChild<ToggleGroup>("FenleiAllToggles");
- closeBtn = dlg.GetBreadthChild<Button>("CloseBtn");
- closeBtn.onClick.AddListener(ClickOnClose);
- loadBtn = dlg.GetBreadthChild<Button>("LoadBtn");
- loadBtn.onClick.AddListener(ClickOnLoad);
- canelBtn = dlg.GetBreadthChild<Button>("CanelBtn");
- canelBtn.onClick.AddListener(ClickOnCanel);
- searchBtn = dlg.GetBreadthChild<Button>("SearchBtn");
- searchBtn.onClick.AddListener(ClickOnSearch);
- clearBtn = dlg.GetBreadthChild<Button>("ClearBtn");
- clearBtn.onClick.AddListener(ClickOnClear);
- searchInputField = dlg.GetBreadthChild<SCInputField>("SearchInputField");
- //searchInputField.onEndEdit.AddListener(SearchInputEndEdit);
- searchInputField.onValueChanged.AddListener(SearchInputValueChanged);
- Toggle[] toggles = fenleiAllTogglesTran.GetComponentsInChildren<Toggle>(true);
- for (int i = 0; i < toggles.Length; i++)
- {
- Toggle toggle = toggles[i];
- toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
- if (i == 0)
- {
- OnToggle(true, toggles[i]);
- }
- }
- }
- private void ClickOnClear()
- {
- searchInputField.text = "";
- clearBtn.gameObject.SetActive(false);
- GetToggleOn();
- }
- private void SearchInputValueChanged(string searchInput)
- {
- if (searchInput != "")
- {
- clearBtn.gameObject.SetActive(true);
- }
- else
- {
- ClickOnClear();
- }
- }
- private void ClickOnSearch()
- {
- if (searchInputField.text != "")
- {
- if (searchInputField.text.Trim() != string.Empty)
- {
- GetToggleOn();
- }
- else
- {
- ConsoleDlg.Instance.ShowTipPop("搜索内容不能全为空格");
- }
- }
- else
- {
- ConsoleDlg.Instance.ShowTipPop("搜索内容不能为空");
- }
- }
- public void GetToggleOn()
- {
- Toggle temptoggle = null;
- foreach (var toggle in fenleiAllTogglesGroup.ActiveToggles())
- {
- temptoggle = toggle;
- }
- if (temptoggle != null)
- {
- OnToggle(true, temptoggle);
- }
- }
- private void ClickOnCanel()
- {
- NeedLoadartInfos.Clear();
- CanelLoadAction?.Invoke();
- }
- private void ClickOnLoad()
- {
- if (NeedLoadartInfos.Count > 0)
- {
- for (int i = 0; i < NeedLoadartInfos.Count; i++)
- {
- WSHandler.Room.CreateGood(NeedLoadartInfos[i].AID, NeedLoadartInfos[i].ArtId, NeedLoadartInfos[i].ArtName, UnityUtil.ArtTransferInfo(NeedLoadartInfos[i], i), "", ShowViewMgr.Instance.roomId);
- }
- if (NeedLoadartInfos.Count == 1)
- {
- ConsoleDlg.IsOne = true;
- }
- else
- {
- ConsoleDlg.IsOne = false;
- }
- ClickOnClose();
- }
- }
- private void ClickOnClose()
- {
- if (ConsoleDlg.Instance)
- {
- ConsoleDlg.Instance.SetClose();
- }
- }
- private void OnDisable()
- {
- ClickOnCanel();
- }
- private void OnToggle(bool isOn, Toggle toggle)
- {
- if (isOn)
- {
- switch (toggle.name)
- {
- case "AllToggle":
- RequestSearch(-1);
- break;
- case "Model2DToggle":
- RequestSearch(5);
- break;
- case "Model3DToggle":
- RequestSearch(0);
- break;
- case "PicToggle":
- RequestSearch(1);
- break;
- case "MP4Toggle":
- RequestSearch(3);
- break;
- case "ProjectToggle":
- SearchArtList(null);
- break;
- }
- }
- }
- public void RequestSearch(int artType, int fileType = 2)
- {
- NeedLoadartInfos.Clear();
- HomeProxy.Instance.RequestSearchArtList(artType, fileType, searchInputField.text);
- }
- private void SearchArtList(List<ArtInfo> ArtInfoList)
- {
- if (gameObject.activeSelf)
- {
- wuwenjian.gameObject.SetActive(false);
- ziYuanFileList.DestoryAll();
- if (ArtInfoList != null && ArtInfoList.Count > 0)
- {
- for (int i = 0; i < ArtInfoList.Count; i++)
- {
- if (ziYuanFileList)
- {
- ziYuanFileList.AddFileItem(ArtInfoList[i]);
- }
- }
- }
- else
- {
- wuwenjian.gameObject.SetActive(true);
- }
- }
- }
- private void ShowNoArt()
- {
- if (gameObject.activeSelf)
- {
- ziYuanFileList.DestoryAll();
- wuwenjian.gameObject.SetActive(true);
- }
- }
- protected override void OnDestroy()
- {
- base.OnDestroy();
- if (HomeProxy.Instance)
- {
- HomeProxy.Instance.SearchArtListAction -= SearchArtList;
- HomeProxy.Instance.NoArtReturnAction -= ShowNoArt;
- }
- }
- }
- }
|