Example #1
0
 private void OnDisable()
 {
     if (this.local && !base.destroying && !NetInstance.IsCurrentlyDestroying(this))
     {
         Debug.LogWarning("The local player got disabled", this);
     }
 }
Example #2
0
        public override void InvokeMethod(NetMethodInfo methodInfo, NetInstance target, NetVariantVector parameters,
                                          NetVariant result)
        {
            var handle = (GCHandle)target.GetGCHandle();
            var o      = handle.Target;

            List <object> methodParameters = null;

            if (parameters.Count > 0)
            {
                methodParameters = new List <object>();
                foreach (var parameterInstance in parameters)
                {
                    object v = null;
                    Unpackvalue(ref v, parameterInstance);
                    methodParameters.Add(v);
                }
            }

            var r = o.GetType()
                    .GetMethod(methodInfo.GetMethodName(), BindingFlags.Instance | BindingFlags.Public)
                    .Invoke(o, methodParameters?.ToArray());

            if (result == null)
            {
                // this method doesn't have return type
            }
            else
            {
                PackValue(ref r, result);
            }
        }
Example #3
0
    private bool ShouldDoStandardInitialization(NetInstance instance)
    {
        bool flag;

        UnityEngine.Object obj2 = this._customInstantiator;
        try
        {
            this._customInstantiator = instance;
            if (instance.args.hasCustomInstantiator)
            {
                try
                {
                    return(instance.args.customInstantiate.InitializePrefabInstance(instance));
                }
                catch (Exception exception)
                {
                    object[] args = new object[] { instance.args.customInstantiate, this, instance.args.prefab, exception };
                    Debug.LogError(string.Format("A exception was thrown during InitializePrefabInstance with '{0}' as custom instantiate, prefab '{1}' instance '{2}'.\r\ndoing standard initialization..\r\n{3}", args), instance);
                }
            }
            flag = true;
        }
        finally
        {
            this._customInstantiator = obj2;
        }
        return(flag);
    }
Example #4
0
    private NetworkView Create(ref CustomInstantiationArgs args, out IDMain instance)
    {
        NetworkView view3;

        if ((float.IsNaN(args.position.x) || float.IsNaN(args.position.y)) || float.IsNaN(args.position.z))
        {
            Debug.LogWarning("NetMainPrefab -> Create -  args.position = " + args.position);
            Debug.LogWarning("This means you're creating an object with a bad position!");
        }
        NetInstance instance2 = _currentNetInstance;

        try
        {
            _currentNetInstance = null;
            if (args.hasCustomInstantiator)
            {
                NetworkView networkView;
                instance = null;
                try
                {
                    instance = args.customInstantiate.CustomInstantiatePrefab(ref args);
                }
                catch (Exception exception)
                {
                    Debug.LogError(string.Format("Thrown Exception during custom instantiate via '{0}' with instantiation '{2}'\r\ndefault instantiation will now occur --  exception follows..\r\n{1}", args.customInstantiate, exception, this), this);
                    if (instance != null)
                    {
                        Object.Destroy(instance);
                    }
                    instance = null;
                }
                try
                {
                    networkView = instance.networkView;
                    if (networkView == null)
                    {
                        Debug.LogWarning(string.Format("The custom instantiator '{0}' with instantiation '{1}' did not return a idmain with a network view. so its being added", args.customInstantiate, this), this);
                        networkView = instance.gameObject.AddComponent <uLinkNetworkView>();
                    }
                }
                catch (Exception exception2)
                {
                    networkView = null;
                    Debug.LogError(string.Format("The custom instantiator '{0}' did not instantiate a IDMain with a networkview or something else with instantiation '{2}'.. \r\n {1}", args.customInstantiate, exception2, this), this);
                }
                if (networkView != null)
                {
                    return(networkView);
                }
            }
            NetworkView view2 = (NetworkView)NetworkInstantiatorUtility.Instantiate(args.prefabNetworkView, args.args);
            instance = view2.GetComponent <IDMain>();
            view3    = view2;
        }
        finally
        {
            _currentNetInstance = instance2;
        }
        return(view3);
    }
