コード例 #1
0
        private void ProcessSpawnAll(NetIncomingMessage msg)
        {
            int objectCount          = msg.ReadInt32();
            int expectedSceneObjects = JNet.EnableSceneObjectNetworking ? JNet.TrackedObjectCount : 0;

            JNet.Log($"Recieved {objectCount} objects from the server.");

            for (int i = 0; i < objectCount; i++)
            {
                ushort prefabID = msg.ReadUInt16();
                ushort netID    = msg.ReadUInt16();

                // Get the prefab for that ID...
                NetObject prefab = JNet.GetPrefab(prefabID);
                if (prefab == null && netID > expectedSceneObjects)
                {
                    JNet.Error("Failed to find prefab for ID " + prefabID + ", object not spawned on client. Desync incoming!");
                    return;
                }

                if (netID == 0)
                {
                    JNet.Error("Client got spawn message with instance net ID of zero, server error or corruption? Object not spawned, prefab id was " + prefabID + " (" + prefab + ").");
                    return;
                }

                // Instantiate the game object, if not scene object.
                NetObject no;
                if (prefab != null)
                {
                    no = GameObject.Instantiate(prefab);
                }
                else
                {
                    no = JNet.GetObject(netID);
                }

                // We need to register the object to the system, if not scene object.
                if (prefab != null)
                {
                    JNet.Tracker.Register(no, netID);
                }

                // Read all the behaviours.
                no.Deserialize(msg, true);
            }

            UponWorldRecieved?.Invoke();
        }
コード例 #2
0
 protected void Log(string s, params object[] args)
 {
     JNet.Log((IsServer ? "[S] " : "[C] ") + string.Format(s, args));
 }
コード例 #3
0
ファイル: NetBehaviour.cs プロジェクト: Epicguru/ProjectB
        internal static void UpdateClassMap()
        {
            classMap.Clear();

            var s = new System.Diagnostics.Stopwatch();

            s.Start();

            Type parent        = typeof(JNetGeneratedBehaviour);
            uint typeCount     = 0;
            uint assemblyCount = 0;
            var  assemblies    = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in assemblies)
            {
                string name = assembly.GetName().Name;

                if (name.StartsWith("Unity"))
                {
                    continue;
                }
                if (name.StartsWith("Mono"))
                {
                    continue;
                }
                if (name.StartsWith("System"))
                {
                    continue;
                }
                if (name.StartsWith("Microsoft"))
                {
                    continue;
                }
                if (name == "mscorlib")
                {
                    continue;
                }

                // JNet.Log(name);
                assemblyCount++;

                var types = assembly.GetTypes();
                foreach (var type in types)
                {
                    typeCount++;

                    if (!type.IsClass)
                    {
                        continue;
                    }
                    if (!type.IsSealed)
                    {
                        continue;
                    }

                    if (type.IsSubclassOf(parent))
                    {
                        var attribute = type.GetCustomAttribute <GeneratedTargetAttribute>();
                        if (attribute != null)
                        {
                            var targetType = attribute.GetTargetType();

                            classMap.Add(targetType, type);
                        }
                    }
                }
            }

            s.Stop();
            JNet.Log(string.Format("Rebuild class map in {0}ms, scanned {1} assemblies and {2} types.", s.Elapsed.TotalMilliseconds, assemblyCount, typeCount));
        }