using UnityEngine;
using System.Collections;
namespace YLBattle
{
///
/// 战场静态公共函数
///
public class BattleStaticFunc
{
///
/// 查找Transform
///
/// 父级
/// 名称
///
public static Transform FindTransform(Transform tran, string name)
{
Transform[] trans = tran.GetComponentsInChildren();
for (int i = 0; i < trans.Length; i++)
{
if (trans[i].name == name)
{
return trans[i];
}
}
return null;
}
///
/// 查找GameObject
///
/// 父级
/// 名称
///
public static GameObject FindGameObject(Transform tran, string name)
{
Transform[] trans = tran.GetComponentsInChildren();
for (int i = 0; i < trans.Length; i++)
{
if (trans[i].name == name)
{
return trans[i].gameObject;
}
}
return null;
}
///
///
///
///
///
public static void TranformResetLayer(Transform tran, int layer)
{
Transform[] all = tran.GetComponentsInChildren();
foreach (Transform rc in all)
{
rc.gameObject.layer = LayerMask.NameToLayer("BattleScreen"); //指定Layer
}
}
///
///
///
static string hierarchyPath;
///
///
///
///
///
///
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;
}
///
///
///
static Component result = null;
///
///
///
///
///
///
///
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;
}
///
///
///
static GameObject resultTran = null;
///
///
///
///
///
///
///
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;
}
///
/// 获取括号内数值
///
///
///
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;
}
///
/// 获取括号外数值
///
///
///
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;
}
///
/// 计算特殊字符串
///
/// 索引(等级)
/// 基础数据
/// 物理
/// 魔法
/// 待分析数值
///
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;
}
/////
///// 获取栗子特效时间 (未启用)
/////
/////
/////
//public static float ParticleSystemLength(Transform tr)
//{
// ParticleSystem[] particleSystems = tr.GetComponentsInChildren();
// 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;
//}
}
}