internal static void Init() { GsSerializer.OnNewEventHandler += OnNewEventHandler; GsSerializer.OnNewSnapShotReceived += OnNewSnapShotReceived; GsSerializer.CurrentPlayerLeftRoom += CurrentPlayerLeftRoom; GsSerializer.CurrentPlayerJoinRoom += CurrentPlayerJoinRoom; RealTimeEventHandlers.JoinedRoom += JoinedRoom; RealTimeEventHandlers.LeftRoom += LeftRoom; RealTimeEventHandlers.RoomMembersDetailReceived += RoomMembersDetailReceived; _monoBehaviourHandler = new MonoBehaviourHandler(); _prefabHandler = new PrefabHandler(); _functionHandler = new FunctionHandler(); _propertyHandler = new PropertyHandler(); _memberHandler = new MemberHandler(); _monoBehaviourHandler.Init(); _memberHandler.Init(); _propertyHandler.Init(_memberHandler); TypeUtil.Init(); ObjectUtil.Init(); IsAvailable = true; }
internal static void ApplySnapShot(IEnumerable <SnapShotData> data, IPrefabHandler handler = null, IMonoBehaviourHandler monoBehaviourHandler = null, IPropertyHandler propertyHandler = null) { foreach (var shotData in data) { switch (shotData.Type) { case SnapShotType.Function: ApplyFunction(shotData.Buffer, monoBehaviourHandler: monoBehaviourHandler); break; case SnapShotType.Object: ApplyObject((byte)ObjectActions.Instantiate, shotData.Buffer, shotData.OwnerId, handler); break; case SnapShotType.MemberProperty: ApplyProperty((byte)PropertyAction.SetOrUpdateMemberProperty, shotData.Buffer, shotData.OwnerId, propertyHandler); break; case SnapShotType.RoomProperty: ApplyProperty((byte)PropertyAction.SetOrUpdateRoomProperty, shotData.Buffer, shotData.OwnerId, propertyHandler); break; default: throw new GameServiceException("Invalid SnapShot Type!"); } } }
internal static void ApplyData(Types types, string ownerId, byte[] subCaller, byte[] extra, IPrefabHandler handler = null, IMonoBehaviourHandler monoBehaviourHandler = null, IPropertyHandler propertyHandler = null) { switch (types) { case Types.ObserverActions: ApplyTransform(subCaller[1], ownerId, extra); break; case Types.ObjectsActions: ApplyObject(subCaller[1], extra, ownerId, handler); break; case Types.RunFunction: ApplyFunction(extra, monoBehaviourHandler: monoBehaviourHandler); break; case Types.Property: ApplyProperty(subCaller[1], extra, ownerId, propertyHandler); break; default: throw new ArgumentOutOfRangeException(nameof(types), types, null); } }
internal static void ApplyFunction(byte[] buffer = null, FunctionData functionData = null, IMonoBehaviourHandler monoBehaviourHandler = null) { var func = functionData; object[] parameters = null; if (func == null && buffer != null) { func = new FunctionData(); GsSerializer.Object.CallReadStream(func, buffer); } var haveBuffer = func.ExtraData != null; if (haveBuffer) { parameters = GsSerializer.Function.DeserializeParams(func.ExtraData); } monoBehaviourHandler.RefreshMonoBehaviourCache(); var(baseObj, info) = ObjectUtil.GetFunction(func.MethodName, func.FullName, parameters); info.Invoke(baseObj, parameters); }