public RPCInstanceCache(RuntimeTypeHandle messageInfoHandle)
 {
     _receiver          = RPCReceiver.Off;
     _observed          = null;
     _rpcs              = new System.Collections.Generic.Dictionary <string, RPCInstance>();
     _messageInfoHandle = messageInfoHandle;
 }
        public RPCInstance Find(Component source, RPCReceiver receiver, Component observed, GameObject[] listOfGameObjects, string rpcName)
        {
            if (_receiver != receiver || !_observed.ReferenceEquals(observed) || _observed.IsDestroyed())
            {
                _receiver = receiver;
                _observed = observed.IsNotDestroyed() ? observed : null;
                _rpcs.Clear();
            }

            RPCInstance rpc;

            if (!_rpcs.TryGetValue(rpcName, out rpc) || rpc.instance.IsNullOrDestroyed())
            {
                rpc            = new RPCInstance(source, receiver, observed as UnityEngine.MonoBehaviour, listOfGameObjects, rpcName, _messageInfoHandle);
                _rpcs[rpcName] = rpc;
            }

            return(rpc);
        }
コード例 #3
0
        public RPCInstance(Component source, RPCReceiver receiver, UnityEngine.MonoBehaviour observed, GameObject[] listOfGameObjects, string rpcName, RuntimeTypeHandle messageInfoHandle)
        {
            UnityEngine.MonoBehaviour[] components;

            switch (receiver)
            {
            case RPCReceiver.OnlyObservedComponent:                     // look only at the observed component if it is a MonoBehaviour
                components = !observed.IsNullOrDestroyed() ? new[] { observed } : new UnityEngine.MonoBehaviour[0];
                break;

            case RPCReceiver.ThisGameObject:                     // look at all MonoBehaviours in this gameobject
                components = source.GetComponents <UnityEngine.MonoBehaviour>();
                break;

            case RPCReceiver.ThisGameObjectAndChildren:                     // look at all MonoBehaviours in this gameobject and all MonoBehaviours in any of it's children
                components = source.GetComponentsInChildren <UnityEngine.MonoBehaviour>();
                break;

            case RPCReceiver.RootGameObjectAndChildren:                     // look at all MonoBehaviours in the root of this gameobject and down to any of it's children
                components = source.transform.root.GetComponentsInChildren <UnityEngine.MonoBehaviour>();
                break;

            case RPCReceiver.AllActiveGameObjects:                     // look at all active MonoBehaviours in the scene
                components = Object.FindObjectsOfType(typeof(UnityEngine.MonoBehaviour)) as UnityEngine.MonoBehaviour[];
                break;

            case RPCReceiver.GameObjects:
                components = GetComponents <UnityEngine.MonoBehaviour>(listOfGameObjects);
                break;

            default:
                //throw new NetworkException("Dropping RPC, case clause!");
                return;
            }

            _Initialize(source, components, rpcName, messageInfoHandle);
        }