示例#1
0
 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;
 }
示例#2
0
 void Start()
 {
     netView = GetComponent<NetView>();
     netView.OnWriteSync += WriteSync;
     netView.OnWriteProxyData += WriteProxyData;
     SetTargetPosition();
 }
示例#3
0
        void Start() {
            view = GetComponent<NetView>();
            view.Scope.OnOut += DisableAll;
            view.Scope.OnIn += EnableAll;

            CacheAllComponents();
        }
示例#4
0
        void Awake() {
            view = GetComponent<NetView>();
            inventory = GetComponent<Inventory>();
            catAnimator = GetComponentInChildren<CatAnimator>();

            view.OnReadInstantiateData += Instantiate;

            InputHandler.Instance.ListenToKeyDown(TryPickup, KeyBind.Code(Bind.Interact));
        }
示例#5
0
 /// <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);
         }
     }
 }
示例#6
0
        private void RegisterHit(Transform hitTarget)
        {
            NetView hitView = hitTarget.GetComponent <NetView>();

            if (hitView == null)
            {
                return;
            }
            if (!view.AmServer)
            {
                view.SendReliable("ReceiveHit", RpcTarget.Server, hitView.Id);
            }
        }
示例#7
0
    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;
    }
示例#8
0
    // 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);
    }
示例#9
0
        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));
        }
示例#10
0
        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));
        }
示例#11
0
        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);
        }
示例#12
0
    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;
    }
示例#13
0
    // =============================================================================



    // =============================================================================
    // 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);
        }
    }
示例#14
0
        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);
        }
示例#15
0
    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);
        }
示例#17
0
        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;
        }
示例#18
0
        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);
        }
示例#19
0
        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;
        }
示例#20
0
        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);
        }
示例#21
0
 private void Awake()
 {
     _controller = GetComponent <BaseController>();
     _view       = GetComponent <NetView>();
 }
示例#22
0
        private void Awake() {
            view = GetComponent<NetView>();

            view.Scope.DisableScopeCalculation();
            view.OnWriteProxyData += WriteInstantiateData;
        }
示例#23
0
 private void Awake()
 {
     _view           = GetComponent <NetView>();
     _actorRpc       = new ActorViewRpc(_view);
     _moveController = GetComponent <CharacterController>();
 }
示例#24
0
 private void Start()
 {
     player        = GetComponent <PlayerCreator>();
     view          = GetComponent <NetView>();
     formattedName = player.PlayerName.ToCharArray();
 }
示例#25
0
 private void Start()
 {
     view = GetComponent <NetView>();
 }
示例#26
0
 protected virtual void Awake()
 {
     _view = GetComponent <NetView>();
 }
示例#27
0
 void Awake()
 {
     chaser        = GetComponent <AggroChaser>();
     view          = GetComponent <NetView>();
     attackChecker = GetComponent <AttackChecker>();
 }
示例#28
0
    protected override void Awake()
    {
        base.Awake();

        _view = GetComponent <NetView>();
    }
示例#29
0
 public ActorViewRpc(NetView view, TimeSpan?timeout = null)
     : base(NetClientGlobal.Instance.Client, new NetViewRequestWaiter(view), timeout)
 {
     DeliveryMethod = DeliveryMethod.Unreliable;
     DeliveryTarget = DeliveryTarget.Others;
 }
示例#30
0
        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.");
        }
示例#31
0
 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";
 }
示例#32
0
        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;
        }
示例#33
0
 /// <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;
     }
 }
示例#34
0
        /// <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);
        }
示例#35
0
        /// <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;
        }
示例#36
0
 void Awake()
 {
     view      = GetComponent <NetView>();
     character = GetComponent <Character>();
 }
示例#37
0
 void Start() {
     netView = GetComponent<NetView>();
     netView.OnWriteSync += WriteSync;
 }
示例#38
0
 private void TriggerTakeHit(NetView from, int damage) {
     if (OnTakeDamage != null) OnTakeDamage(from, damage);
 }
示例#39
0
 private void Awake()
 {
     view = GetComponent <NetView>();
     view.OnReadInstantiateData += ReadInstantiateData;
 }
示例#40
0
 void Awake() {
     view = GetComponent<NetView>();
     view.OnReadInstantiateData += Instantiate;
 }
示例#41
0
 // for override
 protected void DoTrigger()
 {
     //NetView.RPC ( "RPCDoTrigger", RPCMode.AllBuffered );
     NetView.RPC("RPCDoTrigger", RPCMode.All);
 }
示例#42
0
 private void OnNetViewCreated(NetView view)
 {
     Debug.Log(view.name + " created");
 }
示例#43
0
 void Awake() {
     chaser = GetComponent<AggroChaser>();
     view = GetComponent<NetView>();
     attackChecker = GetComponent<AttackChecker>();
 }
示例#44
0
 void TakePlayerDamage(NetView attackerView, int damage) {
     if (Dead) return;
     currentHealth -= damage;
     if (Dead) Die();
 }
示例#45
0
 void Awake()
 {
     view             = GetComponent <NetView>();
     view.OnReadSync += ReadSync;
 }
示例#46
0
 void Awake() {
     view = GetComponent<NetView>();
     view.OnReadSync += ReadSync;
 }
示例#47
0
 private void Awake() {
     view = GetComponent<NetView>();
     view.OnReadInstantiateData += ReadInstantiateData;
     view.OnReadSync += ReadSync;
 }
示例#48
0
 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);
 }
示例#49
0
        /// <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);
        }
示例#50
0
 public bool TryGetView(int viewId, out NetView foundView) {
     if (ViewLookup.ContainsKey(viewId)) {
         foundView = ViewLookup[viewId];
         return true;
     }
     foundView = null;
     return false;
 }
示例#51
0
 void Awake()
 {
     view      = GetComponent <NetView>();
     character = GetComponent <Character>();
     limbsCam  = GameObject.Find("LimbsCamera").GetComponent <CameraFollow>();
 }
示例#52
0
        /// <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);
            }
        }
示例#53
0
 void Start()
 {
     netView              = GetComponent <NetView>();
     netView.OnWriteSync += WriteSync;
 }
示例#54
0
        /// <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;
        }
示例#55
0
 private void Start() {
     view = GetComponent<NetView>();
 }
示例#56
0
 private void Start() {
     player = GetComponent<PlayerCreator>();
     view = GetComponent<NetView>();
     formattedName = player.PlayerName.ToCharArray();
 }
示例#57
0
 void Start()
 {
     netView              = transform.parent.GetComponent <NetView>();
     netView.OnWriteSync += WriteSync;
 }
示例#58
0
 private void Awake()
 {
     _view          = GetComponent <NetView>();
     _actorScaleRpc = new ActorScaleRpc(_view);
 }