This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using System; //Last 3 for Serialization | |
| using System.Runtime.Serialization.Formatters.Binary; | |
| using System.IO; | |
| public class GameControl : MonoBehaviour { //Trying to display info, alter it, and then save it to test Serialization! | |
| public static GameControl control; | |
| public GuardA playerA; | |
| 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 Start() | |
| { | |
| playerA = new GuardA (); | |
| } | |
| void OnGUI() | |
| { | |
| //Display the following | |
| GUILayout.Label (playerA.profile.Name); | |
| GUILayout.Label (playerA.profile.stdType); | |
| GUILayout.Label (playerA.profile.Level.ToString()); | |
| GUILayout.Label (playerA.profile.Profession); | |
| GUILayout.Label (playerA.profile.ProfessionDescription); | |
| GUILayout.Label (playerA.profile.Health.ToString()); | |
| GUILayout.Label (playerA.profile.Mana.ToString()); | |
| GUILayout.Label (playerA.profile.TP.ToString()); | |
| GUILayout.Label (playerA.profile.Attack.ToString()); | |
| GUILayout.Label (playerA.profile.Defense.ToString()); | |
| GUILayout.Label (playerA.profile.MagicAttack.ToString()); | |
| GUILayout.Label (playerA.profile.MagicDefense.ToString()); | |
| GUILayout.Label (playerA.profile.Critical.ToString()); | |
| GUILayout.Label (playerA.profile.Dexterity.ToString()); | |
| GUILayout.Label (playerA.profile.HitRate.ToString()); | |
| if (GUI.Button (new Rect (110, 140, 100, 30), "Health up")) | |
| { | |
| playerA.profile.Health += 10; | |
| } | |
| if (GUI.Button (new Rect (110, 180, 100, 30), "Health down")) | |
| { | |
| playerA.profile.Health -= 10; | |
| } | |
| } | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| using System; //Last 3 for Serialization | |
| using System.Runtime.Serialization.Formatters.Binary; | |
| using System.IO; | |
| [System.Serializable] | |
| public class GuardA : MonoBehaviour{ | |
| public static GuardA template; | |
| /*[SerializeField]*/ public StandardPlayerParadigm profile; //typically these are private, but I tested some things with GameControl.cs and needed them public | |
| public Mercenary job; | |
| public GuardPrototype type; | |
| void Awake () //Keep this around | |
| { | |
| if (template == null) | |
| { | |
| DontDestroyOnLoad (gameObject); //keep only one object, there can be only one | |
| template = this; | |
| } | |
| else if (template != this) | |
| { | |
| Destroy (gameObject); | |
| } | |
| } | |
| // 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; | |
| } | |
| // Update is called once per frame | |
| void Update () { | |
| } | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| [System.Serializable] | |
| public class JobParadigm { | |
| public string Job; | |
| public string JobDescription; | |
| //other stuff to come | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!"; | |
| //Other stuff to come | |
| } | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| [System.Serializable] | |
| public class StandardParadigm : TypeParadigm { | |
| //Standard Character Child Classes have no buffs to any stat | |
| public string stdType; | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| [System.Serializable] | |
| public class StandardPlayerParadigm : StandardParadigm{ | |
| public string Name; | |
| public int Level; | |
| public string Profession; | |
| public string ProfessionDescription; | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| [System.Serializable] | |
| public class TypeParadigm { | |
| //Standard, Chosen, or Muted | |
| public string Type; | |
| //Stats are 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; | |
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.IO; | |
| 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