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().OriginAttr = value; role.GetComponent().CurrentAttr = value; // 加载图片资源 Texture2D tex = Resources.Load("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().sprite = sp; } // 最后将其加入数组中 BattleFieldManager.Instance.GetRoleArray().Add(role.transform); } }