Example #5
0
        /// <summary>创建一个工作流网实例</summary>
        /// <param name="workflowDef"></param>
        /// <returns></returns>
        public INetInstance createNetInstance(WorkflowDefinition workflowDef)
        {
            if (workflowDef == null)
            {
                return(null);
            }
            WorkflowProcess workflowProcess = null;

            workflowProcess = workflowDef.getWorkflowProcess();//解析fpdl

            //Map nodeInstanceMap = new HashMap();
            if (workflowProcess == null)
            {
                throw new KernelException(null, null, "The WorkflowProcess property of WorkflowDefinition[processId=" + workflowDef.ProcessId + "] is null. ");
            }
            String validateMsg = workflowProcess.validate();//校验工作流定义是否有效

            if (validateMsg != null)
            {
                throw new KernelException(null, null, validateMsg);
            }
            NetInstance netInstance = new NetInstance(workflowProcess, KernelExtensions);

            //netInstance.setWorkflowProcess(workflowProcess);
            netInstance.Version = workflowDef.Version;//设置版本号
            //map的key的组成规则:流程定义ID_V_版本号
            netInstanceMap.Add(workflowDef.ProcessId + "_V_" + workflowDef.Version, netInstance);

            //netInstance.setRtCxt(new RuntimeContext());
            return(netInstance);
        }
Example #6
0
 protected virtual void StandardInitialization(bool didAppend, IDRemote appended, NetInstance instance, Facepunch.NetworkView view, ref uLink.NetworkMessageInfo info)
 {
     if (didAppend)
     {
         IssueLocallyAppended(appended, instance.idMain);
     }
     if (this.ShouldDoStandardInitialization(instance))
     {
         NetworkInstantiatorUtility.BroadcastOnNetworkInstantiate(view, "uLink_OnNetworkInstantiate", info);
     }
 }
        private NetDataWriter CreateRemovePlayerPacket(Entity playerEntity)
        {
            var em = MainWorld.GetOrCreateManager <EntityManager>();

            var msgManager = NetInstance.GetMessageManager();
            var dataWriter = msgManager.Create(m_MsgRemovePlayer);

            dataWriter.Put(playerEntity.Index);

            return(dataWriter);
        }
Example #8
0
        public override void ReadProperty(NetPropertyInfo propertyInfo, NetInstance target, NetVariant result)
        {
            var handle = (GCHandle)target.GetGCHandle();
            var o      = handle.Target;

            var value = o.GetType()
                        .GetProperty(propertyInfo.GetPropertyName(), BindingFlags.Instance | BindingFlags.Public)
                        .GetValue(o);

            PackValue(ref value, result);
        }
Example #9
0
    private NetInstance Summon(IDMain prefab, bool isServer, ref NetworkInstantiateArgs niargs)
    {
        IDMain main;
        CustomInstantiationArgs args     = new CustomInstantiationArgs(this, this._customInstantiator, prefab, ref niargs, isServer);
        NetworkView             view     = this.Create(ref args, out main);
        NetInstance             instance = view.gameObject.AddComponent <NetInstance>();

        instance.args        = args;
        instance.idMain      = main;
        instance.prepared    = false;
        instance.networkView = view;
        return(instance);
    }
Example #10
0
    private NetInstance Summon(IDMain prefab, bool isServer, ref NetworkInstantiateArgs niargs)
    {
        IDMain dMain;
        CustomInstantiationArgs customInstantiationArg = new CustomInstantiationArgs(this, this._customInstantiator, prefab, ref niargs, isServer);

        Facepunch.NetworkView networkView = this.Create(ref customInstantiationArg, out dMain);
        NetInstance           netInstance = networkView.gameObject.AddComponent <NetInstance>();

        netInstance.args        = customInstantiationArg;
        netInstance.idMain      = dMain;
        netInstance.prepared    = false;
        netInstance.networkView = networkView;
        return(netInstance);
    }
