You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
3.1 KiB
81 lines
3.1 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using AX.NetworkSystem; |
|
using AX.Serialization; |
|
using AX.Network.Protocols; |
|
using System; |
|
using System.Reflection; |
|
|
|
public class FIREDEPLOY_ENGINES_SYNC : NetworkMessageBehaviour |
|
{ |
|
protected override void Execute(BinaryMessage message) |
|
{ |
|
InputHistory.Instance.RegisterInputHistory(message); |
|
|
|
var info = message.Body.Deserialize<KeyValuePair<string, List<KeyValuePair<FireCarEngine, int>>>>(); |
|
|
|
FireEnginesData.Instance.AddDeptCar(info); |
|
|
|
//添加在途车辆 |
|
OnwayForceTotal.AddNewDeployedCar(info); |
|
|
|
if (GameSettings.othersSettings.mode == Mode.manoeuvre) |
|
{ |
|
if (!GameSettings.othersSettings.DisPlay_Arrive_Dic.ContainsKey(info.Key)) |
|
{ |
|
GameSettings.othersSettings.DisPlay_Arrive_Dic.Add(info.Key, false); |
|
} |
|
//把所有调派了的车辆添加到一个字典里 |
|
if (!GameSettings.othersSettings.DisCarList_Dic.ContainsKey(info.Key)) |
|
{ |
|
List<KeyValuePair<FireCarEngine, bool>> carlists = new List<KeyValuePair<FireCarEngine, bool>>(); |
|
List<KeyValuePair<FireCarEngine, int>> infovalue = info.Value; |
|
for (int i = 0; i < infovalue.Count; i++) |
|
{ |
|
FireCarEngine caroinfo = infovalue[i].Key; |
|
for (int j = 0; j < infovalue[i].Value; j++) |
|
{ |
|
FireCarEngine car = DeepCopyByReflection(caroinfo); |
|
carlists.Add(new KeyValuePair<FireCarEngine, bool>(car, false)); |
|
} |
|
} |
|
GameSettings.othersSettings.DisCarList_Dic.Add(info.Key, carlists); |
|
} |
|
else |
|
{ |
|
List<KeyValuePair<FireCarEngine, bool>> carlists = new List<KeyValuePair<FireCarEngine, bool>>(); |
|
List<KeyValuePair<FireCarEngine, int>> infovalue = info.Value; |
|
for (int i = 0; i < infovalue.Count; i++) |
|
{ |
|
for (int j = 0; j < infovalue[i].Value; j++) |
|
{ |
|
FireCarEngine car = DeepCopyByReflection(infovalue[i].Key); |
|
carlists.Add(new KeyValuePair<FireCarEngine, bool>(car, false)); |
|
} |
|
} |
|
GameSettings.othersSettings.DisCarList_Dic[info.Key].AddRange(carlists); |
|
} |
|
COMMANDCENTER_FIREMANNUM_SYNC.SetCar(); |
|
} |
|
|
|
} |
|
public static T DeepCopyByReflection<T>(T obj) |
|
{ |
|
if (obj is string || obj.GetType().IsValueType) |
|
return obj; |
|
|
|
object retval = Activator.CreateInstance(obj.GetType()); |
|
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); |
|
foreach (var field in fields) |
|
{ |
|
try |
|
{ |
|
field.SetValue(retval, DeepCopyByReflection(field.GetValue(obj))); |
|
} |
|
catch { } |
|
} |
|
|
|
return (T)retval; |
|
} |
|
}
|
|
|