using System; using System.Collections; using System.Collections.Generic; using LitJson; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using XRTool.Util; public class BaseFilePrefabItem : MonoBehaviour,IPointerHandler { public Text nameText; protected FileConfig fileConfig; public SCButton deleteBtn; public SCButton hideBtn; public GameObject ChooseKuang; private BoundingBox boundBox; protected virtual void Start() { //RoomFile.OnFilePrefabListAction += DeletFilePrefab; deleteBtn.onClick.AddListener(ClickOnDeleteBtn); hideBtn.onClick.AddListener(ClickOnHideBtn); WSHandler.Rtc.OnDeleteFileSucess += DeleteFileSucess; WSHandler.Rtc.OnDeleteFile += NotifyDeleteFile; } private void ClickOnHideBtn() { if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig)) { RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig); } Destroy(this.gameObject); if (this.fileConfig != null) { RoomFile.HidefileChooseAction?.Invoke(this.fileConfig); } } private void NotifyDeleteFile(JsonData data) { if (this.fileConfig != null && data["data"]["path"].ToString() == this.fileConfig.Path) { if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig)) { RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig); } Destroy(this.gameObject); } } private void ClickOnDeleteBtn() { if (this.fileConfig != null) { deleteBtn.enabled = false; WSHandler.Rtc.deleteFile(this.fileConfig.Path); } } 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.OnFileListAction?.Invoke(this.fileConfig); if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig)) { RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig); } Destroy(this.gameObject); } } } } private void OnAction(FileConfig fileConfig) { if (this.fileConfig != null && this.fileConfig == fileConfig) { //gameObject.SetActive(true); ChooseKuang.SetActive(true); } } private void OnHideAction(FileConfig fileConfig) { if (this.fileConfig != null && this.fileConfig == fileConfig) { ChooseKuang.SetActive(false); } } public virtual void Init(FileConfig fileConfig) { if (RoomMainInfo.isCreator == "0") { deleteBtn.gameObject.SetActive(true); } else { deleteBtn.gameObject.SetActive(false); } this.fileConfig = fileConfig; nameText.text = fileConfig.FileName; RoomFile.IfFilePrefabConfigListAction += OnAction; RoomFile.HideChooseKuangAction += OnHideAction; if (!boundBox) { boundBox = GetComponent(); if (!boundBox) { UnityLog.LogError(gameObject.name + "this is no XBoundingBox"); } else { boundBox.ScaleStopped.AddListener(OnScaleStopped); boundBox.RotateStarted.AddListener(OnRotateStarted); boundBox.ScaleStarted.AddListener(OnScaleStarted); } } } public virtual void OnRotateStarted() { if (this.fileConfig != null) { RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig); } } public virtual void OnScaleStarted() { if (this.fileConfig != null) { RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig); } } public virtual void OnScaleStopped() { if (transform.localScale.x < 1f) { transform.localScale = Vector3.one; } } protected virtual void OnDestroy() { RoomFile.IfFilePrefabConfigListAction -= OnAction; //RoomFile.OnFilePrefabListAction -= DeletFilePrefab; RoomFile.HideChooseKuangAction -= OnHideAction; WSHandler.Rtc.OnDeleteFileSucess -= DeleteFileSucess; WSHandler.Rtc.OnDeleteFile -= NotifyDeleteFile; } public void OnPointerExit(PointerEventData eventData) { } public void OnPointerEnter(PointerEventData eventData) { } public void OnPointerDown(PointerEventData eventData) { } public void OnPointerClick(PointerEventData eventData) { if (this.fileConfig != null) { RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig); } } public void OnPointerUp(PointerEventData eventData) { } public void OnDrag(PointerEventData eventData) { } }