問題:我的自定義類 ( public List<ComponentClass> OnCast_Comp = new List<ComponentClass>();) 串列沒有出現在統一編輯器中。我已經[SerializeField]在它上面了,自定義類[System.Serializable]也在它上面。但它仍然不會出現在編輯器中。
SpellHolder.cs:
public class SpellHolder : MonoBehaviour
{
// holds the currently owned spells for the player
// only holds the spell, the content of the spell itself is inside SingleSpellManager.cs
// [SpellHolder.cs] -> SingleSpellManager.cs
[SerializeField]
public List<SingleSpellManager> List_Spells = new List<SingleSpellManager>();
}
SingleSpellManager.cs:
[System.Serializable]
public class SingleSpellManager
{
// stores the magical components (MComp) of the spell
// SpellHolder.cs -> [SingleSpellManager.cs]
[SerializeField]
public List<ComponentClass> OnCast_Comp = new List<ComponentClass>();
[SerializeField]
public List<ComponentClass> OnHit_Comp = new List<ComponentClass>();
[Header ("General Data")]
public string spellName;
}
組件類.cs:
// interface class
[System.Serializable]
public abstract class ComponentClass
{
public virtual void OnCast(){}
public virtual void OnHit(){}
//general info
public string name = null;
public string desc = null;
//floats
public float fl_a, fl_b, fl_c;
//ints (can be used as types)
public int int_a, int_b, int_c;
//bools
public bool bl_a, bl_b, bl_c;
}
// derivatives
[System.Serializable]
public class Projectile : ComponentClass
{
// desc:
// turns the spell into a projectile.
public float power {get {return fl_a;}}
public override void OnCast()
{ // test
UnityEngine.Debug.Log(power);
}
}
uj5u.com熱心網友回復:
SerializeReference當您想在一個集合中保存不同型別的物件時,您需要使用。
[System.Serializable]
public class SingleSpellManager
{
[SerializeReference]
public List<ComponentClass> OnCast_Comp = new List<ComponentClass>();
[SerializeReference]
public List<ComponentClass> OnHit_Comp = new List<ComponentClass>();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/532193.html
