コード例 #1
0
    /// <summary>
    /// Enters the player into the subworld of the given ID.
    /// If the given subworld is the one the player is already in, leave the subworld <see cref="WorldManager.LeaveSubworld"/>
    /// Unloads world chunks
    /// </summary>
    /// <param name="id"></param>
    public void EnterSubworld(int id)
    {
        //Collect subworld based on its ID
        Subworld sub = World.GetSubworld(id);

        //Check for null
        if (sub == null)
        {
            Debug.Error("Subworld of ID '" + id + "' could not be found");
            return;
        }
        if (sub == CurrentSubworld)
        {
            LeaveSubworld();
            return;
        }
        //If the subworld doesn't have an entrance, set its entrance as the current player position.
        if (sub.InternalEntrancePos == null)
        {
            Debug.Error("Subworld " + sub.ToString() + " has no WorldEntrance, Player position " + Player.Position + " has been set");
            sub.SetWorldEntrance(Vec2i.FromVector3(Player.Position));
        }

        if (CurrentSubworld != null)
        {
            Debug.Error("Cannot enter a subworld while already in one.");
            return;
        }
        if (sub != null)
        {
            Debug.Log("Player entering subworld " + sub.ToString(), Debug.NORMAL);
            //First unload all world chunks and set the current subworld
            CurrentSubworld = sub;
            //EntityManager.Instance?.UnloadAllChunks();
            //Load all subworld chunks and add them to the the relevent list
            CRManager.LoadSubworldChunks(sub);

            //GameManager.PathFinder.LoadSubworld(sub);
            //Inform entity manager we are entering the sub world, then teleport player to correct position.

            Player.SetPosition(sub.InternalEntrancePos.AsVector3());
            WaitAndPathScanCoroutine();

            EntityManager.Instance?.EnterSubworld(sub);

            //PlayerManager.Instance.ProceduralGridMover.UpdateGraph();
        }
    }