Beispiel #1
0
        protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, UnSpawnDelegate unspawnHandler)
        {
            SpawnDelegate        spawnHandler         = new SpawnDelegate((x, y) => null);
            SpawnHandlerDelegate spawnHandlerDelegate = new SpawnHandlerDelegate(x => null);

            switch (overload)
            {
            case RegisterPrefabOverload.Prefab_SpawnDelegate:
                ClientScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId:
                ClientScene.RegisterPrefab(prefab, anotherGuid, spawnHandler, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate:
                ClientScene.RegisterPrefab(prefab, spawnHandlerDelegate, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId:
                ClientScene.RegisterPrefab(prefab, anotherGuid, spawnHandlerDelegate, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab:
            case RegisterPrefabOverload.Prefab_NewAssetId:
                Debug.LogError("Overload did not have UnSpawnDelegate parameter");
                break;

            default:
                Debug.LogError("Overload not found");
                break;
            }
        }
Beispiel #2
0
 public SpawnTimer(double spawntime, SpawnDelegate cb, string name)
 {
     SpawnTime = spawntime;
     callback  = cb;
     CanDelete = false;
     Name      = name;
 }
        protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, Guid guid)
        {
            SpawnDelegate        spawnHandler         = new SpawnDelegate((x, y) => null);
            SpawnHandlerDelegate spawnHandlerDelegate = new SpawnHandlerDelegate(x => null);
            UnSpawnDelegate      unspawnHandler       = new UnSpawnDelegate(x => {});

            switch (overload)
            {
            case RegisterPrefabOverload.Prefab_NewAssetId:
                NetworkClient.RegisterPrefab(prefab, guid);
                break;

            case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId:
                NetworkClient.RegisterPrefab(prefab, guid, spawnHandler, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId:
                NetworkClient.RegisterPrefab(prefab, guid, spawnHandlerDelegate, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab:
            case RegisterPrefabOverload.Prefab_SpawnDelegate:
            case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate:
                Debug.LogError("Overload did not have guid parameter");
                break;

            default:
                Debug.LogError("Overload not found");
                break;
            }
        }
Beispiel #4
0
    void FindSpawns(Type type)
    {
        if (type.GetCustomAttribute <SpawnFactoryAttribute>() != null)
        {
            //networkFactoryMethods.AddRange(type.GetMethods().Where(methodInfo => methodInfo.IsDefined(typeof(NetworkInstantiatorAttribute), false)));
            var methods = type
                          .GetMethods()
                          .Where(_ => _.IsDefined(typeof(SpawnAttribute), false))
                          .ToArray();

            foreach (var method in methods)
            {
                SpawnDelegate spawn = null;

                try {
                    spawn = (SpawnDelegate)Delegate.CreateDelegate(
                        typeof(SpawnDelegate),
                        method);
                } catch (Exception) {
                    throw new Exception(string.Format("Wrong signature for {0}. Signature requires static Entity {0}(EntityManager)", method.Name));
                }

                int instanceId = method.GetCustomAttribute <SpawnAttribute>().InstanceId;
                RegisterSpawn(instanceId, spawn);
            }
        }
    }
Beispiel #5
0
 public void SpawnPlayer()
 {
     currTimeToRevive  = 0;
     reviveTimeElapsed = 0;
     travelTimeElapsed = 0;
     if (reviveSlot != null)
     {
         reviveSlot.RemovePlayer();
         reviveSlot = null;
     }
     else
     {
         GameObject parent = SpawnDelegate.getInstance().getPlayerSpawnLocation(playerNum);
         gameObject.transform.SetParent(parent.transform, false);
         gameObject.transform.position = parent.transform.position;
     }
     playerRevivingMe = null;
     playerState      = PlayerState.SPAWNING;
     deathState       = DeathState.STARTING;
     if (rend == null)
     {
         rend = GetComponent <SpriteRenderer> ().GetComponent <Renderer> ();
     }
     ToggleBarrels(currentWeapon, true);
     rend.enabled = true;
     head.GetComponent <SpriteRenderer> ().enabled = true;
     initDone = true;
     StartCoroutine(Flash(SPAWNING_TIME, 0.05f));
 }
Beispiel #6
0
        /// <summary>
        /// Registers a prefab with the spawning system.
        /// <para>When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.</para>
        /// <para>The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.</para>
        /// <para>The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.</para>
        /// </summary>
        /// <param name="prefab">A Prefab that will be spawned.</param>
        /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
        /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
        public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            NetworkIdentity identity = prefab.GetComponent <NetworkIdentity>();

            if (identity == null)
            {
                Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
                return;
            }

            if (spawnHandler == null || unspawnHandler == null)
            {
                Debug.LogError("RegisterPrefab custom spawn function null for " + identity.assetId);
                return;
            }

            if (identity.assetId == Guid.Empty)
            {
                Debug.LogError("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?");
                return;
            }

            if (LogFilter.Debug)
            {
                Debug.Log("Registering custom prefab '" + prefab.name + "' as asset:" + identity.assetId + " " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
            }

            spawnHandlers[identity.assetId]   = spawnHandler;
            unspawnHandlers[identity.assetId] = unspawnHandler;
        }
        private void SpawnEnemy(string enemyName, SpawnDelegate spawnDelegate)
        {
            // Get the corresponding spawn information
            SpawnPositionAndArea spawnPositionAndArea = spawnDelegate();

            // Spawn the enemy object
            _objectPooler.Spawn(enemyName, spawnPositionAndArea.spawnPosition, Quaternion.identity, spawnPositionAndArea.spawnAreaName);
        }
 internal static bool GetSpawnHandler(NetworkHash128 assetId, out SpawnDelegate handler)
 {
     if (NetworkScene.s_SpawnHandlers.ContainsKey(assetId))
     {
         handler = NetworkScene.s_SpawnHandlers[assetId];
         return true;
     }
     handler = null;
     return false;
 }
 /// <summary>
 /// Gets the spawn handler of an asset.
 /// </summary>
 /// <param name="assetIndex">Index of the asset.</param>
 /// <param name="handler">The handler.</param>
 /// <returns></returns>
 public bool GetSpawnHandler(int assetIndex, out SpawnDelegate handler)
 {
     if (_spawnHandlers.ContainsKey(assetIndex))
     {
         handler = _spawnHandlers[assetIndex];
         return(true);
     }
     handler = null;
     return(false);
 }
Beispiel #10
0
 static internal bool GetSpawnHandler(NetworkHash128 assetId, out SpawnDelegate handler)
 {
     if (s_SpawnHandlers.ContainsKey(assetId))
     {
         handler = s_SpawnHandlers[assetId];
         return(true);
     }
     handler = null;
     return(false);
 }
 public static void Prepare()
 {
     SpawnCitizenAI          = GameConnectionManager.Instance.HumanAIConnection.SpawnCitizenAI;
     StartPathFindCitizenAI  = GameConnectionManager.Instance.HumanAIConnection.StartPathFindCitizenAI;
     SimulationStepCitizenAI = GameConnectionManager.Instance.HumanAIConnection.SimulationStepCitizenAI;
     ArriveAtDestination     = GameConnectionManager.Instance.HumanAIConnection.ArriveAtDestination;
     InvalidPath             = GameConnectionManager.Instance.HumanAIConnection.InvalidPath;
     PathfindFailure         = GameConnectionManager.Instance.HumanAIConnection.PathfindFailure;
     PathfindSuccess         = GameConnectionManager.Instance.HumanAIConnection.PathfindSuccess;
 }
Beispiel #12
0
 internal static bool GetSpawnHandler(Guid assetId, out SpawnDelegate handler)
 {
     if (s_SpawnHandlers.ContainsKey(assetId))
     {
         handler = s_SpawnHandlers[assetId];
         return(true);
     }
     handler = null;
     return(false);
 }
        /// <summary>
        /// This is an advanced spawning function that registers a custom assetId with the UNET spawning system.
        /// <para>This can be used to register custom spawning methods for an assetId - instead of the usual method of registering spawning methods for a prefab. This should be used when no prefab exists for the spawned objects - such as when they are constructed dynamically at runtime from configuration data.</para>
        /// </summary>
        /// <param name="assetId">Custom assetId string.</param>
        /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
        /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
        public static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            // We need this check here because we don't want a null handler in the lambda expression below
            if (spawnHandler == null)
            {
                logger.LogError($"Can not Register null SpawnHandler for {assetId}");
                return;
            }

            RegisterSpawnHandler(assetId, msg => spawnHandler(msg.position, msg.assetId), unspawnHandler);
        }
        internal static HumanAIConnection GetConnection()
        {
            try {
                StartPathFindDelegate startPathFindCitizenAI =
                    TranspilerUtil.CreateDelegate <StartPathFindDelegate>(
                        typeof(CitizenAI),
                        "StartPathFind",
                        true);
                SimulationStepDelegate simulationStepCitizenAI =
                    AccessTools.MethodDelegate <SimulationStepDelegate>(
                        TranspilerUtil.DeclaredMethod <SimulationStepTarget>(typeof(CitizenAI), "SimulationStep"),
                        null,
                        false);
                ArriveAtDestinationDelegate arriveAtDestination =
                    TranspilerUtil.CreateDelegate <ArriveAtDestinationDelegate>(
                        typeof(HumanAI),
                        "ArriveAtDestination",
                        true);
                SpawnDelegate spawnCitizenAI =
                    TranspilerUtil.CreateDelegate <SpawnDelegate>(
                        typeof(HumanAI),
                        "Spawn",
                        true);
                InvalidPathHumanAIDelegate invalidPath =
                    TranspilerUtil.CreateDelegate <InvalidPathHumanAIDelegate>(
                        typeof(CitizenAI),
                        "InvalidPath",
                        true);
                PathfindFailureHumanAIDelegate pathfindFailure =
                    TranspilerUtil.CreateDelegate <PathfindFailureHumanAIDelegate>(
                        typeof(HumanAI),
                        "PathfindFailure",
                        true);
                PathfindSuccessHumanAIDelegate pathfindSuccess =
                    TranspilerUtil.CreateDelegate <PathfindSuccessHumanAIDelegate>(
                        typeof(HumanAI),
                        "PathfindSuccess",
                        true);

                return(new HumanAIConnection(
                           spawnCitizenAI,
                           startPathFindCitizenAI,
                           simulationStepCitizenAI,
                           arriveAtDestination,
                           invalidPath,
                           pathfindFailure,
                           pathfindSuccess));
            } catch (Exception e) {
                Log.Error(e.Message);
                return(null);
            }
        }
Beispiel #15
0
        public static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            if (spawnHandler == null || unspawnHandler == null)
            {
                Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId);
                return;
            }

            if (LogFilter.Debug) { Debug.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName()); }

            spawnHandlers[assetId] = spawnHandler;
            unspawnHandlers[assetId] = unspawnHandler;
        }
 internal HumanAIConnection(SpawnDelegate spawnCitizenAI,
                            StartPathFindDelegate startPathFindCitizenAI,
                            SimulationStepDelegate simulationStepCitizenAI,
                            ArriveAtDestinationDelegate arriveAtDestination,
                            InvalidPathHumanAIDelegate invalidPath,
                            PathfindFailureHumanAIDelegate pathfindFailure,
                            PathfindSuccessHumanAIDelegate pathfindSuccess)
 {
     SpawnCitizenAI          = spawnCitizenAI ?? throw new ArgumentNullException(nameof(spawnCitizenAI));
     StartPathFindCitizenAI  = startPathFindCitizenAI ?? throw new ArgumentNullException(nameof(startPathFindCitizenAI));
     SimulationStepCitizenAI = simulationStepCitizenAI ?? throw new ArgumentNullException(nameof(simulationStepCitizenAI));
     ArriveAtDestination     = arriveAtDestination ?? throw new ArgumentNullException(nameof(arriveAtDestination));
     InvalidPath             = invalidPath ?? throw new ArgumentNullException(nameof(invalidPath));
     PathfindFailure         = pathfindFailure ?? throw new ArgumentNullException(nameof(pathfindFailure));
     PathfindSuccess         = pathfindSuccess ?? throw new ArgumentNullException(nameof(pathfindSuccess));
 }
        /// <summary>
        /// Registers a spawn handler.
        /// </summary>
        /// <param name="assetIndex">Id of the asset.</param>
        /// <param name="spawnHandler">The spawn handler.</param>
        /// <param name="unspawnHandler">The unspawn handler.</param>
        public void RegisterSpawnHandler(int assetIndex, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            if (spawnHandler == null || unspawnHandler == null)
            {
                if (TinyNetLogLevel.logError)
                {
                    TinyLogger.LogError("RegisterSpawnHandler custom spawn function null for " + assetIndex);
                }
                return;
            }

            if (TinyNetLogLevel.logDebug)
            {
                TinyLogger.Log("RegisterSpawnHandler asset '" + assetIndex + "' " + spawnHandler.Method.Name + "/" + unspawnHandler.Method.Name);
            }

            _spawnHandlers[assetIndex]   = spawnHandler;
            _unspawnHandlers[assetIndex] = unspawnHandler;
        }
