123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- 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
- {
- /// <summary>
- /// 记事本
- /// 不即时同步,当点击发送的时候再同步
- /// 主动创建流程:点击标签,创建便签,此时创建本地便签。点击发送,将此便签的数据发送至服务器,等待便签的同步数据
- /// </summary>
- 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<Toggle>(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); });
- }
- }
- }
- /// <summary>
- /// 创建本地的资源id
- /// </summary>
- 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);
- }
- /// <summary>
- /// 点击了发送的按钮
- /// </summary>
- private void OnClickSendButton()
- {
- ///添加缓存
- if (CInputField.text != string.Empty)
- {
- ArtInfoMgr.Instance.AddCacheContainer(notePadId, Container);
- SendNotePad();
- OnEndEdit();
- }
- }
- public void SendNotePad()
- {
- Transform worldDlgContainer = this.transform.GetComponentInParent<WorldDlgContainer>().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<SCInputField>(transform, "SCInputField");
- }
- return cInputField;
- }
- }
- public Transform ColorToggleTran
- {
- get
- {
- if (!colorToggleTran)
- {
- colorToggleTran = UnityUtil.GetBreadthChild<Transform>(transform, "ColorToggleGroup");
- }
- return colorToggleTran;
- }
- }
- public GameObject EditState
- {
- get
- {
- if (!editState)
- {
- editState = UnityUtil.GetBreadthChild<Transform>(transform, "EditState").gameObject;
- }
- return editState;
- }
- }
- public GameObject ShowState
- {
- get
- {
- if (!showState)
- {
- showState = UnityUtil.GetBreadthChild<Transform>(transform, "ShowState").gameObject;
- }
- return showState;
- }
- }
- public Image NotePad
- {
- get
- {
- if (!notePad)
- {
- notePad = UnityUtil.GetBreadthChild<Image>(transform, "NotePad");
- }
- return notePad;
- }
- }
- public Text NotePadText
- {
- get
- {
- if (!notePadText)
- {
- notePadText = UnityUtil.GetBreadthChild<Text>(transform, "NotePadText");
- }
- return notePadText;
- }
- }
- /// <summary>
- /// 发送按钮
- /// </summary>
- public Button SendButton
- {
- get
- {
- if (!sendButton)
- {
- sendButton = UnityUtil.GetBreadthChild<Button>(transform, "SendButton");
- }
- return sendButton;
- }
- }
- public override void SetContainer(ArtContainerHandler container, Object art, ArtInfo info)
- {
- base.SetContainer(container, art, info);
- RectTransform tar = GetComponent<RectTransform>();
- tar.offsetMax = Vector2.zero;
- tar.offsetMin = Vector2.zero;
- if (CInputField)
- {
- CInputField.onEndEdit.AddListener(OnEndInput);
- }
- }
- private void OnEndInput(string arg0)
- {
- //OnEndEdit();
- }
- /// <summary>
- /// 完成编辑,删除此标签
- /// </summary>
- public virtual void OnEndEdit()
- {
- ArtInfo info = ArtInfoMgr.Instance.GetArtInfo(notePadId);
- if (string.IsNullOrEmpty(noteData.noteName))
- {
- noteData.noteName = UnityUtil.CurTimeString;
- }
- EditState.SetActive(false);
- ShowState.SetActive(true);
- NotePad.color = NotePadColor;
- NotePadText.text = CInputField.text;
- //noteData.fontSize = FontSize;
- noteData.notePadColor = new XColor(NotePadColor);
- noteData.noteMsg = CInputField.text;
- Container.data.goods_extended = JsonConvert.SerializeObject(noteData);
- Container.data.art_id = notePadId;
- //Transform tmp = transform.parent;
- //transform.SetParent(GameNode.Instance.LocalWorldCanvas);
- //Vector3 scale = transform.localScale;
- //transform.localScale = scale * UnityUtil.maxTransfer;
- Container.data.goods_info = UnityUtil.TransferToString(Container.transform, 2);
- Container.data.rid = info.AID;
- Container.data.goods_name = info.ArtName;
- WSHandler.Room.CreateGood(Container.data);
- //transform.SetParent(tmp);
- //transform.localScale = scale;
- }
- /// <summary>
- /// 同步数据
- /// </summary>
- /// <param name="goods"></param>
- /// <param name="smooth"></param>
- public override void TransferSyn(GoodsInfo goods, bool smooth = true)
- {
- base.TransferSyn(goods, smooth);
- if (!isHadHide && !string.IsNullOrEmpty(goods.goods_extended))
- {
- noteData = JsonConvert.DeserializeObject<NoteData>(goods.goods_extended);
- //FontSize = noteData.fontSize;
- EditState.SetActive(false);
- ShowState.SetActive(true);
- NotePad.color = noteData.notePadColor.Trans();
- NotePadText.text = noteData.noteMsg;
- SetEditActive(false);
- if (NotePad)
- {
- NotePad.SetNativeSize();
- Vector2 size = NotePad.rectTransform.sizeDelta + new Vector2(70, 50);
- DlgContainer.Dlg.DlgTrans.sizeDelta = size;
- DlgContainer.Dlg.SetScale(size, 1);
- if (DlgContainer.Transfer && DlgContainer.Transfer.IsInit)
- {
- DlgContainer.Transfer.RemoveBound();
- TimerMgr.Instance.CreateTimer(() => { DlgContainer.Transfer.IsDragEnable = false; }, 0);
- }
- }
- }
- }
- /// <summary>
- /// 禁用编辑功能
- /// </summary>
- public virtual void SetEditActive(bool isActive = false)
- {
- if (SendButton)
- {
- SendButton.gameObject.SetActive(isActive);
- }
- if (CInputField)
- {
- CInputField.image.enabled = isActive;
- }
- isHadHide = true;
- }
- /// <summary>
- /// 设置文字大小
- /// </summary>
- public int FontSize
- {
- get
- {
- return CInputField.textComponent.fontSize;
- }
- set
- {
- CInputField.textComponent.fontSize = value;
- }
- }
- public void GetNotePadColor(Toggle toggle)
- {
- if (toggle)
- {
- Image img = toggle.transform.Find("Background").GetComponent<Image>();
- NotePadColor = img.color;
- Back.color = NotePadColor;
- }
- }
- private void OnToggle(bool isOn, Toggle toggle)
- {
- if (isOn)
- {
- switch (toggle.name)
- {
- case "ToggleGray":
- GetNotePadColor(toggle);
- break;
- case "ToggleBlue":
- GetNotePadColor(toggle);
- break;
- case "ToggleYellow":
- GetNotePadColor(toggle);
- break;
- case "ToggleRed":
- GetNotePadColor(toggle);
- break;
- case "ToggleGreen":
- GetNotePadColor(toggle);
- break;
- }
- }
- }
- /// <summary>
- /// 设置文字颜色
- /// </summary>
- public Color FontColor
- {
- get
- {
- return CInputField.textComponent.color;
- }
- set
- {
- CInputField.textComponent.color = value;
- }
- }
- public Image Back
- {
- get
- {
- if (!back)
- {
- back = UnityUtil.GetBreadthChild<Image>(transform, "Back");
- }
- return back;
- }
- }
- }
- }
|