123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class FileItem : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
- {
- public Toggle mainToggle;
- public Text nameText;
- public Button deleteBtn;
- public Image iconImage;
- private FileConfig fileConfig;
- public Sprite picIcon;
- public Sprite mp4Icon;
- public Sprite pdfIcon;
- public Sprite zipIcon;
- public Sprite unkownIcon;
- void Start()
- {
- mainToggle.onValueChanged.AddListener(ClickOnMainToggle);
- deleteBtn.onClick.AddListener(ClickOnDeleteBtn);
- //RoomFile.OnFileListAction += DeletFile;
- RoomFile.ClickOnPrefabAction += ClickOnPrefab;
- RoomFile.HidefileChooseAction += HideFileChoose;
- WSHandler.Rtc.OnDeleteFileSucess += DeleteFileSucess;
- WSHandler.Rtc.OnDeleteFile += NotifyDeleteFile;
- RoomFile.SetIsOnFalse += SetIsOn;
- }
- private void SetIsOn()
- {
- if (mainToggle.isOn)
- {
- mainToggle.isOn = false;
- }
- }
- private void HideFileChoose(FileConfig fileConfig)
- {
- if (this.fileConfig != null)
- {
- if (this.fileConfig == fileConfig)
- {
- mainToggle.isOn = false;
- }
- }
- }
- private void ClickOnPrefab(FileConfig fileConfig)
- {
- if (this.fileConfig != null)
- {
- if (this.fileConfig == fileConfig)
- {
- mainToggle.isOn = true;
- }
- else
- {
- mainToggle.isOn = false;
- }
- }
- }
- private void OnDestroy()
- {
- //RoomFile.OnFileListAction -= DeletFile;
- RoomFile.ClickOnPrefabAction -= ClickOnPrefab;
- RoomFile.HidefileChooseAction -= HideFileChoose;
- WSHandler.Rtc.OnDeleteFileSucess -= DeleteFileSucess;
- WSHandler.Rtc.OnDeleteFile -= NotifyDeleteFile;
- RoomFile.SetIsOnFalse -= SetIsOn;
- }
- private void DeleteFileSucess(JsonData data)
- {
- if (data["data"]["code"].ToString() == "200")
- {
- string path = data["data"]["data"]["path"].ToString();
- if (!string.IsNullOrEmpty(path))
- {
- if (this.fileConfig != null && this.fileConfig.Path == path)
- {
- //RoomFile.OnFilePrefabListAction?.Invoke(this.fileConfig);
- Destroy(this.gameObject);
- if (FileList.Instance)
- {
- FileList.Instance.RemoveItem(this.fileConfig);
- }
- }
- }
- }
- }
- private void NotifyDeleteFile(JsonData data)
- {
- if (this.fileConfig != null)
- {
- if (data["data"]["path"].ToString() == this.fileConfig.Path)
- {
- //RoomFile.OnFilePrefabListAction?.Invoke(this.fileConfig);
- Destroy(this.gameObject);
- if (FileList.Instance)
- {
- FileList.Instance.RemoveItem(this.fileConfig);
- }
- }
- }
- }
- private void ClickOnMainToggle(bool isOn)
- {
- if (isOn)
- {
- if (fileConfig != null)
- {
- RoomFile.ClickFileItemAction?.Invoke(fileConfig);
- }
- }
- else
- {
- if (fileConfig != null)
- {
- RoomFile.HideChooseKuangAction?.Invoke(fileConfig);
- }
- }
- }
- public void Init(FileConfig fileConfig)
- {
- mainToggle.group = transform.parent.GetComponent<ToggleGroup>();
- if (fileConfig != null)
- {
- this.fileConfig = fileConfig;
- if (fileConfig.FileName.Length <= 6)
- {
- nameText.text = fileConfig.FileName;
- }
- else
- {
- string str1 = fileConfig.FileName.Substring(0, 6);
- nameText.text = str1+"...";
- }
- switch (fileConfig.FileType)
- {
- case RoomFileType.png:
- iconImage.sprite = picIcon;
- break;
- case RoomFileType.jpg:
- iconImage.sprite = picIcon;
- break;
- case RoomFileType.jpeg:
- iconImage.sprite = picIcon;
- break;
- case RoomFileType.mp4:
- iconImage.sprite = mp4Icon;
- break;
- case RoomFileType.zip:
- iconImage.sprite = zipIcon;
- break;
- case RoomFileType.pdf:
- iconImage.sprite = pdfIcon;
- break;
- case RoomFileType.unknown:
- iconImage.sprite = unkownIcon;
- break;
- }
- }
-
- }
- //private void DeletFile(FileConfig fileConfig)
- //{
- // if (this.fileConfig != null && this.fileConfig == fileConfig)
- // {
- // Destroy(this.gameObject);
- // if (FileList.Instance)
- // {
- // FileList.Instance.RemoveItem(this.fileConfig);
- // }
- // }
- //}
- private void ClickOnDeleteBtn()
- {
- if (this.fileConfig != null)
- {
- deleteBtn.enabled = false;
- WSHandler.Rtc.deleteFile(this.fileConfig.Path);
- }
- }
- public void OnPointerEnter(PointerEventData eventData)
- {
- if (RoomMainInfo.isCreator == "0")
- {
- deleteBtn.gameObject.SetActive(true);
- }
- }
- public void OnPointerExit(PointerEventData eventData)
- {
- if (RoomMainInfo.isCreator == "0")
- {
- deleteBtn.gameObject.SetActive(false);
- }
- }
- }
|