123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using DG.Tweening;
- using ShadowStudio.Tool;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using XRTool.WorldUI;
- namespace ShadowStudio.Model
- {
- /// <summary>
- /// UI容器,可以放置一些UI相关的组件
- /// 记事本,画板,以及后续的相关UI组件,也有可能是视频(角色视频)
- /// UI组件可以被放置在墙上进行展示,具备相关的交互操作
- /// </summary>
- [RequireComponent(typeof(WorldDlg))]
- [RequireComponent(typeof(TransferCell))]
- public class WorldDlgContainer : GoodsContainer
- {
- private WorldDlg dlg;
- private Vector3 dataV3;
- private Vector3 dataDownV3;
- List<Vector3> listV3 = new List<Vector3>();
- /// <summary>
- /// 当处于黑板状态的时候,拖拽要平行于黑板,且不可穿透黑板
- ///
- /// </summary>
- /// <param name="eventData"></param>
- public static GameObject BackGD;
- MeshRenderer bgMr;
- float offsetX = 0.5f;
- float offsetY = 0.5f;
- float BGDX = -(1 / 1.7f);
- float BGDY = (1 / 3.7f);
- float BGDZ = 1 / 24f;
- bool isPlaying;
- ContainerState oldContainerState;
- bool isFrist;
- float inXFz;
- public WorldDlg Dlg
- {
- get
- {
- if (!dlg)
- {
- dlg = GetComponent<WorldDlg>();
- }
- return dlg;
- }
- }
- /// <summary>
- /// 添加美术资源到容器
- /// </summary>
- /// <param name="art"></param>
- /// <param name="info"></param>
- public override void AddToContainer(UnityEngine.Object art, ArtInfo info)
- {
- base.AddToContainer(art, info);
- SetContainer(art, info);
- ResetEditorPosition();
- PlayEffect();
- }
- public virtual void SetContainer(UnityEngine.Object art, ArtInfo info)
- {
- }
- public override void OnZoomTransfer(TransferState state)
- {
- base.OnZoomTransfer(state);
- if (state == TransferState.Stop)
- {
- while (Dlg.DlgSize.magnitude < (Vector2.one * 0.1f).magnitude)
- {
- transform.localScale *= 1.5f;
- }
- //SendTransfer(2, (int)state);
- //TimerMgr.Instance.CreateTimer( ResetEditorPosition,0);
- OnEditTransfer(state);
- }
- }
- public override void OnEditTransfer(TransferState obj)
- {
- base.OnEditTransfer(obj);
- //if (BoardDlg.Instance && Dlg)
- //{
- // BoardDlg.Instance.ExecutePicture(Dlg, obj != TransferState.Stop, true);
- // checkBG();
- //}
- }
- void setBGmat(string name, float f)
- {
- bgMr.material.SetFloat(name, f);
- }
- void checkBG()
- {
- if (BackGD != null)
- {
- // Vector3 v3 = BackGD.transform.InverseTransformPoint((Dlg.DlgRect.points[2] + Dlg.DlgRect.points[3]) / 2 + (Dlg.DlgRect.points[0] + Dlg.DlgRect.points[1]) / 2) / 2;
- Vector3 v3 = ((BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[2]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[3])) / 2 + (BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[0]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[1])) / 2) / 2;
- if (!bgMr)
- {
- bgMr = BackGD.transform.GetComponent<MeshRenderer>();
- }
- if (Dlg.containerState == ContainerState.BoardMove)
- {
- if (oldContainerState != ContainerState.BoardMove && oldContainerState != ContainerState.OnBoard)
- {
- inXFz = v3.z;
- isFrist = true;
- }
- setBGmat("_Mask2_Ani", 0);
- setBGmat("_U", offsetX + v3.x / BGDX);
- setBGmat("_V", offsetY + v3.y / BGDY);
- if (isFrist)
- {
- if ((v3.z / BGDZ) < ((inXFz / BGDZ) / 2))
- {
- isFrist = false;
- }
- if (((inXFz / BGDZ)) >= (v3.z / BGDZ))
- {
- setBGmat("_tuqi", ((inXFz / BGDZ)) - (v3.z / BGDZ));
- }
- else
- {
- isFrist = false;
- }
- }
- else
- {
- setBGmat("_tuqi", (v3.z / BGDZ));
- }
- }
- else if (Dlg.containerState == ContainerState.OnBoard)
- {
- isFrist = false;
- bgMr.material.DOKill(false);
- setBGmat("_U", offsetX + v3.x / BGDX);
- setBGmat("_V", offsetY + v3.y / BGDY);
- // bgMr.material.SetFloat("_tuqi", ((0.2f - (0.2f + v3.z) * 2) - 0.207f) * 10);
- setBGmat("_Mask2_Ani", 0);
- bgMr.material.DOFloat(1, "_Mask2_Ani", 1f).OnComplete<Tween>(() =>
- {
- setBGmat("_U", 2);
- setBGmat("_V", 2);
- });
- }
- else
- {
- if (bgMr.material.GetFloat("_U") != 2 && !isPlaying)
- {
- isPlaying = true;
- setBGmat("_U", offsetX + v3.x / BGDX);
- setBGmat("_V", offsetY + v3.y / BGDY);
- // bgMr.material.SetFloat("_tuqi", ((0.2f - (0.2f + v3.z) * 2) - 0.207f) * 10);
- setBGmat("_Mask2_Ani", 0);
- bgMr.material.DOFloat(1, "_Mask2_Ani", 1f).OnComplete<Tween>(() =>
- {
- setBGmat("_U", 2);
- setBGmat("_V", 2);
- isPlaying = false;
- }).OnKill<Tween>(() =>
- {
- isPlaying = false;
- });
- }
- }
- }
- oldContainerState = Dlg.containerState;
- }
- public virtual void OnPointerBGDown()
- {
- dataV3 = this.transform.position;
- if (Dlg.containerState == ContainerState.OnBoard && bgMr != null)
- {
- //bgMr.material.DOKill(false);
- //Vector3 v3 = ((BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[2]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[3])) / 2 + (BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[0]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[1])) / 2) / 2;
- //float offsetZ = BackGD.transform.InverseTransformPoint(this.transform.parent.TransformPoint(new Vector3(this.transform.localPosition.x, this.transform.localPosition.y, BoardDlg.Instance.boardConf.PressPonit))).z;
- //setBGmat("_U", offsetX + v3.x / BGDX);
- //setBGmat("_V", offsetY + v3.y / BGDY);
- //setBGmat("_tuqi", (offsetZ / BGDZ));
- //setBGmat("_Mask2_Ani", 1);
- //bgMr.material.DOFloat(0, "_Mask2_Ani", 0.5f).OnComplete<Tween>(() =>
- //{
- // //Vector3 pos = this.Dlg.DlgTrans.anchoredPosition3D;
- // ////if (pos.z > BoardDlg.Instance.boardConf.PressPonit)
- // ////{
- // //// pos.z = BoardDlg.Instance.boardConf.PressPonit;
- // ////}
- // //this.Dlg.DlgTrans.anchoredPosition3D = pos;
- //});
- //this.transform.DOKill();
- //this.transform.DOMove(this.transform.parent.TransformPoint(new Vector3(this.transform.localPosition.x, this.transform.localPosition.y, BoardDlg.Instance.boardConf.PressPonit)), 0.3f).SetDelay(0.2f);
- }
- }
- public override void ResetEditorPosition()
- {
- if (EditorRoot)
- {
- Vector3 center = Vector3.down * Dlg.BG.Back.sizeDelta.y / 2;
- center = Dlg.BG.Back.TransformPoint(center);
- center.y -= 0.02f;
- EditorRoot.position = center;
- EditorRoot.rotation = transform.rotation;
- }
- }
- public override void TransferSyn(GoodsInfo goods, bool smooth = true)
- {
- base.TransferSyn(goods, smooth);
- if (TransferState != TransferState.Init)
- {
- //if (BoardDlg.Instance && Dlg)
- //{
- // BoardDlg.Instance.ExecutePicture(Dlg, TransferState == TransferState.Doing, false);
- // checkBG();
- //}
- }
- }
- }
- }
|