Ejemplo n.º 1
0
    /// <summary>
    /// Spawns the things defined in this list at the indicated destination
    /// </summary>
    /// <param name="destination"></param>
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        if (!SpawnableUtils.IsValidDestination(destination))
        {
            return(SpawnableResult.Fail(destination));
        }

        List <GameObject> spawned = new List <GameObject>();

        foreach (var prefab in contents)
        {
            var result = Spawn.ServerPrefab(prefab, destination);
            if (!result.Successful)
            {
                Logger.LogWarningFormat("An item in SpawnableList {0} is missing, please fix prefab reference.", Category.ItemSpawn,
                                        name);
            }
            else
            {
                spawned.AddRange(result.GameObjects);
            }
        }

        return(SpawnableResult.Multiple(spawned, destination));
    }
Ejemplo n.º 2
0
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        if (!SpawnableUtils.IsValidDestination(destination))
        {
            return(SpawnableResult.Fail(destination));
        }

        if (prefab == null)
        {
            Logger.LogWarning("Cannot spawn, prefab to use is null", Category.ItemSpawn);
            return(SpawnableResult.Fail(destination));
        }
        Logger.LogTraceFormat("Spawning using prefab {0}", Category.ItemSpawn, prefab);

        bool isPooled;

        GameObject tempObject = Spawn._PoolInstantiate(prefab, destination,
                                                       out isPooled);

        if (!isPooled)
        {
            Logger.LogTrace("Prefab to spawn was not pooled, spawning new instance.", Category.ItemSpawn);
            NetworkServer.Spawn(tempObject);
            tempObject.GetComponent <CustomNetTransform>()
            ?.NotifyPlayers();                     //Sending clientState for newly spawned items
        }
        else
        {
            Logger.LogTrace("Prefab to spawn was pooled, reusing it...", Category.ItemSpawn);
        }

        return(SpawnableResult.Single(tempObject, destination));
    }
Ejemplo n.º 3
0
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        if (!SpawnableUtils.IsValidDestination(destination))
        {
            return(SpawnableResult.Fail(destination));
        }

        if (prefab == null)
        {
            Logger.LogWarning("Cannot spawn, prefab to use is null", Category.ItemSpawn);
            return(SpawnableResult.Fail(destination));
        }
        Logger.LogTraceFormat("Spawning using prefab {0}", Category.ItemSpawn, prefab);

        if (Spawn._ObjectPool.TryPoolInstantiate(prefab, destination, false, out var spawnedObject))
        {
            return(SpawnableResult.Single(spawnedObject, destination));
        }
        else
        {
            return(SpawnableResult.Fail(destination));
        }
    }