コード例 #1
0
    public void SavePlayerState()
    {
        GameObject playerObj = GameObject.FindWithTag("Player");

        if (playerObj == null)
        {
            //This most likely means the player is dead
            //and we are restarting the level.
            return;
        }
        GameObject obj = SceneMessenger.GetMainPlayerObject(playerObj);

        if (obj == null)
        {
            //This most likely means the player is dead
            //and we are restarting the level.
            return;
        }
        int health = obj.GetComponent <Health> ().health;
        int armor  = obj.GetComponent <Health> ().armor;
        List <PickupType> activePickups = obj.GetComponent <PickupController> ().GetActivePowerups();
        int  points    = GameObject.FindGameObjectWithTag("UIController").GetComponent <UIController> ().Points;
        bool gunActive = obj.GetComponent <PlayerInput> ().gunActive;

        SceneMessenger.playerData = new ScenePersistence(health, armor, activePickups, points, gunActive);
    }
コード例 #2
0
    public void LoadPlayerState()
    {
        GameObject obj = SceneMessenger.GetMainPlayerObject(GameObject.FindWithTag("Player"));

        if (obj != null && SceneMessenger.playerData != null)
        {
            int  health    = SceneMessenger.playerData.health;
            int  armor     = SceneMessenger.playerData.armor;
            int  points    = SceneMessenger.playerData.points;
            bool gunActive = SceneMessenger.playerData.gunActive;
            int  maxHealth = obj.GetComponent <Health> ().maxHealth;
            int  maxArmor  = obj.GetComponent <Health> ().maxArmor;
            obj.GetComponent <Health> ().health = health;
            obj.GetComponent <Health> ().armor  = armor;
            obj.GetComponent <PickupController> ().SetActivePowerups(SceneMessenger.playerData.activePowerups);
            obj.GetComponent <PlayerInput> ().gunActive = gunActive;
            GameObject.FindGameObjectWithTag("UIController").GetComponent <UIController> ().Points = points;

            Invoke(Message.HEALTH_UPDATED, new object[] { health, maxHealth, armor, maxArmor });
            Invoke(Message.POINTS_RECEIVED, new object[] { 0 });

            SceneMessenger.playerData = null;
        }
    }