1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using FSRole;
- using FSBattle;
- /*
- * 角色管理
- * 未来角色的创建和销毁都在这里
- */
- public class RoleManager : MonoBehaviour {
- // 角色预制体
- public GameObject rolePrefab;
- // 我方位置
- public Transform armyLoc;
- // 地方位置
- public Transform enemyLoc;
- // Use this for initialization
- void Start () {
- RoleAttr value = new RoleAttr();
- value.Camp = RoleCamp.ENEMY;
- CreateRole(value);
- value.Camp = RoleCamp.ARMY;
- CreateRole(value);
- }
-
- // Update is called once per frame
- void Update () {
-
- }
- /*
- * 创建角色
- */
- private void CreateRole(RoleAttr value) {
- GameObject role = null;
- // 判断是哪个阵营的,则放在指定位置下
- if (value.Camp == RoleCamp.ARMY) {
- role = Instantiate(rolePrefab, armyLoc);
- } else {
- role = Instantiate(rolePrefab, enemyLoc);
- role.transform.localScale = new Vector3(-1, 1, 1);
- }
- role.transform.localPosition = new Vector3(0, 0, 0);
- // 添加属性
- role.GetComponent<Role>().OriginAttr = value;
- role.GetComponent<Role>().CurrentAttr = value;
- // 加载图片资源
- Texture2D tex = Resources.Load<Texture2D>("Textures/Roles/hero/airborne01");
- Sprite sp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector3(0.5f, 0.5f));
- if (sp != null) {
- role.GetComponent<SpriteRenderer>().sprite = sp;
- }
- // 最后将其加入数组中
- BattleFieldManager.Instance.GetRoleArray().Add(role.transform);
- }
- }
|