halfmagic
10/11/2019 - 7:01 AM

Unity Input Field Save / Load Function

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingManager : MonoBehaviour {
    public CalibrationManager calibrationManager;
    void Start () {
        Load ();
    }
    public void Save () {
        // Save Camera Calibration Values
        for (int i = 0; i < calibrationManager.camRef.Length; i++) {
            PlayerPrefs.SetString ("camPosX" + i, calibrationManager.camRef[i].calibrationValue[0].text);
            PlayerPrefs.SetString ("camPosY" + i, calibrationManager.camRef[i].calibrationValue[1].text);
            PlayerPrefs.SetString ("camPosZ" + i, calibrationManager.camRef[i].calibrationValue[2].text);
            PlayerPrefs.SetString ("camFOV" + i, calibrationManager.camRef[i].calibrationValue[3].text);
        }
        Debug.Log ("Settings Saved");
    }
    public void Load () {
        for (int i = 0; i < calibrationManager.camRef.Length; i++) {
            calibrationManager.camRef[i].calibrationValue[0].text = PlayerPrefs.GetString ("camPosX" + i);
            calibrationManager.camRef[i].calibrationValue[1].text = PlayerPrefs.GetString ("camPosY" + i);
            calibrationManager.camRef[i].calibrationValue[2].text = PlayerPrefs.GetString ("camPosZ" + i);
            calibrationManager.camRef[i].calibrationValue[3].text = PlayerPrefs.GetString ("camFOV" + i);
        }
        Debug.Log ("Settings Loaded");
    }
}