Skip to content

Instantly share code, notes, and snippets.

@swt02026
Created December 28, 2014 14:20
Show Gist options
  • Save swt02026/1fa3d71671c9311cc6db to your computer and use it in GitHub Desktop.
Save swt02026/1fa3d71671c9311cc6db to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class CollectGameItem : MonoBehaviour {
public GameObject button;
public int id;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void TakeGameItem(){
//button.transform.SetParent(panel.transform);
GameItemsStorer.AddUncountableItem(id);
}
}
using UnityEngine;
using System.Linq;
using System.IO;
using System.Collections;
public class GameConfigurationStorer{
const string FILENAME = "config";
static float seLevel = 0;
static float soundLevel = 0;
static int speedChoose = 0;
static public float SELevel{
get{
return seLevel;
}
set{
seLevel = value;
}
}
static public int SpeedChoose{
get{
return speedChoose;
}
set{
speedChoose = value;
}
}
static public float SoundLevel{
get{
return soundLevel;
}
set{
soundLevel=value;
}
}
static public void ReadFromFile(){
string fullPath = Application.persistentDataPath+"/"+FILENAME;
if(!File.Exists(fullPath))
{
WriteConfiguration();
}
else{
var dataArray = File.ReadAllLines(fullPath);
seLevel = float.Parse(dataArray[0]);
soundLevel = float.Parse( dataArray[1]);
speedChoose = int.Parse( dataArray[2]);
}
}
static public void WriteFromFile(){
string fullPath = Application.persistentDataPath+"/"+FILENAME;
using(FileStream fs = new FileStream(fullPath,FileMode.Create,FileAccess.Write)){
using(StreamWriter stream = new StreamWriter(fs)){
string fullContent =
string.Format("{0}\n{1}\n{2}",seLevel,soundLevel,speedChoose);
stream.Write(fullContent);
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class GameItemsStorer {
static List<int> uncountableGameItems = new List<int>();
static int countableGameItem = 0;
const string FILENAME = "gameitem";
public static int CountableGameItem{
get {
return countableGameItem;
}
}
static public void ReadFromFile(){
string fullPath = Application.persistentDataPath+"/"+FILENAME;
if(!File.Exists(fullPath))
{
uncountableGameItems.Add(-1);
WriteToFile();
}
else{
var readItems = File.ReadAllLines(fullPath);
var readUncountableItem
= (from element in readItems[0].Split()
select int.Parse(element));
uncountableGameItems = readUncountableItem.ToList();
countableGameItem = int.Parse(readItems[1]);
}
}
static public void WriteToFile(){
string fullPath = Application.persistentDataPath+"/"+FILENAME;
using(FileStream fs = new FileStream(fullPath,FileMode.Create,FileAccess.Write)){
using(StreamWriter stream = new StreamWriter(fs)){
var listContent =
uncountableGameItems.Distinct().Select(e => e.ToString());
string content = string.Join(" ",listContent.ToArray());
stream.WriteLine(content);
stream.WriteLine(countableGameItem.ToString());
}
}
}
static public void AddUncountableItem(int i){
uncountableGameItems.Add(i);
}
static public bool IsUncountableGameItemExist(int i){
return uncountableGameItems.Exists(e => e == i);
}
static public void RemoveUncountableItem(int i){
uncountableGameItems.RemoveAll(e => e == i);
}
static public void PrintGameItem(){
var listContent = uncountableGameItems.Select(e => e.ToString());
string content = string.Join(" ",listContent.ToArray());
Debug.Log("List GameItem:"+content);
Debug.Log("Countable GameItem:"+countableGameItem.ToString());
}
static public void AddCountableItem(){
countableGameItem++;
}
static public bool IsCountableGameItemExist(){
return countableGameItem != 0;
}
static public void RemoveCountableItem(){
if(IsCountableGameItemExist()){
countableGameItem--;
}
}
}
using UnityEngine;
using UnityEngineInternal;
using System.Collections;
public class SceneManager: MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void GotoScene(string sceneName){
Application.LoadLevel(sceneName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment