using UnityEngine; using System.Collections; using System; using System.Collections.Generic; namespace YLBattle { /// /// 地图 /// public class FightingMap : MonoBehaviour { #region 组件 /// /// 转盘状态机 /// internal Animator SenceCameraAnimator = null; /// /// 转盘状态机(配合背景状态机做攻击和旋转动作) /// internal Animator MapAnimator = null; /// /// 背景状态机(配合地图状态机做攻击和旋转动作) /// internal Animator SenceBgAnimator = null; /// /// 地图挂载点 /// private Transform mMapAttachTran = null; /// /// /// private MeshRenderer[] mBgRenders = null; /// /// /// private MeshRenderer[] mMapRenders = null; #endregion #region 基础变量 /// /// /// internal TimeHelper MapTimeHelper = new TimeHelper(); /// /// 已加载的地图资源 /// private List mLoadedMapBundle = new List(); /// /// 当前中心占位 /// internal int curtSeat = 0; /// /// 上一个中心占位 /// internal int lastSeat = -1; /// /// 是否锁定 /// private bool mLocked = false; /// /// /// public bool Locked { get { return mLocked; } } /// /// 地图模式 /// protected int mMapMode = 0; /// /// 地图模式 [0=普通关卡 1=无穷尽 2=pvp 3=test 4=guide] /// public int MapMode { get { return this.mMapMode; } } /// /// /// private FightingMapState mFMS = null; /// /// 当前平板状态机名称 /// internal string PlatAnimatorName = string.Empty; /// /// 当前地图资源 /// private GameObject mMapObj = null; /// /// /// public Vector3 MapPos { get { Vector3 pos = Vector3.zero; if (this.mMapObj != null) { pos = this.mMapObj.transform.position; } return pos; } } /// /// 当前地图背景资源 /// private GameObject mMapBgObj = null; #endregion /// /// 实例 /// public static FightingMap mInstance; /// /// 获取单键 /// /// 单键实例 public static FightingMap Instance { get { if (mInstance == null) { GameObject obj = GameObject.Find("FightingManager"); if (obj != null) { mInstance = obj.AddComponent(); mInstance.InitComponents(); } } return mInstance; } } /// /// 初始化 /// public void InitComponents() { this.MapTimeHelper.Start(); ///转盘状态机 // 新战斗对接 移除多余相机 //this.SenceCameraAnimator = CameraManager.Instance.SenceCameraAnimator; //this.SenceBgAnimator = CameraManager.Instance.SenceBgCameraAnimator; this.mMapAttachTran = this.transform.Find("Map"); ///状态 this.mFMS = new FightingMapState(); this.mFMS.Initialize(this); } /// /// 获取当前处于中心位置的占位编号 /// /// public int GetCenterSeat() { return this.curtSeat; } /// /// 获取当前处于中心位置的占位编号 /// /// public int GetLastSeat() { return this.lastSeat; } /// /// 设置锁定状态 /// /// public void SetLock(bool _lock) { this.mLocked = _lock; } /// /// 设置地图模式 /// [0=普通关卡 1=无穷尽 2=pvp 3=test 4=guide] /// /// public void SetMapMode(int _mode) { this.mMapMode = _mode; } /// /// 地图震动 /// public void SetShaking(int shakeLevel) { //if (shakeLevel == 1) //{ // if (this.mMapAnimator.GetCurrentAnimatorStateInfo(0).IsName("BeAttack")) // { // this.mMapAnimator.Play("Interrupt"); // } // else // { // this.mMapAnimator.Play("BeAttack"); // } //} } /// /// 获取状态机 /// /// 状态机管理器对象 public FightingMapState GetState() { return this.mFMS; } /// /// /// void Update() { this.MapTimeHelper.Update(); if (this.mFMS != null) { this.mFMS.OnUpdateState(); } } /// /// 加载地图 /// /// /// public void LoadMapBundle(string bunldeName, Action ac) { if (this.mLoadedMapBundle.Contains(bunldeName)) { return; } this.mLoadedMapBundle.Add(bunldeName); ResourceHelper.Instance.LoadAssetBundle(bunldeName, ab => { //if (ab != null) //{ // GameObject obj = (GameObject)Instantiate(ab.LoadAsset(bunldeName)); // ///0索引是传入的地图物体,要挂载在当前地图节点下 // if (ab.mainAsset.name.IndexOf("MAP") != -1) // { // this.mMapObj = obj; // this.mMapRenders = this.mMapObj.GetComponentsInChildren(); // obj.transform.SetParent(mMapAttachTran); // this.MapAnimator = obj.GetComponent(); // } // else // { // this.mMapBgObj = obj; // this.mBgRenders = this.mMapBgObj.GetComponentsInChildren(); // } // obj.transform.localRotation = Quaternion.identity; // obj.transform.localPosition = Vector3.zero; // obj.transform.localScale = new Vector3(1, 1, 1); // ac(bunldeName); //} //else //{ // LogHelper.LogError("地图加载失败" + bunldeName + " 不存在"); //} }); } /// /// 设置地图render颜色 /// /// public void SetMapDark() { for (int i = 0; i < this.mBgRenders.Length; i++) { this.mBgRenders[i].material.SetColor("_Color", new Color(0.329f, 0.329f, 0.329f, 1f)); } for (int i = 0; i < this.mMapRenders.Length; i++) { this.mMapRenders[i].material.SetColor("_Color", new Color(0.329f, 0.329f, 0.329f, 1f)); } } /// /// 设置地图render颜色 /// /// public void SetMapLight() { for (int i = 0; i < this.mBgRenders.Length; i++) { this.mBgRenders[i].material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 1f)); } for (int i = 0; i < mMapRenders.Length; i++) { mMapRenders[i].material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 1f)); } } /// /// boss展示地图特效开始 /// public void StartMapBossEffect() { this.mMapObj.SetActive(false); this.mMapBgObj.SetActive(false); } /// /// boss展示地图特效完成 /// public void OverMapBossEffect() { this.mMapObj.SetActive(true); this.mMapBgObj.SetActive(true); } /// /// 卸载地图资源 /// public void UnloadMapBundle() { foreach (string s in this.mLoadedMapBundle) { ResourceHelper.Instance.UnloadAssetBundle(s); } } /// /// 停止拖拽行为 /// public void OverDrag() { FightingManager.Instance.FiledBattlingHandler().ConfirmBattleMapDragComplete(); } } }