Beispiel #18
0
        static internal void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            if (spawnHandler == null || unspawnHandler == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId);
                }
                return;
            }

            if (LogFilter.logDebug)
            {
                Debug.Log("RegisterSpawnHandler asset '" + assetId + "' " + spawnHandler.GetMethodName() + "/" + unspawnHandler.GetMethodName());
            }

            s_SpawnHandlers[assetId]   = spawnHandler;
            s_UnspawnHandlers[assetId] = unspawnHandler;
        }
        public void SpawnDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload)
        {
            int handlerCalled = 0;

            Guid          guid    = GuidForOverload(overload);
            SpawnDelegate handler = new SpawnDelegate((pos, rot) =>
            {
                handlerCalled++;
                return(null);
            });

            CallRegisterPrefab(validPrefab, overload, handler);


            Assert.IsTrue(NetworkClient.spawnHandlers.ContainsKey(guid));

            // check spawnHandler above is called
            SpawnHandlerDelegate handlerInDictionary = NetworkClient.spawnHandlers[guid];

            handlerInDictionary.Invoke(default);
        public void SpawnDelegate_AddsHandlerToSpawnHandlers()
        {
            int handlerCalled = 0;

            Guid          guid         = Guid.NewGuid();
            SpawnDelegate spawnHandler = new SpawnDelegate((pos, rot) =>
            {
                handlerCalled++;
                return(null);
            });
            UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {});

            ClientScene.RegisterSpawnHandler(guid, spawnHandler, unspawnHandler);

            Assert.IsTrue(spawnHandlers.ContainsKey(guid));

            // check spawnHandler above is called
            SpawnHandlerDelegate handler = spawnHandlers[guid];

            handler.Invoke(default);
        /// <summary>
        /// Registers a prefab with the spawning system.
        /// <para>When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.</para>
        /// <para>The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.</para>
        /// <para>The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.</para>
        /// </summary>
        /// <param name="prefab">A Prefab that will be spawned.</param>
        /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
        /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
        public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
        {
            if (prefab == null)
            {
                logger.LogError("Could not register handler for prefab because the prefab was null");
                return;
            }

            NetworkIdentity identity = prefab.GetComponent <NetworkIdentity>();

            if (identity == null)
            {
                logger.LogError("Could not register handler for '" + prefab.name + "' since it contains no NetworkIdentity component");
                return;
            }

            if (identity.sceneId != 0)
            {
                logger.LogError($"Can not Register '{prefab.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
                return;
            }

            Guid assetId = identity.assetId;

            if (assetId == Guid.Empty)
            {
                logger.LogError($"Can not Register handler for '{prefab.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead");
                return;
            }

            // We need this check here because we don't want a null handler in the lambda expression below
            if (spawnHandler == null)
            {
                logger.LogError($"Can not Register null SpawnHandler for {assetId}");
                return;
            }

            RegisterPrefab(prefab, msg => spawnHandler(msg.position, msg.assetId), unspawnHandler);
        }
Beispiel #22
0
 /// <summary>
 /// Registers a prefab with the spawning system.
 /// <para>When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.</para>
 /// <para>The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.</para>
 /// <para>The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.</para>
 /// </summary>
 /// <param name="prefab">A Prefab that will be spawned.</param>
 /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
 /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
 public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     RegisterPrefab(prefab, msg => spawnHandler(msg.position, msg.assetId), unspawnHandler);
 }
 /// <summary>
 ///   <para>Registers a prefab with the UNET spawning system.</para>
 /// </summary>
 /// <param name="prefab">A Prefab that will be spawned.</param>
 /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
 /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
 /// <param name="newAssetId">An assetId to be assigned to this prefab. This allows a dynamically created game object to be registered for an already known asset Id.</param>
 public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
   NetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
 }
 internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
   NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
   if ((Object) component == (Object) null)
   {
     if (!LogFilter.logError)
       return;
     Debug.LogError((object) ("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component"));
   }
   else if (spawnHandler == null || unspawnHandler == null)
   {
     if (!LogFilter.logError)
       return;
     Debug.LogError((object) ("RegisterPrefab custom spawn function null for " + (object) component.assetId));
   }
   else if (!component.assetId.IsValid())
   {
     if (!LogFilter.logError)
       return;
     Debug.LogError((object) ("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?"));
   }
   else
   {
     if (LogFilter.logDebug)
       Debug.Log((object) ("Registering custom prefab '" + prefab.name + "' as asset:" + (object) component.assetId + " " + spawnHandler.Method.Name + "/" + unspawnHandler.Method.Name));
     NetworkScene.s_SpawnHandlers[component.assetId] = spawnHandler;
     NetworkScene.s_UnspawnHandlers[component.assetId] = unspawnHandler;
   }
 }
 internal static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
   if (spawnHandler == null || unspawnHandler == null)
   {
     if (!LogFilter.logError)
       return;
     Debug.LogError((object) ("RegisterSpawnHandler custom spawn function null for " + (object) assetId));
   }
   else
   {
     if (LogFilter.logDebug)
       Debug.Log((object) ("RegisterSpawnHandler asset '" + (object) assetId + "' " + spawnHandler.Method.Name + "/" + unspawnHandler.Method.Name));
     NetworkScene.s_SpawnHandlers[assetId] = spawnHandler;
     NetworkScene.s_UnspawnHandlers[assetId] = unspawnHandler;
   }
 }
 /// <summary>
 ///   <para>This is an advanced spawning funciotn that registers a custom assetId with the UNET spawning system.</para>
 /// </summary>
 /// <param name="assetId">Custom assetId string.</param>
 /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
 /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
 public static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
   NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
 }
        protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload overload, SpawnDelegate spawnHandler)
        {
            UnSpawnDelegate unspawnHandler = new UnSpawnDelegate(x => {});

            switch (overload)
            {
            case RegisterPrefabOverload.Prefab_SpawnDelegate:
                NetworkClient.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId:
                NetworkClient.RegisterPrefab(prefab, anotherGuid, spawnHandler, unspawnHandler);
                break;

            case RegisterPrefabOverload.Prefab:
            case RegisterPrefabOverload.Prefab_NewAssetId:
            case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate:
            case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId:
                Debug.LogError("Overload did not have SpawnDelegate parameter");
                break;

            default:
                Debug.LogError("Overload not found");
                break;
            }
        }
