123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- namespace YLBattle
- {
- /// <summary>
- /// 技能控制器
- /// </summary>
- //[RequireComponent(typeof(SkillReady))]
- //[RequireComponent(typeof(SkillShoot))]
- //[RequireComponent(typeof(SkillExplode))]
- public partial class SkillControl : MonoBehaviour
- {
- /// <summary>
- /// 技能准备.
- /// </summary>
- private SkillReady skillReady;
- /// <summary>
- /// 技能发射.
- /// </summary>
- private SkillShoot skillShoot;
- /// <summary>
- /// 技能爆炸.
- /// </summary>
- private SkillExplode skillExplode;
- /// <summary>
- /// 地图中心位置(特效 type=2 敌方)
- /// </summary>
- private Vector3 mMapCenter = Vector3.zero;
- /// <summary>
- /// 地图中心位置(特效 type=2 己方)
- /// </summary>
- private Vector3 mUICenter = Vector3.zero;
- /// <summary>
- /// 实例
- /// </summary>
- public static SkillControl mInstance;
- /// <summary>
- /// 数据交互接口
- /// </summary>
- private IBattleGlobalOper mBattleFeildAdapter = null;
- /// <summary>
- /// 子弹字典
- /// </summary>
- private Dictionary<string, ProjectileBase> ProjectileBases = new Dictionary<string, ProjectileBase>();
- /// <summary>
- /// 爆炸字典
- /// </summary>
- private Dictionary<string, ExplodeBase> ExplodeBases = new Dictionary<string, ExplodeBase>();
- /// <summary>
- /// 准备阶段 技能字典
- /// </summary>
- public Dictionary<string, GameObject> mCommonBaseObjs = new Dictionary<string, GameObject>();
- /// <summary>
- /// 画布
- /// </summary>
- private Canvas m_Canvas = null;
- /// <summary>
- ///
- /// </summary>
- public Canvas SkillCanvas
- {
- get { return m_Canvas; }
- }
- /// <summary>
- ///坐标
- /// </summary>
- private RectTransform rectTransform;
- /// <summary>
- /// 获取单键
- /// </summary>
- /// <returns>单键实例</returns>
- public static SkillControl Instance
- {
- get
- {
- if (mInstance == null)
- {
- GameObject obj = GameObject.Find("SkillControl");
- if (obj != null)
- {
- mInstance = obj.AddComponent<SkillControl>();
- }
- }
- return mInstance;
- }
- }
- /// <summary>
- /// Start
- /// </summary>
- private void Start()
- {
- this.gameObject.AddComponent<SkillReady>();
- this.gameObject.AddComponent<SkillShoot>();
- this.gameObject.AddComponent<SkillExplode>();
- skillReady = GetComponent<SkillReady>();
- skillShoot = GetComponent<SkillShoot>();
- skillExplode = GetComponent<SkillExplode>();
- m_Canvas = GetComponent<Canvas>();
- rectTransform = m_Canvas.transform as RectTransform;
- this.mMapCenter = transform.Find("MapEffectPoint").transform.position;
- this.mUICenter = transform.Find("UIEffectPoint").transform.position;
- }
- /// <summary>
- /// 设置数据交互接口.
- /// </summary>
- /// <param name="op">Op.</param>
- public void SetOp(IBattleGlobalOper op)
- {
- mBattleFeildAdapter = op;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="resName"></param>
- /// <param name="pos"></param>
- public void createPosEffect(string resName, Vector3 pos, Action<GameObject> ac)
- {
- ResourceHelper.Instance.LoadAssetBundle(resName, ab =>
- {
- if (ab != null)
- {
- GameObject comUIEff = (GameObject)Instantiate(ab.LoadAsset(resName));
- comUIEff.SetActive(false);
- this.TranformHandle(comUIEff.transform, pos);
- if (ac != null)
- {
- ac.Invoke(comUIEff);
- }
- }
- });
- }
- /// <summary>
- /// 在目标位置(UI层)上创建特效
- /// </summary>
- /// <param name="Id">目标Id</param>
- /// <param name="resName">资源名称</param>
- /// <param name="posType">位置类型 0=transform脚底 1=shoot/hit 2=指定位置</param>
- public void createPosEffect(string Id, string resName, Vector3 pos, int posType = 0, float time = 1.0f)
- {
- Fighter target = FightingManager.Instance.GetFighter(Id);
- #region 加载准备阶段光效
- ResourceHelper.Instance.LoadAssetBundle(resName, ab =>
- {
- if (ab != null)
- {
- GameObject comUIEff = (GameObject)Instantiate(ab.LoadAsset(resName));
- Vector3 targetPos = Vector3.zero;
- if (posType == 2)
- {
- targetPos = WorldToGUI(pos);
- }
- else if (target != null)
- {
- if (posType == 1)
- {
- if (target.mTeam == EBattleTeam.REDTEAM)
- {
- targetPos = WorldToGUI(target.mBodyCenterPos);
- }
- else
- {
- targetPos = target.mBodyCenterPos;
- }
- }
- else
- {
- if (target.mTeam == EBattleTeam.REDTEAM)
- {
- targetPos = WorldToGUI(target.mBodyRootPos);
- }
- else
- {
- targetPos = target.mBodyRootPos;
- }
- }
- }
- this.TranformHandle(comUIEff.transform, targetPos);
- ExplodeBase exloreScript = comUIEff.GetComponent<ExplodeBase>();
- if (exloreScript != null)
- {
- exloreScript.enabled = false;
- }
- ///(用于非战斗的定点位置爆炸跟踪使用)
- ExplodeTraceBase explode = comUIEff.GetComponent<ExplodeTraceBase>();
- if (explode == null)
- {
- explode = comUIEff.AddComponent<ExplodeTraceBase>();
- }
- explode.lifeTime = time;
- explode.TargetId = Id;
- explode.posType = posType;
- }
- else
- {
- LogHelper.LogWarning("特效模版数据有误!!! " + resName);
- }
- });
- #endregion
- }
- /// <summary>
- /// 创建UI屏幕特效(例如,boss出现[全屏])
- /// </summary>
- /// <param name="Id"></param>
- /// <param name="resName"></param>
- public void createUIScreenEffect(string Id, string resName)
- {
- ResourceHelper.Instance.LoadAssetBundle(resName, ab =>
- {
- if (ab != null)
- {
- GameObject uiEff = (GameObject)Instantiate(ab.LoadAsset(Id));
- uiEff.transform.SetParent(transform);
- uiEff.transform.position = Vector3.zero;
- uiEff.transform.rotation = Quaternion.identity;
- uiEff.transform.localScale = new Vector3(1, 1, 1);
- this.mCommonBaseObjs.Add(Id, uiEff);
- }
- }
- );
- }
- /// <summary>
- /// Tranform的处理,3D->UI
- /// </summary>
- /// <param name="model"></param>
- /// <param name="trgPos"></param>
- public void TranformHandle(Transform model, Vector3 trgPos)
- {
- Transform[] all = model.GetComponentsInChildren<Transform>();
- ///默认UI相机照射所有特效
- ///如果是bomb在敌人身上(3D)身上,则使用3D摄像机;
- foreach (Transform rc in all)
- {
- rc.gameObject.layer = LayerMask.NameToLayer("UI"); //指定Layer
- }
- model.transform.SetParent(transform);
- model.transform.position = trgPos;
- model.transform.rotation = Quaternion.identity;
- model.transform.localScale = new Vector3(1, 1, 1);
- }
- /// <summary>
- /// 创建子弹.
- /// </summary>
- /// <param name="_bulletLoadParam">子弹参数</param>
- public void createProjectile(BulletLoadParam _bulletLoadParam)
- {
- ///发起者
- Fighter tempCaster = FightingManager.Instance.GetFighter(_bulletLoadParam.uid);
- if (tempCaster == null)
- {
- LogHelper.Log("发起者 id=" + _bulletLoadParam.uid + " 不存在(死亡),反射失败");
- return;
- }
- Vector3 point = tempCaster.mBodyCenterPos;
- #region 弹道设定
- ///无弹道->模拟
- if (_bulletLoadParam.traject == EBulletTrajectoryType.EBULLET_TRAJECT_NONE)
- {
- CreateNoneTrajectBullet(_bulletLoadParam, point);
- return;
- }
- CreatePrebBullet(_bulletLoadParam, point, tempCaster.mTeam == EBattleTeam.BLUETEAM);
- #endregion
- }
- /// <summary>
- /// 查找Transform
- /// </summary>
- /// <param name="tran">父级</param>
- /// <param name="name">名称</param>
- /// <returns>Transform</returns>
- private Transform FindTransform(Transform tran, string name)
- {
- Transform[] trans = tran.GetComponentsInChildren<Transform>();
- for (int i = 0; i < trans.Length; i++)
- {
- if (trans[i].name.Trim().IndexOf(name.Trim(), 0, trans[i].name.Trim().Length) != -1)
- {
- return trans[i];
- }
- }
- return null;
- }
- /// <summary>
- /// 创建外部预置物体类型子弹
- /// </summary>
- /// <param name="_bulletloadParam"></param>
- /// <param name="muzzplePos">发射点</param>
- void CreatePrebBullet(BulletLoadParam _bulletLoadParam, Vector3 muzzplePos, bool isScreen)
- {
- ///弹道效果
- GameObject projectileEff = null;
- ResourceHelper.Instance.LoadAssetBundle(_bulletLoadParam.res + "_sending", ab =>
- {
- if (ab != null)
- {
- projectileEff = (GameObject)Instantiate(ab.LoadAsset(_bulletLoadParam.res));
- }
- else
- {
- projectileEff = new GameObject();
- projectileEff.name = _bulletLoadParam.tid + "_sending";
- }
- this.TranformHandle(projectileEff.transform, muzzplePos);
- AddProjectileComponent(_bulletLoadParam, projectileEff);
- });
- }
- /// <summary>
- /// 子弹增加轨道组件
- /// </summary>
- /// <param name="_bulletLoadParam"></param>
- /// <param name="projectileEff"></param>
- public void AddProjectileComponent(BulletLoadParam _bulletLoadParam, GameObject projectileEff)
- {
- ProjectileBase Projectile = null;
- switch (_bulletLoadParam.traject)
- {
- /// 无弹道,直接出现在目标位置处
- case EBulletTrajectoryType.EBULLET_TRAJECT_NONE:
- ///不会走到这里滴~~
- Debug.LogError("擦,真没数据啊。。。。。");
- break;
- /// 抛物线子弹
- case EBulletTrajectoryType.EBULLET_TRAJECT_PARABOLA:
- Projectile = projectileEff.AddComponent<ProjectileArcGUI>() as ProjectileArcGUI;
- break;
- case EBulletTrajectoryType.EBULLET_TRAJECT_LINE:
- Projectile = projectileEff.AddComponent<ProjectileArcLine>() as ProjectileArcLine;
- break;
- /// 屏幕
- }
- ///创建子弹完毕,隐藏,待shoot调用
- if (Projectile != null)
- {
- projectileEff.SetActive(false);///关闭对象显示
- Projectile.bulletLoadParam = _bulletLoadParam;
- if (ProjectileBases.ContainsKey(_bulletLoadParam.id) == false)
- {
- ProjectileBases.Add(_bulletLoadParam.id, Projectile);
- }
- else
- {
- ProjectileBases[_bulletLoadParam.id] = Projectile;
- }
- }
- }
- /// <summary>
- /// 创建无弹道轨迹的子弹
- /// </summary>
- /// <param name="_bulletloadParam"></param>
- /// <param name="muzzplePos">发射点</param>
- void CreateNoneTrajectBullet(BulletLoadParam _bulletloadParam, Vector3 muzzplePos)
- {
- GameObject projNoneObj = new GameObject(_bulletloadParam.res + "+_ProjectileNONE");
- projNoneObj.transform.SetParent(transform);
- ProjectileBase ProjectileNONE = projNoneObj.AddComponent<ProjectileBase>();
- ProjectileNONE.isHit = true;
- ProjectileNONE.bulletLoadParam = _bulletloadParam;
- if (ProjectileBases.ContainsKey(_bulletloadParam.id))
- {
- ProjectileBases[_bulletloadParam.id] = ProjectileNONE;
- }
- else
- {
- ProjectileBases.Add(_bulletloadParam.id, ProjectileNONE);
- }
- }
- /// <summary>
- /// 创建发射阶段效果.
- /// </summary>
- /// <param name="id">目标</param>
- /// <param name="_targetPoint">目标位置</param>
- /// <param name="_targetTransform">目标trans</param>
- /// <param name="isMapProjectile">是否为(地图坐标型)全屏特效</param>
- public void createSkillShoot(string id, Vector3 _targetPoint, string targetID, bool isMapProjectile, int posType)
- {
- Fighter temp = FightingManager.Instance.GetFighter(targetID);//获取目标对象
- if (temp == null && isMapProjectile == false)
- {
- ///角色已死亡
- return;
- }
- ///根据id获取子弹对象
- if (ProjectileBases.ContainsKey(id))
- {
- ProjectileBase _projectileBase = ProjectileBases[id];
- _projectileBase.bulletLoadParam.targetId = targetID;
- ///bulletlaunch时设定是否为地图定点子弹,主要根据其子弹目标类型
- ///地图坐标型子弹.
- _projectileBase.isMapProjectile = isMapProjectile;
- _projectileBase.posType = posType;
- ///无弹道直接爆炸/全屏特效无坐标
- if (_projectileBase.bulletLoadParam.traject == EBulletTrajectoryType.EBULLET_TRAJECT_NONE ||
- _targetPoint == Vector3.zero) //||
- // isMapProjectile == true)
- {
- createSkillExplode(_targetPoint, _projectileBase.bulletLoadParam, isMapProjectile, posType);
- }
- else
- {
- skillShoot.Shoot(_projectileBase, _targetPoint, temp != null ? temp.transform : null);//发射弹道
- }
- }
- else
- {
- SkillControl.Instance.removeExplode(id);
- }
- }
- /// <summary>
- /// 创建爆炸阶段效果.
- /// </summary>
- /// <param name="point">目标位置</param>
- /// <param name="_bulletLoadParam">参数</param>
- /// <param name="isMapProjectile">是否为场景坐标轨迹型子弹</param>
- /// <param name="posType">位置类型</param>
- public void createSkillExplode(Vector3 point, BulletLoadParam _bulletLoadParam, bool isMapProjectile, int posType = 0)
- {
- ///发起者
- Fighter temp = FightingManager.Instance.GetFighter(_bulletLoadParam.uid);
- ///加载爆炸光效
- ResourceHelper.Instance.LoadAssetBundle(_bulletLoadParam.res + "_bomb", ab =>
- {
- GameObject explodeEff = null;
- ExplodeBase newExplode = null;
- if (ab != null)
- {
- if (temp == null)
- {
- ///角色已死亡
- return;
- }
- explodeEff = (GameObject)Instantiate(ab.LoadAsset(_bulletLoadParam.res));
- newExplode = explodeEff.GetComponent<ExplodeBase>();
- }
- else
- {
- explodeEff = new GameObject();
- explodeEff.name = _bulletLoadParam.res + "_bomb";
- }
- if (newExplode == null)
- {
- newExplode = explodeEff.AddComponent<ExplodeBase>();
- }
- ///子弹参数
- newExplode.bulletId = _bulletLoadParam.id;
- newExplode.OnDestoryAction = removeExplode;
- //***************************位置处理***************************
- //Debug.LogError("子弹模板:"+_bulletLoadParam.tid);
- if (posType == 3)
- ///全屏特效 屏幕中心
- {
- if (_bulletLoadParam.team == EBattleTeam.BLUETEAM)
- {
- this.TranformHandle(explodeEff.transform, this.mUICenter);
- }
- else
- {
- this.TranformHandle(explodeEff.transform, this.mMapCenter);
- }
- }
- else if (posType == 4)
- {
- this.TranformHandle(explodeEff.transform, Vector3.zero);
- }
- else if (posType == 2) //地图跟随
- {
- if (_bulletLoadParam.team == EBattleTeam.BLUETEAM)
- {
- this.TranformHandle(explodeEff.transform, this.mUICenter);
- }
- else
- {
- this.TranformHandle(explodeEff.transform, WorldToGUI(FightingMap.Instance.MapPos));
- ///如果是蓝队,则会出现镜头转向时,特效被旋转偏移
- ///子弹(附加)追踪脚本
- ExplodeTrace newExplodeTrace = explodeEff.AddComponent<ExplodeTrace>();
- newExplodeTrace.SetMapFollow((int)_bulletLoadParam.hitpoint, this.rectTransform, this.m_Canvas);
- newExplodeTrace.gameObject.SetActive(false);
- }
- }
- else//角色跟随
- {
- this.TranformHandle(explodeEff.transform, point);
- ///如果是蓝队,则会出现镜头转向时,特效被旋转偏移
- ///子弹(附加)追踪脚本
- ExplodeTrace newExplodeTrace = explodeEff.AddComponent<ExplodeTrace>();
- newExplodeTrace.SetFighterFollow(_bulletLoadParam.id, _bulletLoadParam.targetId, (int)_bulletLoadParam.hitpoint);
- newExplodeTrace.gameObject.SetActive(false);
- }
- //***************************位置处理结束 ***************************
- if (!ExplodeBases.ContainsKey(_bulletLoadParam.id))
- {
- ExplodeBases.Add(_bulletLoadParam.id, newExplode);
- }
- else
- {
- LogHelper.LogError("error: uid=" + _bulletLoadParam.uid +
- "、tid " + _bulletLoadParam.tid +
- "、targetId" + _bulletLoadParam.targetId +
- "、id" + _bulletLoadParam.id
- );
- }
- Fighter trgFighter = FightingManager.Instance.GetFighter(_bulletLoadParam.targetId);
- if ((trgFighter != null && !trgFighter.IsDead) || isMapProjectile)
- {
- //LogHelper.LogError(_bulletLoadParam.tid + ".............................bomb");
- skillExplode.create(_bulletLoadParam.tid, explodeEff);
- }
- else
- {
- LogHelper.Log("角色死亡 " + _bulletLoadParam.targetId + "/" + _bulletLoadParam.tid + ".............................bomb");
- //if (!isMapProjectile)
- //{
- SkillControl.Instance.removeExplode(_bulletLoadParam.id);
- return;
- //}
- }
- if (_bulletLoadParam.audio.Length >= 3)
- {
- AudioManager.Instance.PlaySkillSoundEffect(_bulletLoadParam.audio[2]);
- }
- else
- {
- //LogHelper.LogError("audio :"+_bulletLoadParam.tid+" 没有音效数据[cfg_bullet无此模板数据,请添加]");
- }
- //LogHelper.LogError(_bulletLoadParam.tid + ".............................bomb");
- ///通知子弹碰撞
- if (mBattleFeildAdapter != null)
- {
- mBattleFeildAdapter.OnBulletCollideEvent(_bulletLoadParam.id, _bulletLoadParam.uid);
- }
- });
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public Vector3 WorldToGUI(Vector3 orgPos)
- {
- Vector2 pos;
- Vector3 screenPos = CameraManager.Instance.SenceCamara.WorldToScreenPoint(orgPos);
- RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform,
- screenPos, CameraManager.Instance.SenceUICamera, out pos);
- return pos;
- }
- /// <summary>
- /// 清理当前运行时的技能数据
- /// </summary>
- public void ClearRuningSkill()
- {
- /// 子弹字典
- List<ProjectileBase> projectileBases = new List<ProjectileBase>(ProjectileBases.Values);
- for (int i = 0; i < projectileBases.Count; i++)
- {
- Destroy(projectileBases[i].gameObject);
- }
- ProjectileBases.Clear();
- ///爆炸字典
- List<ExplodeBase> explodeBase = new List<ExplodeBase>(ExplodeBases.Values);
- for (int i = 0; i < explodeBase.Count; i++)
- {
- Destroy(explodeBase[i].gameObject);
- }
- ExplodeBases.Clear();
- }
- /// <summary>
- /// 清除所有技能特效
- /// </summary>
- public void ClearAllSkill()
- {
- this.ClearRuningSkill();
- List<GameObject> commReses = new List<GameObject>(mCommonBaseObjs.Values);
- /// 准备阶段
- for (int i = 0; i < commReses.Count; i++)
- {
- Destroy(commReses[i]);
- }
- mCommonBaseObjs.Clear();
- }
- }
- }
|