I have recently re-entered into the world of programming after quite the hiatus, now I have dove back in head first and promptly sunk
So where I am currently running into issue, is in attempting to write a script that will allow me to pair up multiple definitions for levels to a world definition (I am using the word definition loosely).
If you skim over the comments in the code below, you will see what I had in my mind when I began writing the script. I currently am struggling where it comes to defining the array of WorldData as a SerializedField, in reading through the documentation it came to light that the ability doesn’t exist to serialize a standard class. I would like to stray away from having to have my WorldData and LevelData classes as GameObjects as that would create an unnecessary number of GameObjects that shouldn’t be needed, I would also like to avoid using a XML definition file and having to use Resource.Load if at all possible for the Texture2D field within both of my data classes.
So I guess after all of this rambling, I am asking if someone might be able to be able to provide some insight on how I might achieve what I am attempting to preform here. As I am fairly certain that the solution is not that complicated or far away, but I simply have spent to much time staring at the same script. Thank you in advance for anyone able to assist!
/*
* Each field editable within Inspector
* [RELATION CONTAINER]
* -+ World 1
* ---+ Level 1
* ---+ Level 2
* -+ World 2
* ---+ Level 1
* ---+ Level 2
* ---+ Level 3
* -+ World 3
* ---+ Level 1
* -+ World 4
* ---+ Level 1
* ---+ Level 2
*
* Usage pseudocode: Application.LoadLevel(WorldToLevelRelations[1].Level[2].LevelName);
*/
using UnityEngine;
public class WorldLevelRelation : MonoBehaviour
{
//-------------------------------------------------------------------
#region Fields
[SerializeField]
private WorldData[] m_WorldLevelRelations;
#endregion
//-------------------------------------------------------------------
#region Properties
public WorldData[] WorldToLevelRelations
{
get
{
// Return class field
return this.m_WorldLevelRelations;
}
}
#endregion
//-------------------------------------------------------------------
#region Awake class method
private void Awake()
{
// Do not destroy this game object
DontDestroyOnLoad(this);
}
#endregion
}
public class WorldData
{
//-------------------------------------------------------------------
#region Fields
[SerializeField]
private string m_WorldName = "";
[SerializeField]
private Texture2D m_WorldPreview;
[SerializeField]
private LevelData[] m_Level;
#endregion
//-------------------------------------------------------------------
#region Properties
public string WorldName
{
get
{
// Return class field
return this.m_WorldName;
}
}
public Texture2D WorldPreview
{
get
{
// Return class field
return this.m_WorldPreview;
}
}
public LevelData[] Level
{
get
{
// Return class field
return this.m_Level;
}
}
#endregion
}
public class LevelData
{
//-------------------------------------------------------------------
#region Fields
[SerializeField]
private string m_LevelName = "";
[SerializeField]
private Texture2D m_LevelPreview;
[SerializeField]
private string m_InternalLevelName = "";
#endregion
//-------------------------------------------------------------------
#region Properties
public string LevelName
{
get
{
// Return class field
return this.m_LevelName;
}
}
public Texture2D LevelPreview
{
get
{
// Return class field
return this.m_LevelPreview;
}
}
public string InternalLevelName
{
get
{
// Return class field
return this.m_InternalLevelName;
}
}
#endregion
}