void Awake() { view = GetComponent<NetView>(); // Note: Always register OnReadInstantiateData delegate in Awake // OnReadInstantiateData is called immediately after a View is created, so registering // in Start instead of Awake means you might miss out on the instantiate data. view.OnReadInstantiateData += Instantiate; }
void Start() { netView = GetComponent<NetView>(); netView.OnWriteSync += WriteSync; netView.OnWriteProxyData += WriteProxyData; SetTargetPosition(); }
void Start() { view = GetComponent<NetView>(); view.Scope.OnOut += DisableAll; view.Scope.OnIn += EnableAll; CacheAllComponents(); }
void Awake() { view = GetComponent<NetView>(); inventory = GetComponent<Inventory>(); catAnimator = GetComponentInChildren<CatAnimator>(); view.OnReadInstantiateData += Instantiate; InputHandler.Instance.ListenToKeyDown(TryPickup, KeyBind.Code(Bind.Interact)); }
/// <summary> Calculates scope for every connection against the provided view's scope. /// This is useful, for example, when creating a new view so that it can be immediately /// instantiated since a delay may be undesireable. </summary> internal void FullScopeCalculation(NetView view) { if (view.Server != Socket.Self) return; for (int i = 0; i < Socket.Connections.Count; i++) { NetConnection connection = Socket.Connections[i]; if (connection.IsServer || !connection.HasScope) continue; if (view.IsController(connection)) { view.SendInstantiateData(connection); } else if (connection.InGroup(view.Group) && view.CanInstantiateFor(connection) && UpdateScope(connection.Scope, view)) { view.SendInstantiateData(connection); } } }
private void RegisterHit(Transform hitTarget) { NetView hitView = hitTarget.GetComponent <NetView>(); if (hitView == null) { return; } if (!view.AmServer) { view.SendReliable("ReceiveHit", RpcTarget.Server, hitView.Id); } }
void Awake() { view = GetComponent <NetView>(); character = GetComponent <Character>(); character.id = IDManager.GenerateId(); view.OnWriteProxyData += OnWriteInstantiate; view.OnWriteCreatorData += OnWriteInstantiate; view.OnWritePeerData += OnWriteInstantiate; view.OnWriteSync += OnWriteSync; view.OnReadInstantiateData += OnReadInstantiate; }
// this design is stupid, but calling "yield StartCoroutine(Animate())" in DoTrigger() doesn't work private IEnumerator YieldDoTrigger() { if (TakeAnimationLength > 0) { //dan //TODO //yield StartCoroutine(Animate()); yield return(StartCoroutine(Animate())); } EquipManager.Take(LinkedEquipment); NetView.RPC("RPCDoTrigger", RPCMode.AllBuffered); }
private void Start() { cam = Camera.main; cam.transform.parent = transform; cam.transform.position = transform.position + camOffset; netView = GetComponent<NetView>(); InputHandler.Instance.ListenToKey(RotateLeft, KeyBind.Code(Bind.Left)); InputHandler.Instance.ListenToKey(RotateRight, KeyBind.Code(Bind.Right)); InputHandler.Instance.ListenToKey(GoForward, KeyBind.Code(Bind.Forward)); InputHandler.Instance.ListenToKey(GoBackward, KeyBind.Code(Bind.Backward)); InputHandler.Instance.ListenToKeyDown(Jump, KeyBind.Code(Bind.Jump)); }
private void Start() { cam = Camera.main; cam.transform.parent = transform; cam.transform.position = transform.position + camOffset; netView = GetComponent <NetView>(); InputHandler.Instance.ListenToKey(RotateLeft, KeyBind.Code(Bind.Left)); InputHandler.Instance.ListenToKey(RotateRight, KeyBind.Code(Bind.Right)); InputHandler.Instance.ListenToKey(GoForward, KeyBind.Code(Bind.Forward)); InputHandler.Instance.ListenToKey(GoBackward, KeyBind.Code(Bind.Backward)); InputHandler.Instance.ListenToKeyDown(Jump, KeyBind.Code(Bind.Jump)); }
private void Start() { view = GetComponent<NetView>(); TextMesh[] textMeshes = GetComponentsInChildren<TextMesh>(); foreach (var tm in textMeshes) { if (tm.name != "ChatInput") continue; chatInput = tm; break; } chatClient = GetComponentInChildren<ChatClient>(); InputHandler.Instance.ListenToKeyDown(CloseChat, KeyCode.Escape); InputHandler.Instance.ListenToKeyDown(OpenOrSend, KeyCode.Return); InputHandler.Instance.ListenToKeyDown(Backspace, KeyCode.Backspace); InputHandler.Instance.ListenToKey(BackspaceHold, KeyCode.Backspace); InputHandler.Instance.ListenToKeyDown(OpenReply, KeyCode.R); }
void Awake() { cc = GetComponent <CharacterController>(); anim = GetComponentInChildren <Animator>(); view = GetComponent <NetView>(); maxStats = new CharStats(1f); currentStats = new CharStats(maxStats); currentStats.movtSpd = 250f; maxEquipStats = new EquipStats(1f); currentEquipStats = new EquipStats(maxEquipStats); canMove = true; canCast = true; primaryWeapType = WeaponType.unarmed; }
// ============================================================================= // ============================================================================= // METHODS --------------------------------------------------------------------- protected new void DoTrigger() { // StatusLast should not be reset on server // because focus still on FirePort but Highlighting should be off during measurement bool last = statusLast; NetView.RPC("RPCSetStatus", RPCMode.AllBuffered, false); statusLast = last; if (MeasurenentMeter.IsEquipped()) { MeasurenentMeter.MeasureValues(gameObject.name, transform); } else if (Extinguisher.IsEquipped()) { Extinguisher.Extinguish(transform); } }
public async Task <bool> Invoke(object _target_, NetDataReader _reader_, NetDataWriter _writer_) { NetView _view_ = _target_ as NetView; var typeEnum = (IActorScaleRpc_Enum)_reader_.ReadInt32(); switch (typeEnum) { case IActorScaleRpc_Enum.OnSetScale: { var scale = _reader_.ReadVector3(); await _view_.FindRpcHandler <IActorScaleRpc>().OnSetScale(scale); } break; default: return(false); } return(true); }
void Awake() { View = GetComponent <NetView>(); inventory = GetComponent <Inventory>(); equipment = GetComponent <Equipment>(); character = GetComponent <Character>(); character.id = IDManager.GenerateId(); inventory.OnItemAdd += OnItemAdded; inventory.OnItemRemove += OnItemRemoved; equipment.OnEquip += OnEquipped; View.OnWriteOwnerData += WriteOwnerData; View.OnWriteProxyData += WriteInstantiateData; View.OnWritePeerData += WriteInstantiateData; View.OnWriteCreatorData += WriteOwnerData; View.OnReadInstantiateData += ReadInstantiateData; }
public async Task <bool> Invoke(object _target_, NetDataReader _reader_, NetDataWriter _writer_) { NetView _view_ = _target_ as NetView; var typeEnum = (IActorViewRpc_Enum)_reader_.ReadInt32(); switch (typeEnum) { case IActorViewRpc_Enum.OnSetMoveDirection: { var x = _reader_.ReadSingle(); var y = _reader_.ReadSingle(); await _view_.FindRpcHandler <IActorViewRpc>().OnSetMoveDirection(x, y); } break; default: return(false); } return(true); }
void Awake() { view = GetComponent<NetView>(); view.OnWriteSync += WriteSync; view.OnReadSync += ReadSync; // A different method is often used for different instantiate level // For example, Owner might need to know what's in their inventory // but Proxy shouldn't know that information, so OnWriteOwnerData // and OnWriteProxy data would be different. In this case, however, // we only write position, so the same method is used for all. // // Omitting a handler for any OnWrite___Data event will mean a View // will never be instantiated in that manner. For example, if we exempt // OnWriteProxyData, the View will never be instantiated as a Proxy. view.OnWriteOwnerData += WriteInstantiateData; view.OnWriteProxyData += WriteInstantiateData; view.OnWritePeerData += WriteInstantiateData; view.OnWriteCreatorData += WriteInstantiateData; view.OnReadInstantiateData += ReadInstantiateData; }
private void Start() { view = GetComponent <NetView>(); TextMesh[] textMeshes = GetComponentsInChildren <TextMesh>(); foreach (var tm in textMeshes) { if (tm.name != "ChatInput") { continue; } chatInput = tm; break; } chatClient = GetComponentInChildren <ChatClient>(); InputHandler.Instance.ListenToKeyDown(CloseChat, KeyCode.Escape); InputHandler.Instance.ListenToKeyDown(OpenOrSend, KeyCode.Return); InputHandler.Instance.ListenToKeyDown(Backspace, KeyCode.Backspace); InputHandler.Instance.ListenToKey(BackspaceHold, KeyCode.Backspace); InputHandler.Instance.ListenToKeyDown(OpenReply, KeyCode.R); }
void Awake() { view = GetComponent <NetView>(); view.OnWriteSync += WriteSync; view.OnReadSync += ReadSync; // A different method is often used for different instantiate level // For example, Owner might need to know what's in their inventory // but Proxy shouldn't know that information, so OnWriteOwnerData // and OnWriteProxy data would be different. In this case, however, // we only write position, so the same method is used for all. // // Omitting a handler for any OnWrite___Data event will mean a View // will never be instantiated in that manner. For example, if we exempt // OnWriteProxyData, the View will never be instantiated as a Proxy. view.OnWriteOwnerData += WriteInstantiateData; view.OnWriteProxyData += WriteInstantiateData; view.OnWritePeerData += WriteInstantiateData; view.OnWriteCreatorData += WriteInstantiateData; view.OnReadInstantiateData += ReadInstantiateData; }
private void ReceiveWhisperInput(string targetName, char[] input) { if (!CanSend() || !InputValid(input)) { return; } if (!InputValidator.LowercaseOnly(targetName)) { return; } if (player.PlayerName == targetName) { return; } if (!PlayerCreator.Players.ContainsKey(targetName)) { view.SendReliable("ReceiveWhisperFailed", RpcTarget.Controllers); return; } NetView playerView = PlayerCreator.Players[targetName].View; playerView.SendReliable("ReceiveWhisperMessage", RpcTarget.Controllers, player.PlayerName, input); view.SendReliable("ReceiveDeliveredWhisper", RpcTarget.Controllers, targetName, input); }
private void Awake() { _controller = GetComponent <BaseController>(); _view = GetComponent <NetView>(); }
private void Awake() { view = GetComponent<NetView>(); view.Scope.DisableScopeCalculation(); view.OnWriteProxyData += WriteInstantiateData; }
private void Awake() { _view = GetComponent <NetView>(); _actorRpc = new ActorViewRpc(_view); _moveController = GetComponent <CharacterController>(); }
private void Start() { player = GetComponent <PlayerCreator>(); view = GetComponent <NetView>(); formattedName = player.PlayerName.ToCharArray(); }
private void Start() { view = GetComponent <NetView>(); }
protected virtual void Awake() { _view = GetComponent <NetView>(); }
void Awake() { chaser = GetComponent <AggroChaser>(); view = GetComponent <NetView>(); attackChecker = GetComponent <AttackChecker>(); }
protected override void Awake() { base.Awake(); _view = GetComponent <NetView>(); }
public ActorViewRpc(NetView view, TimeSpan?timeout = null) : base(NetClientGlobal.Instance.Client, new NetViewRequestWaiter(view), timeout) { DeliveryMethod = DeliveryMethod.Unreliable; DeliveryTarget = DeliveryTarget.Others; }
private NetView InstantiateView(string prefabRoot, NetView.Relation relation) { var viewObject = InstantiatePrefab != null ? InstantiatePrefab(prefabRoot, relation) : (GameObject)Instantiate(Resources.Load(Prefab(prefabRoot, relation))); var view = viewObject.GetComponent<NetView>(); if (view != null) return view; Destroy(viewObject); throw new Exception("Prefab does not have a NetView component attached."); }
private static string Prefab(string prefabRoot, NetView.Relation relation) { if (relation == NetView.Relation.Creator) return prefabRoot + "@Creator"; if (relation == NetView.Relation.Owner) return prefabRoot + "@Owner"; if (relation == NetView.Relation.Peer) return prefabRoot + "@Peer"; return prefabRoot + "@Proxy"; }
private NetView CreateView(NetConnection controller, NetConnection server, int viewId, int group, string prefabRoot, NetView.Relation relation) { NetView view = null; if (ViewLookup.ContainsKey(viewId)) { NetView oldView = ViewLookup[viewId]; if (oldView.CurrentRelation == relation) { view = oldView; } else if (server == Socket.Self) { NetScope oldScope = oldView.Scope; Vector3 oldPos = oldView.transform.position; if (oldView.Server != server) SendChangeViewServer(viewId); DestroyView(oldView); view = InstantiateView(prefabRoot, relation); view.InternalScope = oldScope; view.transform.position = oldPos; } } if (view == null) view = InstantiateView(prefabRoot, relation); view.Server = server; view.Id = viewId; view.PrefabRoot = prefabRoot; view.Group = group; view.CurrentRelation = relation; if (controller != null) { view.AddController(controller); controller.AddAuthorization(view.Id); controller.AddToGroup(group); if (controller != Socket.Self) { controller.View = view; if (controller.InternalScope != null && view.Controllers.Count == 1) { view.InternalScope = controller.InternalScope; } controller.InternalScope = null; } } view.Scope.FireInEvent(); RegisterNetView(view); return view; }
/// <summary> Sends an RPC to connections that are in-scope for the provided view. </summary> internal void Send(NetView view, NetMessage netMessage, RpcTarget target) { switch (target) { case (RpcTarget.All): for (int i = 0; i < Socket.Connections.Count; i++) { var connection = Socket.Connections[i]; if (!connection.HasScope) continue; if (view.Group != 0 && !connection.InGroup(view.Group)) continue; if ((netMessage.Reliable && connection.Scope.In(view.Id)) || connection.Scope.In(view.Id, syncFrame) || view.IsController(connection)) connection.Send(netMessage); } break; case (RpcTarget.Controllers): foreach (NetConnection controller in view.Controllers) { if (controller == Socket.Self) continue; controller.Send(netMessage); } break; case (RpcTarget.NonControllers): for (int i = 0; i < Socket.Connections.Count; i++) { var connection = Socket.Connections[i]; if (connection.IsServer || !connection.HasScope) continue; if (view.IsController(connection)) continue; if (view.Group != 0 && !connection.InGroup(view.Group)) continue; if ((netMessage.Reliable && connection.Scope.In(view.Id)) || connection.Scope.In(view.Id, syncFrame)) connection.Send(netMessage); } break; case (RpcTarget.Server): if (view.Server != Socket.Self) view.Server.Send(netMessage); else NetLog.Warning("Trying to send message to self."); break; case (RpcTarget.AllInclOutOfScope): for (int i = 0; i < Socket.Connections.Count; i++) { var connection = Socket.Connections[i]; if (view.Group != 0 && !connection.InGroup(view.Group)) continue; connection.Send(netMessage); } break; } }
/// <summary> Post-instantiation configuration of NetView. </summary> private void RegisterNetView(NetView view) { if (view.CachedRpcObjects == null) view.SetRpcCache(RpcInfoCache.CreateInstanceLookup(view.gameObject)); view.Scope.Trans = view.gameObject.transform; view.Socket = Socket; view.ViewManager = this; if (!ViewLookup.ContainsKey(view.Id)) ViewLookup.Add(view.Id, view); if (!Views.Contains(view)) Views.Add(view); }
/// <summary> The provided scope is updated if the provided view has gone in or out of scope. /// False is returned if there is no change. </summary> internal bool UpdateScope(NetScope source, NetView view) { bool scopeChanged = false; float distance = Vector3.Distance(source.Position, view.Scope.Position); // If the source scope is configured to override, use its scope distances instead: var rulesScope = source.TakePrecedence ? source : view.Scope; if (view.Scope.CalcDisabled || distance > rulesScope.OutScopeDist) { if (!source.In(view.Id)) return false; scopeChanged = true; source.SetOut(view.Id); } else if (distance < rulesScope.InScopeDist) { if (!source.In(view.Id)) scopeChanged = true; if (distance < rulesScope.LevelOne) source.SetIn(view.Id, 1); else if (distance < rulesScope.LevelTwo) source.SetIn(view.Id, 2); else source.SetIn(view.Id, 3); } return scopeChanged; }
void Awake() { view = GetComponent <NetView>(); character = GetComponent <Character>(); }
void Start() { netView = GetComponent<NetView>(); netView.OnWriteSync += WriteSync; }
private void TriggerTakeHit(NetView from, int damage) { if (OnTakeDamage != null) OnTakeDamage(from, damage); }
private void Awake() { view = GetComponent <NetView>(); view.OnReadInstantiateData += ReadInstantiateData; }
void Awake() { view = GetComponent<NetView>(); view.OnReadInstantiateData += Instantiate; }
// for override protected void DoTrigger() { //NetView.RPC ( "RPCDoTrigger", RPCMode.AllBuffered ); NetView.RPC("RPCDoTrigger", RPCMode.All); }
private void OnNetViewCreated(NetView view) { Debug.Log(view.name + " created"); }
void Awake() { chaser = GetComponent<AggroChaser>(); view = GetComponent<NetView>(); attackChecker = GetComponent<AttackChecker>(); }
void TakePlayerDamage(NetView attackerView, int damage) { if (Dead) return; currentHealth -= damage; if (Dead) Die(); }
void Awake() { view = GetComponent <NetView>(); view.OnReadSync += ReadSync; }
void Awake() { view = GetComponent<NetView>(); view.OnReadSync += ReadSync; }
private void Awake() { view = GetComponent<NetView>(); view.OnReadInstantiateData += ReadInstantiateData; view.OnReadSync += ReadSync; }
private void StartHandoff(NetView view, NetZone peer) { view.SendCreatorData(peer.Server); view.Server = peer.Server; foreach (NetConnection connection in view.Controllers) { if (connection.View == view) connection.InternalScope = view.Scope; } ViewManager.DestroyView(view); }
/// <summary> Called by the server to destroy a NetView across the network. </summary> public void DestroyView(NetView view) { if (view.Server == Socket.Self) SendDestroyView(view); if (view.Controllers.Count != 0) { foreach (NetConnection connection in view.Controllers) { connection.RemoveAuthorization(view.Id); } } ViewLookup.Remove(view.Id); Views.Remove(view); if (DestroyViewObject != null) DestroyViewObject(view.gameObject); else Destroy(view.gameObject); }
public bool TryGetView(int viewId, out NetView foundView) { if (ViewLookup.ContainsKey(viewId)) { foundView = ViewLookup[viewId]; return true; } foundView = null; return false; }
void Awake() { view = GetComponent <NetView>(); character = GetComponent <Character>(); limbsCam = GameObject.Find("LimbsCamera").GetComponent <CameraFollow>(); }
/// <summary> Sends command to all connected clients to destroy the provided view. </summary> private void SendDestroyView(NetView view) { var destroyViewMessage = NetMessage.Create((ushort)ViewCmd.DestroyView, 0, 1, true); destroyViewMessage.Parameters[0] = view.Id; for (int i = 0; i < Socket.Connections.Count; i++) { var connection = Socket.Connections[i]; if (connection.IsServer) continue; if (view.Group == 0 || connection.InGroup(view.Group)) connection.Send(destroyViewMessage); } }
void Start() { netView = GetComponent <NetView>(); netView.OnWriteSync += WriteSync; }
/// <summary> /// Returns the connection that matches the supplied target. /// Returns the server for Server or the first controller for Controllers. /// </summary> internal NetConnection GetTarget(RpcTarget target, NetView view) { switch (target) { case RpcTarget.Server: return view.Server; case RpcTarget.Controllers: return view.Controllers[0]; } NetLog.Error("Invalid RpcTarget for GetTarget. Only RpcTarget.Server or RpcTarget.Controllers can be used."); return null; }
private void Start() { view = GetComponent<NetView>(); }
private void Start() { player = GetComponent<PlayerCreator>(); view = GetComponent<NetView>(); formattedName = player.PlayerName.ToCharArray(); }
void Start() { netView = transform.parent.GetComponent <NetView>(); netView.OnWriteSync += WriteSync; }
private void Awake() { _view = GetComponent <NetView>(); _actorScaleRpc = new ActorScaleRpc(_view); }