123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- using SC.XR.Unity;
- using ShadowStudio.Tool;
- using ShadowStudio.UI;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Dynamic;
- using System.Text.RegularExpressions;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- namespace ShadowStudio.Model
- {
- /// <summary>
- /// 资源的编辑
- /// </summary>
- [RequireComponent(typeof(WorldDlg))]
- public class ArtEditorContainer : UnitySingleton<ArtEditorContainer>
- {
- private ArtContainer artContainer;
- private Button lastStepBtn;
- private Button nextStepBtn;
- private ToggleButton editToggleBtn;
- private Button copyBtn;
- private Button deleteBtn;
- private WorldDlg dlg;
- private XRIcon lastIcon;
- private XRIcon nextIcon;
- public float checkTime = 1;
- private float lastTime;
- private Text nameText;
- private void Init()
- {
- if (dlg == null)
- {
- dlg = GetComponent<WorldDlg>();
- lastStepBtn = dlg.GetBreadthChild<Button>("LastStepBtn");
- nextStepBtn = dlg.GetBreadthChild<Button>("NextStepBtn");
- editToggleBtn = dlg.GetBreadthChild<ToggleButton>("EditToggleBtn");
- copyBtn = dlg.GetBreadthChild<Button>("CopyBtn");
- deleteBtn = dlg.GetBreadthChild<Button>("DeleteBtn");
- lastIcon = dlg.GetBreadthChild<XRIcon>("LastIcon");
- nextIcon = dlg.GetBreadthChild<XRIcon>("NextIcon");
- nameText = dlg.GetBreadthChild<Text>("NameText");
- lastStepBtn.onClick.AddListener(ClickOnLastStep);
- nextStepBtn.onClick.AddListener(ClickOnNextStep);
- copyBtn.onClick.AddListener(ClickOnCopy);
- deleteBtn.onClick.AddListener(ClickOnDelete);
- editToggleBtn.OnValueChanged += OnClickEditValueChange;
- }
- }
- private void OnClickEditValueChange(bool ison)
- {
- Cleartime();
- if (artContainer != null)
- {
- if (ison)
- {
- artContainer.Transfer.IsJiXingScale = true;
- if (ToggleShowBtnTip.Instance)
- {
- ToggleShowBtnTip.Instance.BtnTiptext.text = "拉伸";
- }
- }
- else
- {
- artContainer.Transfer.IsJiXingScale = false;
- if (ToggleShowBtnTip.Instance)
- {
- ToggleShowBtnTip.Instance.BtnTiptext.text = "缩放";
- }
- }
- if (ArtMoreEditor.Instance)
- {
- ArtMoreEditor.Instance.ReFresh();
- }
- }
- }
- private void ClickOnDelete()
- {
- Cleartime();
- if (artContainer != null)
- {
- if (ItemFileList.Instance)
- {
- ItemFileList.Instance.DeleteFileIcon(this.artContainer);
- }
- else
- {
- this.artContainer.DestroyArt();
- gameObject.SetActive(false);
- }
- }
- }
- private void ClickOnCopy()
- {
- Cleartime();
- if (artContainer != null)
- {
- artContainer.CloneContainer();
- }
- }
- private void ClickOnNextStep()
- {
- Cleartime();
- if (artContainer != null)
- {
- if (artContainer.AheadCount() > 0)
- {
- artContainer.GoAhead();
- }
- RefreshUI();
- }
- }
- private void ClickOnLastStep()
- {
- Cleartime();
- if (artContainer != null)
- {
- if (artContainer.BackCount() > 0)
- {
- artContainer.GoBack();
- }
- RefreshUI();
- }
- }
- public void SetTarget(ArtContainer art, bool isDel)
- {
- Init();
- nameText.text = art.GetGoodsInfo().goods_name;
- if (isDel)
- {
- try
- {
- if (this.artContainer != null && artContainer.Transfer)
- {
- artContainer.Transfer.TransferStateChange -= OnTransferStateChange;
- artContainer.Transfer.TransferDisEnable -= OnTransferDisEnable;
- }
- }
- catch
- {
- UnityLog.Instance.LogError("菜单编辑器错误");
- }
- this.artContainer = null;
- gameObject.SetActive(false);
- return;
- }
- this.artContainer = art;
- if (art.Transfer)
- {
- art.Transfer.TransferStateChange += OnTransferStateChange;
- artContainer.Transfer.TransferDisEnable += OnTransferDisEnable;
- }
- var container = art.GetEditorCenter();
- if (container)
- {
- transform.position = container.position;
- transform.rotation = container.rotation;
- RefreshUI();
- }
- ReFresh();
- }
- private void OnTransferDisEnable()
- {
- gameObject.SetActive(false);
- if (artContainer != null && artContainer.Transfer)
- {
- artContainer.Transfer.TransferDisEnable -= OnTransferDisEnable;
- }
- }
- public void ReFresh()
- {
- if (artContainer != null && artContainer.Transfer)
- {
- if (artContainer.Transfer.IsJiXingScale)
- {
- editToggleBtn.isOn = true;
- editToggleBtn.image.sprite = editToggleBtn.openImg;
- }
- else
- {
- editToggleBtn.isOn = false;
- editToggleBtn.image.sprite = editToggleBtn.closeImg;
- }
- }
- }
- private void OnTransferStateChange(TransferState state)
- {
- try
- {
- if (artContainer != null && artContainer.GetInstace())
- {
- if (state == TransferState.Stop)
- {
- lastTime = 0;
- if (!gameObject.activeSelf)
- {
- gameObject.SetActive(true);
- }
- RefreshUI();
- }
- else
- {
- gameObject.SetActive(false);
- }
- }
- }
- catch
- {
- gameObject.SetActive(false);
- }
- }
- /// <summary>
- /// 编辑同步和
- /// </summary>
- private void Update()
- {
- if (artContainer != null)
- {
- try
- {
- if (!artContainer.GetInstace())
- {
- artContainer = null;
- return;
- }
- }
- catch
- {
- artContainer = null;
- return;
- }
- if (Input.GetKeyDown(KeyCode.Space))
- {
- UnityLog.Instance.Log("Back:" + artContainer.BackCount() + " Ahead:" + artContainer.AheadCount());
- artContainer.CloneContainer();
- }
- //if (Time.time - lastTime > checkTime)
- //{
- // lastTime = Time.time;
- // artContainer.ResetEditorPosition();
- // var container = artContainer.GetEditorCenter();
- // if (container)
- // {
- // transform.position = container.position;
- // transform.rotation = container.rotation;
- // }
- //}
- }
- }
- private void RefreshUI()
- {
- if (artContainer.BackCount() <= 0)
- {
- lastStepBtn.enabled = false;
- lastIcon.color = Color.gray;
- }
- else
- {
- lastStepBtn.enabled = true;
- lastIcon.color = Color.white;
- }
- if (artContainer.AheadCount() <= 0)
- {
- nextStepBtn.enabled = false;
- nextIcon.color = Color.gray;
- }
- else
- {
- nextStepBtn.enabled = true;
- nextIcon.color = Color.white;
- }
- }
- private void Cleartime()
- {
- if (artContainer != null)
- {
- artContainer.Transfer.ClearTime();
- }
- }
- }
- }
|