Skip to content

Instantly share code, notes, and snippets.

@alucard55
Last active July 18, 2016 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alucard55/61df6f96fef4d9111ec98315a4f8a785 to your computer and use it in GitHub Desktop.
Save alucard55/61df6f96fef4d9111ec98315a4f8a785 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System; //Last 3 for Serialization
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class GameControl : MonoBehaviour {
public static GameControl control;
void Awake ()
{
if (control == null) {
DontDestroyOnLoad (gameObject); //keep only one object, there can be only one
control = this;
}
else if (control != this)
{
Destroy (gameObject);
}
}
void OnGUI ()
{
//GUI.Label (new Rect(10, 10, 100, 30), "Health: " + health);
//GUI.Label (new Rect(10, 40, 150, 30), "Experience: " + exp);
}
public void Save ()
{
//Create Formatter and Stream, then serialize data TO the Stream under the Formatter ex. bf.Serialize(Stream, info)
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + "/player.dat");
PlayerData data = new PlayerData ();
//playerdata needs to contain info to be serialized
bf.Serialize (file, data);
file.Close ();
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + "/player.dat"))
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/playerInfo.dat", FileMode.Open);
file.Close();
}
}
}
[Serializable] //CAN save to file
class PlayerData
{
//I have no idea what to put here
}
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
[Serializable]
public class GuardA : MonoBehaviour {
public StandardPlayerParadigm profile;
private Mercenary job;
private GuardPrototype type;
// Use this for initialization
void Start () {
profile = new StandardPlayerParadigm ();
job = new Mercenary ();
type = new GuardPrototype ();
//decl the stats
profile.Name = "Guard A";
profile.stdType = type.stdType; //Which child of StandardType?
profile.Job = job.Job; //Class
profile.JobDescription = job.JobDescription; //ClassDescription
profile.Level = 1;
profile.Health = type.Health;
profile.Mana = type.Mana;
profile.TP = type.TP;
profile.Attack = type.Attack;
profile.Defense = type.Defense;
profile.MagicAttack = type.MagicAttack;
profile.MagicDefense = type.MagicDefense;
profile.Critical = type.Critical;
profile.Dexterity = type.Dexterity;
profile.HitRate = type.HitRate;
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
//Display the following to confirm values
GUILayout.Label (profile.Name);
GUILayout.Label (profile.stdType);
GUILayout.Label (profile.Level.ToString());
GUILayout.Label (profile.Job);
GUILayout.Label (profile.JobDescription);
GUILayout.Label (profile.Health.ToString());
GUILayout.Label (profile.Mana.ToString());
GUILayout.Label (profile.TP.ToString());
GUILayout.Label (profile.Attack.ToString());
GUILayout.Label (profile.Defense.ToString());
GUILayout.Label (profile.MagicAttack.ToString());
GUILayout.Label (profile.MagicDefense.ToString());
GUILayout.Label (profile.Critical.ToString());
GUILayout.Label (profile.Dexterity.ToString());
GUILayout.Label (profile.HitRate.ToString());
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class GuardPrototype : StandardParadigm{
public GuardPrototype()
{
stdType = "Royal Guard";
Health = 20f;
Mana = 0f; //for now
TP = 0f; //for now
Attack = 12f;
Defense = 6f;
MagicAttack = 3f;
MagicDefense = 5f;
Critical = .03f;
Dexterity = 0f; //for now
HitRate = .7f; //for now
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class JobParadigm: MonoBehaviour {
public string Job { get; set; }
public string JobDescription { get; set; }
//Eventually will have stat mods
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Mercenary : JobParadigm {
public Mercenary()
{
Job = "Mercenary";
JobDescription = "Made a living out of it -- must be good at it!";
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class StandardParadigm : TypeParadigm {
public string stdType { get; set; }
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class StandardPlayerParadigm : StandardParadigm{
public string Name { get; set; }
public int Level { get; set; }
public string Job { get; set; }
public string JobDescription { get; set; }
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class TypeParadigm {
public string Type { get; set; }
//Stats are controlled by type
public float Health { get; set; }
public float Mana { get; set; }
public float TP { get; set; } //Tech Points
public float Attack { get; set; }
public float Defense { get; set; }
public float MagicAttack { get; set; }
public float MagicDefense { get; set; }
public float Critical { get; set; }
public float Dexterity { get; set; } //Speed
public float HitRate { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment