Esempio 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));
    }
Esempio n. 2
0
    public SpawnableResult ClientSpawnAt(SpawnDestination destination)
    {
        bool isPooled;         // not used for Client-only instantiation
        var  go = Spawn._PoolInstantiate(prefab, destination, out isPooled);

        return(SpawnableResult.Single(go, destination));
    }
Esempio 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);

        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));
    }
Esempio n. 4
0
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        var prefab = Spawn.DeterminePrefab(toClone);

        if (prefab == null)
        {
            Logger.LogErrorFormat(
                "Object {0} cannot be cloned because it has no PoolPrefabTracker and its name" +
                " does not match a prefab name, so we cannot" +
                " determine the prefab to instantiate. Please fix this object so that it" +
                " has an attached PoolPrefabTracker or so its name matches the prefab it was created from.",
                Category.ItemSpawn, toClone);
            return(SpawnableResult.Fail(destination));
        }

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

        if (!isPooled)
        {
            NetworkServer.Spawn(tempObject);
            tempObject.GetComponent <CustomNetTransform>()
            ?.NotifyPlayers();                     //Sending clientState for newly spawned items
        }

        return(SpawnableResult.Single(tempObject, destination));
    }
Esempio n. 5
0
 public SpawnableResult ClientSpawnAt(SpawnDestination destination)
 {
     if (Spawn._ObjectPool.TryPoolInstantiate(prefab, destination, true, out var spawnedObject))
     {
         return(SpawnableResult.Single(spawnedObject, destination));
     }
     else
     {
         return(SpawnableResult.Fail(destination));
     }
 }
Esempio n. 6
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));
        }
    }
Esempio n. 7
0
    public SpawnableResult SpawnAt(SpawnDestination destination)
    {
        var prefab = Spawn.DeterminePrefab(toClone);

        if (prefab == null)
        {
            Logger.LogErrorFormat(
                "Object {0} cannot be cloned because it has no PoolPrefabTracker and its name" +
                " does not match a prefab name, so we cannot" +
                " determine the prefab to instantiate. Please fix this object so that it" +
                " has an attached PoolPrefabTracker or so its name matches the prefab it was created from.",
                Category.ItemSpawn, toClone);
            return(SpawnableResult.Fail(destination));
        }

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