Hello,
I need some help saving the type of class a list holds. Currently I have a script called QuestEntity which contains a list<> of QuestNodes. These QuestNodes are all of different types (for example: StartNode), but they all inherit from QuestNode. When I exit unity they all get reset to the base QuestNode, and are not recognized as their specific type (StartNode). Does anyone know how to get around this.
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class QuestNode
{
[SerializeField]
public Rect rect;
[SerializeField]
public List<QuestNode> nextNodes = new List<QuestNode>();
public QuestNode()
{
rect = new Rect (0, 0, 140, 70);
}
public override bool Equals (object obj)
{
if(!(obj is QuestNode))
return false;
QuestNode n = (QuestNode)obj;
return n.ToString () == ToString ();
}
public override string ToString()
{
return "Q-Node";
}
public virtual void Activate()
{
foreach(QuestNode node in nextNodes)
{
node.Activate();
}
}
// Custom node classes.
#region Node Classes
[System.Serializable]
public class StartNode : QuestNode
{
public override void Activate ()
{
base.Activate ();
}
public override string ToString ()
{
return "Start";
}
}
#endregion
}