我是靠谱客的博主 正直指甲油,这篇文章主要介绍unity游戏开发(四):怪物类的开发(建造者模式)声明建造者接口类IBulider:怪物类的属性:怪物建造者类:,现在分享给大家,希望可以做个参考。

声明建造者接口类IBulider:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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); }

怪物类的属性:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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() { } }

怪物建造者类:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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游戏开发(四):怪物类内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部