示例#1
0
    /// <summary>
    /// (Use CallDeferred) Spawn multiple instances from PackedScene's list with a delay   (scene must ihnerits from Node2D)
    /// </summary>
    /// <param name="pDestinationNode_Deferred">The node where to add the instance (usually THIS to use CallDeferred / NULL = do not use CallDeferred)</param>
    /// <param name="pGlobalPosition">Where to display the scene spawned (NULL = do not use set a position)</param>
    /// <param name="pTiming">A Spawn_Timing object to define timing options</param>
    /// <param name="pSpawnNumber">How many instance to create</param>
    /// <param name="pRandomInstance">If true, get a random scene from the scenes loaded in Load_NewScene() method. Else, load scene in the same order</param>
    /// <param name="pGroupName">Name of the group the instance will belong</param>
    /// <returns>An instance of the scene</returns>
    public async Task <T> Add_Multiple_Instances_With_Delay <T>(Node pDestinationNode_Deferred, Vector2?pGlobalPosition, Spawn_Timing pTiming, int pSpawnNumber = 1, bool pRandomInstance = false, string pGroupName = "") where T : Node2D
    {
        if (ListScenes == null || ListScenes.Count == 0 || pSpawnNumber < 1)
        {
            return(null);
        }

        // Create the instance
        T   instance = null;
        int scene_id = 0;

        // For instances to create
        for (int i = 0; i < pSpawnNumber; i++)
        {
            // Create the delayed instance
            instance = await Add_Instance_With_Delay <T>(pDestinationNode_Deferred, pGlobalPosition, pTiming, scene_id, pGroupName);

            // Select a random scene if needed or load the next scene in the list
            if (pRandomInstance && ListScenes.Count > 1)
            {
                scene_id = Nucleus_Maths.Rnd.RandiRange(0, ListScenes.Count - 1);
            }
            else if (ListScenes.Count > 1)
            {
                scene_id = (scene_id < ListScenes.Count - 1) ? scene_id + 1 : 0;
            }
        }

        return(instance);
    }
示例#2
0
    /// <summary>
    /// (Use CallDeferred) Spawn a single instance of the index of the PackedScene's list with a delay   (scene must ihnerits from Node2D)
    /// </summary>
    /// <param name="pDestinationNode_Deferred">The node where to add the instance (usually THIS to use CallDeferred / NULL = do not use CallDeferred)</param>
    /// <param name="pGlobalPosition">Where to display the scene spawned (NULL = do not use set a position)</param>
    /// <param name="pTiming">A Spawn_Timing object to define timing options</param>
    /// <param name="pIndexSceneToDisplay">The index of the PackedScene to display (0 by default) </param>
    /// <param name="pGroupName">Name of the group the instance will belong ("" by default)</param>
    /// <returns>An instance of the scene</returns>
    public async Task <T> Add_Instance_With_Delay <T>(Node pDestinationNode_Deferred, Vector2?pGlobalPosition, Spawn_Timing pTiming, int pIndexSceneToDisplay = 0, string pGroupName = "") where T : Node2D
    {
        if (ListScenes == null || ListScenes.Count == 0 || ListScenes[pIndexSceneToDisplay] == null)
        {
            return(null);
        }

        // Set the timing options and wait
        float spawn_time = pTiming.GetTiming();

        if (pTiming.IsTimed)
        {
            await ToSignal(GetTree().CreateTimer(spawn_time), "timeout");
        }

        // Create and return the instance
        return(Add_Instance <T>(pDestinationNode_Deferred, pGlobalPosition, pIndexSceneToDisplay, pGroupName));
    }