123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace YLBattle
- {
- public class FightingTipManager : MonoBehaviour
- {
- /// <summary>
- /// 画布
- /// </summary>
- private Canvas m_Canvas = null;
- /// <summary>
- ///坐标
- /// </summary>
- private RectTransform rectTransform;
- /// <summary>
- /// 实例
- /// </summary>
- static FightingTipManager mInstance;
- /// <summary>
- /// 获取单键
- /// </summary>
- /// <returns>单键实例</returns>
- public static FightingTipManager Instance
- {
- get
- {
- if (mInstance == null)
- {
- GameObject obj = GameObject.Find("FightingTipManager");
- if (obj != null)
- {
- mInstance = obj.AddComponent<FightingTipManager>();
- }
- }
- return mInstance;
- }
- }
- void Start()
- {
- m_Canvas = GetComponent<Canvas>();
- rectTransform = m_Canvas.transform as RectTransform;
- }
- /// <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>
- ///
- /// </summary>
- /// <returns></returns>
- public Vector3 WorldToGUI(Vector3 orgPos)
- {
- Vector2 pos;
- Vector3 screenPos = CameraManager.Instance.SenceCamara.WorldToScreenPoint(orgPos);
- RectTransformUtility.ScreenPointToLocalPointInRectangle(this.rectTransform,
- screenPos, CameraManager.Instance.SenceTIPCamera, out pos);
- return pos;
- }
- /// <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("Tip"); //指定Layer
- }
- model.transform.SetParent(transform);
- model.transform.position = trgPos;
- model.transform.rotation = Quaternion.identity;
- model.transform.localScale = new Vector3(1, 1, 1);
- }
- }
- }
|