123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Linq;
- using System;
- public class TeacherOperateData {
- public TeacherOperateData()
- {
- }
- public void Init()
- {
- }
- public void Dispose()
- {
- }
- //老师的广播消息的接收
- public void AcceptOperateMsg(Engine.Net.NetMsg iMsg)
- {
-
- BrocastClass b_data = new BrocastClass();
- iMsg.UnPackMsg(ref b_data);
- //如果是房主的话 不进行处理
- if (GamePlayerData.Instance.IsMaster)
- {
- switch ((BrocastClassType)b_data.mType)
- {
- case BrocastClassType.CoreData:
- StudentTaskReceiveManager.Instance.CheckCoreData(iMsg);
- break;
- }
- }
- if(GamePlayerData.Instance.IsFangzhu())
- {
- return;
- }
- if (b_data.mType != 0)
- {
- //CDebug.Log(((BrocastClassType)b_data.mType).ToString());
- }
- //学生同步的逻辑
- switch((BrocastClassType) b_data.mType)
- {
- case BrocastClassType.MR:
- CheckMRClick(iMsg);
- break;
- case BrocastClassType.Audio:
- CheckAudioClick(iMsg);
- break;
- case BrocastClassType.UIChange:
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_BACK_UI_CHANGE_DATA, iMsg);
- break;
- case BrocastClassType.DrawData:
- CheckCoreData(iMsg);
- break;
- }
- }
- //更新最新的射线位置信息
- public void RefreshPos(Engine.Net.NetMsg iMsg)
- {
- //如果是房主的话 不进行处理
- if (GamePlayerData.Instance.room_data.IsReconnectOwner())
- {
- return;
- }
- MoveData data = new MoveData();
- iMsg.UnPackMsg(ref data);
- if(UIParentPoint.Instance == null)
- {
- return;
- }
- Vector3 pos = UIParentPoint.Instance.transform.TransformPoint(data.pos);
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_REFRESH_LINE_TARGET_POS_DATA, pos);
- }
- private void CheckAudioClick(Engine.Net.NetMsg iMsg)
- {
- AudioData data = new AudioData();
- iMsg.UnPackMsg(ref data);
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ACCEPT_AUDIO_SOCKET_DATA, data);
- }
- private void CheckMRClick(Engine.Net.NetMsg iMsg)
- {
- MRData data = new MRData();
- iMsg.UnPackMsg(ref data);
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_MR_PLAY_DATA, data);
- }
- //发送位置信息
- //低于这个位置偏移就要传送
- private float minDis = 0.02f;
- //最小的发送间隔
- private float minSendCD = 0.1f;//12.5
- //上次发送的时间点
- private float lastSendTime;
- private Vector3 lastPos;//上次发送的位置点
- public void CheckPos()
- {
- if (!GamePlayerData.Instance.NeedSendLineMsg())
- {
- return;//不在房间里不发送 不是房主 房间里没人
- }
- if (!GameNetManager.Instance.mSocketMsgCenter.IsConnecting)
- {
- return;//Socket 没有连接不发送
- }
- if(SC.InputSystem.InputSystem.Instant == null)
- {
- return;//SDK没有的时候 是个手机旁观模式
- }
- if(UIParentPoint.Instance == null)
- {
- return;
- }
- //相对于UI的坐标
- Vector3 pos = UIParentPoint.Instance.transform.InverseTransformPoint(API_InputSystem.Position);
- if (lastSendTime + minSendCD > Time.realtimeSinceStartup && Vector3.Distance(lastPos, pos) < minDis)
- {
- return;//没必要发送
- }
- //CDebug.Log("位置偏移 " + Vector3.Distance(lastPos, pos) + pos.ToString() + " lastSendTime " + lastSendTime + " " + Time.realtimeSinceStartup);
- lastSendTime = Time.realtimeSinceStartup;
- lastPos = pos;
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SEND_TEACHER_LINE_POS_SOCKET_DATA, pos);
- }
- //老师的广播消息的接收
- public void AcceptRefreshMsg(Engine.Net.NetMsg iMsg)
- {
- if(iMsg.UserId == GamePlayerData.Instance.user_id)
- {
- CDebug.Log("这是给我的同步的消息");
- AcceptOperateMsg(iMsg);
- }
- else
- {
- CDebug.Log("ID不对");
- }
- }
- public void RefreshAudioData(Engine.Net.NetMsg iMsg)
- {
- CDebug.Log("接收到了语音消息");
- VoiceChatPacket data = new VoiceChatPacket();
- iMsg.UnPackMsg(ref data);
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ACCEPT_AUDIO_DATA, data);
- }
- private void CheckCoreData(Engine.Net.NetMsg iMsg)
- {
- SocketCoreData data = new SocketCoreData();
- iMsg.UnPackMsg(ref data);
- List<SocketClassData> dataList = new List<SocketClassData>();
- for (int i = 0; i < data.ct; i++)
- {
- SocketClassData s_data = new SocketClassData();
- iMsg.UnPackMsg(ref s_data);
- dataList.Add(s_data);
- }
- for (int i = 0; i < data.ct; i++)
- {
- string className = dataList[i].DataClassName;//这个是对应的自定义数据的类名
- Type type = Type.GetType(className);
- var s_data = Activator.CreateInstance(type);
- iMsg.UnPackMsg(ref s_data);
- //这里可以对s_data进行类型的判定 再进行数据的处理
- switch(s_data.GetType().ToString())
- {
- case "DrawData":
- MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_ACCEPT_DRAW_SOCKET_DATA, s_data);
- break;
- }
- }
- }
- }
|