声明建造者接口类IBulider:
public interface IBuilder<T>
{
/// <summary>
/// 获取到游戏物体身上的脚本对象,从而去赋值
/// </summary>
T GetProductClass(GameObject gameObject);
/// <summary>
/// 使用工厂去获取具体的游戏对象
/// </summary>
GameObject GetProduct();
/// <summary>
/// 获取信息数据
/// </summary>
void GetData(T productClassGo);
/// <summary>
/// 获取特有的资源和信息
/// </summary>
void GetOtherResources(T ProductClassGO);
}
怪物类的属性:
public class Monster : MonoBehaviour
{
//属性值
public int monsterID;
public int HP;//总血量
public int currentHP;//当前血量
public float moveSpeed;//当前速度
public float initMoveSpeed;//初始速度
public int prize;//奖励金钱
//引用
private Animator animator;
private Slider slider;
//private GameController.Instance GameController.Instance;
private List<Vector3> monsterPointList;
//用于计数的属性或开关
private int roadPointIndex = 1;//路点的索引
private bool reachCarrot;//到达终点
//资源
public RuntimeAnimatorController runtimeAnimatorController;
private void Awake()
{
animator = GetComponent<Animator>();
slider = transform.Find("MonsterCanvas").Find("HPSlider").GetComponent<Slider>();
slider.gameObject.SetActive(false);
monsterPointList = GameController.Instance.mapMaker.monsterPathPos;
}
/// <summary>
/// 获取不同怪物自身特殊属性的方法
/// </summary>
public void GetMonsterProperty()
{
}
}
怪物建造者类:
public class MonsterBuilder : IBuilder<Monster>
{
public int m_monsterID;
public void GetData(Monster productClassGo)
{
productClassGo.monsterID = m_monsterID;
productClassGo.HP = m_monsterID * 100;
productClassGo.currentHP = productClassGo.HP;
productClassGo.initMoveSpeed = m_monsterID;
productClassGo.moveSpeed = m_monsterID;
productClassGo.prize = m_monsterID * 50;
}
public void GetOtherResources(Monster ProductClassGO)
{
ProductClassGO.GetMonsterProperty();
}
public GameObject GetProduct()
{
GameObject itemGo = GameController.Instance.GetGameObjectResource("MonsterPrefab");
Monster monster = GetProductClass(itemGo);
GetData(monster);
GetOtherResources(monster);
return itemGo;
}
public Monster GetProductClass(GameObject gameObject)
{
return gameObject.GetComponent<Monster>();
}
}
最后
以上就是正直指甲油最近收集整理的关于unity游戏开发(四):怪物类的开发(建造者模式)声明建造者接口类IBulider:怪物类的属性:怪物建造者类:的全部内容,更多相关unity游戏开发(四):怪物类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复