123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- using UnityEngine;
- using System.Collections;
- namespace YLBattle
- {
- /// <summary>
- /// 战场静态公共函数
- /// </summary>
- public class BattleStaticFunc
- {
- /// <summary>
- /// 查找Transform
- /// </summary>
- /// <param name="tran">父级</param>
- /// <param name="name">名称</param>
- /// <returns></returns>
- public static Transform FindTransform(Transform tran, string name)
- {
- Transform[] trans = tran.GetComponentsInChildren<Transform>();
- for (int i = 0; i < trans.Length; i++)
- {
- if (trans[i].name == name)
- {
- return trans[i];
- }
- }
- return null;
- }
- /// <summary>
- /// 查找GameObject
- /// </summary>
- /// <param name="tran">父级</param>
- /// <param name="name">名称</param>
- /// <returns></returns>
- public static GameObject FindGameObject(Transform tran, string name)
- {
- Transform[] trans = tran.GetComponentsInChildren<Transform>();
- for (int i = 0; i < trans.Length; i++)
- {
- if (trans[i].name == name)
- {
- return trans[i].gameObject;
- }
- }
- return null;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="tran"></param>
- /// <param name="layer"></param>
- public static void TranformResetLayer(Transform tran, int layer)
- {
- Transform[] all = tran.GetComponentsInChildren<Transform>();
- foreach (Transform rc in all)
- {
- rc.gameObject.layer = LayerMask.NameToLayer("BattleScreen"); //指定Layer
- }
- }
- /// <summary>
- ///
- /// </summary>
- static string hierarchyPath;
- /// <summary>
- ///
- /// </summary>
- /// <param name="t"></param>
- /// <param name="initPath"></param>
- /// <returns></returns>
- public static string GetHierarchyPath(Transform t, bool initPath = true)
- {
- if (initPath) hierarchyPath = "";
- if (t.parent != null)
- {
- hierarchyPath = t.name + hierarchyPath;
- Transform parent = t.parent;
- if (t.parent.parent != null)
- {
- hierarchyPath = "/" + hierarchyPath;
- }
- GetHierarchyPath(parent, false);
- }
- return hierarchyPath;
- }
- /// <summary>
- ///
- /// </summary>
- static Component result = null;
- /// <summary>
- ///
- /// </summary>
- /// <param name="t"></param>
- /// <param name="scriptName"></param>
- /// <param name="initPath"></param>
- /// <returns></returns>
- public static Component GetParentScript(Transform t, string scriptName, bool initPath = true)
- {
- if (initPath)
- {
- result = t.gameObject.GetComponent(scriptName);
- if (result != null)
- {
- return result;
- }
- }
- if (t.gameObject.GetComponent(scriptName) != null)
- {
- result = t.gameObject.GetComponent(scriptName);
- }
- else if (t.parent != null)
- {
- result = GetParentScript(t.parent, scriptName, false);
- }
- return result;
- }
- /// <summary>
- ///
- /// </summary>
- static GameObject resultTran = null;
- /// <summary>
- ///
- /// </summary>
- /// <param name="t"></param>
- /// <param name="objName"></param>
- /// <param name="initPath"></param>
- /// <returns></returns>
- public static GameObject GetUpGameObject(Transform t, string objName, bool initPath = true)
- {
- if (initPath)
- {
- if (t.gameObject.name == objName)
- {
- return t.gameObject;
- }
- resultTran = FindGameObject(t, objName);
- if (resultTran != null)
- {
- return resultTran;
- }
- }
- if (t.Find(objName) != null)
- {
- resultTran = t.Find(objName).gameObject;
- }
- else if (t.parent != null)
- {
- resultTran = GetUpGameObject(t.parent, objName, false);
- }
- return resultTran;
- }
- /// <summary>
- /// 获取括号内数值
- /// </summary>
- /// <param name="_value"></param>
- /// <returns></returns>
- public static string GetInSideKuoHaoValue(string _value)
- {
- string result = string.Empty;
- if (_value.IndexOf('(') != -1)
- {
- int _startIndex = _value.IndexOf('(') + 1;
- int _endIndex = _value.IndexOf(')');
- result = _value.Substring(_startIndex, _endIndex - _startIndex);
- return result;
- }
- return result;
- }
- /// <summary>
- /// 获取括号外数值
- /// </summary>
- /// <param name="_value"></param>
- /// <returns></returns>
- public static string GetOutSideKuoHaoValue(string _value)
- {
- string result = string.Empty;
- if (_value.IndexOf('(') != -1)
- {
- int _startIndex = _value.IndexOf('(');
- result = _value.Substring(0, _startIndex);
- return result;
- }
- result = _value;
- return result;
- }
- /// <summary>
- /// 计算特殊字符串
- /// </summary>
- /// <param name="index">索引(等级)</param>
- /// <param name="baseData">基础数据</param>
- /// <param name="adData">物理</param>
- /// <param name="apData">魔法</param>
- /// <param name="trgString">待分析数值</param>
- /// <returns></returns>
- public static int CalculateSpecialString(LogicFighter caster, int index, float baseData, string trgString)
- {
- int result1 = 0;
- int result2 = 0;
- float adData = caster.GetProperty(EBattleProperty.ATTACK);
- float apData = caster.GetProperty(EBattleProperty.MAGICSTRENGTH);
- string baseValue = string.Empty;
- string extraValue = string.Empty;
- string outSideValue = GetOutSideKuoHaoValue(trgString);
- string inSideValue = GetInSideKuoHaoValue(trgString);
- if (outSideValue.IndexOf('/') != -1)
- {
- string[] outSideAry = outSideValue.Split('/');
- if (index <= outSideAry.Length)
- {
- baseValue = outSideAry[index - 1];
- }
- else
- {
- baseValue = outSideAry[outSideAry.Length - 1];
- }
- }
- else
- {
- baseValue = outSideValue;
- }
- int rate1 = 1;
- if (baseValue.IndexOf('F') != -1)
- {
- rate1 = 100;
- baseValue = baseValue.Substring(0, baseValue.IndexOf('F'));
- result1 = (int)(baseData * int.Parse(baseValue) / rate1);
- }
- else
- {
- result1 = int.Parse(baseValue);
- }
- string _aValue = "0";
- int rate2 = 1;
- float typeValue = 0;
- if (inSideValue != string.Empty)
- {
- _aValue = inSideValue;
- if (inSideValue.IndexOf('F') != -1)
- {
- rate2 = 100;
- _aValue = _aValue.Substring(0, inSideValue.IndexOf('F'));
- }
- string type = inSideValue.Substring(inSideValue.IndexOf('F') + 1, 2);
- switch (type)
- {
- case "AP":
- typeValue = apData;
- break;
- case "AD":
- typeValue = adData;
- break;
- }
- }
- result2 = (int)(typeValue * int.Parse(_aValue) / rate2);
- return result1 + result2;
- }
- ///// <summary>
- ///// 获取栗子特效时间 (未启用)
- ///// </summary>
- ///// <param name="transform"></param>
- ///// <returns></returns>
- //public static float ParticleSystemLength(Transform tr)
- //{
- // ParticleSystem[] particleSystems = tr.GetComponentsInChildren<ParticleSystem>();
- // float maxDuration = 0;
- // foreach (ParticleSystem ps in particleSystems)
- // {
- // if (ps.enableEmission)
- // {
- // if (ps.loop)
- // {
- // return -1f;
- // }
- // float dunration = 0f;
- // if (ps.emissionRate <= 0)
- // {
- // dunration = ps.startDelay + ps.startLifetime;
- // }
- // else
- // {
- // dunration = ps.startDelay + Mathf.Max(ps.duration, ps.startLifetime);
- // }
- // if (dunration > maxDuration)
- // {
- // maxDuration = dunration;
- // }
- // }
- // }
- // return maxDuration;
- //}
- }
- }
|