Scorr / RetroUnity

Unity frontend for the libretro API.
GNU General Public License v3.0
41 stars 23 forks source link

GameManager error in unity3d 5.3.4 #4

Closed supneo closed 8 years ago

supneo commented 8 years ago

Error CS0103 The name 'File' does not exist in the current context

GameManager.cs Old Error:

using UnityEngine;

public class GameManager : MonoBehaviour {

    private const string CoreName = "snes9x_libretro.dll";
    private const string RomName = "Chrono Trigger (USA).sfc";
    private LibretroWrapper.Wrapper wrapper;

    public Renderer Display;

    private void Start() {
        Application.targetFrameRate = 60;
        LoadRom(Application.streamingAssetsPath + "/" + RomName);
    }

    private void Update() {
        if (wrapper != null) {
            wrapper.Update();
        }
        if (LibretroWrapper.tex != null) {
            Display.material.mainTexture = LibretroWrapper.tex;
        }

        // debug input
        //if (Input.GetButton("B")) Debug.Log("B");
        //if (Input.GetButton("Y")) Debug.Log("Y");
        //if (Input.GetButton("SELECT")) Debug.Log("SELECT");
        //if (Input.GetButton("START")) Debug.Log("START");
        //if (Input.GetAxisRaw("DpadX") >= 1.0f) Debug.Log("UP");
        //if (Input.GetAxisRaw("DpadX") <= -1.0f) Debug.Log("DOWN");
        //if (Input.GetAxisRaw("DpadY") >= 1.0f) Debug.Log("RIGHT");
        //if (Input.GetAxisRaw("DpadY") <= -1.0f) Debug.Log("LEFT");
        //if (Input.GetButton("A")) Debug.Log("A");
        //if (Input.GetButton("X")) Debug.Log("X");
        //if (Input.GetButton("L")) Debug.Log("L");
        //if (Input.GetButton("R")) Debug.Log("R");

    }

    public void LoadRom(string path) {
#if !UNITY_ANDROID
        // Doesn't work on Android because you can't do File.Exists in StreamingAssets folder.
        // Should figure out a different way to perform check later.
        // If the file doesn't exist the application gets stuck in a loop.
        if (!File.Exists(path)) {
            Debug.LogError(path + " not found.");
            return;
        }
#endif
        Display.material.color = Color.white;

        wrapper = new LibretroWrapper.Wrapper(Application.streamingAssetsPath + "/" + CoreName);

        wrapper.Init();
        wrapper.LoadGame(path);
    }
}

GameManager.cs New Fixed :

using System.IO;
using UnityEngine;

public class GameManager : MonoBehaviour {

    private const string CoreName = "snes9x_libretro.dll";
    private const string RomName = "Chrono Trigger (USA).sfc";
    private LibretroWrapper.Wrapper wrapper;

    public Renderer Display;

    private void Start() {
        Application.targetFrameRate = 60;
        LoadRom(Application.streamingAssetsPath + "/" + RomName);
    }

    private void Update() {
        if (wrapper != null) {
            wrapper.Update();
        }
        if (LibretroWrapper.tex != null) {
            Display.material.mainTexture = LibretroWrapper.tex;
        }

        // debug input
        //if (Input.GetButton("B")) Debug.Log("B");
        //if (Input.GetButton("Y")) Debug.Log("Y");
        //if (Input.GetButton("SELECT")) Debug.Log("SELECT");
        //if (Input.GetButton("START")) Debug.Log("START");
        //if (Input.GetAxisRaw("DpadX") >= 1.0f) Debug.Log("UP");
        //if (Input.GetAxisRaw("DpadX") <= -1.0f) Debug.Log("DOWN");
        //if (Input.GetAxisRaw("DpadY") >= 1.0f) Debug.Log("RIGHT");
        //if (Input.GetAxisRaw("DpadY") <= -1.0f) Debug.Log("LEFT");
        //if (Input.GetButton("A")) Debug.Log("A");
        //if (Input.GetButton("X")) Debug.Log("X");
        //if (Input.GetButton("L")) Debug.Log("L");
        //if (Input.GetButton("R")) Debug.Log("R");

    }

    public void LoadRom(string path) {
#if !UNITY_ANDROID
        // Doesn't work on Android because you can't do File.Exists in StreamingAssets folder.
        // Should figure out a different way to perform check later.
        // If the file doesn't exist the application gets stuck in a loop.
        if (!File.Exists(path)) {
            Debug.LogError(path + " not found.");
            return;
        }
#endif
        Display.material.color = Color.white;

        wrapper = new LibretroWrapper.Wrapper(Application.streamingAssetsPath + "/" + CoreName);

        wrapper.Init();
        wrapper.LoadGame(path);
    }
}
Scorr commented 8 years ago

Thanks for catching this! Apparently when you set the target platform to Android this piece of code won't compile even in the editor. I must've gotten overzealous with removing unused includes (this one wasn't unused at all!)

Scorr commented 8 years ago

(Sorry about the opening and closing, still getting to know Github)