Example #11
0
        public override void WriteProperty(NetPropertyInfo propertyInfo, NetInstance target, NetVariant value)
        {
            base.WriteProperty(propertyInfo, target, value);

            var handle = (GCHandle)target.GetGCHandle();
            var o      = handle.Target;

            var pInfo = o.GetType()
                        .GetProperty(propertyInfo.GetPropertyName(), BindingFlags.Instance | BindingFlags.Public);

            object newValue = null;

            Unpackvalue(ref newValue, value);

            pInfo.SetValue(o, newValue);
        }
        /// <summary>
        /// Create a packet who contains data about the player
        /// </summary>
        /// <param name="playerEntity"></param>
        /// <param name="owned"></param>
        /// <returns></returns>
        private NetDataWriter CreatePlayerDataPacket(Entity playerEntity, NetPeer peer)
        {
            var em         = MainWorld.GetOrCreateManager <EntityManager>();
            var peerLink   = em.GetSharedComponentData <PlayerPeerLink>(playerEntity);
            var userLink   = em.GetSharedComponentData <PlayerUserLink>(playerEntity);
            var masterLink = em.GetSharedComponentData <MasterServerPlayerId>(playerEntity);

            var msgManager = NetInstance.GetMessageManager();
            var dataWriter = msgManager.Create(m_MsgUpdatePlayer);

            // The index is used to determin the id of the entity in the server
            dataWriter.Put(StMath.DoubleIntToLong(playerEntity.Index, playerEntity.Version));
            dataWriter.Put(userLink.Target.Index);
            dataWriter.Put(masterLink.Id);
            dataWriter.Put(peerLink.Target == peer);

            return(dataWriter);
        }
Example #13
0
    protected NetworkView _Creator(string prefabName, NetworkInstantiateArgs args, NetworkMessageInfo info)
    {
        NetInstance instance = this.Summon(this.proxyPrefab, false, ref args);

        if (instance == null)
        {
            return(null);
        }
        NetworkView networkView = instance.networkView;

        if (networkView == null)
        {
            return(null);
        }
        info = new NetworkMessageInfo(info, networkView);
        NetInstance instance2 = _currentNetInstance;

        try
        {
            _currentNetInstance = instance;
            instance.info       = info;
            instance.prepared   = true;
            instance.local      = args.viewID.isMine;
            bool     didAppend = false;
            IDRemote appended  = null;
            if (instance.local)
            {
                IDRemote localAppend = this.localAppend;
                if (localAppend != null)
                {
                    appended  = DoLocalAppend(localAppend, instance.idMain, this.GetLocalAppendTransform(instance.idMain));
                    didAppend = true;
                }
            }
            instance.zzz___onprecreate();
            this.StandardInitialization(didAppend, appended, instance, networkView, ref info);
            instance.zzz___onpostcreate();
        }
        finally
        {
            _currentNetInstance = instance2;
        }
        return(networkView);
    }
Example #14
0
    protected void _Destroyer(uLink.NetworkView networkView)
    {
        NetInstance netInstance = NetMainPrefab._currentNetInstance;

        try
        {
            NetInstance component = networkView.GetComponent <NetInstance>();
            NetMainPrefab._currentNetInstance = component;
            if (component)
            {
                component.zzz___onpredestroy();
            }
            UnityEngine.Object.Destroy(networkView.gameObject);
        }
        finally
        {
            NetMainPrefab._currentNetInstance = netInstance;
        }
    }
Example #15
0
    protected uLink.NetworkView _Creator(string prefabName, NetworkInstantiateArgs args, uLink.NetworkMessageInfo info)
    {
        NetInstance netInstance = this.Summon(this.proxyPrefab, false, ref args);

        if (!netInstance)
        {
            return(null);
        }
        Facepunch.NetworkView networkView = netInstance.networkView;
        if (!networkView)
        {
            return(null);
        }
        info = new uLink.NetworkMessageInfo(info, networkView);
        NetInstance netInstance1 = NetMainPrefab._currentNetInstance;

        try
        {
            NetMainPrefab._currentNetInstance = netInstance;
            netInstance.info     = info;
            netInstance.prepared = true;
            netInstance.local    = args.viewID.isMine;
            bool     flag    = false;
            IDRemote dRemote = null;
            if (netInstance.local)
            {
                IDRemote dRemote1 = this.localAppend;
                if (dRemote1)
                {
                    dRemote = NetMainPrefab.DoLocalAppend(dRemote1, netInstance.idMain, this.GetLocalAppendTransform(netInstance.idMain));
                    flag    = true;
                }
            }
            netInstance.zzz___onprecreate();
            this.StandardInitialization(flag, dRemote, netInstance, networkView, ref info);
            netInstance.zzz___onpostcreate();
        }
        finally
        {
            NetMainPrefab._currentNetInstance = netInstance1;
        }
        return(networkView);
    }
