SebastianLawe

Untitled

Apr 26th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. using System.IO;
  7. using Inventory;
  8.  
  9. namespace IOUtility {
  10.     public class IOAccess {
  11.         static int _onlineScore = 0;
  12.  
  13.         public static int OnlineScore {
  14.             get {
  15.                 return _onlineScore;
  16.             }
  17.             set {
  18.                 _onlineScore = value;
  19.             }
  20.         }
  21.         public static void SaveCredentials(string path, string userName, string password) {
  22.             string filepath = Application.persistentDataPath + @"/" + path;
  23.             using (StreamWriter writer = new StreamWriter(filepath)) {
  24.                 writer.WriteLine(userName);
  25.                 writer.WriteLine(password);
  26.             }
  27.         }
  28.         public static string[] OpenCredentials(string path) {
  29.             string[] userNameAndPass = new string[2];
  30.             userNameAndPass[0] = " ";
  31.             userNameAndPass[1] = " ";
  32.             string filepath = Application.persistentDataPath + @"/" + path;
  33.             if (File.Exists(filepath)) {
  34.                 using (StreamReader reader = new StreamReader(filepath)) {
  35.                     userNameAndPass[0] = reader.ReadLine();
  36.                     userNameAndPass[1] = reader.ReadLine();
  37.                 }
  38.             }
  39.             return userNameAndPass;
  40.         }
  41.         public static void SaveString(string path, string stringValue) {
  42.             string filepath = Application.persistentDataPath + @"/" + path;
  43.             using (StreamWriter writer = new StreamWriter(filepath)) {
  44.                 writer.WriteLine(ballName);
  45.             }
  46.         }
  47.         public static string OpenString(string path) {
  48.             string filepath = Application.persistentDataPath + @"/" + path;
  49.             if (File.Exists(filepath)) {
  50.                 using (StreamReader reader = new StreamReader(filepath)) {
  51.                     return reader.ReadLine();
  52.                 }
  53.             }
  54.             return null;
  55.         }
  56.         public static void SaveInt(string path, int score) {
  57.             string filepath = Application.persistentDataPath + @"/" + path;
  58.             using (FileStream stream = new FileStream(filepath, FileMode.Create, FileAccess.Write)) {
  59.                 using (BinaryWriter writer = new BinaryWriter(stream)) {
  60.                     //using (StreamWriter writer = new StreamWriter(filepath)) {
  61.                     writer.Write(score);
  62.                     //writer.WriteLine(score);
  63.                     //}
  64.                 }
  65.             }
  66.         }
  67.         public static int OpenInt(string path) {
  68.             int score = 0;
  69.             string filepath = Application.persistentDataPath + @"/" + path;
  70.             if (File.Exists(filepath)) {
  71.                 using (FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read)) {
  72.                     using (BinaryReader reader = new BinaryReader(stream)) {
  73.                         //  using (StreamReader reader = new StreamReader(filepath)) {
  74.                         score = reader.ReadInt32();
  75.                         //score = int.Parse(reader.ReadLine());
  76.                         //}
  77.                     }
  78.                 }
  79.             }
  80.             return score;
  81.         }
  82.         public void SaveStringOnline(string ballName) {
  83.  
  84.         }
  85.         public static string OpenStringOnline() {
  86.             return null;
  87.         }
  88.         public static void SaveIntOnline(int score) {
  89.             //GJAPI.Data.Set("score", score.ToString(), true);
  90.         }
  91.         public static string CallBack(string data) {
  92.             return data;
  93.         }
  94.         public static void OpenIntOnline() {
  95.             string onlineData = string.Empty;
  96.             //GJAPI.Data.DataReady += delegate {
  97.             //  _onlineScore = int.Parse(GJAPI.Data.StringData);
  98.             //};
  99.             //GJAPI.Data.Get("score", true);
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment