TestArtCreate.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using ShadowStudio.Model;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using XRTool.Util;
  7. using Newtonsoft.Json;
  8. using ShadowStudio.UI;
  9. using SC.XR.Unity.Module_InputSystem;
  10. using ShadowStudio.Tool;
  11. using XRTool.UI;
  12. public class TestArtCreate : MonoBehaviour
  13. {
  14. public ArtType artType;
  15. public int indexOfArt;
  16. public Transform left;
  17. public Transform right;
  18. public PlayerAnimatorController PlayerAnimator;
  19. public Renderer TestRender;
  20. // Start is called before the first frame update
  21. void Start()
  22. {
  23. ArtInfoMgr.Instance.OpenLocalData();
  24. //TransferState state = (TransferState)10;
  25. //print(state.ToString());
  26. //PlayerAnimator.SetHands(left,right);
  27. //DispatcherBase.KeyDownDelegateRegister(OnKeyDownAction);
  28. //DispatcherBase.KeyUpDelegateRegister(OnKeyUpAction);
  29. //if (DataConfMgr<ServerConfig>.Instance.TableHelper == null)
  30. //{
  31. // DataConfMgr<ServerConfig>.Instance.OpenData(Application.persistentDataPath);
  32. //}
  33. //DataConfMgr<ServerConfig>.Instance.TableHelper.readConfComplete += OnReadConfComplete;
  34. //DataConfMgr<ServerConfig>.Instance.OpenTable("serverName");
  35. }
  36. private void OnReadConfComplete()
  37. {
  38. if (DataConfMgr<ServerConfig>.Instance.TableHelper.DataList != null && DataConfMgr<ServerConfig>.Instance.TableHelper.DataList.Count > 0)
  39. {
  40. print(JsonConvert.SerializeObject( DataConfMgr<ServerConfig>.Instance.TableHelper.DataList));
  41. }
  42. else
  43. {
  44. ServerConfig sc = new ServerConfig();
  45. sc.serverName = "fat";
  46. sc.loginUrl = "https://webapi-fat.shadowcreator.com/100009/index.php?s=index/command/gateway";
  47. sc.lobbyUrl = "wss://studiosignaling.tech.shadowcreator.com/fatlobby/?appId=100009";
  48. sc.roomUrl = "wss://studiosignaling.tech.shadowcreator.com/fatroom/?token=";
  49. sc.rtcUrl = "wss://studiosignaling.tech.shadowcreator.com/rtc/";
  50. DataConfMgr<ServerConfig>.Instance.TableHelper.AddData(sc);
  51. }
  52. }
  53. private void OnKeyUpAction(InputKeyCode keyCode, InputDevicePartBase part)
  54. {
  55. if (part.PartType == InputDevicePartType.HandLeft)
  56. {
  57. if (PlayerAnimator)
  58. {
  59. PlayerAnimator.LeftHandState = 0;
  60. }
  61. }
  62. else if (part.PartType == InputDevicePartType.HandRight)
  63. {
  64. if (PlayerAnimator)
  65. {
  66. PlayerAnimator.RightHandState = 0;
  67. }
  68. }
  69. }
  70. private void OnKeyDownAction(InputKeyCode keyCode, InputDevicePartBase part)
  71. {
  72. if (part.PartType == InputDevicePartType.HandLeft)
  73. {
  74. if (PlayerAnimator)
  75. {
  76. PlayerAnimator.LeftHandState = 1;
  77. }
  78. }
  79. else if (part.PartType == InputDevicePartType.HandRight)
  80. {
  81. if (PlayerAnimator)
  82. {
  83. PlayerAnimator.RightHandState = 1;
  84. }
  85. }
  86. }
  87. private void GetAllInfo()
  88. {
  89. for (int i = 0; i < ArtInfoMgr.Instance.ArtInfoList.Count; i++)
  90. {
  91. print(ArtInfoMgr.Instance.ArtInfoList[i].ArtName);
  92. }
  93. }
  94. // Update is called once per frame
  95. void Update()
  96. {
  97. if (Input.GetKeyDown(KeyCode.Space))
  98. {
  99. CreateUser();
  100. }
  101. if (Input.GetKeyDown(KeyCode.C))
  102. {
  103. CreateArt(artType, indexOfArt);
  104. }
  105. if (Input.GetKeyDown(KeyCode.F))
  106. {
  107. for (int i = 0; i < ArtInfoMgr.Instance.ArtInfoList.Count; i++)
  108. {
  109. CreateArt(ArtInfoMgr.Instance.ArtInfoList[i]);
  110. }
  111. }
  112. PlayerAnimator.transform.position = GameSession.Instance.gameHead.position;
  113. PlayerAnimator.transform.forward = GameSession.Instance.BodyForward;
  114. PlayerAnimator.playerHead.rotation = GameSession.Instance.gameHead.rotation;
  115. Vector3 leftpos;
  116. Quaternion leftRot;
  117. if (GameSession.Instance.TryHandLeftPosition(out leftpos, out leftRot))
  118. {
  119. if (!PlayerAnimator.HandLeft.gameObject.activeSelf)
  120. {
  121. PlayerAnimator.HandLeft.gameObject.SetActive(true);
  122. }
  123. PlayerAnimator.HandLeft.position = leftpos;
  124. PlayerAnimator.HandLeft.rotation = leftRot;
  125. }
  126. else
  127. {
  128. if (PlayerAnimator.HandLeft.gameObject.activeSelf)
  129. {
  130. PlayerAnimator.HandLeft.gameObject.SetActive(false);
  131. }
  132. }
  133. Vector3 rightpos;
  134. Quaternion rightRot;
  135. if (GameSession.Instance.TryHandRightPosition(out rightpos, out rightRot))
  136. {
  137. if (!PlayerAnimator.HandRight.gameObject.activeSelf)
  138. {
  139. PlayerAnimator.HandRight.gameObject.SetActive(true);
  140. }
  141. PlayerAnimator.HandRight.position = rightpos;
  142. PlayerAnimator.HandRight.rotation = rightRot;
  143. }
  144. else
  145. {
  146. if (PlayerAnimator.HandRight.gameObject.activeSelf)
  147. PlayerAnimator.HandRight.gameObject.SetActive(false);
  148. }
  149. }
  150. /// <summary>
  151. /// 创建用户
  152. /// </summary>
  153. public void CreateUser()
  154. {
  155. CommonMethod.MyPeer = new Peer();
  156. CommonMethod.MyPeer.PeerId = "Test";
  157. CommonMethod.MyPeer.NickName = "Test";
  158. ArtInfoMgr.Instance.OnUserChange(new List<Peer>() { CommonMethod.MyPeer }, true);
  159. }
  160. private void CreateArt(ArtInfo info)
  161. {
  162. ArtHandler handler = ArtInfoMgr.Instance.CreateArtHandler(info);
  163. handler.CreateArt();
  164. }
  165. private void CreateArt(ArtType artType, int indexOfArt)
  166. {
  167. Debug.Log(artType);
  168. var list = ArtInfoMgr.Instance.GetArtInfoList(artType);
  169. if (list != null)
  170. {
  171. print(list.Count);
  172. if (indexOfArt >= 0 && indexOfArt < list.Count)
  173. {
  174. ArtInfo info = list[indexOfArt];
  175. print(info.ArtName);
  176. ArtHandler handler = ArtInfoMgr.Instance.CreateArtHandler(info);
  177. print(handler.GetIcon());
  178. var container = handler.CreateArt();
  179. container.Position = GameSession.Instance.GetHeadForwadPos(1);
  180. //gameObject.hideFlags = HideFlags.HideAndDontSave;
  181. }
  182. }
  183. else
  184. {
  185. UnityLog.Instance.LogError(artType.ToString() + " is null list!");
  186. }
  187. }
  188. }