using BeinLab.Util; using Newtonsoft.Json; using PublicTools.Unity; using SC.XR.Unity; using ShadowStudio.Tool; using ShadowStudio.UI; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using XRTool.Util; using XRTool.WorldUI; namespace ShadowStudio.Model { /// /// 记事本 /// 不即时同步,当点击发送的时候再同步 /// 主动创建流程:点击标签,创建便签,此时创建本地便签。点击发送,将此便签的数据发送至服务器,等待便签的同步数据 /// public class NotePadComponent : UIComponent { private NoteData noteData = new NoteData(); private SCInputField cInputField; private Button sendButton; private Transform colorToggleTran; //private ToggleGroup colorToggleGroup; private GameObject editState; private GameObject showState; private Image notePad; private Text notePadText; private bool isHadHide = false; private Color NotePadColor; private Image back; private static Vector2 defSize = new Vector2(200, 130); public static string notePadId = "ArtId_NodePad"; public virtual void Start() { if (SendButton) { SendButton.onClick.AddListener(OnClickSendButton); } if (ColorToggleTran) { Toggle[] toggles = ColorToggleTran.GetComponentsInChildren(true); bool isInit = false; for (int i = 0; i < toggles.Length; i++) { Toggle toggle = toggles[i]; if (!isInit && toggle) { GetNotePadColor(toggle); isInit = true; } toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); }); } } } /// /// 创建本地的资源id /// public static ArtContainer CreateLocalNotePad() { ArtInfo info = ArtInfoMgr.Instance.GetArtInfo(notePadId); ArtHandler handler = ArtInfoMgr.Instance.CreateArtHandler(info); var container = handler.CreateArt(); WorldDlgContainer dlg = container as WorldDlgContainer; if (dlg) { dlg.Dlg.DlgTrans.sizeDelta = defSize; dlg.Dlg.SetScale(defSize, 1); } container.Position = GameSession.Instance.GetHeadForwadPos(0.35f); return container; } public void Init() { EditState.SetActive(true); ShowState.SetActive(false); } /// /// 点击了发送的按钮 /// private void OnClickSendButton() { ///添加缓存 if (CInputField.text != string.Empty) { ArtInfoMgr.Instance.AddCacheContainer(notePadId, Container); SendNotePad(); OnEndEdit(); } } public void SendNotePad() { Transform worldDlgContainer = this.transform.GetComponentInParent().transform; worldDlgContainer.SetParent(ConsoleDlg.Instance.WorldCanvas, true); worldDlgContainer.localPosition = new Vector3(0f, 0f, -0.01f); worldDlgContainer.localEulerAngles = new Vector3(0f, 0f, 0f); worldDlgContainer.localScale = new Vector3(1f, 1f, 1f); if (ConsoleDlg.Instance.PiZhuToggle) { ConsoleDlg.Instance.PiZhuToggle.isOn = false; } } public SCInputField CInputField { get { if (!cInputField) { cInputField = UnityUtil.GetBreadthChild(transform, "SCInputField"); } return cInputField; } } public Transform ColorToggleTran { get { if (!colorToggleTran) { colorToggleTran = UnityUtil.GetBreadthChild(transform, "ColorToggleGroup"); } return colorToggleTran; } } public GameObject EditState { get { if (!editState) { editState = UnityUtil.GetBreadthChild(transform, "EditState").gameObject; } return editState; } } public GameObject ShowState { get { if (!showState) { showState = UnityUtil.GetBreadthChild(transform, "ShowState").gameObject; } return showState; } } public Image NotePad { get { if (!notePad) { notePad = UnityUtil.GetBreadthChild(transform, "NotePad"); } return notePad; } } public Text NotePadText { get { if (!notePadText) { notePadText = UnityUtil.GetBreadthChild(transform, "NotePadText"); } return notePadText; } } /// /// 发送按钮 /// public Button SendButton { get { if (!sendButton) { sendButton = UnityUtil.GetBreadthChild