这是 CreatureData ,这是一个包含信息的类,需要输入 Creature 的构造函数来实例化它:
&(conn->db->rows[id])
这里我有一个抽象类生物,它包含了一个生物。
--CreatureData.cs
using UnityEngine.UI;
[System.Serializable]
class CreatureData {
//To be set by Unity engine's inspector.
[SerializeField] private Sprite creatureHead;
[SerializeField] private int creatureStartingDamage;
Sprite CreatureHead {
get{
return creatureHead;
}
}
Sprite CreatureStartingDamage {
get{
return creatureStartingDamage;
}
}
}
有数以千计的密封生物类型来自生物,这是一个例子:
--Creature.cs
public class Creature {
protected Sprite creatureHead;
protected int creatureDamage;
public Creature(CreatureData creatureData){
creatureHead = creatureData.CreatureHead;
creatureDamage = creatureData.CreatureStartingDamage
}
public abstract void getAttackedBy(Creature other);
}
CreatureDatabase将包含一个 Dictionary ,用于存储 CreatureData ,并将从 Creature 派生的任何密封类链接到最多1个对应的 CreatureData ::
--Creature_MoonDancer.cs
public sealed class Creature_MoonDancer : Creature{
private int moonOrbsInPossession;
public Creature_MoonDancer (CreatureData creatureData, int startingMoonOrbs) : base(creatureData){
moonOrbsInPossession = startingMoonOrbs;
}
public override void getAttackedBy(Creature other){
if(moonOrbsInPossession > other.creatureDamage){
Debug.Log("MoondancerWins");
}
else if(Random.value < 0.5)
Debug.Log("MoondancerDies");
else
Debug.Log("MoondancerWins");
}
}
以下是游戏经理试图从creatureDatabaseDictionary 字典中获取值:
--CreatureDatabase.cs
public class CreatureDatabase : MonoBehaviour {
private static class CreatureDataCustomSerializableDictionary
: CustomSerializableDictionary<typeof(Creature),CreatureData> {}
//TODO: Create custom property drawer for CustomSerializableDictionary
[SerializeField] private CreatureDataCustomSerializableDictionary creatureDatabaseDictionary;
public CreatureDatabaseDictionary {
get{
return creatureDatabaseDictionary;
}
}
}
以下是一些项目要求:
答案 0 :(得分:2)
这是您编写的代码,以便使用示例分配进行编译:
public interface mybaby {}
public class mytom : mybaby {}
public class mydick : mybaby {}
public class myharry : mybaby {}
public class Test
{
mybaby mychild = new myharry();
}
这是有效的C#代码。