This commit is contained in:
陈向学 2024-02-27 13:42:57 +08:00
parent 823cbef0f6
commit e29060cbfe
104 changed files with 4 additions and 7894 deletions

View File

@ -26,7 +26,6 @@ namespace AdamSync
public GameObject registInfoPanel; public GameObject registInfoPanel;
public Button registConfirmBtn; public Button registConfirmBtn;
public RoomItem roomItemPrefab;
public Transform roomItemParent; public Transform roomItemParent;
public RoomInstructController roomInstructController; public RoomInstructController roomInstructController;

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 37f3ff4babdf2324280ea5cde7e1d28c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,175 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using UnityEngine;
using System.Linq;
using DataModel.Model;
using LitJson;
public class ScoreBase : MonoBehaviour
{
/// <summary>
/// 评估序号
/// </summary>
public int code;
/// <summary>
/// 评估点
/// </summary>
[DisplayOnly]
public string scoreName;
/// <summary>
/// 岗位名
/// </summary>
[DisplayOnly]
public string seatName;
/// <summary>
/// 步骤序号
/// </summary>
[DisplayOnly]
public int stepOrder;
/// <summary>
/// 分值
/// </summary>
[DisplayOnly]
public int scoreValue;
[Header("如果有前置打分点,则配置有效")]
/// <summary>
/// 是否有前置打分点
/// </summary>
public bool hasFrontPoint;
/// <summary>
/// 前置评估点编号
/// </summary>
public int frontScorePointCode;
/// <summary>
/// 前置打分点
/// </summary>
[HideInInspector]
public ScoreBase frontScorePoint;
[Header("==============")]
/// <summary>
/// 评分点是否正确
/// </summary>
[DisplayOnly]
public bool IsRight;
/// <summary>
/// 是否激活
/// </summary>
[DisplayOnly]
public bool IsActive = false;
/// <summary>
/// 判断点完成顺序
/// </summary>
[HideInInspector]
public int Completed = 0;
public virtual void Init(string subjectName,int code)
{
this.code = code;
XmlNode node = ScoreManage.scoreXML.SelectSingleNode("root/Sub_" + subjectName);
foreach (XmlNode item in node.ChildNodes)
{
if(item.Attributes["code"].Value==code.ToString())
{
scoreName = item.Attributes["Text"].Value;
seatName= item.Attributes["seatName"].Value;
scoreValue = int.Parse(item.Attributes["scoreValue"].Value);
stepOrder = int.Parse(item.Attributes["stepOrder"].Value);
break;
}
}
//获取前置
if (hasFrontPoint)
{
ScoreBase sb= transform.parent.GetComponentsInChildren<ScoreBase>(true).ToList().Find(a => a.code == frontScorePointCode);
if(sb!=null)
{
frontScorePoint = sb;
}
else
{
Debug.LogError("前置条件错误:" + subjectName + " " + code);
}
}
}
/// <summary>
/// 激活(按科目激活)
/// </summary>
public virtual void SetActive(bool isActive)
{
IsActive = isActive;
if(isActive)
{
transform.GetComponentsInChildren<ScoreJudge_FixedValue>(true).ToList().ForEach(a =>
{
a.AddAction();
});
}
else
{
transform.GetComponentsInChildren<ScoreJudge_FixedValue>(true).ToList().ForEach(a =>
{
a.RemoveAction();
});
}
}
public virtual void SetIsRight()
{
}
/// <summary>
/// 提交分表分数 (暂定点击步骤结束提交)
/// </summary>
public virtual void Submit()
{
if (IsActive)
{
SetActive(false);
appraisedetail appraisedetail = new appraisedetail
{
Id = System.Guid.NewGuid().ToString(),
PracticeId = LoadManage.Instance.currentPractice.Id,
AppraiseId = LoadManage.Instance.currentPractice.Id,
SubjectId = LoadManage.Instance.psubjects.Find(a => a.Name == transform.parent.name).SubjectId,
PracticeSubjectId= LoadManage.Instance.psubjects.Find(a => a.Name == transform.parent.name).Id,
UserAccount = LoadManage.Instance.me.user.user_name,
RoleName = seatName,
Idx = code,
Notice = scoreName,
Score = (IsRight ? 0 : -scoreValue),
Completed=(IsRight ? 1:0)
};
//提交数据库
string url = "http://"+MyNetMQClient.CallIP+ "/Handler/Api_Appraise.ashx";
var tmp= new KeyValuePair<string, string>[2];
tmp[0] = new KeyValuePair<string, string>("action", "setScore");
tmp[1] = new KeyValuePair<string, string>("appraiseDetail", JsonMapper.ToJson(appraisedetail));
StartCoroutine(MyNetMQClient.CallPost(url, tmp, result =>
{
var json = JsonMapper.ToObject<CallResultObject>(result);
if (json.state)
{
Debug.Log("上传分数:++++++++++++++++++++++++++++++" + JsonMapper.ToJson(appraisedetail));
}
else
{
Debug.Log(json.message);
}
}));
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ef3666abb6f9b174a8d7396d0363e3ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,170 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
/// <summary>
/// 配置单值判断标准
/// </summary>
public class ScoreJudge_FixedValue : MonoBehaviour
{
public string ;
[SerializeField]
[HideInInspector]
public OneValueSyncObject oneValueSyncObject;
[SerializeField]
[HideInInspector]
public bool mybool;
[SerializeField]
[HideInInspector]
public byte mybyte;
[SerializeField]
[HideInInspector]
public short myshort;
[SerializeField]
[HideInInspector]
public int myint;
[SerializeField]
[HideInInspector]
public float myfloat;
[SerializeField]
[HideInInspector]
public double mydouble;
[SerializeField]
[HideInInspector]
public string mystring;
[SerializeField]
[HideInInspector]
public Vector3 myvector3;
/// <summary>
/// 是否正确
/// </summary>
[DisplayOnly]
public bool Isright;
/// <summary>
/// 所属打分点
/// </summary>
[HideInInspector]
public ScoreBase scoreBase;
/// <summary>
/// 完成顺序
/// </summary>
[HideInInspector]
public int index=-1;
public void Init(ScoreBase scoreBase)
{
this.scoreBase = scoreBase;
if(oneValueSyncObject==null)
{
Debug.LogError();
}
}
public void AddAction()
{
oneValueSyncObject.action_apprisedetail += TrySetScore;
Debug.Log("添加打分回调:"+ oneValueSyncObject.Id);
}
public void RemoveAction()
{
oneValueSyncObject.action_apprisedetail -= TrySetScore;
Debug.Log("移除打分回调:"+ oneValueSyncObject.Id);
}
/// <summary>
/// 尝试判对
/// </summary>
public void TrySetScore()
{
if (!Isright && scoreBase.IsActive)
{
//判断前置条件
if (scoreBase.hasFrontPoint && !scoreBase.frontScorePoint.IsRight)
{
return;
}
switch (oneValueSyncObject.valueType)
{
case ValueType.Null:
Debug.LogError("错误");
return;
case ValueType.Bool:
if (mybool == oneValueSyncObject.mybool)
{
Isright=true;
}
break;
case ValueType.Byte:
if (mybyte == oneValueSyncObject.mybyte)
{
Isright = true;
}
break;
case ValueType.Short:
if (myshort == oneValueSyncObject.myshort)
{
Isright = true;
}
break;
case ValueType.Int:
if (myint == oneValueSyncObject.myint)
{
Isright = true;
}
break;
case ValueType.Float:
if (myfloat == oneValueSyncObject.myfloat)
{
Isright = true;
}
break;
case ValueType.Double:
if (mydouble == oneValueSyncObject.mydouble)
{
Isright = true;
}
break;
case ValueType.String:
if (mystring == oneValueSyncObject.mystring)
{
Isright = true;
}
break;
case ValueType.Vector3:
if (myvector3 == oneValueSyncObject.myvector3)
{
Isright = true;
}
break;
default:
Debug.LogError("错误");
return;
}
if (Isright)
{
index = scoreBase.Completed;
scoreBase.Completed++;
scoreBase.SetIsRight();
//操作点 | 科目物体名称 | 评估点序号 | 操作点物体名称 | index
MyNetMQClient.instance.Send(LoadManage.Instance.currentRoomArea, 70, Encoding.UTF8.GetBytes("操作点" + "|" + scoreBase.transform.parent.name + "|" + scoreBase.code + "|" + gameObject.name +"|"+index));
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5a02eb8717f80ae429d04eb922b8ec5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,68 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Text;
/// <summary>
/// 固定值打分
/// </summary>
public class ScoreObject : ScoreBase
{
/// <summary>
/// 是否有序
/// </summary>
[SerializeField]
public ScoreType scoreType;
/// <summary>
/// 判断标准
/// </summary>
List<ScoreJudge_FixedValue> list;
public override void Init(string subjectName, int code)
{
base.Init(subjectName, code);
list = transform.GetComponentsInChildren<ScoreJudge_FixedValue>(true).ToList();
if(list==null)
{
Debug.LogError("错误,不能为空");
}
else
{
list.ForEach(a =>
{
a.Init(this);
});
}
}
/// <summary>
/// 获取评估点对错
/// </summary>
/// <returns></returns>
public override void SetIsRight()
{
if (!IsRight)
{
switch (scoreType)
{
case ScoreType.:
IsRight= list.All(a => a.Isright);
break;
case ScoreType.:
IsRight= list.All(a => a.Isright && a.index == list.IndexOf(a));
break;
}
if(IsRight)
{
//评估点 | 科目物体名称 | 评估点序号 | 当前index
MyNetMQClient.instance.Send(LoadManage.Instance.currentRoomArea, 70, Encoding.UTF8.GetBytes("评估点|"+transform.parent.name+"|"+code+"|"+Completed));
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 90e504cd920201448b62630b72e006d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 5acb8fb1052be364db480657a58d73ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,144 +0,0 @@
using System;
using System.IO;
public class ByteArray
{
MemoryStream ms = new MemoryStream();
BinaryReader br;
BinaryWriter bw;
public ByteArray()
{
bw = new BinaryWriter(ms);
br = new BinaryReader(ms);
}
public ByteArray(byte[] buff)
{
ms = new MemoryStream(buff);
br = new BinaryReader(ms);
bw = new BinaryWriter(ms);
}
#region
public void Read(out int vaule)
{
vaule = br.ReadInt32();
}
public void Read(out byte value)
{
value = br.ReadByte();
}
public void Read(out byte[] vaule, int length)
{
vaule = br.ReadBytes(length);
}
public void Read(out bool value)
{
value = br.ReadBoolean();
}
public void Read(out string value)
{
value = br.ReadString();
}
public void Read(out long value)
{
value = br.ReadInt64();
}
public void Read(out double value)
{
value = br.ReadDouble();
}
public void Read(out float value)
{
value = br.ReadSingle();
}
#endregion
#region
public void Write(int value)
{
bw.Write(value);
}
public void Write(byte value)
{
bw.Write(value);
}
public void Write(bool value)
{
bw.Write(value);
}
public void Write(byte[] value)
{
bw.Write(value);
}
public void Write(string value)
{
bw.Write(value);
}
public void Write(long value)
{
bw.Write(value);
}
public void Write(double value)
{
bw.Write(value);
}
public void Write(float value)
{
bw.Write(value);
}
#endregion
public int Length
{
get
{
return (int)ms.Length;
}
}
public int Position
{
get
{
return (int)ms.Position;
}
}
/// <summary>
/// 是否读取完了
/// </summary>
public bool ReadOver
{
get
{
if (Position < Length)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 关闭读写
/// </summary>
public void Close()
{
br.Close();
bw.Close();
ms.Close();
}
public byte[] GetBuffer()
{
byte[] result = new byte[ms.Length];
Buffer.BlockCopy(ms.GetBuffer(), 0, result, 0, (int)ms.Length);
return result;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4a2fdde09d86a5f438d0725b1be508d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,537 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;
/// <summary>
/// 客户端socket是属于那一种处理方式
/// </summary>
public enum OpenClientSocketEnum
{
Null,
,
}
public class ClientSocket
{
#region
public Socket socket;
public byte[] readBuff;
List<byte> cache = new List<byte>();
public List<string> reciveMessagejosn = new List<string>();//收到的消息列表
public List<byte[]> sendMessages = new List<byte[]>();//发送列表
private bool isreading = false;
public bool threadRun = true;//线程运行控制
public Action<bool, int> closeExeCallBack = null;//关闭exe回调
public Action<bool, string> zhiHuiCallBack = null;//指挥回调
// public Timer timer;
public byte[] currentMessage;
public OpenClientSocketEnum openClientSocketEnum;//打开类型
public bool success = true;//是否成功发送消息
public ClientSocket(Socket tmpsocket, OpenClientSocketEnum openClientSocketEnum)
{
readBuff = new byte[1024];
socket = tmpsocket;
socket.ReceiveTimeout = 8000;
socket.SendTimeout = 8000;
this.openClientSocketEnum = openClientSocketEnum;
// timer = new Timer(TimerCallBack, currentMessage, Timeout.Infinite, 10000);
}
/// <summary>
///接收数据(线程)
/// </summary>
public void BeginRecv()
{
UnityEngine.Debug.Log("开始接收消息");
socket.BeginReceive(readBuff, 0, 1024, SocketFlags.None, ReciveCallBack, readBuff);//开始接收客户端发送字节
}
/// <summary>
/// 接收回调委托
/// </summary>
/// <param name="ar"></param>
public void ReciveCallBack(IAsyncResult ar)
{
try
{
int length = socket.EndReceive(ar);//接收完成
byte[] massge = new byte[length];
//接受0字节关闭socket
if(length==0)
{
if(openClientSocketEnum == OpenClientSocketEnum.)
{
threadRun = false;
if(socket.Connected)
{
socket.Shutdown(SocketShutdown.Both);
}
socket.Close();
// ServerSocket.socketList.Remove(this);
}
}
Buffer.BlockCopy(readBuff, 0, massge, 0, length);//拷贝消息
cache.AddRange(massge);//存储消息
if (isreading == false)
{
isreading = true;
OnDate();//解析数据
}
else
{
Console.WriteLine("数据正在被读");
}
if (threadRun == true)
{
//递归
if (socket == null)
{
threadRun = false;
}
else
{
if (!socket.Connected)
{
threadRun = false;
socket.Close();
}
}
if (socket != null)
{
socket.BeginReceive(readBuff, 0, 1024, SocketFlags.None, ReciveCallBack, readBuff);//接收下一条消息
}
}
//else
//{
// return;
//}
}
catch(Exception e)
{
UnityEngine.Debug.Log("接受线程异常"+e.Message);
if (openClientSocketEnum == OpenClientSocketEnum.)
{
if (fangzhenClient != null && this == fangzhenClient)
{
if (!fangzhenClient.socket.Connected)
{
//断线重连
ConnectFangZhenSocekt(LoadManage.Instance.currentPractice.IpAddress, LoadManage.Instance.currentPractice.Port.Value);
}
//CloseFangZhenSocket();
}
}
}
}
/// <summary>
/// 解析消息
/// </summary>
public void OnDate()
{
//反序列化
byte[] result = Decode(ref cache);
//如果解析完了,重新置为可读
if (result == null)
{
isreading = false;
return;
}
//消息体解码
string message = Mdecode(result);
if (message == null)
{
Console.WriteLine("message为空");
isreading = false;
return;
}
//存储消息体(json)
//reciveMessagejosn.Add(message);
//处理消息
if (openClientSocketEnum == OpenClientSocketEnum.)
{
MessageRecive(message);
}
OnDate();//递归,直到全部解析完成
}
/// <summary>
///消息体长度解码(去头部)
/// </summary>
/// <returns></returns>
public byte[] Decode(ref List<byte> cache)
{
if (cache.Count < 4)
{
return null;
}
MemoryStream ms = new MemoryStream(cache.ToArray());//内存流读写消息
BinaryReader br = new BinaryReader(ms);//二进制读取
int length = br.ReadInt32();//读取头部4个字节,得到消息内容长度
if (length > ms.Length - ms.Position)//消息不完整
{
//UnityEngine.Debug.Log("消息不完整");
return null;
}
byte[] result = br.ReadBytes(length);//光标继续移动,读取消息内容
cache.Clear();//清空消息
cache.AddRange(br.ReadBytes((int)(ms.Length - ms.Position)));//去掉第一个消息
br.Close();
ms.Close();
return result;
}
/// <summary>
/// 消息体内容解析(json字符串)
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public string Mdecode(byte[] value)
{
string jsonStr = Encoding.UTF8.GetString(value);//反序列化为jstring
return jsonStr;
}
/// <summary>
/// 加入发送队列(改成直接发送消息)
/// </summary>
/// <param name="tmpStr"></param>
public void ReadySend(MessageModel message)
{
try
{
if(!this.socket.Connected)
{
UnityEngine.Debug.Log("未连接,发送失败");
return;
}
if (message == null)
{
return;
}
//实例化一个消息对象
string jsonstr = LitJson.JsonMapper.ToJson(message);
byte[] ba = Encoding.UTF8.GetBytes(jsonstr);//得到byte[] message
if (ba.Length == 0)
{
return;
}
//长度编码
ByteArray arr = new ByteArray();
arr.Write(ba.Length);
arr.Write(ba);
byte[] sendBuffer = arr.GetBuffer();
socket.Send(sendBuffer);
}
catch(Exception e)
{
UnityEngine.Debug.Log("发送错误"+e.Message);
if (openClientSocketEnum == OpenClientSocketEnum.)
{
if (fangzhenClient != null && this == fangzhenClient)
{
if(!fangzhenClient.socket.Connected)
{
//断线重连
ConnectFangZhenSocekt(LoadManage.Instance.currentPractice.IpAddress, LoadManage.Instance.currentPractice.Port.Value);
}
//CloseFangZhenSocket();
}
}
}
}
/// <summary>
/// 处理消息
/// </summary>
public void MessageRecive(string json)
{
try
{
if (json == null || json == "")
{
return;
}
MessageModel message = LitJson.JsonMapper.ToObject<MessageModel>(json);
switch (message.operationEnum)
{
case SimOperationEnum.:
//步骤
if (zhiHuiCallBack != null)
{
zhiHuiCallBack(true, message.str);
zhiHuiCallBack = null;
}
else
{
// HandleResult._Instance.zhiHuiStr.AddRange(JsonConvert.DeserializeObject<List<string>>(message.str));
}
break;
case SimOperationEnum.:
//转发给给服务器
//HandleResult._Instance.subjectSet.Add(message.str);
break;
case SimOperationEnum.:
//HandleResult._Instance.changeSubject.Add(message);
break;
case SimOperationEnum.:
//操作软件发来的
//SoftManage.Instance.Soft.Add(message);
break;
}
}
catch(Exception e)
{
UnityEngine.Debug.LogWarning(json);
UnityEngine.Debug.LogWarning(e.Message);
}
}
#endregion
#region
public static ClientSocket fangzhenClient;//客户端socket连接仿真服务器
/// <summary>
/// 连接仿真服务器
/// </summary>
public static void ConnectFangZhenSocekt(string serverIP, int port,Action<bool> action=null)
{
UnityEngine.Debug.Log("开启仿真服务器客户端socket"+ serverIP+ ":port");
if (fangzhenClient!=null && fangzhenClient.socket.Connected)
{
UnityEngine.Debug.Log("仿真客户端不为空");
if (action != null)
{
action(true);
}
}
else
{
try
{
UnityEngine.Debug.Log("正在连接仿真服务器中。。。。");
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IPAddress.Parse(serverIP), port);
if (socket.Connected)
{
UnityEngine.Debug.Log("连接成功");
//创建客户端对象
fangzhenClient = new ClientSocket(socket, OpenClientSocketEnum.);
//开启异步接收
fangzhenClient.BeginRecv();
if (action != null)
{
action(true);
}
}
else
{
if (action != null)
{
action(false);
}
else
{
UnityEngine.Debug.Log("连接仿真服务器失败,重新连接");
ConnectFangZhenSocekt(serverIP, port);
}
}
}
catch(Exception e)
{
UnityEngine.Debug.Log("连接仿真服务器失败,请重试:"+e.Message);
if (action != null)
{
action(false);
}
}
}
}
/// <summary>
/// 关闭仿真服务器客户端
/// </summary>
public static void CloseFangZhenSocket()
{
if (fangzhenClient != null)
{
fangzhenClient.threadRun = false;
if (fangzhenClient.socket.Connected)
{
fangzhenClient.socket.Shutdown(SocketShutdown.Both);
}
fangzhenClient.socket.Close();
fangzhenClient = null;
UnityEngine.Debug.Log("关闭仿真服务客户端socket成功");
}
}
public static void SendToTongBuFangZhenServerByAllUser(MessageModel message)
{
if (fangzhenClient != null)
{
if (fangzhenClient.socket.Connected)
{
fangzhenClient.ReadySend(message);
}
else
{
ConnectFangZhenSocekt(LoadManage.Instance.currentPractice.IpAddress, LoadManage.Instance.currentPractice.Port.Value, (a) =>
{
if(a)
{
fangzhenClient.ReadySend(message);
}
else
{
UnityEngine.Debug.Log("连接失败");
}
});
}
}
else
{
try
{
UnityEngine.Debug.Log("正在连接仿真服务器中。。。。");
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IPAddress.Parse(LoadManage.Instance.currentPractice.IpAddress), LoadManage.Instance.currentPractice.Port.Value);
if (socket.Connected)
{
UnityEngine.Debug.Log("连接成功");
//创建客户端对象
fangzhenClient = new ClientSocket(socket, OpenClientSocketEnum.);
//开启异步接收
fangzhenClient.BeginRecv();
fangzhenClient.ReadySend(message);
}
}
catch
{
UnityEngine.Debug.Log("连接仿真服务器失败,请重试");
}
}
}
/// <summary>
/// 发送同步数据给仿真服务器
/// </summary>
/// <param name="message">发送的消息</param>
/// <param name="callback">返回的字符串</param>
public static void SendToTongBuFangZhenServer(MessageModel message)
{
if (fangzhenClient != null && fangzhenClient.socket.Connected)
{
fangzhenClient.ReadySend(message);
//UnityEngine.Debug.Log("发送的同步消息内容__________ " + message.str);
}
else
{
try
{
UnityEngine.Debug.Log("正在连接仿真服务器中。。。。");
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IPAddress.Parse(LoadManage.Instance.currentPractice.IpAddress), LoadManage.Instance.currentPractice.Port.Value);
if (socket.Connected)
{
UnityEngine.Debug.Log("连接成功");
//创建客户端对象
fangzhenClient = new ClientSocket(socket, OpenClientSocketEnum.);
//开启异步接收
fangzhenClient.BeginRecv();
fangzhenClient.ReadySend(message);
//UnityEngine.Debug.Log("发送的同步消息内容__________ " + message.str);
}
}
catch
{
UnityEngine.Debug.Log("连接仿真服务器失败,请重试");
}
}
}
/// <summary>
/// 发送命令给仿真服务器
/// </summary>
/// <param name="message"></param>
public static void SendCommondToFangZhenServer(MessageModel message)
{
if (fangzhenClient != null && fangzhenClient.socket.Connected)
{
fangzhenClient.ReadySend(message);
}
else
{
try
{
UnityEngine.Debug.Log("正在连接仿真服务器中。。。。");
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IPAddress.Parse(LoadManage.Instance.currentPractice.IpAddress), LoadManage.Instance.currentPractice.Port.Value);
if (socket.Connected)
{
UnityEngine.Debug.Log("连接成功");
//创建客户端对象
fangzhenClient = new ClientSocket(socket, OpenClientSocketEnum.);
//开启异步接收
fangzhenClient.BeginRecv();
fangzhenClient.ReadySend(message);
}
}
catch
{
UnityEngine.Debug.Log("连接仿真服务器失败,请重试");
}
}
}
/// <summary>
/// 发送指挥给仿真服务器
/// </summary>
/// <param name="message">发送的消息</param>
/// <param name="callback">返回的字符串</param>
public static void SendZhiHuiToFangZhenServer(MessageModel message, Action<bool, string> callback)
{
if (fangzhenClient != null && fangzhenClient.socket.Connected)
{
fangzhenClient.zhiHuiCallBack = callback;
fangzhenClient.ReadySend(message);
}
}
/// <summary>
/// 同步设备字典
/// </summary>
/// <param name="deviceId"></param>
/// <param name="content"></param>
public static void DevicesSyncByDic(string deviceId,string content)
{
MessageModel message = new MessageModel(SimOperationEnum.);
message.str = "设备属性按字典同步字典";
message.canShu = deviceId +"$"+ content;
if (fangzhenClient != null && fangzhenClient.socket.Connected)
{
fangzhenClient.ReadySend(message);
}
}
#endregion
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 689baea31e156a4458510b83acbc13ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,67 +0,0 @@
/// <summary>
/// 协同交互服务操作类型
/// </summary>
public enum SimOperationEnum
{
EXE开启 ,
EXE开启收到 ,
EXE开启完成 ,
EXE关闭客户端 ,
ExE关闭服务端,
EXE关闭收到 ,
EXE关闭完成 ,
,
,
,
,
,
,
,
,
,
,
Commond客户端,
Commond服务端,
,
,
,
,
,
,
,
,
,
,
,
,
,
}
public class MessageModel
{
public SimOperationEnum operationEnum;//操作方式(不能为0)
public object canShu;
public int port;
public string str;
public float floatData;
public string str2;
public MessageModel(SimOperationEnum operationEnum, object canShu)
{
this.operationEnum = operationEnum;
this.canShu = canShu;
}
public MessageModel(SimOperationEnum operationEnum)
{
this.operationEnum = operationEnum;
}
public MessageModel(SimOperationEnum operationEnum, int port)
{
this.operationEnum = operationEnum;
this.port = port;
}
public MessageModel()
{
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 439bc84f09e4815438c689e86de5a4ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: edaaf0d27d87ce64c8c4d285659bb33e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,49 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FunctionSync_Active : OneValueSyncObject
{
public void Init()
{
if (!hasInit)
{
InitDynamic("active_" + gameObject.name, CallBack, ValueType.Bool);
}
}
/// <summary>
/// 显示物体
/// </summary>
public void ShowObject()
{
gameObject.SetActive(true);
mybool = true;
SendSync();
}
/// <summary>
/// 隐藏物体
/// </summary>
public void DisShowObject()
{
gameObject.SetActive(false);
mybool = false;
SendSync();
}
/// <summary>
/// 回调
/// </summary>
/// <param name="id"></param>
public void CallBack(string id,bool isEnterRoom)
{
if(mybool)
{
gameObject.SetActive(true);
}
else
{
gameObject.SetActive(false);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d87d349b2a4c38146bb6702b8307a902
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,63 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 注意:尽量用协程代替动画,直接用动画同步会出现各客户端动画播放不一致的情况。
/// </summary>
public class FunctionSync_Animator : OneValueSyncObject
{
Animator anim;
List<string> state = new List<string>();
string currentTriger;
private void Start()
{
Init();
}
public void Init()
{
if (!hasInit)
{
anim = GetComponent<Animator>();
InitDynamic("animator" + gameObject.name, CallBack, ValueType.String);
}
}
public void SetAnimatorState(string TriggerParameter)
{
if (!state.Contains(mystring))
{
state.Add(mystring);
}
currentTriger = mystring;
anim.SetTrigger(TriggerParameter);
mystring = TriggerParameter;
SendSync();
}
/// <summary>
/// 回调
/// </summary>
/// <param name="id"></param>
private void CallBack(string id,bool isEnterRoom)
{
if(!state.Contains(mystring))
{
state.Add(mystring);
currentTriger = mystring;
anim.SetTrigger(mystring);
Debug.Log("动画同步:" + id + "," + mystring);
}
else
{
if (currentTriger!=mystring)
{
currentTriger = mystring;
anim.SetTrigger(mystring);
Debug.Log("动画同步:" + id + "," + mystring);
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e97790970474bcc47a6beff0dfbe8570
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,72 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FunctionSync_Audio : OneValueSyncObject
{
private AudioSource audioSource;
public bool ;
public void Init()
{
if (!hasInit)
{
audioSource = GetComponent<AudioSource>();
InitDynamic("audio_" + gameObject.name, CallBack, ValueType.Int);
}
}
/// <summary>
/// 操作同步声音
/// </summary>
/// <param name="audioControlEnum"></param>
public void SetAudio(AudioControlEnum audioControlEnum)
{
myint = (int)audioControlEnum;
switch (audioControlEnum)
{
case AudioControlEnum.Play:
audioSource.Play();
break;
case AudioControlEnum.Pause:
audioSource.Pause();
break;
case AudioControlEnum.Stop:
audioSource.Stop();
break;
}
SendSync();
}
private void CallBack(string callback,bool isjoinRoom)
{
if(isjoinRoom && !)
{
return;
}
switch ((AudioControlEnum)myint)
{
case AudioControlEnum.Play:
audioSource.Play();
break;
case AudioControlEnum.Pause:
audioSource.Pause();
break;
case AudioControlEnum.Stop:
audioSource.Stop();
break;
}
}
}
/// <summary>
/// 声音操作枚举
/// </summary>
public enum AudioControlEnum
{
NULL,
Play,
Pause,
Stop
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b53f3d994ae112749b54a98b2d818302
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,111 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
/// <summary>
/// 生成物体同步,是单例
/// </summary>
public class FunctionSync_CreateObejct : MonoBehaviour
{
public static FunctionSync_CreateObejct Instance;
private st_Motions st = new st_Motions { m_iOperaType = 10008 };
public static Dictionary<string, GameObject> createDic = new Dictionary<string, GameObject>();
private bool hasInit;
void Start()
{
Init();
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="callback"></param>
public void Init()
{
if (!GameManage.Instance.is单机模式)
{
if (!hasInit)
{
Instance = this;
st.area = LoadManage.Instance.currentRoomArea;
//发送数据
List<byte> tmpbytes = new List<byte>();
//syncId
tmpbytes.AddRange(BitConverter.GetBytes(LoadManage.Instance.SyncId));
//postionroatescale
tmpbytes.AddRange(new byte[36]);
//string长度
tmpbytes.AddRange(new byte[4]);
st.m_sOperaData = tmpbytes.ToArray();
hasInit = true;
}
}
}
/// <summary>
/// 生成物体
/// </summary>
/// <param name="path">Resource</param>
/// <param name="pos">position</param>
/// <param name="roate">eulerAngles</param>
/// <param name="scale">localScale</param>
public void CreateObejct(string path,Vector3 pos,Vector3 roate,Vector3 scale)
{
if (!createDic.ContainsKey(path))
{
createDic.Add(path, Resources.Load<GameObject>(path));
}
GameObject obj = Instantiate<GameObject>(createDic[path]);
obj.transform.position = pos;
obj.transform.eulerAngles = roate;
obj.transform.localScale = scale;
SendSync(path, pos, roate, scale);
}
/// <summary>
/// 回调
/// </summary>
/// <param name="data"></param>
public void CallBack(byte[] data)
{
Vector3 pos = new Vector3(BitConverter.ToSingle(data, 4), BitConverter.ToSingle(data, 8), BitConverter.ToSingle(data, 12));
Vector3 roate = new Vector3(BitConverter.ToSingle(data, 16), BitConverter.ToSingle(data, 20), BitConverter.ToSingle(data, 24));
Vector3 scale = new Vector3(BitConverter.ToSingle(data, 28), BitConverter.ToSingle(data, 32), BitConverter.ToSingle(data, 36));
int legth = BitConverter.ToInt32(data, 40);
string path = Encoding.UTF8.GetString(data, 44,legth);
if (!createDic.ContainsKey(path))
{
createDic.Add(path, Resources.Load<GameObject>(path));
}
GameObject obj = Instantiate<GameObject>(createDic[path]);
obj.transform.position = pos;
obj.transform.eulerAngles = roate;
obj.transform.localScale = scale;
}
private void SendSync(string path, Vector3 pos, Vector3 roate, Vector3 scale)
{
byte[] strs=Encoding.UTF8.GetBytes(path);
byte[] data = new byte[strs.Length + 44];
//sysid
Array.Copy(st.m_sOperaData, 0, data, 0, 4);
//pos
Array.Copy(BitConverter.GetBytes(pos.x), 0, data, 4, 4);
Array.Copy(BitConverter.GetBytes(pos.y), 0, data, 8, 4);
Array.Copy(BitConverter.GetBytes(pos.z), 0, data, 12, 4);
//roate
Array.Copy(BitConverter.GetBytes(roate.x), 0, data, 16, 4);
Array.Copy(BitConverter.GetBytes(roate.y), 0, data, 20, 4);
Array.Copy(BitConverter.GetBytes(roate.z), 0, data, 24, 4);
//scale
Array.Copy(BitConverter.GetBytes(scale.x), 0, data, 28, 4);
Array.Copy(BitConverter.GetBytes(scale.y), 0, data, 32, 4);
Array.Copy(BitConverter.GetBytes(scale.z), 0, data, 36, 4);
//string长度
Array.Copy(BitConverter.GetBytes(strs.Length), 0, data, 40, 4);
//string
Array.Copy(strs, 0, data, 44, strs.Length);
st.m_sOperaData = data;
LoadManage.Instance.RSclient.Send(st);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dcdb571f478b1b84ea88f914db0c8e1e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,59 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FunctionSync_Material : OneValueSyncObject
{
Renderer renderer;
/// <summary>
/// MeshRender上材质球索引
/// </summary>
public int materialIndex = 0;
Dictionary<string, Material> matDic = new Dictionary<string, Material>();
private void Start()
{
Init();
}
public void Init()
{
if (!hasInit)
{
renderer = GetComponent<Renderer>();
InitDynamic("Material_" + gameObject.name, CallBack, ValueType.String);
}
}
/// <summary>
/// 设置材质
/// </summary>
/// <param name="ResourcePath">Resource文件下加载路径</param>
public void SetMaterial(string ResourcePath)
{
if(!matDic.ContainsKey(ResourcePath))
{
Material m = Resources.Load<Material>(ResourcePath);
matDic.Add(ResourcePath, m);
}
renderer.materials[materialIndex].CopyPropertiesFromMaterial(matDic[ResourcePath]);
mystring = ResourcePath;
SendSync();
}
/// <summary>
/// 回调
/// </summary>
/// <param name="id"></param>
public void CallBack(string id, bool isEnterRoom)
{
if (!matDic.ContainsKey(mystring))
{
Material m = Resources.Load<Material>(mystring);
matDic.Add(mystring, m);
}
renderer.materials[materialIndex].CopyPropertiesFromMaterial(matDic[mystring]);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 703a02f3fc117284ea7c17d003f734de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,123 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class FunctionSync_MaterialTexture : OneValueSyncObject
{
Renderer renderer;
Dictionary<int, Texture> matDic = new Dictionary<int, Texture>();
private void Start()
{
Init();
}
public void Init()
{
if (!hasInit)
{
renderer = GetComponent<Renderer>();
InitDynamic("MaterialTex_" + gameObject.name, CallBack, ValueType.Int);
}
}
/// <summary>
/// 设置材质
/// </summary>
/// <param name="ResourcePath">Resource文件下加载路径</param>
public void SetMaterial(int num)
{
if(num<0)
{
return;
}
else if(num>0)
{
}
myint = num;
SendSync();
if (num == 0)
{
//关闭
renderer.material.mainTexture = null;
}
else
{
if (!matDic.ContainsKey(num))
{
//StartCoroutine(GetTexture(num, MediaPanel.instance.dicPicture[num].url, a =>
//{
// if (a)
// {
// renderer.material.mainTexture = matDic[num];
// }
// else
// {
// Debug.LogError("下载图片失败:" + num);
// }
//}));
}
else
{
renderer.material.mainTexture = matDic[num];
}
}
}
/// <summary>
/// 下载图片
/// </summary>
/// <returns></returns>
IEnumerator GetTexture(int num, string url1, Action<bool> callback)
{
WWW www1 = new WWW(url1);
yield return www1;
if (www1.isDone)
{
if (!string.IsNullOrEmpty(www1.error))
{
Debug.LogError(www1.error);
MessagePanel.ShowMessage("获取图片失败:" + www1.error, GameObject.Find("Canvas").transform, a => { });
callback.Invoke(false);
}
else
{
Debug.Log("下载图片成功:" + num);
matDic.Add(num, www1.texture);
callback.Invoke(true);
}
}
}
/// <summary>
/// 回调
/// </summary>
/// <param name="id"></param>
public void CallBack(string id, bool isEnterRoom)
{
if (myint == 0)
{
renderer.material.mainTexture = null;
}
else if (!matDic.ContainsKey(myint))
{
//StartCoroutine(GetTexture(myint, MediaPanel.instance.dicPicture[myint].url, a =>
//{
// if (a)
// {
// renderer.material.mainTexture = matDic[myint];
// }
// else
// {
// Debug.LogError("下载图片失败:" + myint);
// }
//}));
}
else
{
renderer.material.mainTexture = matDic[myint];
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 60c58dc1d14e27244b9adf0fd99f1294
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,254 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using System.Text;
using System;
/// <summary>
/// 多媒体同步适用于图片ppt视频集成在一个材质上
/// </summary>
public class FunctionSync_Media : MonoBehaviour
{
public static Dictionary<string, FunctionSync_Media> functionSync_MediaDic = new Dictionary<string, FunctionSync_Media>();
/// <summary>
/// type编号如果为ppt索引
/// </summary>
public string Id;
private VideoPlayer videoPlayer;
private Renderer renderer;
/// <summary>
/// 关闭的texture
/// </summary>
private Texture nullTexture;
/// <summary>
/// 当前视频播放时间
/// </summary>
[HideInInspector]
public double PlayTime;
private int currentTextureNum;
private int currentPPTnum;
[HideInInspector]
public int currentPPTsubNum;
private int currentVideoNum;
[HideInInspector]
public byte videoState;
/// <summary>
/// id流
/// </summary>
private byte[] idbytes;
public void Init()
{
renderer = GetComponent<Renderer>();
videoPlayer = GetComponent<VideoPlayer>();
nullTexture = renderer.material.mainTexture;
Id = "media_" + gameObject.name;
idbytes = Encoding.UTF8.GetBytes(Id);
functionSync_MediaDic.Add(Id, this);
}
float time = 0;
private void Update()
{
//学生回拉,老师不在视频不播放
if (!GameManage.Instance.is单机模式)
{
//if (!LoadManage.Instance.loadPackage.isOwner)
//{
// if (videoPlayer.isPlaying && videoPlayer.time > PlayTime + 1)
// {
// videoPlayer.time = PlayTime + 1;
// }
//}
//else
{
if (videoPlayer.isPlaying && videoState==1)
{
time += Time.deltaTime;
if (time > 1)
{
time = 0;
PlayTime = videoPlayer.time;
//发送时间
SetVideo(currentVideoNum, 1, PlayTime);
}
}
}
}
}
public void SetTexture(int num)
{
List<byte> tmp = new List<byte>();
//id
tmp.AddRange(BitConverter.GetBytes(idbytes.Length));
tmp.AddRange(idbytes);
//图片
tmp.Add(0);
tmp.AddRange(BitConverter.GetBytes(num));
LoadManage.Instance.RSclient.Send(LoadManage.Instance.currentRoomArea, 10010, tmp.ToArray());
}
public void SetPPT(int num,int index)
{
List<byte> tmp = new List<byte>();
//id
tmp.AddRange(BitConverter.GetBytes(idbytes.Length));
tmp.AddRange(idbytes);
//ppt
tmp.Add(2);
tmp.AddRange(BitConverter.GetBytes(num));
tmp.AddRange(BitConverter.GetBytes(index));
LoadManage.Instance.RSclient.Send(LoadManage.Instance.currentRoomArea, 10010, tmp.ToArray());
}
public void SetVideo(int num,byte isOpen,double playtime)
{
List<byte> tmp = new List<byte>();
//id
tmp.AddRange(BitConverter.GetBytes(idbytes.Length));
tmp.AddRange(idbytes);
//视频
tmp.Add(1);
tmp.AddRange(BitConverter.GetBytes(num));
tmp.Add(isOpen);
tmp.AddRange(BitConverter.GetBytes(playtime));
LoadManage.Instance.RSclient.Send(LoadManage.Instance.currentRoomArea, 10010, tmp.ToArray());
}
public void CallBack(byte[] data,bool isJoinRoom=false)
{
int num=BitConverter.ToInt32(data,1+4+idbytes.Length);
if (data[4 + idbytes.Length] == 0)
{
currentTextureNum = num;
//type,num
//图片
videoPlayer.Stop();
//下载
//StartCoroutine(GetTexture(MediaPanel.instance.dicPicture[num].url, (a,tex) =>
//{
// if (a)
// {
// renderer.material.mainTexture = tex;
// }
// else
// {
// Debug.LogError("下载图片失败:" + num);
// }
//}));
}
else if(data[4 + idbytes.Length] == 1)
{
currentVideoNum = num;
videoState = data[5+4+idbytes.Length];
//if (videoPlayer.url != MediaPanel.instance.dicVideo[num].url)
//{
// videoPlayer.url = MediaPanel.instance.dicVideo[num].url;
//}
//type,num,开关,播放时间
//视频
if (data[5 + 4 + idbytes.Length] ==0)
{
//关闭
videoPlayer.Stop();
PlayTime = 0;
}
else if(data[5 + 4 + idbytes.Length] ==1)
{
//开启
videoPlayer.playbackSpeed = 1;
if (!videoPlayer.isPlaying)
{
videoPlayer.Play();
}
PlayTime = videoPlayer.time;
}
else if(data[5 + 4 + idbytes.Length] ==2)
{
//暂停
videoPlayer.playbackSpeed = 0;
PlayTime = videoPlayer.time;
}
if (isJoinRoom)
{
videoPlayer.time = BitConverter.ToDouble(data, 6 + 4 + idbytes.Length);
}
else
{
//if (!LoadManage.Instance.loadPackage.isOwner)
//{
// videoPlayer.time = BitConverter.ToDouble(data, 6 + 4 + idbytes.Length);
//}
}
}
else if(data[4 + idbytes.Length] == 2)
{
currentPPTnum = num;
//type,num,索引
//PPT
int index = BitConverter.ToInt32(data,5 + 4 + idbytes.Length);
currentPPTsubNum = index;
videoPlayer.Stop();
if (index < 0)
{
//关闭ppt
renderer.material.mainTexture = nullTexture;
}
else
{
//无索引
//下载
//StartCoroutine(GetTexture(MediaPanel.instance.dicPPT[num].subTextures[index], (a, tex) =>
//{
// if (a)
// {
// //pptTexDic[num].ppttextureDic.Add(index, tex);
// renderer.material.mainTexture = tex;
// }
// else
// {
// Debug.LogError("下载PPT图片失败" + num);
// }
//}));
}
}
}
/// <summary>
/// 下载图片
/// </summary>
/// <returns></returns>
IEnumerator GetTexture(string url1, Action<bool,Texture> callback)
{
WWW www1 = new WWW(url1);
yield return www1;
if (www1.isDone)
{
if (!string.IsNullOrEmpty(www1.error))
{
Debug.LogError(www1.error);
MessagePanel.ShowMessage("获取图片失败:" + www1.error, GameObject.Find("Canvas").transform, a => { });
callback.Invoke(false,null);
}
else
{
Debug.Log("下载图片成功");
callback.Invoke(true,www1.texture);
}
}
}
}
/// <summary>
/// ppt信息
/// </summary>
public class PPTtextureDate
{
public Dictionary<int, Texture> ppttextureDic = new Dictionary<int, Texture>();
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 7f2350bc421efea4a93328a98aafc0b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,97 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class FunctionSync_Parent : OneValueSyncObject
{
/// <summary>
/// 是否为父物体
/// </summary>
public bool isParent;
private OneValueSyncObject localposSync;
private OneValueSyncObject localangSync;
private void Start()
{
Init();
}
public void Init()
{
if(!hasInit)
{
InitDynamic("parent_" + gameObject.name, CallBackParent, ValueType.String);
if (!isParent)
{
localposSync = gameObject.AddComponent<OneValueSyncObject>();
localposSync.InitDynamic(Id + "pos", CallBackPos, ValueType.Vector3);
localangSync = gameObject.AddComponent<OneValueSyncObject>();
localangSync.InitDynamic(Id + "ang", CallBackAng, ValueType.Vector3);
}
}
}
/// <summary>
/// 设置父物体
/// </summary>
/// <param name="parent"></param>
/// <param name="Localpos"></param>
/// <param name="LocalEulerAngles"></param>
public void SetParent(FunctionSync_Parent parent, Vector3 Localpos,Vector3 LocalEulerAngles)
{
if(!isParent)
{
transform.parent = parent.transform;
transform.localPosition = Localpos;
transform.localEulerAngles = LocalEulerAngles;
mystring = parent.Id;
SendSync();
SetLocalPos(Localpos);
SetLocalAng(LocalEulerAngles);
}
else
{
Debug.LogError("父物体不能再设置父物体");
}
}
/// <summary>
/// 设置局部坐标
/// </summary>
public void SetLocalPos(Vector3 localpos)
{
localposSync.myvector3 = localpos;
localposSync.SendSync();
}
/// <summary>
/// 设置局部旋转
/// </summary>
public void SetLocalAng(Vector3 localang)
{
localangSync.myvector3 = localang;
localangSync.SendSync();
}
private void CallBackParent(string id, bool isEnterRoom)
{
if (!isParent)
{
transform.parent = OneValueSyncObject.OneAxisSyncObjectList[mystring].transform;
}
}
private void CallBackPos(string id, bool isEnterRoom)
{
if (!isParent)
{
transform.localPosition = localposSync.myvector3;
}
}
private void CallBackAng(string id, bool isEnterRoom)
{
if (!isParent)
{
transform.localEulerAngles = localangSync.myvector3;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e73d48c6e85b7ed40ae3ca2c88f64ffb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,71 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FunctionSync_ParticleSystem : OneValueSyncObject
{
ParticleSystem ps;
private void Start()
{
Init();
}
public void Init()
{
if(!hasInit)
{
ps = GetComponent<ParticleSystem>();
if (ps != null)
{
InitDynamic("ps_" + gameObject.name, CallBack, ValueType.Int);
}
}
}
/// <summary>
/// 操作粒子
/// </summary>
/// <param name="state"></param>
public void SetParticleSystem(ParticleSystemState state)
{
myint = (int)state;
switch (state)
{
case ParticleSystemState.Play:
ps.Play();
break;
case ParticleSystemState.Stop:
ps.Stop();
break;
case ParticleSystemState.Pause:
ps.Pause();
break;
}
SendSync();
}
private void CallBack(string id, bool isEnterRoom)
{
switch ((ParticleSystemState)myint)
{
case ParticleSystemState.Play:
ps.Play();
break;
case ParticleSystemState.Stop:
ps.Stop();
break;
case ParticleSystemState.Pause:
ps.Pause();
break;
}
}
}
/// <summary>
/// 粒子操作枚举
/// </summary>
public enum ParticleSystemState
{
Null,
Play,
Stop,
Pause
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 8e9990bb948d68d44b43ba99602d723e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,430 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
/// <summary>
/// 注意1.此脚本和动画共用时,需要注意动画激活时,位置会被锁死,无法移动。
/// 2.有控制权才能移动,结束后需释放控制权(控制权专属除外)
/// </summary>
public class FunctionSync_PositionRoate : SyncBase
{
public static Dictionary<string, FunctionSync_PositionRoate> positionRoateSyncObejctList = new Dictionary<string, FunctionSync_PositionRoate>();
[Tooltip("同步坐标")]
public bool isPositionSync;
[HideInInspector]
public bool isLocalPotion=true;
[Tooltip("同步角度")]
public bool isRoateSync;
[HideInInspector]
public bool isLocalRoate=true;
/// <summary>
/// 是否本地锁定
/// </summary>
[DisplayOnly]
public bool isLock=true;
//同步的位置
[DisplayOnly]
public float[] pos = new float[6];
private Vector3 tmpPos = new Vector3();
private Vector3 tmpRat = new Vector3();
private st_Motions st_Motions = new st_Motions { m_iOperaType = 10007 };
private int lastindex;
private void OnDestroy()
{
if(positionRoateSyncObejctList.ContainsKey(Id))
{
positionRoateSyncObejctList.Remove(Id);
}
}
public void Init()
{
if (!hasInit)
{
if (!positionRoateSyncObejctList.ContainsValue(this))
{
InitDynamic("move_" + gameObject.name);
}
}
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="id"></param>
/// <param name="Tmpislock">是否获取控制权</param>
public void InitDynamic(string id,bool isControl=false)
{
if (GameManage.Instance.is单机模式)
{
return;
}
if (hasInit)
{
Debug.Log("已经初始化,不能重复初始化");
return;
}
if (string.IsNullOrEmpty(id))
{
if (string.IsNullOrEmpty(Id))
{
Debug.LogError("Id为空");
return;
}
}
else
{
Id = id;
}
if (LoadManage.Instance != null)
{
st_Motions.area = LoadManage.Instance.currentRoomArea;
}
isLock = !isControl;
//初始化缓存
if(isPositionSync)
{
lastpos = isLocalPotion ? transform.localPosition : transform.position;
}
if(isRoateSync)
{
lastrot = isLocalRoate ? transform.localEulerAngles : transform.eulerAngles;
}
List<byte> tmpbytes = new List<byte>();
//syncId
if (LoadManage.Instance != null)
{
tmpbytes.AddRange(BitConverter.GetBytes(LoadManage.Instance.SyncId));
}
//id
byte[] data = Encoding.UTF8.GetBytes(Id);
tmpbytes.AddRange(BitConverter.GetBytes(data.Length));
tmpbytes.AddRange(data);
//类型
if(isPositionSync&& !isRoateSync)
{
tmpbytes.Add(0);
lastindex = tmpbytes.Count;
//坐标系
tmpbytes.Add(isLocalPotion ? (byte)1 : (byte)0);
tmpbytes.AddRange(new byte[12]);
}
else if(!isPositionSync && isRoateSync)
{
tmpbytes.Add(1);
lastindex = tmpbytes.Count;
//坐标系
tmpbytes.Add(isLocalRoate ? (byte)1 : (byte)0);
tmpbytes.AddRange(new byte[12]);
}
else if(isPositionSync && isRoateSync)
{
tmpbytes.Add(2);
lastindex = tmpbytes.Count;
//坐标系
tmpbytes.Add(isLocalPotion ? (byte)1 : (byte)0);
tmpbytes.AddRange(new byte[12]);
tmpbytes.Add(isLocalRoate ? (byte)1 : (byte)0);
tmpbytes.AddRange(new byte[12]);
}
else
{
tmpbytes.Add(3);
lastindex = tmpbytes.Count;
//坐标系
tmpbytes.Add(isLocalPotion ? (byte)1 : (byte)0);
tmpbytes.AddRange(new byte[12]);
tmpbytes.Add(isLocalRoate ? (byte)1 : (byte)0);
tmpbytes.AddRange(new byte[12]);
}
//初始化
pos[0] = isLocalPotion ? transform.localPosition.x : transform.position.x;
pos[1] = isLocalPotion ? transform.localPosition.y : transform.position.y;
pos[2] = isLocalPotion ? transform.localPosition.z : transform.position.z;
pos[3] = isLocalPotion ? transform.localEulerAngles.x : transform.eulerAngles.x;
pos[4] = isLocalPotion ? transform.localEulerAngles.y : transform.eulerAngles.y;
pos[5] = isLocalPotion ? transform.localEulerAngles.z : transform.eulerAngles.z;
st_Motions.m_sOperaData = tmpbytes.ToArray();
positionRoateSyncObejctList.Add(Id, this);
hasInit = true;
}
/// <summary>
/// 获取控制权
/// </summary>
public void GetControl()
{
isLock = false;
Debug.Log("获取控制权:" + Id);
}
/// <summary>
/// 释放控制权
/// </summary>
public void ReleaseControl()
{
isLock = true;
SendSync();
Debug.Log("释放控制权:" + Id);
}
[DisplayOnly]
public float PostionOnceTime = 0.06f;
[DisplayOnly]
public float RoateOneTime = 1;
Vector3 lastpos = new Vector3();
Vector3 lastrot = new Vector3();
public virtual void LateUpdate()
{
if (!GameManage.Instance.is单机模式)
{
//发同步
if (!isLock)
{
bool isAlreadySend = false;
if (isPositionSync)
{
if (isLocalPotion)
{
if (Vector3.Distance(lastpos, transform.localPosition) >= PostionOnceTime)
{
SendSync();
isAlreadySend = true;
}
}
else
{
if (Vector3.Distance(lastpos, transform.position) >= PostionOnceTime)
{
if (!isLock)
{
SendSync();
isAlreadySend = true;
}
}
}
}
//位置没法同步时判断角度是否发
if (isRoateSync && !isAlreadySend)
{
if (isLocalRoate)
{
if (Vector3.Distance(lastrot, transform.localEulerAngles) >= RoateOneTime)
{
SendSync();
}
}
else
{
if (Vector3.Distance(lastrot, transform.eulerAngles) >= RoateOneTime)
{
SendSync();
}
}
}
}
else
{
//锁定位置
if (isPositionSync)
{
tmpPos.x = pos[0];
tmpPos.y = pos[1];
tmpPos.z = pos[2];
if (!isLocalPotion)
{
transform.position = tmpPos;
lastpos = transform.position;
}
else
{
transform.localPosition = tmpPos;
lastpos = transform.localPosition;
}
}
if (isRoateSync)
{
tmpRat.x = pos[3];
tmpRat.y = pos[4];
tmpRat.z = pos[5];
if (!isLocalRoate)
{
transform.eulerAngles = tmpRat;
lastrot = transform.eulerAngles;
}
else
{
transform.localEulerAngles = tmpRat;
lastrot = transform.localEulerAngles;
}
}
}
}
}
public void SendSync()
{
if (!GameManage.Instance.is单机模式)
{
if (isPositionSync)
{
Vector3 tmp;
if (isLocalPotion)
{
tmp = transform.localPosition;
lastpos = transform.localPosition;
}
else
{
tmp = transform.position;
lastpos = transform.position;
}
SetPos(isLocalPotion, tmp.x, tmp.y, tmp.z);
}
if (isRoateSync)
{
Vector3 tmp;
if (isLocalRoate)
{
tmp = transform.localEulerAngles;
lastrot = transform.localEulerAngles;
}
else
{
tmp = transform.eulerAngles;
lastrot = transform.eulerAngles;
}
SetRot(isLocalRoate, tmp.x, tmp.y, tmp.z);
}
if (isPositionSync && !isRoateSync)
{
st_Motions.m_sOperaData[lastindex] = (isLocalPotion ? (byte)1 : (byte)0);
Array.Copy(BitConverter.GetBytes(pos[0]), 0, st_Motions.m_sOperaData, lastindex + 1, 4);
Array.Copy(BitConverter.GetBytes(pos[1]), 0, st_Motions.m_sOperaData, lastindex + 5, 4);
Array.Copy(BitConverter.GetBytes(pos[2]), 0, st_Motions.m_sOperaData, lastindex + 9, 4);
}
else if (!isPositionSync && isRoateSync)
{
st_Motions.m_sOperaData[lastindex] = (isLocalRoate ? (byte)1 : (byte)0);
Array.Copy(BitConverter.GetBytes(pos[3]), 0, st_Motions.m_sOperaData, lastindex + 1, 4);
Array.Copy(BitConverter.GetBytes(pos[4]), 0, st_Motions.m_sOperaData, lastindex + 5, 4);
Array.Copy(BitConverter.GetBytes(pos[5]), 0, st_Motions.m_sOperaData, lastindex + 9, 4);
}
else if (isPositionSync && isRoateSync)
{
st_Motions.m_sOperaData[lastindex] = (isLocalPotion ? (byte)1 : (byte)0);
Array.Copy(BitConverter.GetBytes(pos[0]), 0, st_Motions.m_sOperaData, lastindex + 1, 4);
Array.Copy(BitConverter.GetBytes(pos[1]), 0, st_Motions.m_sOperaData, lastindex + 5, 4);
Array.Copy(BitConverter.GetBytes(pos[2]), 0, st_Motions.m_sOperaData, lastindex + 9, 4);
st_Motions.m_sOperaData[lastindex + 13] = (isLocalPotion ? (byte)1 : (byte)0);
Array.Copy(BitConverter.GetBytes(pos[3]), 0, st_Motions.m_sOperaData, lastindex + 14, 4);
Array.Copy(BitConverter.GetBytes(pos[4]), 0, st_Motions.m_sOperaData, lastindex + 18, 4);
Array.Copy(BitConverter.GetBytes(pos[5]), 0, st_Motions.m_sOperaData, lastindex + 22, 4);
}
LoadManage.Instance.RSclient.Send(st_Motions);
}
}
public void SetPos(bool islocalPos,float x,float y,float z)
{
this.isLocalPotion = islocalPos;
pos[0] = x;
pos[1] = y;
pos[2] = z;
}
public void SetRot(bool islocalRoate,float x,float y,float z)
{
this.isLocalRoate = islocalRoate;
pos[3] = x;
pos[4] = y;
pos[5] = z;
}
public void SetValue(int start,byte[] data)
{
if(data[start]==0)
{
//只同步坐标
if (data[start+1]==1)
{
//local
isLocalPotion = true;
}
else
{
//世界
isLocalPotion = false;
}
pos[0] = BitConverter.ToSingle(data, start + 2);
pos[1] = BitConverter.ToSingle(data, start + 6);
pos[2] = BitConverter.ToSingle(data, start + 10);
}
else if(data[start]==1)
{
//只同步角度
if (data[start + 1] == 1)
{
//local
isLocalRoate = true;
}
else
{
//世界
isLocalRoate = false;
}
pos[3] = BitConverter.ToSingle(data, start + 2);
pos[4] = BitConverter.ToSingle(data, start + 6);
pos[5] = BitConverter.ToSingle(data, start + 10);
}
else if(data[start]==2)
{
//同步位置和角度
if (data[start + 1] == 1)
{
//local
isLocalPotion = true;
}
else
{
//世界
isLocalPotion = false;
}
pos[0] = BitConverter.ToSingle(data, start + 2);
pos[1] = BitConverter.ToSingle(data, start + 6);
pos[2] = BitConverter.ToSingle(data, start + 10);
if (data[start + 14] == 1)
{
//local
isLocalRoate = true;
}
else
{
//世界
isLocalRoate = false;
}
pos[3] = BitConverter.ToSingle(data, start + 15);
pos[4] = BitConverter.ToSingle(data, start + 19);
pos[5] = BitConverter.ToSingle(data, start + 23);
}
}
}
public class DisplayOnly : PropertyAttribute
{
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 97bf24f09ee4e6c40a9da590d36bfb67
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,63 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 注意1.此脚本和动画共用时,需要注意动画激活时,缩放会被锁死,无法移动。
/// 2.有控制权才能移动,结束后需释放控制权(控制权专属除外)
/// </summary>
public class FunctionSync_Scale : OneValueSyncObject
{
/// <summary>
/// 是否有控制权
/// </summary>
public bool isControl=false;
private void Start()
{
Init();
}
public void Init()
{
if(!hasInit)
{
InitDynamic("Scale_" + gameObject.name, null, ValueType.Vector3);
myvector3 = transform.localScale;
}
}
/// <summary>
/// 获取控制权
/// </summary>
public void GetControl()
{
isControl = true;
}
/// <summary>
/// 释放控制权
/// </summary>
public void ReleaseControl()
{
isControl = false;
myvector3 = transform.localScale;
SendSync();
}
[DisplayOnly]
public float OnceTime = 0.1f;
private void LateUpdate()
{
if (!GameManage.Instance.is单机模式)
{
if (!isControl)
{
transform.localScale = myvector3;
}
else
{
if (Vector3.Distance(myvector3, transform.localScale) > OnceTime)
{
myvector3 = transform.localScale;
SendSync();
}
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c8216020d45268146bc855315c01feb1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,68 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public class FunctionSync_Text : OneValueSyncObject
{
/// <summary>
/// 是否自动初始化,不可中途改变
/// </summary>
public bool isAutoInit=true;
Action<string, string> callback;
Text Text;
public void Init(Action<string, string> callback =null)
{
if(isAutoInit)
{
Text = GetComponent<Text>();
if(Text==null)
{
Debug.LogError("错误自动初始化需找到Text组件");
return;
}
}
else
{
if (callback != null)
{
this.callback = callback;
}
else
{
Debug.LogError("错误,自己初始化需要传回调");
return;
}
}
InitDynamic("text_" + gameObject.name, CallBack, ValueType.String);
}
/// <summary>
/// 如果是自动初始化,设置并同步字符串
/// </summary>
/// <param name="message"></param>
public void SetText(string message)
{
mystring = message;
if(callback!=null)
{
callback.Invoke(Id, message);
}
SendSync();
}
private void CallBack(string id, bool isEnterRoom)
{
if(isAutoInit)
{
Text.text = mystring;
}
else
{
if (callback != null)
{
callback(id, mystring);
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 580a665771fcf7d46af23cf9a147feb1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,173 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using System.Text;
using System;
/// <summary>
/// 视频播放同步
/// </summary>
public class FunctionSync_Video : MonoBehaviour
{
public static Dictionary<string, FunctionSync_Video> dicVideo = new Dictionary<string, FunctionSync_Video>();
public string id;
private VideoPlayer videoPlayer;
private st_Motions st = new st_Motions { m_iOperaType = 10009 };
/// <summary>
/// 视频播放器状态
/// </summary>
public int State;
/// <summary>
/// 当前视频播放时间
/// </summary>
private double PlayTime;
private bool hasInit;
private int index;
void Start()
{
Init();
}
public void Init()
{
if (!GameManage.Instance.is单机模式)
{
if (!hasInit)
{
st.area = LoadManage.Instance.currentRoomArea;
id = "video_" + gameObject.name;
videoPlayer = GetComponent<VideoPlayer>();
byte[] idbyte = Encoding.UTF8.GetBytes(id);
byte[] tmp = new byte[4 + 4 + 8 + idbyte.Length];
index = 4 + idbyte.Length;
//id
Array.Copy(BitConverter.GetBytes(idbyte.Length), 0, tmp, 0, 4);
Array.Copy(idbyte, 0, tmp, 4, idbyte.Length);
//状态
//时间
st.m_sOperaData = tmp;
dicVideo.Add(id, this);
hasInit = true;
}
}
}
private void Update()
{
//学生回拉,老师不在视频不播放
if(!GameManage.Instance.is单机模式 )
{
if(videoPlayer.isPlaying && videoPlayer.time>PlayTime+1)
{
videoPlayer.time = PlayTime+1;
}
}
}
/// <summary>
/// 操作同步视频
/// </summary>
public void SetAudio(int num)
{
State = num;
if (num == 0)
{
//关闭
videoPlayer.Stop();
PlayTime = 0;
}
else if (num == -1)
{
//暂停
videoPlayer.playbackSpeed=0;
PlayTime = videoPlayer.time;
}
else if (num == -2)
{
//继续
videoPlayer.playbackSpeed = 1;
PlayTime = videoPlayer.time;
}
else if(num==1)
{
//播放
videoPlayer.playbackSpeed = 1;
videoPlayer.Play();
PlayTime = videoPlayer.time;
}
SendSync();
}
/// <summary>
/// 回调(老师不执行)
/// </summary>
/// <param name="state"></param>
/// <param name="time"></param>
public void CallBack(int state,double time)
{
State = state;
PlayTime = time;
if (State == 0)
{
//关闭
videoPlayer.Stop();
}
else if (State == -1)
{
//暂停
videoPlayer.playbackSpeed = 0;
}
else if(State==1)
{
//播放
videoPlayer.playbackSpeed = 1;
videoPlayer.Play();
}
videoPlayer.time = time;
}
public void JoinRoomCallBack(int state, double time)
{
State = state;
PlayTime = time;
if (State == -1)
{
//暂停
videoPlayer.Play();
videoPlayer.playbackSpeed = 1;
videoPlayer.time = time;
videoPlayer.playbackSpeed = 0;
}
else if (State == 1)
{
//播放
videoPlayer.Play();
videoPlayer.playbackSpeed = 1;
videoPlayer.time = time;
}
}
/// <summary>
/// 更新时间
/// </summary>
/// <param name="time"></param>
public void SetCurrentTime(double time)
{
PlayTime = time;
SendSync();
}
private void SendSync()
{
//状态
Array.Copy(BitConverter.GetBytes(State), 0, st.m_sOperaData, index, 4);
//时间
Array.Copy(BitConverter.GetBytes(PlayTime), 0, st.m_sOperaData, index + 4, 8);
LoadManage.Instance.RSclient.Send(st);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 60ec3eff123f7d843a6532028407035a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,105 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class MyPlayer : FunctionSync_PositionRoate
{
public string id = "";
public string name = "";
public TextMesh text;
public GameObject m_carryingIcon;
public MeshRenderer m_carryingIconMeshRenderer;
private float value;
public Animator anim;
public bool isTeacher;
/// <summary>
/// 预制体类型
/// </summary>
public byte PrefbType;
public void Init(string id,string name,byte isTeather,byte PrefbType)
{
this.id = id;
this.name = name;
this.PrefbType = PrefbType;
isPositionSync = true;
isRoateSync = true;
//初始化同步
if (LoadManage.Instance != null)
{
InitDynamic(id, id == LoadManage.Instance.MyId);
}
else
{
InitDynamic(id, true);
}
//名字
text =GetComponentInChildren<TextMesh>();
text.text = name;
m_carryingIcon = text.transform.Find("CarryingIcon").gameObject;
m_carryingIconMeshRenderer = m_carryingIcon.GetComponent<MeshRenderer>();
//自己或学生隐藏textmesh
if (LoadManage.Instance == null)
{
text.gameObject.SetActive(false);
}
else
{
if (id == LoadManage.Instance.MyId)
{
text.gameObject.SetActive(false);
}
else
{
text.gameObject.SetActive(true);
}
}
m_carryingIcon.SetActive(isTeacher);
anim = GetComponent<Animator>();
}
Vector3 lastpos=new Vector3();
public float OnceTime = 0.06f;
public override void LateUpdate()
{
if (!GameManage.Instance.is单机模式)
{
//发送同步
if (id == LoadManage.Instance.MyId)
{
if (Vector3.Distance(lastpos, transform.position) >= OnceTime)
{
lastpos = transform.position;
SendSync();
}
}
else
{
base.LateUpdate();
}
}
if (text != null)
{
text.transform.LookAt(Camera.main.transform);
text.transform.Rotate(Vector3.up, 180, Space.Self);
}
}
/// <summary>
/// 立即同步一次
/// </summary>
public void SyncAtOnce()
{
if (id == LoadManage.Instance.MyId)
{
lastpos = transform.position;
SendSync();
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 69210b4fce550684aa3e3d3bda7df6b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,144 +0,0 @@
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using UnityEngine;
/// <summary>
/// 订阅模块
/// </summary>
public class NetMqListener
{
private string serverSubIP;
private string serverArea;
private Thread _listenerWorker;
public bool _listenerCancelled;
/// <summary>
/// 自定义名称
/// </summary>
public string typeName;
/// <summary>
/// 处理函数委托
/// </summary>
/// <param name="st"></param>
public delegate void ReceiceMessageInMono(st_Motions st);
public delegate void ReciveMessageInThread(st_Motions st);
/// <summary>
/// mono里处理消息
/// </summary>
private readonly ReceiceMessageInMono _reciveMessageInMono;
/// <summary>
/// 线程里处理模型
/// </summary>
private readonly ReciveMessageInThread _reciveMessageInThread;
private readonly List<st_Motions> _messageReciveStmotion = new List<st_Motions>();
/// <summary>
/// 注册委托函数
/// </summary>
public NetMqListener(string subIP,string area , ReciveMessageInThread _reciveInThread, ReceiceMessageInMono reciveInMono)
{
serverSubIP = subIP;
serverArea = area;
_reciveMessageInThread += _reciveInThread;
_reciveMessageInMono += reciveInMono;
StartListen();
}
/// <summary>
/// 开始监听
/// </summary>
public void StartListen()
{
_listenerCancelled = false;
_listenerWorker = new Thread(ByteListenerWork);
_listenerWorker.IsBackground = true;
_listenerWorker.Start();
}
/// <summary>
/// 停止监听
/// </summary>
public void StopListen()
{
_listenerCancelled = true;
//_listenerWorker.Join();
}
public SubscriberSocket subSocket;
/// <summary>
/// 接收线程
/// </summary>
private void ByteListenerWork()
{
AsyncIO.ForceDotNet.Force();
using (subSocket = new SubscriberSocket())
{
subSocket.Options.ReceiveHighWatermark = 1000;
subSocket.Subscribe(serverArea);
subSocket.Connect(serverSubIP);
UnityEngine.Debug.Log("客户端开启成功" + _listenerCancelled);
while (!_listenerCancelled)
{
//try
//{
List<byte[]> frameByte = new List<byte[]>();
if (!subSocket.TryReceiveMultipartBytes(ref frameByte)) continue;
//UnityEngine.Debug.Log("线程收到一条");
st_Motions stS = new st_Motions();
string tmp = Encoding.UTF8.GetString(frameByte[0]);
stS.m_iOperaType = BitConverter.ToInt32(frameByte[1], 0);
stS.m_sOperaData = new byte[frameByte[1].Length - 4];
stS.area = tmp;
Array.Copy(frameByte[1], 4, stS.m_sOperaData, 0, frameByte[1].Length - 4);
_reciveMessageInThread(stS);
//}
//catch (Exception e)
//{
// UnityEngine.Debug.LogError(_listenerCancelled+"------------" + e.Message);
//}
}
subSocket.Close();
}
NetMQConfig.Cleanup();
UnityEngine.Debug.LogError("接收线程退出:"+typeName);
}
public void AddToMono(st_Motions st)
{
_messageReciveStmotion.Add(st);
}
/// <summary>
/// 处理一条byte[]消息
/// </summary>
public void UpdateByte()
{
if (_messageReciveStmotion.Count > 0)
{
List<st_Motions> tmps = _messageReciveStmotion.GetRange(0, _messageReciveStmotion.Count);
tmps.ForEach(data =>
{
if (data.m_sOperaData != null)
{
_reciveMessageInMono(data);
UnityEngine.Debug.Log("处理:" + data.m_iOperaType + "st_motion" + "------" + data.m_sOperaData.Length);
}
else
{
UnityEngine.Debug.LogError(data.m_iOperaType + "st_motion结构错误");
}
});
_messageReciveStmotion.RemoveRange(0, tmps.Count);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1c56a871da744e04281c1949b604e3e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,108 +0,0 @@
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
/// <summary>
/// 发布模块
/// </summary>
public class NetMqPublisher
{
private string serverPubIP;
private Thread _listenerWorker;
public bool _listenerCancelled;
/// <summary>
/// 自定义名称
/// </summary>
public string typeName;
public delegate void MessageDelegateByte(st_Motions st);
private readonly MessageDelegateByte _messageDelegateByte;
/// <summary>
/// 发送队列
/// </summary>
private readonly ConcurrentQueue<st_Motions> _messageQueueData = new ConcurrentQueue<st_Motions>();
public NetMqPublisher(string pubIP)
{
serverPubIP = pubIP;
StartListen();
}
/// <summary>
/// 开始监听
/// </summary>
public void StartListen()
{
_listenerCancelled = false;
_listenerWorker = new Thread(ByteListenerWork);
_listenerWorker.IsBackground = true;
_listenerWorker.Start();
}
/// <summary>
/// 停止监听
/// </summary>
public void StopListen()
{
_listenerCancelled = true;
//_listenerWorker.Join();
}
/// <summary>
/// 发送线程
/// </summary>
private void ByteListenerWork()
{
AsyncIO.ForceDotNet.Force();
using (var publishSocket = new PublisherSocket())
{
publishSocket.Options.ReceiveHighWatermark = 1000;
publishSocket.Connect(serverPubIP);
UnityEngine.Debug.Log("客户端开启成功" + _listenerCancelled);
while (!_listenerCancelled)
{
if (!_messageQueueData.IsEmpty)
{
st_Motions sendData = new st_Motions();
if (_messageQueueData.TryDequeue(out sendData))
{
if(_listenerCancelled)
{
UnityEngine.Debug.LogError("_listenerCancelled="+true);
}
byte[] tmpbytes = new byte[4 + sendData.m_sOperaData.Length];
Array.Copy(BitConverter.GetBytes(sendData.m_iOperaType), 0, tmpbytes, 0, 4);
Array.Copy(sendData.m_sOperaData, 0, tmpbytes, 4, sendData.m_sOperaData.Length);
if (!_listenerCancelled && !publishSocket.SendMoreFrame(sendData.area).TrySendFrame(tmpbytes)) continue;
UnityEngine.Debug.Log("发送一个消息:" + sendData.area + "," + sendData.m_iOperaType);
}
}
}
publishSocket.Close();
}
NetMQConfig.Cleanup();
UnityEngine.Debug.LogError("发送线程退出:"+typeName);
}
public void AddMessageToSendQue(string area, int type, byte[] data)
{
st_Motions sendData = new st_Motions { area = area, m_iOperaType = type, m_sOperaData = data };
_messageQueueData.Enqueue(sendData);
}
public void AddMessageToSendQue(st_Motions st)
{
if (!string.IsNullOrEmpty(st.area))
{
_messageQueueData.Enqueue(st);
}
else
{
UnityEngine.Debug.LogError("area空:type=" + st.m_iOperaType);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c85fca99ce47b964cb0439a78a984a09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,272 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
/// <summary>
/// 单值同步
/// </summary>
public class OneValueSyncObject : SyncBase
{
public static Dictionary<string, OneValueSyncObject> OneAxisSyncObjectList = new Dictionary<string, OneValueSyncObject>();
[HideInInspector]
[SerializeField]
public ValueType valueType;
/// <summary>
/// 同步回调 <id,是否为进房间>
/// </summary>
[HideInInspector]
public Action<string,bool> callbackInmono;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public bool mybool;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public byte mybyte;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public short myshort;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public int myint;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public float myfloat;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public double mydouble;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public string mystring;
[SerializeField]
[HideInInspector]
[DisplayOnly]
public Vector3 myvector3;
public bool = false;
private st_Motions st_Motions = new st_Motions { m_iOperaType = 10006 };
private int lastindex;
/// <summary>
/// 打分回调
/// </summary>
public Action action_apprisedetail;
private void OnDestroy()
{
if(OneAxisSyncObjectList.ContainsKey(Id))
{
OneAxisSyncObjectList.Remove(Id);
}
}
public void InitDynamic(string id = "", Action<string,bool> callbackInMono = null, ValueType TmpvalueType = ValueType.Null)
{
if (GameManage.Instance.is单机模式)
{
return;
}
if (hasInit)
{
Debug.Log("已经初始化,不能重复初始化");
return;
}
if (string.IsNullOrEmpty(id))
{
if (string.IsNullOrEmpty(Id))
{
Debug.LogError("Id为空");
return;
}
}
else
{
Id = id;
}
if(TmpvalueType!= ValueType.Null)
{
this.valueType = TmpvalueType;
}
else if(valueType== ValueType.Null)
{
Debug.LogError("类型为空:"+gameObject.name);
return;
}
this.callbackInmono= callbackInMono;
st_Motions.area = LoadManage.Instance.currentRoomArea;
List<byte> tmpbytes = new List<byte>();
//syncId
tmpbytes.AddRange(BitConverter.GetBytes(LoadManage.Instance.SyncId));
//id
byte[] data=Encoding.UTF8.GetBytes(Id);
tmpbytes.AddRange(BitConverter.GetBytes(data.Length));
tmpbytes.AddRange(data);
//类型
tmpbytes.Add((byte)valueType);
//回调
tmpbytes.Add(callbackInmono == null?(byte)0:(byte)1);
switch (valueType)
{
case ValueType.Null:
Debug.LogError("类型不能为空");
return;
case ValueType.Bool:
tmpbytes.Add(new byte());
lastindex = tmpbytes.Count - 1;
break;
case ValueType.Byte:
tmpbytes.Add(new byte());
lastindex = tmpbytes.Count - 1;
break;
case ValueType.Short:
tmpbytes.AddRange(new byte[2]);
lastindex = tmpbytes.Count - 2;
break;
case ValueType.Int:
tmpbytes.AddRange(new byte[4]);
lastindex = tmpbytes.Count - 4;
break;
case ValueType.Float:
tmpbytes.AddRange(new byte[4]);
lastindex = tmpbytes.Count - 4;
break;
case ValueType.Double:
tmpbytes.AddRange(new byte[8]);
lastindex = tmpbytes.Count - 8;
break;
case ValueType.String:
tmpbytes.AddRange(new byte[4]);
lastindex = tmpbytes.Count - 4;
break;
case ValueType.Vector3:
tmpbytes.AddRange(new byte[12]);
lastindex = tmpbytes.Count - 12;
break;
}
st_Motions.m_sOperaData = tmpbytes.ToArray();
OneAxisSyncObjectList.Add(Id, this);
hasInit = true;
}
/// <summary>
/// 发送同步
/// </summary>
public void SendSync()
{
if (!GameManage.Instance.is单机模式)
{
switch (valueType)
{
case ValueType.Null:
Debug.LogError("类型不能为空");
return;
case ValueType.Bool:
st_Motions.m_sOperaData[lastindex] = mybool ? (byte)1 : (byte)0;
break;
case ValueType.Byte:
st_Motions.m_sOperaData[lastindex] = mybyte;
break;
case ValueType.Short:
Array.Copy(BitConverter.GetBytes(myshort), 0, st_Motions.m_sOperaData, lastindex, 2);
break;
case ValueType.Int:
Array.Copy(BitConverter.GetBytes(myint), 0, st_Motions.m_sOperaData, lastindex, 4);
break;
case ValueType.Float:
Array.Copy(BitConverter.GetBytes(myfloat), 0, st_Motions.m_sOperaData, lastindex, 4);
break;
case ValueType.Double:
Array.Copy(BitConverter.GetBytes(mydouble), 0, st_Motions.m_sOperaData, lastindex, 8);
break;
case ValueType.String:
byte[] tmpstring = Encoding.UTF8.GetBytes(mystring);
Array.Copy(BitConverter.GetBytes(tmpstring.Length), 0, st_Motions.m_sOperaData, lastindex, 4);
byte[] data = new byte[lastindex + 4 + tmpstring.Length];
Array.Copy(st_Motions.m_sOperaData, 0, data, 0, lastindex + 4);
Array.Copy(tmpstring, 0, data, lastindex + 4, tmpstring.Length);
st_Motions.m_sOperaData = data;
break;
case ValueType.Vector3:
Array.Copy(BitConverter.GetBytes(myvector3.x), 0, st_Motions.m_sOperaData, lastindex, 4);
Array.Copy(BitConverter.GetBytes(myvector3.y), 0, st_Motions.m_sOperaData, lastindex + 4, 4);
Array.Copy(BitConverter.GetBytes(myvector3.z), 0, st_Motions.m_sOperaData, lastindex + 8, 4);
break;
}
LoadManage.Instance.RSclient.Send(st_Motions);
}
}
/// <summary>
/// 设置值
/// </summary>
public void SetValue(int start,byte[] data)
{
switch ((ValueType)(data[start]))
{
case ValueType.Null:
Debug.LogError("类型不能为空");
return ;
case ValueType.Bool:
mybool = (data[start + 2] == 1 ? true : false);
break;
case ValueType.Byte:
mybyte = data[start+2];
break;
case ValueType.Short:
myshort = BitConverter.ToInt16(data, start+2);
break;
case ValueType.Int:
myint = BitConverter.ToInt32(data, start + 2);
break;
case ValueType.Float:
myfloat = BitConverter.ToSingle(data, start + 2);
break;
case ValueType.Double:
mydouble = BitConverter.ToDouble(data, start + 2);
break;
case ValueType.String:
int length = BitConverter.ToInt32(data, start + 2);
mystring = Encoding.UTF8.GetString(data, start + 6, length);
break;
case ValueType.Vector3:
myvector3.x = BitConverter.ToSingle(data, start + 2);
myvector3.y= BitConverter.ToSingle(data, start + 6);
myvector3.z = BitConverter.ToSingle(data, start + 10);
break;
}
}
}
public enum ValueType
{
Null,
Bool,
Byte,
Short,
Int,
Float,
Double,
String,
Vector3
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 0ae554fc30ab6d042ae5837141efe935
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,115 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using System;
public class PlayerMove : MonoBehaviour
{
public float speed = 3f;
Animator anim;
[HideInInspector]
public Vector3 move;
MyPlayer myPlayer;
/// <summary>
/// 跟随模式
/// </summary>
public bool FollowMode;
public bool Freeze;
void Start()
{
anim = GetComponent<Animator>();
// myPlayer = GameManage.Instance.me.GetComponent<MyPlayer>();
if (!GameManage.Instance.is单机模式)
{
stdong.area = LoadManage.Instance.currentRoomArea;
stBudong.area = LoadManage.Instance.currentRoomArea;
byte[] idbyte = Encoding.UTF8.GetBytes(LoadManage.Instance.MyId);
//动
byte[] data1 = new byte[4 + idbyte.Length + 1];
Array.Copy(BitConverter.GetBytes(idbyte.Length), 0, data1, 0, 4);
Array.Copy(idbyte, 0, data1, 4, idbyte.Length);
data1[4 + idbyte.Length] = 1;
stdong.m_sOperaData = data1;
//停
byte[] data2 = new byte[4 + idbyte.Length + 1];
Array.Copy(BitConverter.GetBytes(idbyte.Length), 0, data2, 0, 4);
Array.Copy(idbyte, 0, data2, 4, idbyte.Length);
data2[4 + idbyte.Length] = 0;
stBudong.m_sOperaData = data2;
}
}
st_Motions stdong = new st_Motions { m_iOperaType = 8};
st_Motions stBudong = new st_Motions { m_iOperaType = 8 };
bool issend = false;
bool issendStop = false;
void Update()
{
if (!GameManage.Instance.is单机模式)
{
//if (Input.GetKeyDown(KeyCode.Y))
//{
// ChatPanel.instance.gameObject.SetActive(!ChatPanel.instance.gameObject.activeInHierarchy);
//}
//if (ChatPanel.instance.gameObject.activeInHierarchy)
//{
// return;
//}
}
if (Freeze) return;
if (FollowMode) return;
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
move = new Vector3(x, 0, z);
move = new Vector3(x, 0,z);
if (move != Vector3.zero)
{
issendStop = false;
//播放动画
if (!issend)
{
if (LoadManage.Instance != null && LoadManage.Instance.RSclient != null)
LoadManage.Instance.RSclient.Send(stdong);
issend = true;
}
// 转向
move = Quaternion.Euler(0, Camera.main.transform.eulerAngles.y, 0) * move;
transform.position += move * speed* Time.deltaTime;
RotatePlayer();
}
else
{
issend = false;
//停止动画
if (!issendStop)
{
if (LoadManage.Instance!=null && LoadManage.Instance.RSclient != null)
LoadManage.Instance.RSclient.Send(stBudong);
issendStop = true;
}
}
UpdateAnim();
}
void UpdateAnim()
{
anim.SetFloat("InputMagnitude", move.magnitude);
}
private void RotatePlayer()
{
//向量v围绕y轴旋转cameraAngle.y度
Vector3 vec = Quaternion.Euler(0, 0, 0) * move;
Quaternion qua = Quaternion.LookRotation(vec);
transform.rotation = Quaternion.Lerp(transform.rotation, qua, Time.deltaTime * 100);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 33d3ab1f9bb81aa41929f206a3b702a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SyncBase : MonoBehaviour
{
[DisplayOnly]
public string Id = "";
public string ;
/// <summary>
/// 是否已经初始化
/// </summary>
[HideInInspector]
public bool hasInit;
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 561fc113ec1f3b345b148960a6325261
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,107 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SyncTest:MonoBehaviour
{
public bool isME;
public FunctionSync_Active active;
public FunctionSync_Animator animator;
public FunctionSync_Material material;
public FunctionSync_Scale scale;
public FunctionSync_PositionRoate PositionRoate;
public FunctionSync_Parent parent;
public FunctionSync_Parent transParent;
int dir = 1;
private void Start()
{
//InitDynamic(gameObject.name, isME);
}
bool isred;
private void Update()
{
//if (isME)
//{
// if (transform.position.y <= 3)
// {
// dir = 1;
// }
// else if (transform.position.y >= 30)
// {
// dir = -1;
// }
// transform.Translate(Vector3.up *3* dir * Time.deltaTime, Space.World);
// transform.Rotate(Vector3.up *3* Time.deltaTime);
//}
if(Input.GetKeyDown( KeyCode.Z))
{
//显隐
if (!active.gameObject.activeInHierarchy)
{
active.ShowObject();
}
else
{
active.DisShowObject();
}
}
else if(Input.GetKeyDown(KeyCode.X))
{
//材质
if (isred)
{
isred = false;
material.SetMaterial("Material/green");
}
else
{
isred = true;
material.SetMaterial("Material/red");
}
}
else if (Input.GetKey(KeyCode.C))
{
//缩放
if(scale.transform.localScale.x>10)
{
dir = -1;
}
else if(scale.transform.localScale.x <0.3f)
{
dir = 1;
}
scale.transform.localScale += Vector3.one * dir * Time.deltaTime;
}
else if (Input.GetKeyDown(KeyCode.V))
{
//动画
animator.SetAnimatorState("SyncTest");
}
else if(Input.GetKeyDown(KeyCode.B))
{
//获取移动权限
PositionRoate.GetControl();
}
else if (Input.GetKeyDown(KeyCode.N))
{
//释放移动权限
PositionRoate.ReleaseControl();
}
else if(Input.GetKeyDown(KeyCode.Space))
{
//生成物体
Vector3 pos = new Vector3(Random.Range(-50f, 50f), Random.Range(-50f, 50f), Random.Range(-50f, 50f));
Vector3 roate= new Vector3(Random.Range(-50f, 50f), Random.Range(-50f, 50f), Random.Range(-50f, 50f));
Vector3 scale= new Vector3(Random.Range(1f, 5f), Random.Range(1f, 5f), Random.Range(1f, 5f));
FunctionSync_CreateObejct.Instance.CreateObejct("Prefabs/Test/Cube", pos, roate, scale);
}
else if(Input.GetKeyDown(KeyCode.P))
{
transParent.SetParent(parent, new Vector3(10, 10, 10), new Vector3(30, 50, 90));
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dcfbc35f49166e54ebb91f595e61f7e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: a805f9833a71ec142935604492207a0d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,189 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DataModel.Model;
using UnityEngine.UI;
using System.Linq;
using LitJson;
using TMPro;
public class CheckPanel : MonoBehaviour
{
practice practice1;
List<practicesubject> practicesubjects;
[HideInInspector]
public GameObject subejctItemPrefb;
[HideInInspector]
public GameObject seatItemPrefb;
public VerticalLayoutGroup subjectGroup;
public VerticalLayoutGroup seatGroup;
public Button JoinBtn;
public Button CloseBtn;
public Text practiceNameText;
public Text subejctText;
public Text Text;
public Text Text;
public Sprite sprite;
public Sprite sprite;
public static CheckPanel instance;
public void Init(practice practice)
{
instance = this;
practice1 = practice;
practiceNameText.text = practice1.Name;
if (subejctItemPrefb == null)
{
subejctItemPrefb = Resources.Load<GameObject>("UI/Item/CheckPanelSubjectItem");
}
if (seatItemPrefb == null)
{
seatItemPrefb = Resources.Load<GameObject>("UI/Item/CheckPanelSeatItem");
}
JoinBtn.onClick.AddListener(Join);
CloseBtn.onClick.AddListener(() =>
{
Destroy(gameObject,0.2f);
});
//获取所有practiceSubejct
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=querypracticesubject&PracticeId=" + practice1.Id, str =>
{
var json = JsonMapper.ToObject<CallResultList<practicesubject>>(str);
if (json.state)
{
//生成科目
practicesubjects = json.data.OrderBy(a => a.OrderIndex).ToList();
int index = 0;
foreach (var item in practicesubjects)
{
GameObject obj = Instantiate<GameObject>(subejctItemPrefb, subjectGroup.transform);
obj.GetComponent<CheckPanelSubjectItem>().Init(item, index);
index++;
}
Invoke("SetInteractable", 2);
}
else
{
Debug.LogError(json.message);
}
})); ;
}
/// <summary>
/// 允许点击加入房间
/// </summary>
public void SetInteractable()
{
JoinBtn.interactable = true;
}
private void Join()
{
//检查本人是否选择了岗位
var list = subjectGroup.transform.GetComponentsInChildren<CheckPanelSubjectItem>(true).ToList().FindAll(a=>a.MyChose!=null);
if (list!=null && list.Count>0)
{
List<BindData> bindDatas = new List<BindData>();
list.ForEach(b =>
{
if (b.MyChose.userAccount.text == LoadManage.Instance.me.user.user_name)
{
bindDatas.Add(new BindData { practiceSeatId = b.MyChose.practiceseat1.Id, userAccount = b.MyChose.userAccount.text, userName = b.MyChose.userName.text });
}
});
//更新选择的岗位
StartCoroutine(MyNetMQClient.CallPost("http://" + MyNetMQClient.CallIP + "/Handler/PracticeSeat.ashx?action=UpdatePracticeSeatUser", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("BindData", JsonMapper.ToJson(bindDatas)) }, str =>
{
var json = JsonMapper.ToObject<CallResultObject>(str);
if (json.state)
{
if ((int)json.data == 0)
{
//更新成功,加入房间
LoadManage.Instance.currentPractice = practice1;
LoadManage.Instance.psubjects = practicesubjects;
Debug.Log("选择岗位成功");
//获取syncid
StartCoroutine(MyNetMQClient.CallGet("http://"+MyNetMQClient.CallIP+"/Handler/Practice.ashx?action=getAccountIndex&PracticeId="+practice1.Id+"&Account="+LoadManage.Instance.me.user.user_name,str2=>
{
var json2 = JsonMapper.ToObject<CallResultObject>(str2);
if (json2.state)
{
int syncid=(int)json2.data;
if(syncid==0)
{
Debug.LogError("未找到syncid");
MessagePanel.ShowMessage("未找到syncid", RoomListPanel.instance.canvas.transform);
}
else
{
//创建mq连接
Debug.Log("syncid为" + syncid);
try
{
LoadManage.Instance.CreateRoomServerClient(practice1.SubIP, practice1.PubIP, practice1.RoomArea, syncid);
}
catch (System.Exception e)
{
GameObject.Find("Text (TMP)").GetComponent<TextMeshProUGUI>().text = e.Message;
}
if (LoadManage.Instance.systemMode == SystemMode.PC)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("GameSencePC");
}
else if(LoadManage.Instance.systemMode == SystemMode.MR)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("GameSenceMR");
}
}
}
else
{
string msg = json2.message;
Debug.LogError(msg);
MessagePanel.ShowMessage(msg, RoomListPanel.instance.canvas.transform);
}
}));
}
else
{
Debug.Log("有岗位未绑定成功,请重新选择");
MessagePanel.ShowMessage("有岗位未绑定成功,请重新选择", RoomListPanel.instance.canvas.transform);
Destroy(gameObject);
}
}
else
{
string msg = json.message;
Debug.LogError(msg);
MessagePanel.ShowMessage(msg, RoomListPanel.instance.canvas.transform);
}
}));
}
else
{
Debug.Log("请选择岗位");
MessagePanel.ShowMessage("请选择岗位", RoomListPanel.instance.canvas.transform);
}
}
}
public struct BindData
{
public string practiceSeatId;
public string userName;
public string userAccount;
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d8366a49a74a4984a8e5e7a327301e6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,97 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class ChoseUserPanel : MonoBehaviour
{
SeatBindSubjectItem createRoomSubjectItem1;
CreateRoomSeatItem createRoomSeatItem1;
public VerticalLayoutGroup group;
public Button tijiaoBtn;
public Button quxiaoBtn;
public Button CheckBtn;
public Button CloseBtn;
public InputField NameInput;
public InputField accountInput;
public ToggleGroup togglegroup;
[HideInInspector]
public GameObject itemPrefb;
public void Init(SeatBindSubjectItem subjectItem, CreateRoomSeatItem createRoomSeatItem)
{
createRoomSubjectItem1 = subjectItem;
createRoomSeatItem1 = createRoomSeatItem;
if (itemPrefb==null)
{
itemPrefb = Resources.Load<GameObject>("UI/Item/ChoseUserItem");
}
quxiaoBtn.onClick.AddListener(() =>
{
Destroy(gameObject);
});
CloseBtn.onClick.AddListener(() =>
{
Destroy(gameObject);
});
//生成item
//LoadManage.Instance.allUsers.ForEach(a =>
//{
// GameObject obj = Instantiate<GameObject>(itemPrefb, group.transform);
// if (subjectItem.seatItems.Any(b=>b.useraccount .text== a.login_name))
// {
// obj.GetComponent<ChoseUserItem>().Init(a, false, createRoomSeatItem1, this) ;
// }
// else
// {
// obj.GetComponent<ChoseUserItem>().Init(a, true, createRoomSeatItem1,this);
// }
//});
//提交
tijiaoBtn.onClick.AddListener(()=>
{
if(togglegroup.AnyTogglesOn())
{
Toggle toggle=togglegroup.ActiveToggles().ToList().Find(a => a.isOn);
toggle.transform.GetComponentInParent<ChoseUserItem>().Chose();
//销毁页面
Destroy(gameObject);
}
});
//查询
CheckBtn.onClick.AddListener(() =>
{
if(NameInput.text=="" && accountInput.text=="")
{
//显示全部
group.transform.GetComponentsInChildren<ChoseUserItem>(true).ToList().ForEach(a =>
{
a.gameObject.SetActive(true);
});
}
else
{
//筛选
group.transform.GetComponentsInChildren<ChoseUserItem>(true).ToList().ForEach(a =>
{
if(a.userName.text.Contains(NameInput.text) && a.userAccount.text.Contains(accountInput.text))
{
a.gameObject.SetActive(true);
}
else
{
a.gameObject.SetActive(false);
}
});
}
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1e5b7f8fbbf09184983a330f9cf2f89f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,316 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
using System.Linq;
using LitJson;
using System;
public class CreateRoomPanel : MonoBehaviour
{
/// <summary>
/// 创建名称界面
/// </summary>
public Transform CreateNameP;
/// <summary>
/// 选择想定界面
/// </summary>
public Transform ChoseThinkingP;
/// <summary>
/// 绑定岗位界面
/// </summary>
public Transform BindSeatP;
public InputField inputName;
public Toggle xunlianTog;
public Toggle kaoheTog;
public Button quxiaoBtn1;
public Button nextBtn1;
public VerticalLayoutGroup group2;
public Button frontBtn2;
public Button nextBtn2;
public Button frontBtn3;
public Button nextBtn3;
public VerticalLayoutGroup group3seat;
public Text thinkingName;
public Text thinkingMode;
public VerticalLayoutGroup group2_2;
public Button closeBtn2;
public Button closeBtn3;
/// <summary>
/// 房间名称
/// </summary>
string PracticeName;
/// <summary>
/// 考核训练
/// </summary>
string MissionModel;
/// <summary>
/// 选中的想定
/// </summary>
[HideInInspector]
public thinkingfile choseThinkingfile;
/// <summary>
/// 岗位绑定的人员
/// </summary>
List<SeatBindUserData> seatBindUser=new List<SeatBindUserData>();
[HideInInspector]
public GameObject thinkingItemPrefb;
[HideInInspector]
public GameObject subjectItemPrefb;
[HideInInspector]
public GameObject subjectItemPrefb;
[HideInInspector]
public GameObject seatItemPrefb;
[HideInInspector]
public GameObject seat2Prefb;
[HideInInspector]
public GameObject choseUserPrefb;
public static CreateRoomPanel instance;
private void Awake()
{
instance = this;
if (thinkingItemPrefb==null)
{
thinkingItemPrefb = Resources.Load<GameObject>("UI/Item/选择想定/CreateRoomThinkingItem");
}
if(subjectItemPrefb==null)
{
subjectItemPrefb= Resources.Load<GameObject>("UI/Item/选择想定/CreateRoomSubjectItem");
}
if(subjectItemPrefb == null)
{
subjectItemPrefb = Resources.Load<GameObject>("UI/Item/席位分配/subject");
}
if (seatItemPrefb == null)
{
seatItemPrefb = Resources.Load<GameObject>("UI/Item/席位分配/seat");
}
if(seat2Prefb==null)
{
seat2Prefb= Resources.Load<GameObject>("UI/Item/席位分配/seatitem");
}
if (choseUserPrefb==null)
{
choseUserPrefb = Resources.Load<GameObject>("UI/ChoseUserPanel");
}
quxiaoBtn1.onClick.AddListener(()=>
{
Destroy(gameObject);
});
closeBtn2.onClick.AddListener(() =>
{
Destroy(gameObject);
});
closeBtn3.onClick.AddListener(() =>
{
Destroy(gameObject);
});
//名字界面下一步按钮
nextBtn1.onClick.AddListener(() =>
{
if(!string.IsNullOrEmpty(inputName.text))
{
PracticeName = inputName.text;
MissionModel = xunlianTog.isOn ? "训练" : "考核";
CreateNameP.gameObject.SetActive(false);
ChoseThinkingP.gameObject.SetActive(true);
BindSeatP.gameObject.SetActive(false);
UpdataThinking();
}
});
//选择想定界面下一步按钮
nextBtn2.onClick.AddListener(() =>
{
if(choseThinkingfile!=null)
{
CreateNameP.gameObject.SetActive(false);
ChoseThinkingP.gameObject.SetActive(false);
BindSeatP.gameObject.SetActive(true);
//初始化席位分配界面
InitSeatPanel();
}
});
//选择想定界面上一步按钮
frontBtn2.onClick.AddListener(() =>
{
choseThinkingfile = null;
CreateNameP.gameObject.SetActive(true);
ChoseThinkingP.gameObject.SetActive(false);
BindSeatP.gameObject.SetActive(false);
});
//绑定人员界面确定按钮
nextBtn3.onClick.AddListener(() =>
{
List<SeatBindUserData> tmps = new List<SeatBindUserData>();
group3seat.transform.GetComponentsInChildren<CreateRoomSeatItem>(true).ToList().ForEach(a=>
{
if(a.useraccount.text!="999")
{
tmps.Add(new SeatBindUserData { seatId = a.seat1.seatId, subjectId = a.seat1.subjectId, username = a.username.text, useraccount = a.useraccount.text });
}
});
seatBindUser=tmps;
Create();
});
//绑定人员界面上一步按钮
frontBtn3.onClick.AddListener(() =>
{
CreateNameP.gameObject.SetActive(false);
ChoseThinkingP.gameObject.SetActive(true);
BindSeatP.gameObject.SetActive(false);
group3seat.transform.GetComponentsInChildren<SeatBindSubjectItem>().ToList().ForEach(a =>
{
DestroyImmediate(a.gameObject);
});
group3seat.transform.GetComponentsInChildren<SeatBindSeatItem>().ToList().ForEach(a =>
{
DestroyImmediate(a.gameObject);
});
});
}
/// <summary>
/// 更新想定文件
/// </summary>
private void UpdataThinking()
{
group2.transform.GetComponentsInChildren<CreateRoomThinkingItem>(true).ToList().ForEach(a=>
{
DestroyImmediate(a.gameObject);
});
StartCoroutine(MyNetMQClient.CallGet("http://"+MyNetMQClient.CallIP+"/Handler/Thinkingfile.ashx?action=all", result =>
{
var json = JsonMapper.ToObject<CallResultList<thinkingfile>>(result);
var jsondata = JsonMapper.ToObject(result)["data"];
if (json.state)
{
jsondata.ValueAsArray().ToList().ForEach(a =>
{
json.data.Find(b => b.Id == a["Id"].ToString()).CreateTime =DateTime.Parse(a["CreateTime"].ToString());
});
var thinkingfiles = json.data.OrderByDescending(a=>a.CreateTime).ToList();
int index = 0;
CreateRoomThinkingItem first=null;
thinkingfiles.ForEach(a =>
{
GameObject obj = Instantiate<GameObject>(thinkingItemPrefb, group2.transform);
obj.GetComponent<CreateRoomThinkingItem>().Init(a);
if(index==0)
{
//第一个
first = obj.GetComponent<CreateRoomThinkingItem>();
}
index++;
});
if (first != null)
{
first.Chose();
}
}
else
{
string msg = json.message;
Debug.LogError(msg);
}
}));
}
/// <summary>
/// 创建房间数据
/// </summary>
public void Create()
{
if(choseThinkingfile!=null && !string.IsNullOrEmpty(MissionModel))
{
KeyValuePair<string, string>[] datas = new KeyValuePair<string, string>[3];
datas[0] = new KeyValuePair<string, string>("thinkingfile_id",choseThinkingfile.Id);
datas[1] = new KeyValuePair<string, string>("SeatBindUserData",JsonMapper.ToJson(seatBindUser));
datas[2] = new KeyValuePair<string, string>("data", JsonMapper.ToJson(new practice { Name= PracticeName, MissionModel= MissionModel }));
StartCoroutine(MyNetMQClient.CallPost("http://"+MyNetMQClient.CallIP+"/Handler/Practice.ashx?action=add",datas, result =>
{
var json = JsonMapper.ToObject<CallResultObject>(result);
if (json.state)
{
string str =json.data.ToString();
//创建成功
Debug.Log("创建房间成功:" + PracticeName);
MessagePanel.ShowMessage("创建房间成功", RoomListPanel.instance.canvas.transform);
//房间列表刷新
RoomListPanel.instance.Refresh();
Destroy(gameObject);
}
else
{
string msg = json.message;
Debug.LogError(msg);
MessagePanel.ShowMessage(msg, RoomListPanel.instance.canvas.transform);
}
}));
}
}
/// <summary>
/// 初始化席位分配页面
/// </summary>
private void InitSeatPanel()
{
ThinkingData data =JsonMapper.ToObject<ThinkingData>(choseThinkingfile.VirtualPath);
data.subjectsInfo.ForEach(a =>
{
//创建科目
GameObject obj = Instantiate<GameObject>(subjectItemPrefb, group3seat.transform);
SeatBindSubjectItem subjectScript = obj.GetComponent<SeatBindSubjectItem>();
subjectScript.Init(a);
//创建席位容器框
GameObject obj2 = Instantiate<GameObject>(seatItemPrefb, group3seat.transform);
a.seatInfos.ForEach(b =>
{
//创建席位
GameObject obj3 = Instantiate<GameObject>(seat2Prefb, obj2.transform);
CreateRoomSeatItem createRoomSeatItem = obj3.GetComponent<CreateRoomSeatItem>();
createRoomSeatItem.Init(b, subjectScript);
});
});
}
}
public class SeatBindUserData
{
public string subjectId;
public string seatId;
public string username;
public string useraccount;
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 924fefc00376dce4baadbfc4cf0238a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,95 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Net;
public class IPsettingPanel : MonoBehaviour
{
public static IPsettingPanel instance;
public InputField syncidInput;
public InputField interfanceInput;
public Button quedingBtn;
public Button quxiaoBtn;
private void Awake()
{
instance = this;
quedingBtn.onClick.AddListener(()=>
{
if (Check())
{
PlayerPrefs.SetString("协同交互IP", syncidInput.text);
PlayerPrefs.SetString("接口服务IP", interfanceInput.text);
MyNetMQClient.CallIP = interfanceInput.text;
gameObject.SetActive(false);
}
else
{
Debug.Log("请检查IP格式");
MessagePanel.ShowMessage("请检查IP格式", LoginPanel.instance.canvas.transform);
}
});
quxiaoBtn.onClick.AddListener(()=>
{
gameObject.SetActive(false);
});
gameObject.SetActive(false);
}
public void Show()
{
syncidInput.text= PlayerPrefs.GetString("协同交互IP", "");
interfanceInput.text= PlayerPrefs.GetString("接口服务IP", "");
MyNetMQClient.CallIP = interfanceInput.text;
gameObject.SetActive(true);
}
private bool Check()
{
if(string.IsNullOrEmpty(syncidInput.text) || string.IsNullOrEmpty(interfanceInput.text))
{
return false;
}
if(!syncidInput.text.Contains(":") || !interfanceInput.text.Contains(":"))
{
return false;
}
string[] tmp1=syncidInput.text.Split(':');
string[] tmp2 = interfanceInput.text.Split(':');
if(tmp1.Length!=2 || tmp2.Length!=2)
{
return false;
}
IPAddress iPAddress1;
IPAddress iPAddress2;
if (!IPAddress.TryParse(tmp1[0], out iPAddress1) || !IPAddress.TryParse(tmp2[0], out iPAddress2))
{
return false;
}
int port1;
int port2;
if(!int.TryParse(tmp1[1],out port1)|| !int.TryParse(tmp2[1],out port2))
{
return false;
}
if(port2<=0 || port2<=0)
{
return false;
}
//成功
return true;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 61549f3496950c44ca7ac9d695a7e7ce
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 4272a394941acba4998e63fa7d934e69
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,73 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
public class CheckPanelSeatItem : MonoBehaviour
{
public practiceseat practiceseat1;
CheckPanelSubjectItem checkPanelSubjectItem;
public Text SeatName,userName,userAccount;
public Toggle toggle;
public void Init(practiceseat practiceseat, CheckPanelSubjectItem subjectitem)
{
practiceseat1 = practiceseat;
checkPanelSubjectItem = subjectitem;
SeatName.text = practiceseat1.SeatName;
userName.text = practiceseat1.UserName;
userAccount.text = practiceseat1.UserAccount;
if (!string.IsNullOrEmpty(practiceseat1.UserAccount) && practiceseat1.UserAccount != "999")
{
//已被选择
toggle.interactable = false;
toggle.isOn = true;
if(practiceseat1.UserAccount==LoadManage.Instance.me.user.user_name)
{
//是自己
checkPanelSubjectItem.MyChose = this;
}
}
else
{
//未被选择
toggle.interactable = true;
toggle.isOn = false;
toggle.group = checkPanelSubjectItem.toggleGroup;
}
toggle.onValueChanged.AddListener(a =>
{
if(a)
{
//选中
checkPanelSubjectItem.items.ForEach(b =>
{
if (b.toggle.interactable)
{
b.userName.text = "虚兵";
b.userAccount.text = "999";
if (b != this)
{
b.toggle.isOn = false;
}
}
});
userName.text = LoadManage.Instance.me.user.nickName;
userAccount.text = LoadManage.Instance.me.user.user_name;
checkPanelSubjectItem.MyChose = this;
}
else
{
if(checkPanelSubjectItem.MyChose==this)
{
checkPanelSubjectItem.MyChose = null;
userName.text = "虚兵";
userAccount.text = "999";
}
}
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 05da0c26209fd8e4594bec16a6467e53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,169 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
using System.Linq;
using LitJson;
public class CheckPanelSubjectItem : MonoBehaviour
{
practicesubject practicesubject1;
List<practiceseat> practiceseats1;
/// <summary>
/// 科目管理的seatitem
/// </summary>
[HideInInspector]
public List<CheckPanelSeatItem> items;
/// <summary>
/// 本人选择的岗位
/// </summary>
[HideInInspector]
public CheckPanelSeatItem MyChose;
public Button self;
public Text Name;
/// <summary>
/// 未启动
/// </summary>
public Image state0;
/// <summary>
/// 进行中
/// </summary>
public Image state1;
/// <summary>
/// 已结束
/// </summary>
public Image state2;
public ToggleGroup toggleGroup;
public void Init(practicesubject practicesubject,int index)
{
practicesubject1 = practicesubject;
Name .text= practicesubject1.Name;
//if (practicesubject1.State==0)
//{
// state0.gameObject.SetActive(true);
// state1.gameObject.SetActive(false);
// state2.gameObject.SetActive(false);
//}
//else if (practicesubject1.State == 1)
//{
// state0.gameObject.SetActive(false);
// state1.gameObject.SetActive(true);
// state2.gameObject.SetActive(false);
//}
//else if (practicesubject1.State == 2)
//{
// state0.gameObject.SetActive(false);
// state1.gameObject.SetActive(false);
// state2.gameObject.SetActive(true);
//}
//获取所有practiceseat
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=querypracticeseat&PracticeSubjectId=" + practicesubject1.Id, str =>
{
var json = JsonMapper.ToObject<CallResultList<practiceseat>>(str);
if (json.state)
{
//生成岗位
practiceseats1 = json.data.OrderBy(a=>a.SeatNo).ToList();
items = new List<CheckPanelSeatItem>();
foreach (var item in practiceseats1)
{
GameObject obj = Instantiate<GameObject>(CheckPanel.instance.seatItemPrefb, CheckPanel.instance.seatGroup.transform);
CheckPanelSeatItem script = obj.GetComponent<CheckPanelSeatItem>();
items.Add(script);
script.Init(item, this);
if (index == 0)
{
obj.SetActive(true);
}
else
{
obj.SetActive(false);
}
}
//自己不能重复选择
if (practiceseats1.Any(a => !string.IsNullOrEmpty(a.UserAccount) && a.UserAccount == LoadManage.Instance.me.user.user_name))
{
items.ForEach(b =>
{
b.toggle.interactable = false;
});
}
//点击科目按钮
self.onClick.AddListener(() =>
{
ShowSeat();
ShowSuebjcet();
ChangeButtonState();
});
//默认显示第一个
if(index==0)
{
ShowSuebjcet();
transform.GetComponent<Image>().sprite = CheckPanel.instance.sprite;
}
else
{
transform.GetComponent<Image>().sprite = CheckPanel.instance.sprite;
}
}
else
{
Debug.LogError(json.message);
}
}));
}
/// <summary>
/// 切换seat
/// </summary>
public void ShowSeat()
{
CheckPanel.instance.seatGroup.transform.GetComponentsInChildren<CheckPanelSeatItem>(true).ToList().ForEach(a =>
{
if(a.practiceseat1.Field_Char1== practicesubject1.Id)
{
a.gameObject.SetActive(true);
}
else
{
a.gameObject.SetActive(false);
}
});
}
/// <summary>
/// 切换subject
/// </summary>
public void ShowSuebjcet()
{
CheckPanel.instance.subejctText.text = practicesubject1.Name;
CheckPanel.instance.Text.text = practicesubject1.OperateModel;
CheckPanel.instance.Text.text = practicesubject1.OperateProcess;
}
private void ChangeButtonState()
{
CheckPanel.instance.subjectGroup.transform.GetComponentsInChildren<CheckPanelSubjectItem>(true).ToList().ForEach(a =>
{
if (a == this)
{
a.transform.GetComponent<Image>().sprite = CheckPanel.instance.sprite;
}
else
{
a.transform.GetComponent<Image>().sprite = CheckPanel.instance.sprite;
}
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 930864f2f91d5874f95527641bc1ab00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,33 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
public class ChoseUserItem : MonoBehaviour
{
admin_user user;
CreateRoomSeatItem createRoomSeatItem1;
ChoseUserPanel choseUserPanel1;
public Text userName;
public Text userAccount;
public Toggle choseToggle;
public void Init(admin_user admin_User,bool isinterable, CreateRoomSeatItem createRoomSeatItem, ChoseUserPanel choseUserPanel)
{
user = admin_User;
createRoomSeatItem1 = createRoomSeatItem;
choseUserPanel1 = choseUserPanel;
userName.text = user.real_name;
userAccount.text = user.login_name;
choseToggle.group = choseUserPanel1.togglegroup;
choseToggle.interactable = isinterable;
}
public void Chose()
{
//选择人员
createRoomSeatItem1.username.text = user.real_name;
createRoomSeatItem1.useraccount.text = user.login_name;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 95a999496042ec444b95af00b9213383
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,80 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
using System.Linq;
public class CreateRoomSubjectItem : MonoBehaviour
{
SubejctsInfo subejctsInfo1;
public List<CreateRoomSeatItem> seatItems;
public Text Name;
public Text subejctMode;
public Text seatinfo;
public Text stepinfo;
public void Init(SubejctsInfo subejctsInfo,int index)
{
subejctsInfo1 = subejctsInfo;
Name.text = subejctsInfo1.subjectName;
subejctMode.text = subejctsInfo1.mode;
seatinfo.text = subejctsInfo.seatInfo;
stepinfo.text = subejctsInfo1.stepInfo;
//强制刷新
////获取所有seat
//StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.instance.CallIP + "/Handler/Subject.ashx?action=querysubjectseat&SubjectId="+ subjectId, result =>
//{
// var json = JObject.Parse(result);
// if (json["state"].ToObject<bool>())
// {
// string str = json["data"].ToString();
// var seats = JsonConvert.DeserializeObject<List<seat>>(str);
// seats.ForEach(a =>
// {
// GameObject obj = Instantiate<GameObject>(CreateRoomPanel.instance.seatItemPrefb,CreateRoomPanel.instance.group3seat.transform);
// CreateRoomSeatItem script = obj.GetComponent<CreateRoomSeatItem>();
// seatItems.Add(script);
// script.Init(a,this);
// if (index == 0)
// {
// obj.gameObject.SetActive(true);
// }
// else
// {
// obj.gameObject.SetActive(false);
// }
// });
// self.onClick.AddListener(()=> { ShowSeats(); });
// self.interactable = true;
// }
// else
// {
// string msg = json["message"].ToString();
// Debug.LogError(msg);
// }
//}));
}
private void ShowSeats()
{
CreateRoomPanel.instance.group3seat.transform.GetComponentsInChildren<CreateRoomSeatItem>(true).ToList().ForEach(a=>
{
if(seatItems.Contains(a))
{
a.gameObject.SetActive(true);
}
else
{
a.gameObject.SetActive(false);
}
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9c3db76530dc04244a0d5c1bf7d464b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,71 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
using System.Linq;
using LitJson;
public class CreateRoomThinkingItem : MonoBehaviour
{
thinkingfile thinkingfile1;
ThinkingData data;
List<CreateRoomSubjectItem> subjectitems1 = new List<CreateRoomSubjectItem>();
public Button self;
public Text Name;
public void Init(thinkingfile thinkingfile)
{
thinkingfile1 = thinkingfile;
Name.text = thinkingfile.Name;
//创建科目item
CreateSubjectitem();
self.onClick.AddListener(()=>
{
Chose();
});
}
/// <summary>
/// 创新建科目item
/// </summary>
private void CreateSubjectitem()
{
ThinkingData data =JsonMapper.ToObject<ThinkingData>(thinkingfile1.VirtualPath);
int index = 0;
data.subjectsInfo.ForEach(a =>
{
GameObject obj = Instantiate<GameObject>(CreateRoomPanel.instance.subjectItemPrefb, CreateRoomPanel.instance.group2_2.transform);
CreateRoomSubjectItem script= obj.GetComponent<CreateRoomSubjectItem>();
script.Init(a, index);
index++;
subjectitems1.Add(script);
});
}
/// <summary>
/// 选择
/// </summary>
public void Chose()
{
//选中
CreateRoomPanel.instance.choseThinkingfile = thinkingfile1;
//显示想定信息
CreateRoomPanel.instance.thinkingName.text = thinkingfile1.Name;
CreateRoomPanel.instance.thinkingMode.text = thinkingfile1.PracticeMode;
CreateRoomPanel.instance.group2_2.transform.GetComponentsInChildren<CreateRoomSubjectItem>(true).ToList().ForEach(a =>
{
if (subjectitems1.Contains(a))
{
a.gameObject.SetActive(true);
}
else
{
a.gameObject.SetActive(false);
}
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 237f2c66a911c5945bbe9b1fc549eef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,89 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
using System.Net.Sockets;
using System.Net;
using System;
using System.Text;
public class RoomItem : MonoBehaviour
{
public Text roomName;
public Button lookBtn;
public Button qidongBtn;
public Button closeBtn;
practice practice1;
public void Init(practice practice)
{
practice1 = practice;
roomName.text = practice.Name;
if(practice.State==0)
{
//未启动
lookBtn.gameObject.SetActive(false);
//qidongBtn.gameObject.SetActive(true);
//closeBtn.gameObject.SetActive(false);
}
else if(practice.State==1)
{
//进行中
lookBtn.gameObject.SetActive(true);
//qidongBtn.gameObject.SetActive(false);
//closeBtn.gameObject.SetActive(true);
}
//不显示按钮
qidongBtn.gameObject.SetActive(false);
closeBtn.gameObject.SetActive(false);
lookBtn.onClick.AddListener(()=>
{
//查看界面
GameObject obj = Instantiate<GameObject>(RoomListPanel.instance.CheckPanelPrefb,RoomListPanel.instance.canvas.transform);
obj.GetComponent<CheckPanel>().Init(practice1);
});
qidongBtn.onClick.AddListener(() =>
{
//启动
qidongBtn.interactable = false;
Invoke("ReSetBtn", 3);
byte[] tmps = Encoding.UTF8.GetBytes(practice1.Id);
byte[] tmpbytes = new byte[8 + tmps.Length];
Array.Copy(BitConverter.GetBytes(10), 0, tmpbytes, 0, 4);
Array.Copy(BitConverter.GetBytes(tmps.Length), 0, tmpbytes, 4, 4);
Array.Copy(tmps, 0, tmpbytes, 8, tmps.Length);
LoadManage.Instance.UdpSend(tmpbytes, new IPEndPoint(IPAddress.Parse(MyNetMQClient.SyncServerIP.Split(':')[0]), int.Parse(MyNetMQClient.SyncServerIP.Split(':')[1])));
});
closeBtn.onClick.AddListener(() =>
{
//关闭
closeBtn.interactable = false;
Invoke("ResetCloseBtn", 3);
});
}
public void ReSetBtn()
{
if (qidongBtn != null)
{
qidongBtn.interactable = true;
}
}
public void ResetCloseBtn()
{
if(closeBtn!=null)
{
closeBtn.interactable = true;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 653b3d77e9069ed469cf5b1d71f4aca5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f5a906ddb68e90a4096e0d81522617dd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,39 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
public class CreateRoomSeatItem : MonoBehaviour
{
[HideInInspector]
public SeatInfo seat1;
SeatBindSubjectItem seatBindSubjectItem;
public Text seatname,username,useraccount;
public Button chosebtn;
public Button resetbtn;
public void Init(SeatInfo seat, SeatBindSubjectItem createRoomSubjectItem)
{
seat1 = seat;
seatBindSubjectItem = createRoomSubjectItem;
seatname.text = seat.seatName;
username.text = "虚兵";
useraccount.text = "999";
createRoomSubjectItem.seatItems.Add(this);
//重置
resetbtn.onClick.AddListener(() =>
{
username.text = "虚兵";
useraccount.text = "999";
});
chosebtn.onClick.AddListener(() =>
{
//显示选择人员界面
GameObject obj = Instantiate<GameObject>(CreateRoomPanel.instance.choseUserPrefb,CreateRoomPanel.instance.transform);
obj.GetComponent<ChoseUserPanel>().Init(seatBindSubjectItem,this);
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 27f4a9e817b081a4985720d45bc6c44c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SeatBindSeatItem : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 98883bdcc19c946449f1de26052ec066
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,21 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SeatBindSubjectItem : MonoBehaviour
{
public Text NaemText;
SubejctsInfo subejctsInfo;
public List<CreateRoomSeatItem> seatItems;
public void Init(SubejctsInfo subejct)
{
subejctsInfo = subejct;
NaemText.text = subejctsInfo.subjectName;
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 7406ee1da8abd364cbada6aeba3e37e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,159 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;
using DataModel.Model;
using LitJson;
public class LoginPanel : MonoBehaviour
{
public InputField zhanghao;
public InputField mima;
public Button quedingbtn;
public Canvas canvas;
public Button settingBtn;
public Button clearBtn;
public Button exitBtn;
public Button anchorSettingBtn;
public static LoginPanel instance;
private void Awake()
{
instance = this;
string zh=PlayerPrefs.GetString("HJZhangHu", "");
string password=PlayerPrefs.GetString("HJMiMa", "");
zhanghao.text = zh;
mima.text = password;
clearBtn.onClick.AddListener(() =>
{
zhanghao.text = "";
mima.text = "";
});
quedingbtn.onClick.AddListener(() =>
{
if (!string.IsNullOrEmpty(zhanghao.text) || !string.IsNullOrEmpty(mima.text))
{
Login(zhanghao.text, mima.text);
}
});
settingBtn.onClick.AddListener(()=>
{
IPsettingPanel.instance.Show();
});
exitBtn.onClick.AddListener(()=>
{
Application.Quit();
});
anchorSettingBtn.onClick.AddListener(() =>
{
UnityEngine.SceneManagement.SceneManager.LoadScene("GetAnchor");
});
}
private void Login(string account, string password)
{
AuthReq user = new AuthReq();
user.passWord = password;
user.sysId = "5";
user.userCode = "001";
user.userName = account;
User tmpuser = new User();
//172.16.1.92:8089
StartCoroutine(MyNetMQClient.InvokeWebPostByUploadhandler("http://"+MyNetMQClient.userIP+":8089/api/auth", JsonMapper.ToJson(user), (ok,result) =>
{
if (ok)
{
JsonData jd = JsonMapper.ToObject(result);
if (jd["success"].ValueAsBoolean())
{
sys_user tmp = new sys_user();
//在这里取数据
tmp.user_name = jd["value"]["userInfo"]["userName"].ToString();
if (jd["value"]["userInfo"]["userCode"] != null)
tmp.user_code = jd["value"]["userInfo"]["userCode"].ToString();
tmp.user_id = int.Parse(jd["value"]["userInfo"]["userId"].ToString());
if (jd["value"]["userInfo"]["deptId"] != null)
tmp.dept_id = int.Parse(jd["value"]["userInfo"]["deptId"].ToString());
if (jd["value"]["userInfo"]["jobId"] != null)
tmp.job_id = int.Parse(jd["value"]["userInfo"]["jobId"].ToString());
tmp.nickName = jd["value"]["userInfo"]["nickName"].ToString();
if (jd["value"]["userInfo"]["avatar"] != null)
tmp.avatar = jd["value"]["userInfo"]["avatar"].ToString();
if (jd["value"]["userInfo"]["certificateNumber"] != null)
tmp.introduce = jd["value"]["userInfo"]["certificateNumber"].ToString();
tmpuser.user = tmp;
//获取角色
StartCoroutine(MyNetMQClient.InvokeWebPostByUploadhandler("http://"+MyNetMQClient.userIP+":8087/role/queryRoleByUserId", JsonMapper.ToJson(new { userId = tmp.user_id.ToString() }), (ok2,result2) =>
{
if (ok2)
{
JsonData jd2 = JsonMapper.ToObject(result2);
if (jd2["success"].ValueAsBoolean())
{
foreach (JsonData item in jd2["value"])
{
string tmpcode=item["roleCode"].ToString();
UserType ut;
if(Enum.TryParse<UserType>(tmpcode, out ut))
{
tmpuser.userType.Add(ut);
Debug.Log("角色:" + tmpcode);
}
else
{
Debug.LogError("未找到此角色:" + tmpcode);
}
}
//登录成功
LoadManage.Instance.me = tmpuser;
PlayerPrefs.SetString("HJZhangHu", account);
PlayerPrefs.SetString("HJMiMa", password);
if (LoadManage.Instance.systemMode == SystemMode.PC)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("MainSencePC");
}
else if (LoadManage.Instance.systemMode == SystemMode.MR)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("MainSenceMR");
}
}
else
{
MessagePanel.ShowMessage(jd2["msg"].ToString(), canvas.transform, null);
}
}
else
{
MessagePanel.ShowMessage(result2, canvas.transform, null);
}
}));
}
else
{
MessagePanel.ShowMessage(jd["msg"].ToString(), canvas.transform, null);
}
}
else
{
MessagePanel.ShowMessage(result, canvas.transform, null);
}
}));
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d2eae5c236c71bf4f9e4f121b184105b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,61 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public class MessagePanel : MonoBehaviour
{
Action<bool> callback;
public Text msgText;
public Button quedingBtn;
public Button quxiaoBtn;
public static GameObject messageItem;
public void Init(string msg, Action<bool> call)
{
msgText.text = msg;
callback = call;
if(call==null)
{
quedingBtn.gameObject.SetActive(false);
quxiaoBtn.gameObject.SetActive(false);
//无回调
Invoke("delete", 5);
}
else
{
//有回调
quedingBtn.onClick.AddListener(() =>
{
callback(true);
Destroy(gameObject);
});
quxiaoBtn.onClick.AddListener(() =>
{
callback(false);
Destroy(gameObject);
});
}
}
public void delete()
{
callback = null;
Destroy(gameObject);
}
public static void ShowMessage(string msg,Transform canvns,Action<bool> back=null)
{
if(messageItem==null)
{
messageItem = Resources.Load<GameObject>("UI/MessagePanel");
}
GameObject obj = Instantiate<GameObject>(messageItem, canvns);
obj.GetComponent<MessagePanel>().Init(msg, back);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 38dc4e14732fa4648a0bf9ce59068e1a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,156 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using DataModel.Model;
using System;
using LitJson;
public class RoomListPanel : MonoBehaviour
{
public GridLayoutGroup connect;
[HideInInspector]
public GameObject itemPrefb;
public Button refreshBtn;
public Button createBtn;
public Canvas canvas;
public Text DateTimeText;
public Button SettingBtn;
public Button QuitBtn;
public Text UserNameText;
public SystrmSettingPanel systrmSettingPanel;
[HideInInspector]
public GameObject CreateRoomPrefb;
[HideInInspector]
public GameObject CheckPanelPrefb;
public static RoomListPanel instance;
private void Awake()
{
instance = this;
if (itemPrefb==null)
{
itemPrefb = Resources.Load<GameObject>("UI/Item/roomItem");
}
if(CheckPanelPrefb==null)
{
CheckPanelPrefb = Resources.Load<GameObject>("UI/CheckPanel");
}
refreshBtn.onClick.AddListener(() =>
{
//刷新
Refresh();
});
createBtn.onClick.AddListener(() =>
{
//创建
if (CreateRoomPrefb == null)
{
CreateRoomPrefb = Resources.Load<GameObject>("UI/CreateRoomPanel");
}
GameObject obj = Instantiate<GameObject>(CreateRoomPrefb, canvas.transform);
});
QuitBtn.onClick.AddListener(() =>
{
LoadManage.Instance.me = null;
if (LoadManage.Instance.systemMode == SystemMode.PC)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("LoginSencePC");
}
else if(LoadManage.Instance.systemMode== SystemMode.MR)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("LoginSenceMR");
}
});
SettingBtn.onClick.AddListener(() =>
{
//显示配置界面
systrmSettingPanel.gameObject.SetActive(true);
});
systrmSettingPanel.Init();
}
private void Start()
{
if (LoadManage.Instance != null)
{
UserNameText.text = LoadManage.Instance.me.user.nickName;
}
//刷新
Refresh();
}
private void FixedUpdate()
{
//刷新按钮旋转
if(refreshBtn.interactable==false)
{
refreshBtn.transform.Rotate(Vector3.forward, 5, Space.Self);
}
DateTimeText.text = DateTime.Now.ToLongDateString()+" "+ DateTime.Now.ToLongTimeString();
}
/// <summary>
/// 刷新
/// </summary>
public void Refresh()
{
refreshBtn.interactable = false;
Invoke("ResetBtn", 3);
connect.transform.GetComponentsInChildren<RoomItem>(true).ToList().ForEach(a=>
{
DestroyImmediate(a.gameObject);
});
StartCoroutine(MyNetMQClient.CallGet("http://"+MyNetMQClient.CallIP+"/Handler/Practice.ashx?action=query&state=0,1", result=>
{
var json = JsonMapper.ToObject<CallResultList<practice>>(result);
var data=JsonMapper.ToObject(result)["data"];
if(data!=null)
{
data.ValueAsArray().ToList().ForEach(a =>
{
json.data.Find(b => b.Id == a["Id"].ToString()).CreateTime = DateTime.Parse(a["CreateTime"].ToString());
});
}
if (json.state)
{
var list = json.data.OrderByDescending(a=>a.CreateTime).ToList();
list.ToList().ForEach(a=>
{
//创建
GameObject item = Instantiate<GameObject>(itemPrefb,connect.transform);
item.GetComponent<RoomItem>().Init(a);
});
}
else
{
string msg = json.message;
Debug.LogError(msg);
MessagePanel.ShowMessage(msg, canvas.transform);
}
}));
}
public void ResetBtn()
{
if (refreshBtn != null)
{
refreshBtn.interactable = true;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f9c96b37d963c1e47bc48452614c7b25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,55 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SystrmSettingPanel : MonoBehaviour
{
public Dropdown ScreemMode;
public Slider ;
public Slider ;
public Button closeBtn;
public void Init()
{
ScreemMode.value= PlayerPrefs.GetInt("屏幕模式", 0);
if(ScreemMode.value==0)
{
//全屏
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
Screen.fullScreen = true;
}
else
{
//窗口化
Screen.fullScreenMode = FullScreenMode.MaximizedWindow;
Screen.fullScreen = false;
}
ScreemMode.onValueChanged.AddListener(index =>
{
if(index==0)
{
//全屏模式
}
else if(index==1)
{
//窗口模式
}
PlayerPrefs.SetInt("屏幕模式", index);
});
.value = PlayerPrefs.GetFloat("音量", 1f);
.value = PlayerPrefs.GetFloat("音效", 1f);
LoadManage.Instance.SourceLiangValue = .value;
LoadManage.Instance.SourceXiaoValue = .value;
closeBtn.onClick.AddListener(() =>
{
LoadManage.Instance.SourceLiangValue = .value;
LoadManage.Instance.SourceXiaoValue = .value;
gameObject.SetActive(false);
});
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a5fa4cfe95bdea54c8adc79dc1a53dbc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,588 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using DataModel.Model;
using LitJson;
public class GameManage : MonoBehaviour
{
public static GameManage Instance;
/// <summary>
/// 初始位置
/// </summary>
public Transform initPos;
public float OnceTime = 0.06f;
public int lerpTime = 2;
public bool is单机模式;
public Canvas canvas;
public ScoreManage scoreManage;
#region
/// <summary>
/// 科目启停回调
/// </summary>
[HideInInspector]
public Action<string, string, string, bool> action_subject;
/// <summary>
/// 步骤启停回调
/// </summary>
[HideInInspector]
public Action<string, string, string, string, bool> action_step;
/// <summary>
/// 开始暂停回调
/// </summary>
[HideInInspector]
public Action<bool> action_Pause;
/// <summary>
/// 关闭房间回调
/// </summary>
[HideInInspector]
public Action action_close;
#endregion
private void Awake()
{
Instance = this;
//房间域
LoadManage.programState = ProgramState.;
//初始化注册
UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects().ToList().ForEach(a =>
{
InitAllSyncInRoot(a.transform, false);
});
if (!is单机模式)
{
//获取步骤信息
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=queryPracticesubjectStep&PracticeId=" + LoadManage.Instance.currentPractice.Id, str =>
{
var json = JsonMapper.ToObject<CallResultList<practicesubjectstep>>(str);
if (json.state)
{
LoadManage.Instance.psteps = json.data;
//获取所有的practiceseat
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/Handler/Practice.ashx?action=querypracticeseat&PracticeId=" + LoadManage.Instance.currentPractice.Id, str2 =>
{
var json2 = JsonMapper.ToObject<CallResultList<practiceseat>>(str2);
if (json2.state)
{
LoadManage.Instance.pseats = json2.data;
LoadManage.Instance.myPracticeSeat = LoadManage.Instance.pseats.FindAll(a => a.UserAccount == LoadManage.Instance.me.user.user_name);
//初始化打分系统
scoreManage.Init();
//恢复当前训练信息
var tmpps = LoadManage.Instance.psubjects.FindAll(a => a.State == 0);
if (tmpps != null && tmpps.Count > 0)
{
foreach (var item in tmpps)
{
practiceseat tmppseat = LoadManage.Instance.myPracticeSeat.Find(a => a.Field_Char1 == item.Id);
if (tmppseat != null)
{
//本人当前科目
LoadManage.Instance.currentPracticeSubejct = item;
LoadManage.Instance.currentPracticeSeat = tmppseat;
//当前正在进行中步骤
LoadManage.Instance.currentPracticeSubjectStep = LoadManage.Instance.psteps.Find(a => a.PracticeSubjectId == item.Id && a.SeatId == tmppseat.SeatId && a.StepState=="0");
Debug.Log("当前科目:" + item.Name);
Debug.Log("当前岗位:" + tmppseat.SeatName);
if (LoadManage.Instance.currentPracticeSubjectStep != null)
{
Debug.Log("当前步骤正在进行中:" + LoadManage.Instance.currentPracticeSubjectStep.Name);
}
//激活当前步骤相应打分点(科目进行中且步骤未完成)
if (LoadManage.Instance.currentPractice.MissionModel == "考核")
{
//未完成的步骤
var noOverSteps = LoadManage.Instance.psteps.FindAll(a => a.PracticeSubjectId == item.Id && a.SeatId == tmppseat.SeatId && a.StepState != "1");
var allSB=scoreManage.transform.Find(item.Name).GetComponentsInChildren<ScoreBase>(true).ToList();
if (noOverSteps!=null && noOverSteps.Count>0)
{
noOverSteps.ForEach(a =>
{
allSB.FindAll(b => b.stepOrder == a.OrderIndex).ForEach(b =>
{
b.SetActive(true);
});
});
}
}
//开二维软件
SoftManage.Instance.StartSoft(LoadManage.Instance.currentPractice.Id, LoadManage.Instance.currentPracticeSubejct.Name, LoadManage.Instance.currentPracticeSeat.SeatName, LoadManage.Instance.currentPracticeSeat.UserAccount, 0);
break;
}
}
}
//当前切换当前科目
GetMaoDian();
}
else
{
string msg = json2.message;
Debug.LogError(msg);
}
}));
;
}
else
{
string msg = json.message;
Debug.LogError(msg);
}
}));
}
}
/// <summary>
/// 获取锚点
/// </summary>
private void GetMaoDian()
{
//获取房间数据
UpLoadMe();
}
private void OnDestroy()
{
action_subject = null;
action_step = null;
}
/// <summary>
/// 注册科目启停回调
/// </summary>
/// <param name="action_subject"> practiceidpraticeSubjectId科目名是否开启</param>
public void SetSubjectAction(Action<string, string, string, bool> action_subject)
{
this.action_subject += action_subject;
}
/// <summary>
/// 注册步骤启停回调
/// </summary>
/// <param name="action_step">practiceidpraticeSubjectId科目名pratciesubjectstepId是否开启</param>
public void SetStepAction(Action<string, string, string, string, bool> action_step)
{
this.action_step += action_step;
}
/// <summary>
/// 注册开始暂停回调 (true:开始 false:暂停)
/// </summary>
/// <param name="action_pause"></param>
public void SetPauseAction(Action<bool> action_pause)
{
this.action_Pause = action_pause;
}
/// <summary>
/// 注册关闭回调
/// </summary>
/// <param name="action_close"></param>
public void SetCloseAction(Action action_close)
{
this.action_close = action_close;
}
/// <summary>
/// 切换科目状态
/// </summary>
/// <param name="msg"></param>
public void SubjectChange(string msg)
{
// practiceId + "," + praticeSubjectId + "," + subjectName + "," + (OpenOrClose ? "开" : "关")
string[] tmps = msg.Split(',');
string practiceId = tmps[0];
string praticeSubjectId = tmps[1];
string subjectName = tmps[2];
string OpenOrClose = tmps[3];
bool oc = true;
if (OpenOrClose == "开")
{
oc = true;
}
else if (OpenOrClose == "关")
{
oc = false;
}
else
{
Debug.LogError("错误:" + OpenOrClose);
return;
}
if (practiceId == LoadManage.Instance.currentPractice.Id)
{
practicesubject ps = LoadManage.Instance.psubjects.Find(a => a.Id == praticeSubjectId);
if (ps != null)
{
if (oc)
{
//开
if (LoadManage.Instance.currentPracticeSubejct != null && LoadManage.Instance.currentPracticeSubejct.OrderIndex != ps.OrderIndex)
{
Debug.LogError("此科目不能并行");
return;
}
ps.State = 0;
LoadManage.Instance.currentPracticeSubejct = ps;
practiceseat pseat = LoadManage.Instance.myPracticeSeat.Find(a => a.Field_Char1 == praticeSubjectId);
if (pseat != null)
{
//自己参与当前科目
LoadManage.Instance.currentPracticeSeat = pseat;
Debug.Log("科目开启成功:" + ps.Name);
if (action_subject != null)
{
action_subject.Invoke(practiceId, praticeSubjectId, subjectName, oc);
}
//开二维软件
SoftManage.Instance.StartSoft(LoadManage.Instance.currentPractice.Id, LoadManage.Instance.currentPracticeSubejct.Name, LoadManage.Instance.currentPracticeSeat.SeatName, LoadManage.Instance.currentPracticeSeat.UserAccount, 0);
//激活自己相应打分
if(LoadManage.Instance.currentPractice.MissionModel=="考核")
{
scoreManage.transform.Find(ps.Name).GetComponentsInChildren<ScoreBase>(true).ToList().ForEach(c =>
{
if (c.seatName == pseat.SeatName)
{
c.SetActive(true);
}
});
}
}
else
{
Debug.Log("未参与此科目:" + ps.Name);
}
}
else
{
//关
if (LoadManage.Instance.currentPracticeSubejct != null && LoadManage.Instance.currentPracticeSubejct.Id == ps.Id)
{
//自己参与当前科目
ps.State = 1;
LoadManage.Instance.currentPracticeSubejct = null;
practiceseat pseat = LoadManage.Instance.myPracticeSeat.Find(a => a.Field_Char1 == praticeSubjectId);
if (pseat != null)
{
LoadManage.Instance.currentPracticeSeat = null;
Debug.Log("科目关闭成功:" + ps.Name);
if (action_subject != null)
{
action_subject.Invoke(practiceId, praticeSubjectId, subjectName, oc);
}
//关闭所有相应打分
if (LoadManage.Instance.currentPractice.MissionModel == "考核")
{
scoreManage.transform.Find(ps.Name).GetComponentsInChildren<ScoreBase>(true).ToList().ForEach(c =>
{
c.SetActive(false);
});
//指挥提交总表
if (pseat.SeatNo == "0")
{
scoreManage.SubmitApprise(subjectName);
}
}
}
else
{
Debug.Log("未参与此科目:" + ps.Name);
}
}
}
}
else
{
Debug.LogError("错误:未找到科目");
}
}
}
/// <summary>
/// 切换步骤状态
/// </summary>
/// <param name="msg"></param>
public void StepChange(string msg)
{
// practiceId + "," + praticeSubjectId + "," + subjectName + "," + pratciesubjectstepId + "," + (OpenOrClose ? "开" : "关")
string[] tmps = msg.Split(',');
string practiceId = tmps[0];
string praticeSubjectId = tmps[1];
string subjectName = tmps[2];
string pratciesubjectstepId = tmps[3];
string OpenOrClose = tmps[4];
bool oc = true;
if (OpenOrClose == "开")
{
oc = true;
}
else if (OpenOrClose == "关")
{
oc = false;
}
else
{
Debug.LogError("错误:" + OpenOrClose);
return;
}
if (practiceId == LoadManage.Instance.currentPractice.Id)
{
practicesubjectstep step = LoadManage.Instance.psteps.Find(a => a.ID == pratciesubjectstepId);
if (step != null)
{
step.StepState = (oc ? 0 : 1).ToString();
if (action_step != null)
{
action_step.Invoke(practiceId, praticeSubjectId, subjectName, pratciesubjectstepId, oc);
}
if (oc)
{
//开启步骤
LoadManage.Instance.currentPracticeSubjectStep = step;
}
else
{
//结束步骤
LoadManage.Instance.currentPracticeSubjectStep = null;
//提交此步骤子表分数
scoreManage.transform.Find(subjectName).GetComponentsInChildren<ScoreBase>(true).ToList().ForEach(c =>
{
if (c.stepOrder == step.OrderIndex)
{
c.Submit();
}
});
}
}
else
{
Debug.LogError("错误:未找到步骤");
}
}
}
/// <summary>
/// 注册一个根物体下所有同步组件
/// </summary>
/// <param name="a"></param>
public void InitAllSyncInRoot(Transform a, bool isPlayer, string id = "")
{
a.GetComponentsInChildren<FunctionSync_Active>(true).ToList().ForEach(b =>
{
if (isPlayer)
{
b.gameObject.name = id + b.gameObject.name;
}
b.Init();
});
a.GetComponentsInChildren<FunctionSync_Animator>(true).ToList().ForEach(b =>
{
if (isPlayer)
{
b.gameObject.name = id + b.gameObject.name;
}
b.Init();
});
a.GetComponentsInChildren<FunctionSync_Audio>(true).ToList().ForEach(b =>
{
if (isPlayer)
{
b.gameObject.name = id + b.gameObject.name;
}
b.Init();
});
a.GetComponentsInChildren<FunctionSync_CreateObejct>(true).ToList().ForEach(b =>
{
b.Init();
});
a.GetComponentsInChildren<FunctionSync_Material>(true).ToList().ForEach(b =>
{
if (isPlayer)
{
b.gameObject.name = id + b.gameObject.name;
}
b.Init();
});
a.GetComponentsInChildren<FunctionSync_Parent>(true).ToList().ForEach(b =>
{
if (isPlayer)
{
b.gameObject.name = id + b.gameObject.name;
}
b.Init();
});
a.GetComponentsInChildren<FunctionSync_ParticleSystem>(true).ToList().ForEach(b =>
{
if (isPlayer)
{
b.gameObject.name = id + b.gameObject.name;
}
b.Init();
});
a.GetComponentsInChildren<FunctionSync_PositionRoate>(true).ToList().ForEach(b =>
{
b.Init();
});
a.GetComponentsInChildren<FunctionSync_Scale>(true).ToList().ForEach(b =>
{
b.Init();
});
a.GetComponentsInChildren<FunctionSync_Text>(true).ToList().ForEach(b =>
{
if (b.isAutoInit)
{
b.Init();
}
});
a.GetComponentsInChildren<FunctionSync_MaterialTexture>(true).ToList().ForEach(b =>
{
b.Init();
});
a.GetComponentsInChildren<OneValueSyncObject>(true).ToList().ForEach(b =>
{
if (!b.)
{
b.InitDynamic("sync_" + b.name, null, b.valueType);
}
});
}
/// <summary>
/// 初始化科目
/// </summary>
public void InitSubject()
{
//初始化科目数据
//设备位置状态
//初始化评估
}
[HideInInspector]
public float checkTime = 6;
private void Update()
{
#if !UNITY_EDITOR
// //检查是否去服务器连接
// checkTime -= Time.deltaTime;
// if (checkTime < 0)
// {
// Debug.Log("时间超过6秒");
// Quit();
// }
#endif
}
/// <summary>
/// 上传自己的信息(加入房间,并获取房间信息)
/// </summary>
public void UpLoadMe()
{
if (!is单机模式)
{
LoadManage.Instance.RSclient.Send(LoadManage.Instance.currentRoomArea,32,new byte[1]);
Debug.Log("发送加入房间");
}
//关闭界面
}
/// <summary>
/// 退出房间
/// </summary>
public void Quit()
{
Debug.Log("退出房间");
//初始化
LoadManage.programState = ProgramState.;
OneValueSyncObject.OneAxisSyncObjectList.Clear();
FunctionSync_PositionRoate.positionRoateSyncObejctList.Clear();
FunctionSync_Video.dicVideo.Clear();
FunctionSync_Media.functionSync_MediaDic.Clear();
FunctionSync_CreateObejct.createDic.Clear();
FunctionSync_CreateObejct.Instance = null;
action_subject = null;
action_step = null;
//发送退出房间指令
if (!is单机模式 && LoadManage.Instance.me != null)
{
//byte[] bytes = Encoding.UTF8.GetBytes(LoadManage.Instance.MyId);
//byte[] names = Encoding.UTF8.GetBytes(LoadManage.Instance.MyName);
//byte[] tmps = new byte[8 + bytes.Length+ names.Length];
//Array.Copy(BitConverter.GetBytes(bytes.Length), 0, tmps, 0, 4);
////id
//Array.Copy(bytes, 0, tmps, 4, bytes.Length);
////name
//Array.Copy(BitConverter.GetBytes(names.Length), 0, tmps, 4 + bytes.Length, 4);
//Array.Copy(names, 0, tmps, 8 + bytes.Length, names.Length);
//LoadManage.Instance.RSclient.Send(LoadManage.Instance.currentRoomArea, 10, tmps);
//Debug.Log("发送退出房间");
}
//初始化LoadManage脚本
LoadManage.Instance.currentRoomArea = "";
//LoadManage.Instance.MyId = "";
LoadManage.Instance.SyncId = 0;
checkTime = 10;
//断开通信
LoadManage.Instance.RemoveRoomServerClient();
if (LoadManage.Instance.systemMode == SystemMode.PC)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("MainSencePC");
}
else if (LoadManage.Instance.systemMode == SystemMode.MR)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("MainSenceMR");
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b4ef00557079cb54fb84de19b7380906
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 600
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,793 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Linq;
using System.Collections;
using DataModel.Model;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using LitJson;
using TMPro;
using System.IO;
public class LoadManage : MonoBehaviour
{
public static LoadManage Instance;
/// <summary>
/// 系统模式
/// </summary>
public SystemMode systemMode;
/// <summary>
/// 本人账户信息
/// </summary>
[HideInInspector]
public User me;
/// <summary>
/// 当前训练 (进房间前赋值)
/// </summary>
[HideInInspector]
public practice currentPractice = null;
/// <summary>
/// 当前科目
/// </summary>
[HideInInspector]
public practicesubject currentPracticeSubejct = null;
/// <summary>
/// 当前岗位
/// </summary>
[HideInInspector]
public practiceseat currentPracticeSeat = null;
/// <summary>
/// 当前步骤
/// </summary>
[HideInInspector]
public practicesubjectstep currentPracticeSubjectStep = null;
/// <summary>
/// 本人在训练中所有岗位信息
/// </summary>
[HideInInspector]
public List<practiceseat> myPracticeSeat = new List<practiceseat>();
/// <summary>
/// 训练科目 (进房间前赋值)
/// </summary>
[HideInInspector]
public List<practicesubject> psubjects;
/// <summary>
/// 训练步骤
/// </summary>
[HideInInspector]
public List<practicesubjectstep> psteps;
/// <summary>
/// 训练岗位
/// </summary>
[HideInInspector]
public List<practiceseat> pseats;
/// <summary>
/// 音量大小
/// </summary>
[DisplayOnly]
public float SourceLiangValue;
/// <summary>
/// 音效大小
/// </summary>
[DisplayOnly]
public float SourceXiaoValue;
[HideInInspector]
public string MyId;
/// <summary>
/// 房间域 "1room"
/// </summary>
[DisplayOnly]
public string currentRoomArea;
/// <summary>
/// 同步Id
/// </summary>
[DisplayOnly]
public int SyncId;
/// <summary>
/// 训练状态
/// </summary>
public static ProgramState programState = ProgramState.;
/// <summary>
/// 是否暂停
/// </summary>
public static bool isPause;
/// <summary>
/// 与RoomServer通信
/// </summary>
[DisplayOnly]
public MyNetMQClient RSclient;
#region UDP
[HideInInspector]
public UdpClient udpClient;
bool udpRun;
int refreshTime = 0;
#endregion
/// <summary>
/// 人员
/// </summary>
public static List<sys_user> persons = new List<sys_user>();
private void Awake()
{
Instance = this;
DontDestroyOnLoad(gameObject);
//启动(测试用)
udpClient = new UdpClient(8889);
udpRun = true;
Thread thread = new Thread(UdpRecive);
thread.IsBackground = true;
thread.Start();
#if UNITY_EDITOR
UnityEngine.Debug.unityLogger.logEnabled = true;
#else
UnityEngine.Debug.unityLogger.logEnabled = false;
#endif
}
void Start()
{
//设置不休眠
Screen.sleepTimeout = SleepTimeout.NeverSleep;
List<string> tmps = File.ReadAllLines(Application.streamingAssetsPath + "/MainSetting.txt").ToList();
int porta, portb, portc;
IPAddress ipd;
tmps.ForEach(a =>
{
string[] data = a.Split('=');
if (a.Split('=')[0] == "协同交互服务UDP")
{
IPAddress.Parse(data[1].Split(':')[0]);
if (int.TryParse(data[1].Split(':')[1], out portb))
{
//MyNetMQClient.SyncServerIP = data[1];
MyNetMQClient.SyncServerIP = "192.168.0.103";
}
else
{
Debug.LogError("协同交互服务UDP配置错误");
}
}
});
GetAllUser();
}
private void Update()
{
if (refreshTime > 0)
{
//刷新房间列表
if (RoomListPanel.instance != null && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Contains("MainSence"))
{
RoomListPanel.instance.Refresh();
refreshTime = 0;
}
}
}
private void UdpRecive()
{
while (udpRun)
{
try
{
IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] data = udpClient.Receive(ref iPEndPoint);
int type = BitConverter.ToInt32(data, 0);
if (type == 13)
{
if (LoadManage.programState == ProgramState.)
{
//开启房间成功
UnityEngine.Debug.Log("开启房间成功");
string practiceid = Encoding.UTF8.GetString(data, 4, data.Length - 4);
refreshTime++;
}
}
else if (type == 26)
{
if (LoadManage.programState == ProgramState.)
{
//开启二维软件失败
int length = BitConverter.ToInt32(data, 4);
string arg = Encoding.UTF8.GetString(data, 8, length);
string[] tmps = arg.Split(':');
SoftManage.Instance.ChangeSoftSubject(tmps[0], tmps[1], SoftManage.Instance.softName, tmps[2], tmps[3]);
}
}
}
catch
{
}
}
}
/// <summary>
/// 发送udp消息
/// </summary>
/// <param name="data"></param>
/// <param name="endPoint"></param>
public void UdpSend(byte[] data, IPEndPoint endPoint)
{
udpClient.Send(data, data.Length, endPoint);
}
/// <summary>
/// 获取所有本系统人员数据,导调角色,操作手
/// </summary>
private void GetAllUser()
{
//使用真实接口
//172.16.1.92:8087
//获取士兵
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.userIP + ":8087/role?roleName=士兵", result1 =>
{
JsonData jd = JsonMapper.ToObject(result1);
if (jd["success"].ValueAsBoolean())
{
List<int> tmp = new List<int>();
foreach (JsonData item in jd["value"])
{
tmp.Add(int.Parse(item["roleId"].ToString()));
}
if (tmp.Count > 0)
{
string tmpjsonvalue = JsonMapper.ToJson(tmp);
//获取所有士兵user
StartCoroutine(MyNetMQClient.InvokeWebPostByUploadhandler("http://" + MyNetMQClient.userIP + ":8087/user/queryAllUsers", JsonMapper.ToJson(new { limit = 1000, roleDtoList = tmpjsonvalue }), (ok, result2) =>
{
if (ok)
{
JsonData jd2 = JsonMapper.ToObject(result2);
if (jd2["success"].ValueAsBoolean())
{
foreach (JsonData item in jd2["value"]["results"])
{
sys_user tmpUser = new sys_user();
//在这里取数据
tmpUser.user_name = item["userName"].ToString();
if (item["userCode"] != null)
tmpUser.user_code = item["userCode"].ToString();
tmpUser.user_id = int.Parse(item["userId"].ToString());
if (item["deptId"] != null)
tmpUser.dept_id = int.Parse(item["deptId"].ToString());
if (item["jobId"] != null)
tmpUser.job_id = int.Parse(item["jobId"].ToString());
if (item["nickName"] != null)
tmpUser.nickName = item["nickName"].ToString();
if (item["avatar"] != null)
tmpUser.avatar = item["avatar"].ToString();
if (item["certificateNumber"] != null)
tmpUser.introduce = item["certificateNumber"].ToString();
persons.Add(tmpUser);
}
//获取所有指挥员
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.userIP + ":8087/role?roleName=指挥员", result3 =>
{
JsonData jd3 = JsonMapper.ToObject(result3);
if (jd3["success"].ValueAsBoolean())
{
List<int> tmp2 = new List<int>();
foreach (JsonData item in jd3["value"])
{
tmp2.Add(int.Parse(item["roleId"].ToString()));
}
if (tmp2.Count > 0)
{
string tmpjsonvalue2 = JsonMapper.ToJson(tmp2);
//获取所有指挥员user
StartCoroutine(MyNetMQClient.InvokeWebPostByUploadhandler("http://" + MyNetMQClient.userIP + ":8087/user/queryAllUsers", JsonMapper.ToJson(new { limit = 1000, roleDtoList = tmpjsonvalue2 }), (ok2, result4) =>
{
if (ok2)
{
JsonData jd4 = JsonMapper.ToObject(result4);
if (jd4["success"].ValueAsBoolean())
{
foreach (JsonData item in jd4["value"]["results"])
{
sys_user tmpUser = new sys_user();
//在这里取数据
tmpUser.user_name = item["userName"].ToString();
if (item["userCode"] != null)
tmpUser.user_code = item["userCode"].ToString();
tmpUser.user_id = int.Parse(item["userId"].ToString());
if (item["deptId"] != null)
tmpUser.dept_id = int.Parse(item["deptId"].ToString());
if (item["jobId"] != null)
tmpUser.job_id = int.Parse(item["jobId"].ToString());
if (item["nickName"] != null)
tmpUser.nickName = item["nickName"].ToString();
persons.Add(tmpUser);
}
Debug.Log("获取人员完成");
//获取考核配置
StartCoroutine(MyNetMQClient.CallGet("http://" + MyNetMQClient.CallIP + "/3DConfig/考核动作标题配置.xml", back =>
{
ScoreManage.SetXml(back);
Debug.Log("考核配置获取完成");
//跳转
if (systemMode == SystemMode.PC)
{
SceneManager.LoadScene("LoginSencePC");
}
else if (systemMode == SystemMode.MR)
{
SceneManager.LoadScene("LoginSenceMR");
}
}));
}
else
{
string msg = jd4["msg"].ToJson();
MessagePanel.ShowMessage(msg, GameObject.Find("Canvas").transform, null);
}
}
else
{
MessagePanel.ShowMessage(result4, GameObject.Find("Canvas").transform, null);
}
}));
}
}
else
{
string msg = jd3["msg"].ToJson();
MessagePanel.ShowMessage(msg, GameObject.Find("Canvas").transform, null);
}
}));
}
else
{
string msg = jd2["msg"].ToJson();
MessagePanel.ShowMessage(msg, GameObject.Find("Canvas").transform, null);
}
}
else
{
MessagePanel.ShowMessage(result2, GameObject.Find("Canvas").transform, null);
}
}));
}
}
else
{
string msg = jd["msg"].ToJson();
MessagePanel.ShowMessage(msg, GameObject.Find("Canvas").transform, null);
}
}));
}
/// <summary>
/// 创建与roomServer通信的客户端
/// </summary>
public void CreateRoomServerClient(string roomServerSubIP, string roomServerPubIP, string roomArea, int syncId)
{
if (RSclient == null)
{
//测试
//roomServerPubIP = "tcp://192.168.1.125:56987";
// roomServerSubIP = "tcp://192.168.1.125:56991";
RSclient = gameObject.AddComponent<MyNetMQClient>();
SyncId = syncId;
currentRoomArea = roomArea;
RSclient.Init(roomServerPubIP, roomServerSubIP, roomArea, ReciveFromRoomServerInThread, ReciveFromRoomServerInMono, "roomServer");
Debug.Log("开启roomServer:" + roomServerPubIP + "------" + roomServerSubIP + "-------" + roomArea);
}
}
public void RemoveRoomServerClient()
{
if (RSclient != null)
{
RSclient.Destroy();
// RSclient = null;
Debug.Log("RSclient置空");
}
}
/// <summary>
/// RoomServermono
/// </summary>
/// <param name="stS"></param>
private void ReciveFromRoomServerInThread(st_Motions stS)
{
//同步域
if (programState == ProgramState.)
{
if (stS.m_iOperaType == 10006)
{
//单值同步
int syncid = BitConverter.ToInt32(stS.m_sOperaData, 0);
if (LoadManage.Instance.SyncId != syncid)
{
int legth = BitConverter.ToInt32(stS.m_sOperaData, 4);
string id = Encoding.UTF8.GetString(stS.m_sOperaData, 8, legth);
if (OneValueSyncObject.OneAxisSyncObjectList.ContainsKey(id))
{
if (stS.m_sOperaData[9 + legth] == 0)
{
//无回调
OneValueSyncObject.OneAxisSyncObjectList[id].SetValue(8 + legth, stS.m_sOperaData);
}
else
{
//有回调
RSclient._netMqListener.AddToMono(stS);
}
}
}
}
else if (stS.m_iOperaType == 10007)
{
//坐标角度同步
int syncid = BitConverter.ToInt32(stS.m_sOperaData, 0);
if (LoadManage.Instance.SyncId != syncid)
{
int legth = BitConverter.ToInt32(stS.m_sOperaData, 4);
string id = Encoding.UTF8.GetString(stS.m_sOperaData, 8, legth);
if (FunctionSync_PositionRoate.positionRoateSyncObejctList.ContainsKey(id))
{
FunctionSync_PositionRoate.positionRoateSyncObejctList[id].SetValue(8 + legth, stS.m_sOperaData);
}
}
}
else if (stS.m_iOperaType == 61)
{
//心跳检测
//XinTiaoCheck();
}
else
{
RSclient._netMqListener.AddToMono(stS);
}
}
}
/// <summary>
/// RoomServermono
/// </summary>
/// <param name="data"></param>
public void ReciveFromRoomServerInMono(st_Motions data)
{
#if !UNITY_EDITOR
try
{
#endif
switch (data.m_iOperaType)
{
case 16:
{
//结束房间
if (GameManage.Instance != null)
{
GameManage.Instance.action_close.Invoke();
}
}
break;
case 25:
{
//二维通信2维-->3维
int length = BitConverter.ToInt32(data.m_sOperaData, 0);
string msg = Encoding.UTF8.GetString(data.m_sOperaData, 4, length);
MessageModel messageModel = JsonMapper.ToObject<MessageModel>(msg);
if (SoftManage.Instance != null)
{
SoftManage.Instance.SoftHandle(messageModel);
}
}
break;
case 31:
{
//开始暂停
int length = BitConverter.ToInt32(data.m_sOperaData, 0);
string practiceid = Encoding.UTF8.GetString(data.m_sOperaData, 4, length);
isPause = (data.m_sOperaData[4 + length] == 1 ? false : true);
if (GameManage.Instance.action_Pause != null)
{
GameManage.Instance.action_Pause.Invoke(isPause);
}
}
break;
case 33://得到房间所有数据
if (programState == ProgramState.)
{
GetRoomData(data.m_sOperaData);
}
break;
case 41:
{
//科目启停
int length = BitConverter.ToInt32(data.m_sOperaData, 0);
string msg = Encoding.UTF8.GetString(data.m_sOperaData, 4, length);
if (GameManage.Instance != null)
{
GameManage.Instance.SubjectChange(msg);
}
}
break;
case 51:
{
//步骤启停
int length = BitConverter.ToInt32(data.m_sOperaData, 0);
string msg = Encoding.UTF8.GetString(data.m_sOperaData, 4, length);
if (GameManage.Instance != null)
{
GameManage.Instance.StepChange(msg);
}
}
break;
case 1000://测试
break;
case 10006://单值同步
if (programState == ProgramState.)
{
int legth = BitConverter.ToInt32(data.m_sOperaData, 4);
string id = Encoding.UTF8.GetString(data.m_sOperaData, 8, legth);
OneValueSyncObject.OneAxisSyncObjectList[id].SetValue(8 + legth, data.m_sOperaData);
OneValueSyncObject.OneAxisSyncObjectList[id].callbackInmono.Invoke(id, false);
}
break;
case 10008://生成物体
if (programState == ProgramState.)
{
int syncId = BitConverter.ToInt32(data.m_sOperaData, 0);
if (LoadManage.Instance.SyncId != syncId)
{
if (FunctionSync_CreateObejct.Instance != null)
{
FunctionSync_CreateObejct.Instance.CallBack(data.m_sOperaData);
}
}
}
break;
case 10010:
if (programState == ProgramState.)
{
//自己也要执行
int legth = BitConverter.ToInt32(data.m_sOperaData, 0);
string id = Encoding.UTF8.GetString(data.m_sOperaData, 4, legth);
if (FunctionSync_Media.functionSync_MediaDic.ContainsKey(id))
{
FunctionSync_Media.functionSync_MediaDic[id].CallBack(data.m_sOperaData);
}
}
break;
}
#if !UNITY_EDITOR
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
#endif
}
public void GetRoomData(byte[] data)
{
//索引
int index = 0;
//暂停
isPause = (data[0] == 1 ? true : false);
index++;
Debug.Log(isPause ? "暂停" : "开始");
if (GameManage.Instance.action_Pause != null)
{
GameManage.Instance.action_Pause.Invoke(isPause);
}
//打分
int countScore = BitConverter.ToInt32(data, index);
index += 4;
for (int i = 0; i < countScore; i++)
{
//取数据
int tmpnum = BitConverter.ToInt32(data, index);
index += 4;
byte[] tmp = new byte[tmpnum];
Array.Copy(data, index, tmp, 0, tmpnum);
index += tmpnum;
//解析
HandleScore(Encoding.UTF8.GetString(tmp));
}
//10008生成
int countCreate = BitConverter.ToInt32(data, index);
index += 4;
for (int i = 0; i < countCreate; i++)
{
//取数据
int tmpnum = BitConverter.ToInt32(data, index);
index += 4;
byte[] tmp = new byte[tmpnum];
Array.Copy(data, index, tmp, 0, tmpnum);
index += tmpnum;
//解析
FunctionSync_CreateObejct.Instance.CallBack(tmp);
}
//10006单值
int couOneValue = BitConverter.ToInt32(data, index);
index += 4;
for (int i = 0; i < couOneValue; i++)
{
//取数据
int tmpnum = BitConverter.ToInt32(data, index);
index += 4;
byte[] tmp = new byte[tmpnum];
Array.Copy(data, index, tmp, 0, tmpnum);
index += tmpnum;
//解析
int legth = BitConverter.ToInt32(tmp, 4);
string id = Encoding.UTF8.GetString(tmp, 8, legth);
if (OneValueSyncObject.OneAxisSyncObjectList.ContainsKey(id))
{
OneValueSyncObject.OneAxisSyncObjectList[id].SetValue(8 + legth, tmp);
if (tmp[9 + legth] == 1)
{
OneValueSyncObject.OneAxisSyncObjectList[id].callbackInmono.Invoke(id, true);
}
}
else
{
Debug.LogError("不存在此物体:" + id);
}
}
//10007坐标旋转
int countPosRot = BitConverter.ToInt32(data, index);
index += 4;
for (int i = 0; i < countPosRot; i++)
{
//取数据
int tmpnum = BitConverter.ToInt32(data, index);
index += 4;
byte[] tmp = new byte[tmpnum];
Array.Copy(data, index, tmp, 0, tmpnum);
index += tmpnum;
//解析
int legth = BitConverter.ToInt32(tmp, 4);
string id = Encoding.UTF8.GetString(tmp, 8, legth);
if (FunctionSync_PositionRoate.positionRoateSyncObejctList.ContainsKey(id))
{
FunctionSync_PositionRoate.positionRoateSyncObejctList[id].SetValue(8 + legth, tmp);
}
}
Debug.Log("数据已恢复");
}
private void HandleScore(string str)
{
var ys = str.Split('|');
if (ys[0] == "评估点")
{
//评估点 | 科目物体名称 | 评估点序号 | 当前index
ScoreBase sb = GameManage.Instance.scoreManage.transform.Find(ys[1]).GetComponentsInChildren<ScoreBase>(true).ToList().Find(a => a.code.ToString() == ys[2]);
sb.IsRight = true;
sb.Completed = int.Parse(ys[3]);
}
else if (ys[1] == "操作点")
{
//操作点 | 科目物体名称 | 评估点序号 | 操作点物体名称 | index
ScoreJudge_FixedValue tmp = GameManage.Instance.scoreManage.transform.Find(ys[1]).GetComponentsInChildren<ScoreBase>(true).ToList().Find(a => a.code.ToString() == ys[2]).transform.Find(ys[3]).GetComponent<ScoreJudge_FixedValue>();
tmp.Isright = true;
tmp.index = int.Parse(ys[4]);
}
Debug.Log("打分恢复:" + str);
}
/// <summary>
/// 心跳检测响应
/// </summary>
public void XinTiaoCheck()
{
if (programState == ProgramState. && LoadManage.Instance != null && !string.IsNullOrEmpty(LoadManage.Instance.MyId) && !string.IsNullOrEmpty(LoadManage.Instance.currentRoomArea))
{
if (GameManage.Instance != null)
{
UnityEngine.Debug.Log("重置6秒");
GameManage.Instance.checkTime = 6;
}
byte[] tmp = Encoding.UTF8.GetBytes(LoadManage.Instance.MyId);
byte[] data = new byte[4 + tmp.Length];
Array.Copy(BitConverter.GetBytes(tmp.Length), 0, data, 0, 4);
Array.Copy(tmp, 0, data, 4, tmp.Length);
RSclient.Send(LoadManage.Instance.currentRoomArea, 6, data);
Debug.Log("心跳" + LoadManage.Instance.currentRoomArea);
}
}
//public void StartRoom(string roomid)
//{
// byte[] roomidbytes = Encoding.UTF8.GetBytes(roomid);
// byte[] tmp = new byte[4 + roomidbytes.Length];
// Array.Copy(BitConverter.GetBytes(roomidbytes.Length), 0, tmp, 0, 4);
// Array.Copy(roomidbytes, 0, tmp, 4, roomidbytes.Length);
// MSclient.Send("mainServer", 100, tmp);
// Debug.Log("启动房间:" + roomidbytes);
//}
//public void CloseRoom(string roomId, string pcArea, string roomArea)
//{
// //string roomId = "abcdasdadasd";
// byte[] roomidbytes = Encoding.UTF8.GetBytes(roomId);
// //string pcArea = "pcserver125";
// byte[] pcbytes = Encoding.UTF8.GetBytes(pcArea);
// //string roomArea = "room1";
// byte[] roombytes = Encoding.UTF8.GetBytes(roomArea);
// byte[] tmp = new byte[12 + roomidbytes.Length + pcbytes.Length + roombytes.Length];
// Array.Copy(BitConverter.GetBytes(roomidbytes.Length), 0, tmp, 0, 4);
// Array.Copy(roomidbytes, 0, tmp, 4, roomidbytes.Length);
// Array.Copy(BitConverter.GetBytes(pcbytes.Length), 0, tmp, 4 + roomidbytes.Length, 4);
// Array.Copy(pcbytes, 0, tmp, 8 + roomidbytes.Length, pcbytes.Length);
// Array.Copy(BitConverter.GetBytes(roombytes.Length), 0, tmp, 8 + roomidbytes.Length + pcbytes.Length, 4);
// Array.Copy(roombytes, 0, tmp, 12 + roomidbytes.Length + pcbytes.Length, roombytes.Length);
// MSclient.Send("mainServer", 110, tmp);
// Debug.Log("关闭房间:" + roomId);
//}
private void OnDestroy()
{
Debug.Log("OnDestroy");
udpRun = false;
if (RSclient != null)
{
RSclient.Destroy();
}
if (udpClient != null)
{
udpClient.Close();
}
}
}
public enum SystemMode
{
PC,
MR
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3f7e635459b7b2a42b6de90ffc7b273a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -188,3 +188,7 @@ public class AuthReq
public string userName; public string userName;
} }
public class DisplayOnly : PropertyAttribute
{
}

View File

@ -1,269 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Diagnostics;
using UnityEngine.Networking;
using DataModel.Model;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
public class MyNetMQClient : MonoBehaviour
{
public static MyNetMQClient instance;
[DisplayOnly]
public string PubIP= "127.0.0.1:8082";
[DisplayOnly]
public string SubIP = "127.0.0.1:8081";
/// <summary>
/// 接口IP (配置文件)
/// </summary>
public static string CallIP = "192.168.0.103:8080";
public static string SyncServerIP = "192.168.0.103:8888";
public static string remoteServerIP = "192.168.0.103:8890";
public static string userIP = "192.168.0.102";
[HideInInspector]
public NetMqListener _netMqListener;
[HideInInspector]
public NetMqPublisher _netMqPublisher;
private void Awake()
{
instance = this;
}
/// <summary>
/// 初始化Netmq
/// </summary>
/// <param name="reciveInMono">接收函数</param>
public void Init(string ServerSubIP,string ServerPubIP,string area, NetMqListener.ReciveMessageInThread reciveInthread, NetMqListener.ReceiceMessageInMono reciveInMono,string typename)
{
SubIP = ServerSubIP;
PubIP = ServerPubIP;
//开启接收模块
_netMqListener = new NetMqListener(ServerSubIP, area, reciveInthread, reciveInMono);
_netMqListener.typeName = typename;
//开启发送模块
_netMqPublisher = new NetMqPublisher(ServerPubIP);
_netMqPublisher.typeName = typename;
}
public void Send(string area,int type,byte[] data)
{
_netMqPublisher.AddMessageToSendQue(area, type, data);
}
public void Send(st_Motions st)
{
_netMqPublisher.AddMessageToSendQue(st);
}
private void Update()
{
if (_netMqListener != null)
{
_netMqListener.UpdateByte();
}
//测试
//if(Input.GetKeyDown(KeyCode.Space))
//{
// Send(LoadManage.Instance.currentPractice.RoomArea, 1000, new byte[5]);
//}
}
public void Destroy()
{
_netMqListener._listenerCancelled = true;
_netMqPublisher._listenerCancelled = true;
UnityEngine.Debug.Log("销毁xxxxx");
Destroy(this);
}
#region
/// <summary>
/// 调接口
/// </summary>
/// <param name="url"></param>
/// <param name="datas"></param>
/// <param name="back"></param>
/// <returns></returns>
public static IEnumerator CallPost(string url, KeyValuePair<string, string>[] datas, Action<string> back)
{
WWWForm form = new WWWForm();
for (int i = 0; i < datas.Length; i++)
{
form.AddField(datas[i].Key, datas[i].Value);
}
UnityWebRequest request = UnityWebRequest.Post(url, form);
yield return request.SendWebRequest();
if (request.isDone)
{
if (request.isHttpError || request.isNetworkError)
{
MessagePanel.ShowMessage("接口异常,isHttpError"+ request.isHttpError+ ".isNetworkError"+ request.isNetworkError, GameObject.FindObjectOfType<Canvas>().transform);
}
else
{
if (back != null)
{
back.Invoke(request.downloadHandler.text);
}
}
}
}
/// <summary>
/// 调接口
/// </summary>
/// <param name="url"></param>
/// <param name="back"></param>
/// <returns></returns>
public static IEnumerator CallGet(string url, Action<string> back)
{
UnityWebRequest request =UnityWebRequest.Get(url);
yield return request.SendWebRequest();
if (request.isDone)
{
if (request.isHttpError || request.isNetworkError)
{
MessagePanel.ShowMessage("接口异常+isHttpError"+ request.isHttpError+ ",isNetworkError"+ request.isNetworkError, GameObject.FindObjectOfType<Canvas>().transform);
}
else
{
if (back != null)
{
back.Invoke(request.downloadHandler.text);
}
}
}
}
public static IEnumerator GetFile(string url,Action<byte[]> back)
{
UnityWebRequest request = UnityWebRequest.Get(url);
yield return request.SendWebRequest();
if (request.isDone)
{
if (request.isHttpError || request.isNetworkError)
{
MessagePanel.ShowMessage("接口异常+isHttpError" + request.isHttpError + ",isNetworkError" + request.isNetworkError, GameObject.FindObjectOfType<Canvas>().transform);
}
else
{
if (back != null)
{
back.Invoke(request.downloadHandler.data);
}
}
}
}
/// <summary>
/// 调用web接口(PostUploadHandler)
/// </summary>
/// <param name="url"></param>
/// <param name="json">数据</param>
/// <param name="callback">回调</param>
/// <returns></returns>
public static IEnumerator InvokeWebPostByUploadhandler(string url, string json, Action<bool,string> callback)
{
byte[] uploadData = Encoding.UTF8.GetBytes(json);
UnityWebRequest webRequest = new UnityWebRequest(url, "POST");
webRequest.SetRequestHeader("accept", "*/*");
webRequest.SetRequestHeader("contentType", "application/json");
webRequest.downloadHandler = new DownloadHandlerBuffer();
webRequest.uploadHandler = new UploadHandlerRaw(uploadData);
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
{
callback(false,webRequest.error);
}
else
{
callback(true,webRequest.downloadHandler.text);
}
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="url"></param>
/// <param name="file"></param>
/// <param name="fileName"></param>
/// <param name="back"></param>
/// <returns></returns>
public static IEnumerator UpLoadFile(string url,byte[] file,string fileName,Action<CallResultObject> back)
{
WWWForm form = new WWWForm();
form.AddField("action", "Add");
form.AddField("saveName", fileName);
form.AddBinaryData("file", file);
UnityWebRequest request = UnityWebRequest.Post(url, form);
yield return request.SendWebRequest();
if (request.isDone)
{
if (request.isHttpError || request.isNetworkError)
{
MessagePanel.ShowMessage("接口异常,isHttpError" + request.isHttpError + ".isNetworkError" + request.isNetworkError, GameObject.FindObjectOfType<Canvas>().transform);
back(new CallResultObject { state = false });
}
else
{
if (back != null)
{
string str=request.downloadHandler.text;
CallResultObject co= LitJson.JsonMapper.ToObject<CallResultObject>(str);
back.Invoke(co);
}
}
}
else
{
back(new CallResultObject { state = false });
}
}
#endregion
}
/// <summary>
/// 消息体
/// </summary>
[Serializable]
public struct st_Motions
{
/// <summary>
/// 域
/// </summary>
public string area;
/// <summary>
/// 消息标识
/// </summary>
public int m_iOperaType;
/// <summary>
/// 消息内容byte[256]
/// </summary>
public byte[] m_sOperaData;
}
/// <summary>
/// 演习状态
/// </summary>
public enum ProgramState
{
,
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: a370c39ec00727e4ba3b391f3e7ea4ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More