WorldDlgContainer.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using DG.Tweening;
  2. using ShadowStudio.Tool;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using XRTool.WorldUI;
  7. namespace ShadowStudio.Model
  8. {
  9. /// <summary>
  10. /// UI容器,可以放置一些UI相关的组件
  11. /// 记事本,画板,以及后续的相关UI组件,也有可能是视频(角色视频)
  12. /// UI组件可以被放置在墙上进行展示,具备相关的交互操作
  13. /// </summary>
  14. [RequireComponent(typeof(WorldDlg))]
  15. [RequireComponent(typeof(TransferCell))]
  16. public class WorldDlgContainer : GoodsContainer
  17. {
  18. private WorldDlg dlg;
  19. private Vector3 dataV3;
  20. private Vector3 dataDownV3;
  21. List<Vector3> listV3 = new List<Vector3>();
  22. /// <summary>
  23. /// 当处于黑板状态的时候,拖拽要平行于黑板,且不可穿透黑板
  24. ///
  25. /// </summary>
  26. /// <param name="eventData"></param>
  27. public static GameObject BackGD;
  28. MeshRenderer bgMr;
  29. float offsetX = 0.5f;
  30. float offsetY = 0.5f;
  31. float BGDX = -(1 / 1.7f);
  32. float BGDY = (1 / 3.7f);
  33. float BGDZ = 1 / 24f;
  34. bool isPlaying;
  35. ContainerState oldContainerState;
  36. bool isFrist;
  37. float inXFz;
  38. public WorldDlg Dlg
  39. {
  40. get
  41. {
  42. if (!dlg)
  43. {
  44. dlg = GetComponent<WorldDlg>();
  45. }
  46. return dlg;
  47. }
  48. }
  49. /// <summary>
  50. /// 添加美术资源到容器
  51. /// </summary>
  52. /// <param name="art"></param>
  53. /// <param name="info"></param>
  54. public override void AddToContainer(UnityEngine.Object art, ArtInfo info)
  55. {
  56. base.AddToContainer(art, info);
  57. SetContainer(art, info);
  58. ResetEditorPosition();
  59. PlayEffect();
  60. }
  61. public virtual void SetContainer(UnityEngine.Object art, ArtInfo info)
  62. {
  63. }
  64. public override void OnZoomTransfer(TransferState state)
  65. {
  66. base.OnZoomTransfer(state);
  67. if (state == TransferState.Stop)
  68. {
  69. while (Dlg.DlgSize.magnitude < (Vector2.one * 0.1f).magnitude)
  70. {
  71. transform.localScale *= 1.5f;
  72. }
  73. //SendTransfer(2, (int)state);
  74. //TimerMgr.Instance.CreateTimer( ResetEditorPosition,0);
  75. OnEditTransfer(state);
  76. }
  77. }
  78. public override void OnEditTransfer(TransferState obj)
  79. {
  80. base.OnEditTransfer(obj);
  81. //if (BoardDlg.Instance && Dlg)
  82. //{
  83. // BoardDlg.Instance.ExecutePicture(Dlg, obj != TransferState.Stop, true);
  84. // checkBG();
  85. //}
  86. }
  87. void setBGmat(string name, float f)
  88. {
  89. bgMr.material.SetFloat(name, f);
  90. }
  91. void checkBG()
  92. {
  93. if (BackGD != null)
  94. {
  95. // Vector3 v3 = BackGD.transform.InverseTransformPoint((Dlg.DlgRect.points[2] + Dlg.DlgRect.points[3]) / 2 + (Dlg.DlgRect.points[0] + Dlg.DlgRect.points[1]) / 2) / 2;
  96. 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;
  97. if (!bgMr)
  98. {
  99. bgMr = BackGD.transform.GetComponent<MeshRenderer>();
  100. }
  101. if (Dlg.containerState == ContainerState.BoardMove)
  102. {
  103. if (oldContainerState != ContainerState.BoardMove && oldContainerState != ContainerState.OnBoard)
  104. {
  105. inXFz = v3.z;
  106. isFrist = true;
  107. }
  108. setBGmat("_Mask2_Ani", 0);
  109. setBGmat("_U", offsetX + v3.x / BGDX);
  110. setBGmat("_V", offsetY + v3.y / BGDY);
  111. if (isFrist)
  112. {
  113. if ((v3.z / BGDZ) < ((inXFz / BGDZ) / 2))
  114. {
  115. isFrist = false;
  116. }
  117. if (((inXFz / BGDZ)) >= (v3.z / BGDZ))
  118. {
  119. setBGmat("_tuqi", ((inXFz / BGDZ)) - (v3.z / BGDZ));
  120. }
  121. else
  122. {
  123. isFrist = false;
  124. }
  125. }
  126. else
  127. {
  128. setBGmat("_tuqi", (v3.z / BGDZ));
  129. }
  130. }
  131. else if (Dlg.containerState == ContainerState.OnBoard)
  132. {
  133. isFrist = false;
  134. bgMr.material.DOKill(false);
  135. setBGmat("_U", offsetX + v3.x / BGDX);
  136. setBGmat("_V", offsetY + v3.y / BGDY);
  137. // bgMr.material.SetFloat("_tuqi", ((0.2f - (0.2f + v3.z) * 2) - 0.207f) * 10);
  138. setBGmat("_Mask2_Ani", 0);
  139. bgMr.material.DOFloat(1, "_Mask2_Ani", 1f).OnComplete<Tween>(() =>
  140. {
  141. setBGmat("_U", 2);
  142. setBGmat("_V", 2);
  143. });
  144. }
  145. else
  146. {
  147. if (bgMr.material.GetFloat("_U") != 2 && !isPlaying)
  148. {
  149. isPlaying = true;
  150. setBGmat("_U", offsetX + v3.x / BGDX);
  151. setBGmat("_V", offsetY + v3.y / BGDY);
  152. // bgMr.material.SetFloat("_tuqi", ((0.2f - (0.2f + v3.z) * 2) - 0.207f) * 10);
  153. setBGmat("_Mask2_Ani", 0);
  154. bgMr.material.DOFloat(1, "_Mask2_Ani", 1f).OnComplete<Tween>(() =>
  155. {
  156. setBGmat("_U", 2);
  157. setBGmat("_V", 2);
  158. isPlaying = false;
  159. }).OnKill<Tween>(() =>
  160. {
  161. isPlaying = false;
  162. });
  163. }
  164. }
  165. }
  166. oldContainerState = Dlg.containerState;
  167. }
  168. public virtual void OnPointerBGDown()
  169. {
  170. dataV3 = this.transform.position;
  171. if (Dlg.containerState == ContainerState.OnBoard && bgMr != null)
  172. {
  173. //bgMr.material.DOKill(false);
  174. //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;
  175. //float offsetZ = BackGD.transform.InverseTransformPoint(this.transform.parent.TransformPoint(new Vector3(this.transform.localPosition.x, this.transform.localPosition.y, BoardDlg.Instance.boardConf.PressPonit))).z;
  176. //setBGmat("_U", offsetX + v3.x / BGDX);
  177. //setBGmat("_V", offsetY + v3.y / BGDY);
  178. //setBGmat("_tuqi", (offsetZ / BGDZ));
  179. //setBGmat("_Mask2_Ani", 1);
  180. //bgMr.material.DOFloat(0, "_Mask2_Ani", 0.5f).OnComplete<Tween>(() =>
  181. //{
  182. // //Vector3 pos = this.Dlg.DlgTrans.anchoredPosition3D;
  183. // ////if (pos.z > BoardDlg.Instance.boardConf.PressPonit)
  184. // ////{
  185. // //// pos.z = BoardDlg.Instance.boardConf.PressPonit;
  186. // ////}
  187. // //this.Dlg.DlgTrans.anchoredPosition3D = pos;
  188. //});
  189. //this.transform.DOKill();
  190. //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);
  191. }
  192. }
  193. public override void ResetEditorPosition()
  194. {
  195. if (EditorRoot)
  196. {
  197. Vector3 center = Vector3.down * Dlg.BG.Back.sizeDelta.y / 2;
  198. center = Dlg.BG.Back.TransformPoint(center);
  199. center.y -= 0.02f;
  200. EditorRoot.position = center;
  201. EditorRoot.rotation = transform.rotation;
  202. }
  203. }
  204. public override void TransferSyn(GoodsInfo goods, bool smooth = true)
  205. {
  206. base.TransferSyn(goods, smooth);
  207. if (TransferState != TransferState.Init)
  208. {
  209. //if (BoardDlg.Instance && Dlg)
  210. //{
  211. // BoardDlg.Instance.ExecutePicture(Dlg, TransferState == TransferState.Doing, false);
  212. // checkBG();
  213. //}
  214. }
  215. }
  216. }
  217. }