Ejemplo n.º 1
0
        protected void RestorePlayer(GameState gs)
        {
            MetaState      mgs    = MetaState.Instance;
            GameObject     player = WorldUtils.GetPlayerObject();
            RestorableData prd    = gs.PlayerWorldState;

            if (prd != null)
            {
                if (player == null)
                {
                    //spawn the player object in
                    player      = Instantiate(CoreUtils.LoadResource <GameObject>("Entities/" + "spec_player"), transform) as GameObject;
                    player.name = "Player";
                    if (mgs.TransitionType == SceneTransitionType.LoadGame)
                    {
                        player.GetComponent <PlayerRestorableComponent>().Restore(prd);
                    }
                    else
                    {
                        // get intent and move
                        RestorePlayerToIntent(mgs, player);
                    }
                }
                else
                {
                    //restore player if relevant, warn either way
                    if (mgs.TransitionType == SceneTransitionType.LoadGame)
                    {
                        player.GetComponent <PlayerRestorableComponent>().Restore(prd);
                        Debug.LogWarning("Player already exists, restoring anyway");
                    }
                    else
                    {
                        //if an intent exists, move
                        RestorePlayerToIntent(mgs, player);
                        Debug.LogWarning("Player already exists");
                    }
                }
            }
            else
            {
                if (player == null)
                {
                    player      = Instantiate(CoreUtils.LoadResource <GameObject>("Entities/" + "spec_player"), transform) as GameObject;
                    player.name = "Player";
                }


                RestorePlayerToIntent(mgs, player);

                //warn that no player data exists
                Debug.LogWarning("No player world data exists!");
            }

            ScriptingModule.CallHooked(ScriptHook.OnPlayerSpawn, this, player);
        }
Ejemplo n.º 2
0
        static void TeleportToMe()
        {
            var playerTransform = WorldUtils.GetPlayerObject().transform;

            Vector3    targetPos = playerTransform.position + (playerTransform.forward.GetFlatVector().GetSpaceVector() * 1f);
            Quaternion targetRot = playerTransform.rotation;

            SelectedObject.transform.position = targetPos;
            SelectedObject.transform.rotation = targetRot;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Finds the player and returns their controller (does not guarantee an actual PlayerController!)
        /// </summary>
        public static BaseController GetPlayerController()                          //TODO split into Get() and TryGet()
        {
            var pc = WorldUtils.GetPlayerObject()?.GetComponent <BaseController>(); //should be safe because GetPlayerObject returns true null

            if (pc != null)
            {
                return(pc);
            }
            else
            {
                Debug.LogWarning("Couldn't find PlayerController!");
                return(null);
            }
        }
Ejemplo n.º 4
0
 static void Spawn(string fid)
 {
     WorldUtils.SpawnEntity(fid, null, (WorldUtils.GetPlayerObject().transform.position + (WorldUtils.GetPlayerObject().transform.forward * 1.0f)), Vector3.zero, null);
 }