123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- 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<BoundingBox>();
- 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)
- {
-
- }
- }
|