Example #16
0
    protected void _Destroyer(uLink.NetworkView networkView)
    {
        NetInstance instance = _currentNetInstance;

        try
        {
            NetInstance component = networkView.GetComponent <NetInstance>();
            _currentNetInstance = component;
            if (component != null)
            {
                component.zzz___onpredestroy();
            }
            UnityEngine.Object.Destroy(networkView.gameObject);
        }
        finally
        {
            _currentNetInstance = instance;
        }
    }
        /// <summary>
        /// On broadcasting data, send all connected players to the new peer
        /// </summary>
        /// <param name="peerInstance"></param>
        public override void OnInstanceBroadcastingData(NetPeerInstance peerInstance)
        {
            if (!NetInstance.SelfHost)
            {
                return;
            }

            var chanManager = NetInstance.GetChannelManager();
            var plBank      = MainWorld.GetOrCreateManager <GamePlayerBank>();
            var gpSystem    = MainWorld.GetOrCreateManager <GamePlayerSystem>();
            var em          = MainWorld.GetOrCreateManager <EntityManager>();

            var connectedPlayers = gpSystem.SlowGetAllConnectedPlayers();

            for (int i = 0; i != connectedPlayers.Length; i++)
            {
                var entity = connectedPlayers.Entities[i];
                if (em.HasComponent <PlayerPeerLink>(entity))
                {
                    var dataWriter = CreatePlayerDataPacket(entity, (NetPeer)peerInstance);
                    chanManager.DefaultChannel.Manager.SendToAll(dataWriter, DeliveryMethod.ReliableOrdered);
                }
            }
        }
Example #18
0
 protected override void StandardInitialization(bool didAppend, IDRemote appended, NetInstance instance, Facepunch.NetworkView view, ref uLink.NetworkMessageInfo info)
 {
     Controllable controllable = ((Character)instance.idMain).controllable;
     controllable.PrepareInstantiate(view, ref info);
     base.StandardInitialization(false, appended, instance, view, ref info);
     if (didAppend)
     {
         NetMainPrefab.IssueLocallyAppended(appended, instance.idMain);
     }
     controllable.OnInstantiated();
 }
        void EventUserStatusChange.IEv.Callback(EventUserStatusChange.Arguments args)
        {
            var caller = args.Caller;
            var user   = args.User;
            var change = args.Change;

            if (!NetInstance.SelfHost || caller.Global.Main != NetInstance)
            {
                return;
            }

            var chanManager = NetInstance.GetChannelManager();
            var plBank      = MainWorld.GetOrCreateManager <GamePlayerBank>();
            var gpSystem    = MainWorld.GetOrCreateManager <GamePlayerSystem>();
            var em          = MainWorld.GetOrCreateManager <EntityManager>();

            var player = new GamePlayer();

            foreach (var bankPlayer in plBank.AllPlayers)
            {
                if (em.HasComponent <PlayerPeerLink>(bankPlayer.WorldPointer))
                {
                    var target = em.GetSharedComponentData <PlayerPeerLink>(bankPlayer.WorldPointer).Target;
                    if (target == (NetPeer)user.GetPeerInstance())
                    {
                        player = bankPlayer;
                        break;
                    }
                }
            }

            if (!player.IsCreated)
            {
                Debug.Log("Player wasn't found");
                return;
            }

            if ((change & StatusChange.Removed) != 0)
            {
                if (player.WorldPointer.HasComponent <PlayerUserLink>(MainWorld))
                {
                    em.RemoveComponent <PlayerUserLink>(player.WorldPointer);
                }
                if (player.WorldPointer.HasComponent <PlayerPeerLink>(MainWorld))
                {
                    em.RemoveComponent <PlayerPeerLink>(player.WorldPointer);
                }
                if (player.WorldPointer.HasComponent <ConnectedPlayerEntity>(MainWorld))
                {
                    em.RemoveComponent <ConnectedPlayerEntity>(player.WorldPointer);
                }

                var manager    = chanManager.DefaultChannel.Manager;
                var dataWriter = CreateRemovePlayerPacket(player.WorldPointer);
                foreach (var otherPeer in manager)
                {
                    otherPeer.Send(dataWriter, DeliveryMethod.ReliableOrdered);
                }
            }

            if ((change & StatusChange.Added) != 0)
            {
                player.WorldPointer.SetOrAddSharedComponentData(new PlayerUserLink(user), MainWorld);
                player.WorldPointer.SetOrAddComponentData(new ConnectedPlayerEntity(), MainWorld);

                var dataWriter = CreatePlayerDataPacket(player.WorldPointer, (NetPeer)user.GetPeerInstance());
                var manager    = chanManager.DefaultChannel.Manager;
                foreach (var otherPeer in manager)
                {
                    if (otherPeer == caller.Peer)
                    {
                        continue;
                    }

                    otherPeer.Send(dataWriter, DeliveryMethod.ReliableOrdered);
                }
            }
        }