Beispiel #28
0
 public static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
 }
 internal static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     if ((spawnHandler == null) || (unspawnHandler == null))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId);
         }
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "RegisterSpawnHandler asset '", assetId, "' ", DotNetCompatibility.GetMethodName(spawnHandler), "/", DotNetCompatibility.GetMethodName(unspawnHandler) }));
         }
         s_SpawnHandlers[assetId] = spawnHandler;
         s_UnspawnHandlers[assetId] = unspawnHandler;
     }
 }
 internal static void RegisterSpawnHandler(NetworkHash128 assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     if (spawnHandler == null || unspawnHandler == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("RegisterSpawnHandler custom spawn function null for " + assetId);
         }
         return;
     }
     if (LogFilter.logDebug)
     {
         Debug.Log(string.Concat(new object[]
         {
             "RegisterSpawnHandler asset '",
             assetId,
             "' ",
             spawnHandler.Method.Name,
             "/",
             unspawnHandler.Method.Name
         }));
     }
     NetworkScene.s_SpawnHandlers[assetId] = spawnHandler;
     NetworkScene.s_UnspawnHandlers[assetId] = unspawnHandler;
 }
 /// <summary>
 /// Gets the spawn handler of an asset.
 /// </summary>
 /// <param name="assetGUID">The asset unique identifier.</param>
 /// <param name="handler">The handler.</param>
 /// <returns></returns>
 public bool GetSpawnHandler(string assetGUID, out SpawnDelegate handler)
 {
     return(GetSpawnHandler(GetAssetIdFromAssetGUID(assetGUID), out handler));
 }
 internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
     if (component == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Could not register '" + prefab.get_name() + "' since it contains no NetworkIdentity component");
         }
         return;
     }
     if (spawnHandler == null || unspawnHandler == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("RegisterPrefab custom spawn function null for " + component.assetId);
         }
         return;
     }
     if (!component.assetId.IsValid())
     {
         if (LogFilter.logError)
         {
             Debug.LogError("RegisterPrefab game object " + prefab.get_name() + " has no prefab. Use RegisterSpawnHandler() instead?");
         }
         return;
     }
     if (LogFilter.logDebug)
     {
         Debug.Log(string.Concat(new object[]
         {
             "Registering custom prefab '",
             prefab.get_name(),
             "' as asset:",
             component.assetId,
             " ",
             spawnHandler.Method.Name,
             "/",
             unspawnHandler.Method.Name
         }));
     }
     NetworkScene.s_SpawnHandlers[component.assetId] = spawnHandler;
     NetworkScene.s_UnspawnHandlers[component.assetId] = unspawnHandler;
 }
