Skip to content

Instantly share code, notes, and snippets.

@alucard55
Last active July 19, 2016 02:44
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/91e78c0488e84ccafa5aa183857d1686 to your computer and use it in GitHub Desktop.
Save alucard55/91e78c0488e84ccafa5aa183857d1686 to your computer and use it in GitHub Desktop.
using System; //Last 3 for Serialization
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
[System.Serializable]
public class GuardA : Monobehaviour {
private 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.Profession = job.Job; //Class
profile.ProfessionDescription = 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;
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class GuardPrototype : StandardParadigm{
//This is a Standard type. To be inherited by guards.
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;
public string JobDescription;
//To be added: Weapon/Armor shit
}
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!";
//To be added: Weapon/Armor uniques
}
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class StandardParadigm : TypeParadigm {
//Stats present in TypeParadigm
//Standard Character Child Classes have no buffs to any stat
public string stdType; //I.e. GuardPrototype, ScholarPrototype, etc
//To be added: Passive Innate Standard Abilities
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class StandardPlayerParadigm : StandardParadigm{
//This is what a Standard character has, see StandardParadigm for more inherited variables.
public string Name;
public int Level;
public string Profession;
public string ProfessionDescription;
}
using UnityEngine;
using System.Collections;
[System.Serializable]
public class TypeParadigm {
//Stats controlled by Type: Chosen, Standard, Muted
//Muted gets no Mana/Magic Attack
public string Type;
//Stats are largely controlled by type
public float Health;
public float Mana;
public float TP; //Tech Points
public float Attack;
public float Defense;
public float MagicAttack;
public float MagicDefense;
public float Critical;
public float Dexterity; //Speed
public float HitRate;
}
using System.Collections.Generic;
using System.Xml.Serialization;
public class XMLSerialization : MonoBehaviour {
public List <GuardA> guardPrototypeA;
public string path;
void Update()
{
if(Input.GetKeyDown(KeyCode.S))
{
SaveToXML (guardPrototypeA);
}
if(Input.GetKeyDown(KeyCode.L))
{
guardPrototypeA = LoadFromXML<List <GuardA>> ();
}
}
void SaveToXML (object obj, bool appendFile = false)
{
var serializer = new XmlSerializer (obj.GetType());
using (var stream = new StreamWriter (Application.dataPath + path, appendFile))
{
serializer.Serialize (stream, obj);
}
}
T LoadFromXML <T>()
{
var serializer = new XmlSerializer (typeof(T));
using (var stream = new StreamReader (Application.dataPath + path))
{
object obj = serializer.Deserialize (stream);
return (T)obj;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment