예제 #1
0
파일: JNet.cs 프로젝트: Epicguru/ProjectB
        /// <summary>
        /// Initializes the JNet system. This must be called before any other JNet functionality can be used.
        /// </summary>
        /// <param name="appID">The application unique indentifier, must not be null or blank. Any leading or trailing whitespace will be trimmed.</param>
        /// <param name="updateClassMap">If false, the class map for NetBehaviours is not refreshed, which can lead to netcode failing to work. Only used for unit testing pruposes internally.</param>
        public static void Init(string appID, bool includeSceneObjects = true)
        {
            if (Initialized)
            {
                Error("Already initialized.");
                return;
            }

            // Validate the app id.
            if (string.IsNullOrWhiteSpace(appID))
            {
                Error("App ID supplied is null or blank, invalid. JNet has not been initialized.");
                return;
            }

            JNet.EnableSceneObjectNetworking = includeSceneObjects;

            AppID    = appID.Trim();
            Tracker  = new WorldStateTracker();
            Prefabs  = new NetObject[ushort.MaxValue + 1];
            Playback = new JNetPlayback();

            NetBehaviour.UpdateClassMap();

            Initialized = true;
        }
예제 #2
0
        internal void UpdateBehaviourList()
        {
            var comps = this.GetComponents <NetBehaviour>();

            if (comps.Length <= 256)
            {
                NetBehaviours = comps;
            }
            else
            {
                NetBehaviours = new NetBehaviour[256];
                System.Array.Copy(comps, NetBehaviours, 256);
                JNet.Error(string.Format("NetObject {0} has {1} NetBehaviour components, but a max of 256 are supported. Some of them will not function properly, and errors will arise.", this.ToString(), comps.Length));
            }

            for (int i = 0; i < NetBehaviours.Length; i++)
            {
                NetBehaviours[i].BehaviourID = (byte)i;
                NetBehaviours[i].NetAwake();
            }

            RefreshParentNodes();
        }
예제 #3
0
파일: JNet.cs 프로젝트: Epicguru/ProjectB
 /// <summary>
 /// Makes a spawned object be registered to the networking system, causing it to be
 /// instantiated on all connected clients.
 /// Note that this does NOT instantiate the object on the server. The object should already be instantiated,
 /// and this method just registers it. In other words, do not pass a prefab to this method.
 /// </summary>
 /// <param name="obj">A behaviour on the net object to spawn.</param>
 public static void Spawn(NetBehaviour behaviour, NetConnection owner = null)
 {
     JNet.Spawn(behaviour.NetObject, owner);
 }