TeacherOperateData.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using System;
  6. public class TeacherOperateData {
  7. public TeacherOperateData()
  8. {
  9. }
  10. public void Init()
  11. {
  12. }
  13. public void Dispose()
  14. {
  15. }
  16. //老师的广播消息的接收
  17. public void AcceptOperateMsg(Engine.Net.NetMsg iMsg)
  18. {
  19. BrocastClass b_data = new BrocastClass();
  20. iMsg.UnPackMsg(ref b_data);
  21. //如果是房主的话 不进行处理
  22. if (GamePlayerData.Instance.IsMaster)
  23. {
  24. switch ((BrocastClassType)b_data.mType)
  25. {
  26. case BrocastClassType.CoreData:
  27. StudentTaskReceiveManager.Instance.CheckCoreData(iMsg);
  28. break;
  29. }
  30. }
  31. if(GamePlayerData.Instance.IsFangzhu())
  32. {
  33. return;
  34. }
  35. if (b_data.mType != 0)
  36. {
  37. //CDebug.Log(((BrocastClassType)b_data.mType).ToString());
  38. }
  39. //学生同步的逻辑
  40. switch((BrocastClassType) b_data.mType)
  41. {
  42. case BrocastClassType.MR:
  43. CheckMRClick(iMsg);
  44. break;
  45. case BrocastClassType.Audio:
  46. CheckAudioClick(iMsg);
  47. break;
  48. case BrocastClassType.UIChange:
  49. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_BACK_UI_CHANGE_DATA, iMsg);
  50. break;
  51. case BrocastClassType.DrawData:
  52. CheckCoreData(iMsg);
  53. break;
  54. }
  55. }
  56. //更新最新的射线位置信息
  57. public void RefreshPos(Engine.Net.NetMsg iMsg)
  58. {
  59. //如果是房主的话 不进行处理
  60. if (GamePlayerData.Instance.room_data.IsReconnectOwner())
  61. {
  62. return;
  63. }
  64. MoveData data = new MoveData();
  65. iMsg.UnPackMsg(ref data);
  66. if(UIParentPoint.Instance == null)
  67. {
  68. return;
  69. }
  70. Vector3 pos = UIParentPoint.Instance.transform.TransformPoint(data.pos);
  71. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_LINE_TARGET_POS_DATA, pos);
  72. }
  73. private void CheckAudioClick(Engine.Net.NetMsg iMsg)
  74. {
  75. AudioData data = new AudioData();
  76. iMsg.UnPackMsg(ref data);
  77. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ACCEPT_AUDIO_SOCKET_DATA, data);
  78. }
  79. private void CheckMRClick(Engine.Net.NetMsg iMsg)
  80. {
  81. MRData data = new MRData();
  82. iMsg.UnPackMsg(ref data);
  83. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_MR_PLAY_DATA, data);
  84. }
  85. //发送位置信息
  86. //低于这个位置偏移就要传送
  87. private float minDis = 0.02f;
  88. //最小的发送间隔
  89. private float minSendCD = 0.1f;//12.5
  90. //上次发送的时间点
  91. private float lastSendTime;
  92. private Vector3 lastPos;//上次发送的位置点
  93. public void CheckPos()
  94. {
  95. if (!GamePlayerData.Instance.NeedSendLineMsg())
  96. {
  97. return;//不在房间里不发送 不是房主 房间里没人
  98. }
  99. if (!GameNetManager.Instance.mSocketMsgCenter.IsConnecting)
  100. {
  101. return;//Socket 没有连接不发送
  102. }
  103. if(SC.InputSystem.InputSystem.Instant == null)
  104. {
  105. return;//SDK没有的时候 是个手机旁观模式
  106. }
  107. if(UIParentPoint.Instance == null)
  108. {
  109. return;
  110. }
  111. //相对于UI的坐标
  112. Vector3 pos = UIParentPoint.Instance.transform.InverseTransformPoint(API_InputSystem.Position);
  113. if (lastSendTime + minSendCD > Time.realtimeSinceStartup && Vector3.Distance(lastPos, pos) < minDis)
  114. {
  115. return;//没必要发送
  116. }
  117. //CDebug.Log("位置偏移 " + Vector3.Distance(lastPos, pos) + pos.ToString() + " lastSendTime " + lastSendTime + " " + Time.realtimeSinceStartup);
  118. lastSendTime = Time.realtimeSinceStartup;
  119. lastPos = pos;
  120. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SEND_TEACHER_LINE_POS_SOCKET_DATA, pos);
  121. }
  122. //老师的广播消息的接收
  123. public void AcceptRefreshMsg(Engine.Net.NetMsg iMsg)
  124. {
  125. if(iMsg.UserId == GamePlayerData.Instance.user_id)
  126. {
  127. CDebug.Log("这是给我的同步的消息");
  128. AcceptOperateMsg(iMsg);
  129. }
  130. else
  131. {
  132. CDebug.Log("ID不对");
  133. }
  134. }
  135. public void RefreshAudioData(Engine.Net.NetMsg iMsg)
  136. {
  137. CDebug.Log("接收到了语音消息");
  138. VoiceChatPacket data = new VoiceChatPacket();
  139. iMsg.UnPackMsg(ref data);
  140. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ACCEPT_AUDIO_DATA, data);
  141. }
  142. private void CheckCoreData(Engine.Net.NetMsg iMsg)
  143. {
  144. SocketCoreData data = new SocketCoreData();
  145. iMsg.UnPackMsg(ref data);
  146. List<SocketClassData> dataList = new List<SocketClassData>();
  147. for (int i = 0; i < data.ct; i++)
  148. {
  149. SocketClassData s_data = new SocketClassData();
  150. iMsg.UnPackMsg(ref s_data);
  151. dataList.Add(s_data);
  152. }
  153. for (int i = 0; i < data.ct; i++)
  154. {
  155. string className = dataList[i].DataClassName;//这个是对应的自定义数据的类名
  156. Type type = Type.GetType(className);
  157. var s_data = Activator.CreateInstance(type);
  158. iMsg.UnPackMsg(ref s_data);
  159. //这里可以对s_data进行类型的判定 再进行数据的处理
  160. switch(s_data.GetType().ToString())
  161. {
  162. case "DrawData":
  163. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ACCEPT_DRAW_SOCKET_DATA, s_data);
  164. break;
  165. }
  166. }
  167. }
  168. }