Esempio n. 1
0
    public void SaveGame()
    {
        PlayerPrefs.SetString("Date" + index, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString());
        var    currentRT = RenderTexture.active;
        Camera camera    = Camera.main.transform.GetChild(0).GetComponent <Camera>();

        RenderTexture.active = camera.targetTexture;
        camera.Render();
        Texture2D image = new Texture2D(camera.targetTexture.width, camera.targetTexture.height);

        image.ReadPixels(new Rect(0, 0, camera.targetTexture.width, camera.targetTexture.height), 0, 0);
        image.Apply();
        RenderTexture.active = currentRT;
        PlayerPrefsX.WriteTextureToPlayerPrefs("Image" + index, image);
        PlayerPrefs.SetString("Level" + index, SceneManager.GetActiveScene().name);
        PlayerPrefsX.SetVector3("Position" + index, CharacterController.Player.transform.position);
        PlayerPrefsX.SetQuaternion("Rotation" + index, CharacterController.Player.transform.rotation);
        PlayerPrefs.SetFloat("Health" + index, CharacterController.Player.Health.CurrentHealth);
        PlayerPrefs.SetFloat("Energy" + index, CharacterController.Player.Energy.CurrentEnergy);
        PlayerPrefsX.SetStringArray("ITriggers" + index, PlayerPrefsX.GetStringArray("ITriggers" + PlayerPrefs.GetInt("Slot")).Concat(Loader.FindObjectsOfTypeAll <MonoBehaviour>().OfType <ITrigger>().Where(e => e.Complete).Select(f => f.GameObject.name).ToArray()).ToArray());
    }