Example #20
0
    public static bool IsCurrentlyDestroying(IDRemote remote)
    {
        NetInstance current = NetInstance.current;

        return((current != null) && (current.idMain == remote.idMain));
    }
Example #21
0
 private static void CallbackFire(NetInstance instance, NetInstance.CallbackFunction func)
 {
     func(instance);
 }
Example #22
0
    public static bool IsCurrentlyDestroying(IDLocal local)
    {
        NetInstance current = NetInstance.current;

        return((current != null) && (current.idMain == local.idMain));
    }
Example #23
0
 private static void CallbackFire(NetInstance instance, CallbackFunction func)
 {
     func(instance);
 }
Example #24
0
    /*void OnGUI()
     * {
     * buttonNum = 0;
     * OnGuiDrawConsole();
     * //OnGuiDrawNetMenu();
     * }*/

    public void GuiEvent(Events.GUI message)
    {
        bool messageSucses = false;

        switch (message)
        {
        case Events.GUI.SERVER_MENU:
            if (nsm.menuState == NetworkState.newInstance)
            {
                nsm.menuState = NetworkState.host_menu;
                messageSucses = true;
            }
            break;

        case Events.GUI.START_SERVER:
            if (nsm.menuState == NetworkState.host_menu)
            {
                netInstance = new Server(nsm, this, Settings.Player.roomname);
                netInstance.Init();
                messageSucses = true;
            }
            break;

        case Events.GUI.MENU_SERVERLIST:
            if (nsm.menuState == NetworkState.newInstance)
            {
                netInstance = new Client(nsm, this);
                netInstance.Init();
                nsm.menuState = NetworkState.client1;
                messageSucses = true;
            }
            break;

        case Events.GUI.BACK:
            if (nsm.menuState == NetworkState.host_menu)
            {
                nsm.menuState = NetworkState.newInstance;
                messageSucses = true;
            }
            if (nsm.menuState == NetworkState.host_lobby)
            {
                netInstance.Close();
                nsm.menuState = NetworkState.newInstance;
                netInstance   = null;
                messageSucses = true;
            }
            if (nsm.menuState == NetworkState.client1)
            {
                nsm.menuState = NetworkState.newInstance;
                messageSucses = true;
            }
            if (nsm.menuState == NetworkState.client2)
            {
                nsm.menuState = NetworkState.newInstance;
                netInstance.Close();
                messageSucses = true;
            }
            break;

        case Events.GUI.REFRESH:
            if (nsm.menuState == NetworkState.client1)
            {
                RefreshHostList();
                messageSucses = true;
            }
            break;
        }
        if (!messageSucses)
        {
            Debug.LogError("NetEvent state error - current state: " + nsm.menuState + " - event: " + message.ToString());
        }
        else
        {
            Debug.Log("NetEvent - current state: " + nsm.menuState + " - event: " + message.ToString());
        }
    }
Example #25
0
 // Update is called once per frame
 void Update()
 {
     NetInstance.Update();
 }
Example #26
0
    public static bool IsCurrentlyDestroying(IDRemote remote)
    {
        NetInstance netInstance = NetInstance.current;

        return(!netInstance ? false : netInstance.idMain == remote.idMain);
    }
Example #27
0
    protected override void StandardInitialization(bool didAppend, IDRemote appended, NetInstance instance, Facepunch.NetworkView view, ref uLink.NetworkMessageInfo info)
    {
        Controllable controllable = ((Character)instance.idMain).controllable;

        controllable.PrepareInstantiate(view, ref info);
        base.StandardInitialization(false, appended, instance, view, ref info);
        if (didAppend)
        {
            NetMainPrefab.IssueLocallyAppended(appended, instance.idMain);
        }
        controllable.OnInstantiated();
    }
Example #28
0
    public static bool IsCurrentlyDestroying(IDLocal local)
    {
        NetInstance netInstance = NetInstance.current;

        return(!netInstance ? false : netInstance.idMain == local.idMain);
    }