123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using FSRole;
- using FSBattle;
- using LitJson;
- using FSFile;
- using FSAssist;
- using UnityEngine.UI;
- using FSCard;
- namespace FSRole {
- public class RoleManager : MonoBehaviour {
-
- public GameObject rolePrefab;
-
- public Transform armyLoc;
-
- public Transform enemyLoc;
-
- public ArrayList roles;
-
- public JsonData roleValue;
-
- public Transform followPanel;
-
- public GameObject bloodPre;
-
- public GameObject parryPre;
-
- public GameObject cardPrefab;
-
- public Transform cachePlace;
-
- void Start() {
- roles = new ArrayList();
- ReadRoleData();
- CreateRole("00000");
- CreateRole("10002");
- }
-
- private void ReadRoleData() {
- string json = FileManager.Instance.ReadResourceText("Jsons/roles");
- if (json != null)
- {
- Debug.Log("读取到 json 字符串 : " + json);
- try {
- roleValue = JsonMapper.ToObject(json);
- } catch (JsonException e){
- Debug.Log(e.ToString());
- }
- }
- }
-
- private void CreateRole(string id) {
- JsonData oneValue = roleValue[id];
- if (oneValue != null && oneValue.IsObject) {
- RoleAttr attr = new RoleAttr();
-
- attr.Hp = AssistMethods.ReadInt(oneValue, "hp");
- attr.MaxHp = attr.Hp;
- attr.Mp = AssistMethods.ReadInt(oneValue, "mp");
- attr.Camp = (AssistMethods.ReadInt(oneValue, "camp") == 1) ? RoleCamp.ARMY : RoleCamp.ENEMY;
- attr.ID = id;
- Role role = CreateRole(attr);
- JsonData cards = oneValue["cards"];
- if (cards != null) {
- if (cards.IsArray) {
- for (int i = 0; i < cards.Count; i++) {
- string cardId = AssistMethods.ReadString(cards, i);
- GameObject cardObj = Instantiate(cardPrefab, cachePlace);
-
- CardManager.Instance.LoadCard(cardObj, cardId, role);
-
- if (role.OriginAttr.Camp == RoleCamp.ARMY) {
- BattleFieldManager.Instance.ArmyTakePool.Add(cardObj.transform);
- } else {
- BattleFieldManager.Instance.EnemyTakePool.Add(cardObj.transform);
- }
- }
- }
- }
- } else {
- throw new System.Exception("id : " + id + "无对应的角色 ... ");
- }
- }
-
- private Role CreateRole(RoleAttr value) {
- GameObject role = null;
- int index;
-
- if (value.Camp == RoleCamp.ARMY) {
- role = Instantiate(rolePrefab, armyLoc);
- BattleFieldManager.Instance.ArmyArray.Add(role.transform);
- index = BattleFieldManager.Instance.ArmyArray.Count - 1;
- } else {
- role = Instantiate(rolePrefab, enemyLoc);
- BattleFieldManager.Instance.EnemyArray.Add(role.transform);
- index = BattleFieldManager.Instance.EnemyArray.Count - 1;
- }
-
- if (index % 2 == 0) {
-
- role.transform.localPosition = new Vector3(index / 2 * AssistConfig.RoleSpace, 0, 0);
- } else {
-
- float loc = (float)index / 2 + 0.5f;
- role.transform.localPosition = new Vector3(loc * AssistConfig.RoleSpace * -1, 0, 0);
- }
- role.transform.localScale = new Vector3(0.6f, 0.6f, 1);
-
-
- role.GetComponent<Role>().OriginAttr = value;
- role.GetComponent<Role>().CurrentAttr = value.copy();
-
-
- GameObject bloodObj = Instantiate(bloodPre, followPanel);
-
- Vector3 roleScreen = Camera.main.WorldToScreenPoint(role.transform.position - new Vector3(0.35f, 0, 0));
- bloodObj.transform.position = roleScreen;
- role.GetComponent<Role>().SetBloodTrs(bloodObj.transform);
-
- GameObject parryObj = Instantiate(parryPre, followPanel);
- parryObj.GetComponent<Text>().text = "格挡值 : 0";
- Vector3 parryPos = Camera.main.WorldToScreenPoint(role.transform.position - new Vector3(-0.85f, 0.5f, 0));
- parryObj.transform.position = parryPos;
- role.GetComponent<Role>().parryTransform = parryObj.transform;
-
- string path = "Textures/Roles/" + value.ID;
- Texture2D tex = Resources.Load<Texture2D>(path);
- Sprite sp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector3(0.5f, 0));
- if (sp != null) {
- role.GetComponent<SpriteRenderer>().sprite = sp;
- }
-
- BattleFieldManager.Instance.RoleArray.Add(role.transform);
- return role.GetComponent<Role>();
- }
- }
- }
|