123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- namespace YLBattle
- {
- /// <summary>
- /// 占位管理
- /// </summary>
- public class FightingSeatManager : MonoBehaviour
- {
- /// <summary>
- /// 元素
- /// </summary>
- private List<Transform> mElements = new List<Transform>();
- /// <summary>
- /// 当前战斗占位模式
- /// 0=普通占位 1=PVP
- /// </summary>
- private int seatMode = -1;
- /// <summary>
- ///
- /// </summary>
- private int mMaxCount = 99;
- /// <summary>
- /// 当前占位根节点
- /// </summary>
- private Transform mSeatRoot = null;
- /// <summary>
- /// 当前占位根节点初始位置
- /// </summary>
- private Vector3 mOrgPosition = Vector3.zero;
- /// <summary>
- /// 实例
- /// </summary>
- public static FightingSeatManager mInstance;
- /// <summary>
- /// 获取单键
- /// </summary>
- /// <returns>单键实例</returns>
- public static FightingSeatManager Instance
- {
- get
- {
- if (mInstance == null)
- {
- GameObject obj = GameObject.Find("FightingManager");
- if (obj != null)
- {
- mInstance = obj.AddComponent<FightingSeatManager>();
- }
- }
- return mInstance;
- }
- }
- /// <summary>
- /// 初始化
- /// 卡槽管理+旋转工具+整形工具
- /// </summary>
- public void InitComponents(int mode)
- {
- this.mElements.Clear();
- this.mSeatRoot = BattleStaticFunc.FindTransform(transform, mode == 2 ? "PvPSeat" : "RoleSeat");
- this.mOrgPosition = mSeatRoot.position;
- for (int ei = 0; ei < mMaxCount; ei++)
- {
- Transform obj = BattleStaticFunc.FindTransform(mSeatRoot, "Seat_" + ei.ToString());
- if (obj != null)
- {
- mElements.Add(obj);
- }
- else
- {
- break;
- }
- }
- }
- /// <summary>
- /// 通过占位获得占位的Trans
- /// </summary>
- /// <param name="_seat">占位</param>
- /// <param name="_mode">当前战斗模式 0=普通 1=PVP</param>
- /// <returns></returns>
- public Transform GetFightingMapSeat(int _seat, int _mode = 0)
- {
- if (_mode != this.seatMode)
- {
- this.seatMode = _mode;
- InitComponents(this.seatMode);
- }
- if (_seat >= 0 && _seat < this.mElements.Count)
- {
- return this.mElements[_seat];
- }
- return null;
- }
- /// <summary>
- ///
- /// </summary>
- void Update()
- {
- if (mSeatRoot != null)
- {
- ///同步地图和占位的位置,以达到地图动画和角色共振的效果
- mSeatRoot.position = this.mOrgPosition + FightingMap.Instance.MapPos;
- }
- }
- }
- }
|