public class LoadText : MonoBehaviour {
private string loadedText;
private CriFsBinder binder = null;
private uint bindId = 0;
void OnEnable()
{
this.binder = new CriFsBinder();
}
IEnumerator Start () {
CriFsBindRequest bind_request = CriFsUtility.BindCpk(
this.binder,
CriWare.streamingAssetsPath +
"/sample.cpk");
yield return bind_request.WaitForDone(this);
if (bind_request.error != null) {
yield break;
}
else {
this.bindId = bind_request.bindId;
}
CriFsLoadFileRequest load_request
= CriFsUtility.LoadFile(this.binder, "sample_text.txt");
yield return load_request.WaitForDone(this);
if (load_request.error != null) {
yield break;
}
Encoding enc = Encoding.GetEncoding("utf-8");
this.loadedText = enc.GetString(load_request.bytes);
}
void Update () {
}
void OnGUI() {
if (this.loadedText == null) {
return;
}
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), this.loadedText);
}
void OnDisable() {
if (this.bindId > 0) {
CriFsBinder.Unbind(this.bindId);
this.bindId = 0;
}
this.binder.Dispose();
this.binder = null;
}
}