/// <summary> Add a async operation to manage. Can optionally provide a callback to be called once the operation is /// finished. </summary> /// <param name="operation"> the operation to manage </param> /// <param name="resolvable"> optional parameter, if not null, will be called after finish executing </param> /// <exception cref="ArgumentNullException"> <paramref name="operation" /> is null </exception> public static ITask <T> AddOperation <T>(T operation) { Argument.NotNull(operation); _operations.Add(operation); var task = new Task <T>(); EngineHook.StartCoroutine(Wait(operation, task)); return(task); }
private void ProcessUtils(NetIncomingMessage msg) { var utilId = msg.ReadByte(); if (utilId == RPCUtils.TimeUpdate) { throw new NotImplementedException("RPCUtils.TimeUpdate"); } else if (utilId == RPCUtils.Instantiate) { //read the path... var resourcePath = msg.ReadString(); var viewId = NetworkViewId.Deserialize(msg); var ownerId = msg.ReadUInt16(); var position = new Vector3(); position.OnDeserialize(msg); var rotation = new Quaternion(); rotation.OnDeserialize(msg); var view = NetworkViewManager.Create(viewId, ownerId); try { EngineHook.Instantiate(resourcePath, view, position, rotation); } catch (Exception e) { Debug.LogError(this, "[EngineHook.Instantiate] {0}", e); } Debug.Log(this, "Created {0}", view); view.DoOnFinishedCreation(); FinishedInstantiate(viewId); } else if (utilId == RPCUtils.Remove) { var viewId = new NetworkViewId(); viewId.OnDeserialize(msg); byte reasonCode; if (!msg.ReadByte(out reasonCode)) { reasonCode = 0; } NetworkView find; if (NetworkViewManager.Find(viewId, out find)) { find.DoOnRemove(reasonCode); } else { Debug.LogError(this, "Attempted to remove {0}, but it could not be found", viewId); } } else if (utilId == RPCUtils.ChangeRoom) { var newRoom = msg.ReadString(); Debug.LogInfo(this, "Changing to room {0}", newRoom); if (OnRoomChange != null) { try { OnRoomChange(newRoom); } catch (Exception e) { Debug.LogError(this, "[OnChangeRoom] {0}", e); } } if (Configuration.DeleteNetworkInstantiatesOnRoomChange) { NetworkViewManager.DestroyAllViews(); } } else if (utilId == RPCUtils.AddView) { var addToId = NetworkViewId.Deserialize(msg); var idToAdd = NetworkViewId.Deserialize(msg); string customFunction; msg.ReadString(out customFunction); NetworkView view; if (NetworkViewManager.Find(addToId, out view)) { var newView = NetworkViewManager.Create(idToAdd, view.OwnerId); try { EngineHook.AddNetworkView(view, newView, customFunction); } catch (Exception e) { Debug.LogError(this, "[EngineHook.AddNetworkView] {0}", e); } } else { Debug.LogError(this, "Attempted to add a network view to id {0}, but it could not be found"); } } else if (utilId == RPCUtils.SetPlayerId) { var playerId = msg.ReadUInt16(); PlayerId = playerId; Debug.LogInfo(this, "Setting player id to " + playerId); } }