public static void SaveControlsData(ControlsSerialize controlsSave)
    {
        BinaryFormatter bf     = new BinaryFormatter();
        FileStream      stream = new FileStream(Application.persistentDataPath + "/controlsfile.citrus", FileMode.Create);
        ControlsData    data   = new ControlsData(controlsSave);

        bf.Serialize(stream, data);
        stream.Close();
    }
 // Use this for initialization
 void Start()
 {
     data               = GameManager.instance.playerData;
     controls           = GameManager.instance.controls;
     motor              = GetComponent <Motor> ();
     motor.turretLimits = GameManager.instance.playerData.cannonVerticleLimit;
     cannon             = gameObject.GetComponent <Cannon> ();
     artillery          = gameObject.GetComponent <Artillery> ();
 }
    void Load()         // Load data
    {
        ControlsData controlsData = SaveControls.LoadControls();

        InputAction inputAction = controlsData.inputAction as InputAction;

        Debug.Log("Controls data loaded: " + inputAction);

        string inputActionString = controlsData.inputActionString;

        Debug.Log("Input action string loaded: " + inputActionString);
    }
    public static void SaveControlsInput(ControlsInput controls)
    {
        //Debug.Log("SaveControlsInput" + controls.m_Action);

        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/controls.cfg";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        ControlsData data = new ControlsData(controls);

        formatter.Serialize(stream, data);
        stream.Close();
    }
    public static KeyCode Load_Pause_Data()
    {
        if (File.Exists(Application.persistentDataPath + "/controlsfile.citrus"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/controlsfile.citrus", FileMode.Open);

            ControlsData data = bf.Deserialize(stream) as ControlsData;

            stream.Close();
            return(data.Pause);
        }
        else
        {
            Debug.Log("Could not Deserialize save data");
            return(KeyCode.Escape);
        }
    }
    public static KeyCode Load_MoveRight_Data()
    {
        if (File.Exists(Application.persistentDataPath + "/controlsfile.citrus"))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(Application.persistentDataPath + "/controlsfile.citrus", FileMode.Open);

            ControlsData data = bf.Deserialize(stream) as ControlsData;

            stream.Close();
            Debug.Log("MoveRight Key: " + data.MoveRight + " Loaded!");
            return(data.MoveRight);
        }
        else
        {
            Debug.Log("Could not Deserialize save data");
            return(KeyCode.RightArrow);
        }
    }
    public static ControlsData LoadControls()
    {
        string path = Application.persistentDataPath + "/controls.cfg";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);

            ControlsData data = formatter.Deserialize(stream) as ControlsData;
            stream.Close();
            return(data);
        }
        else
        {
            Debug.LogError("Save file not found: " + path);
            return(null);
        }
    }