Beispiel #33
0
 // Use this for initialization
 void Start()
 {
     spawnCallback += SpawnOrc;
     spawnCallback += SpawnTroll;
 }
Beispiel #34
0
 // Use this for initialization
 void Start()
 {
     // Subscribe all functions to delegate
     spawnCallback += SpawnOrc;
     spawnCallback += SpawnTroll;
 }
Beispiel #35
0
 /// <summary>
 /// This is an advanced spawning function that registers a custom assetId with the UNET spawning system.
 /// <para>This can be used to register custom spawning methods for an assetId - instead of the usual method of registering spawning methods for a prefab. This should be used when no prefab exists for the spawned objects - such as when they are constructed dynamically at runtime from configuration data.</para>
 /// </summary>
 /// <param name="assetId">Custom assetId string.</param>
 /// <param name="spawnHandler">A method to use as a custom spawnhandler on clients.</param>
 /// <param name="unspawnHandler">A method to use as a custom un-spawnhandler on clients.</param>
 public static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     RegisterSpawnHandler(assetId, msg => spawnHandler(msg.position, msg.assetId), unspawnHandler);
 }
Beispiel #36
0
 public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
 }
 internal static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkIdentity component = prefab.GetComponent<NetworkIdentity>();
     if (component == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Could not register '" + prefab.name + "' since it contains no NetworkIdentity component");
         }
     }
     else if ((spawnHandler == null) || (unspawnHandler == null))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("RegisterPrefab custom spawn function null for " + component.assetId);
         }
     }
     else if (!component.assetId.IsValid())
     {
         if (LogFilter.logError)
         {
             Debug.LogError("RegisterPrefab game object " + prefab.name + " has no prefab. Use RegisterSpawnHandler() instead?");
         }
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "Registering custom prefab '", prefab.name, "' as asset:", component.assetId, " ", DotNetCompatibility.GetMethodName(spawnHandler), "/", DotNetCompatibility.GetMethodName(unspawnHandler) }));
         }
         s_SpawnHandlers[component.assetId] = spawnHandler;
         s_UnspawnHandlers[component.assetId] = unspawnHandler;
     }
 }
Beispiel #38
0
 // Use this for initialization
 void Start()
 {
     // Subscribe to the function
     spawnCallback += SpawnOrc;
     spawnCallback += SpawnTroll;
 }
Beispiel #39
0
 void Awake()
 {
     instance = this;
 }