using UnityEngine;
using System.Collections;
using System;
using System.Text.RegularExpressions;
public class Sutil
{
///
/// 比较两个字符串中,是否包含与对方一样的字符 .
/// 包含就行 返回true
///
///
///
///
public static bool CompareStringByChar(string strA, string strB)
{
bool IsEqual = true;
char[] arrA = strA.ToCharArray();
char[] arrB = strB.ToCharArray();
foreach (char chara in arrA)
{
if (strB.IndexOf(chara) < 0)
{
IsEqual = false;
}
else
{
IsEqual = true;
break;
}
}
return IsEqual;
}
///
/// 获取字符串中的数字
///
/// 字符串
/// 数字
public static string GetNumber(string str)
{
if (str != null && str != string.Empty)
{
if (Regex.IsMatch(str, @"\d"))
{
// 正则表达式剔除非数字字符(不包含小数点.)
str = Regex.Replace(str, @"[^\d.\d]", "");
return str;
}
else
{
Debug.LogError("string not Exist Number");
}
//// 如果是数字,则转换为decimal类型
//if (Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$"))
//{
// return str.Substring(0, count - 1);
//}
}
return "";
}
/**
*获取事件串 时:分:秒 00:00:00
* @param time
* @return
*
*/
public static string turnTimeToStr(UInt32 time)
{
DateTime date = new DateTime().FromUnixStamp(time);
string str = "";
int hour = Mathf.FloorToInt(time / 60 / 60);
int minute = Mathf.FloorToInt((time - hour * 60 * 60) / 60);
int second = Mathf.FloorToInt(time - hour * 60 * 60 - minute * 60);
if (hour < 10)
{
str += "0";
}
str += hour.ToString();
str += ":";
if (minute < 10)
{
str += "0";
}
str += minute.ToString();
str += ":";
if (second < 10)
{
str += "0";
}
str += second.ToString();
return str;
}
/**
* 获取时间串 年月日
* @param time 秒
* @return
*
*/
public static string turnTimeToChinaymd(int time)
{
string res;
DateTime date = new DateTime(time * 1000);
res = date.Year.ToString() + "年" + date.Month.ToString() + "月" + date.Day.ToString() + "日";
return res;
}
/**
* 获取时间串 返回 各式: X月X日
* @param time 秒
* @return
*
*/
public static string turnTimeToChinaymd2(int time)
{
string res;
DateTime date = new DateTime(time * 1000);
res = date.Month.ToString() + "月" + date.Day.ToString() + "日";
return res;
}
/**
* 将日期转换为指定格式和指定间隔符的字符串
* @param sec_ 秒
* @param format_ 格式
* @param split_ 间隔符
* @return 格式化字符串
*
*/
public static string formatTimeToString(int sec_, string format_ = "ymd", string split_ = "//")
{
string res = "";
DateTime date = new DateTime(sec_ * 1000);
for (int i = 0; i < format_.Length; ++i)
{
string formStr = format_.Substring(i, 1);
string splitStr = split_.Substring(i, 1);
switch (formStr)
{
case "y":
res += date.Year.ToString() + splitStr;
break;
case "m":
res += date.Month.ToString() + splitStr;
break;
case "d":
res += date.Day.ToString() + splitStr;
break;
}
}
return res;
}
/**
* 将日期转换为指定格式和指定间隔符的字符串
* 年月日00:00:00
* @param sec_ 秒
* @param format_ 格式
* @param split_ 间隔符
* @return 格式化字符串
*
*/
public static string activeFormatTimeToString(int sec_, string format_ = "ymdhs", string split_ = "//")
{
string res = "";
DateTime date = new DateTime(sec_ * 1000);
for (int i = 0; i < format_.Length; ++i)
{
string formStr = format_.Substring(i, 1);
switch (formStr)
{
case "y":
res += date.Year.ToString() + "年";
break;
case "m":
res += date.Month.ToString() + "月";
break;
case "d":
res += date.Day.ToString() + "日";
break;
case "h":
if (date.Hour < 10)
res += "0" + date.Hour.ToString() + ":";
else
res += date.Hour.ToString() + ":";
break;
case "s":
if (date.Minute < 10)
res += "0" + date.Minute.ToString();
else
res += date.Minute.ToString();
break;
}
}
return res;
}
///
/// 获取事件串 x时x分x秒
///
///
public static string turnTimeToChinaStr(int time)
{
string str = "";
int hour = Mathf.FloorToInt(1.0f *time / 60 / 60);
int minute = Mathf.FloorToInt(((time - hour * 60 * 60) / 60));
int second = Mathf.FloorToInt((time - hour * 60 * 60 - minute * 60));
if (hour > 0)
{
str += hour.ToString() + "小时";
}
if (minute > 0)
{
str += minute.ToString() + "分";
}
if (second > 0)
{
str += second.ToString() + "秒";
}
return str;
}
/////
///// 关于时间转换::最近日期的简易版(类似刚刚,几分钟前等)
/////
/////
/////
//public static string turnTimeToDataStr(UInt32 time)
//{
// string str = "";
// DateTime date = new DateTime().FromUnixStamp(time);
// DateTime now = UserProxy.Instance.GetCurrentDateTime();
// // 如果超过两年
// if (now.Year - date.Year >= 2)
// {
// str = "N年前";
// }
// else
// {
// // 如果超过一年
// long yearSecond = 3156000000;
// if (UserProxy.Instance.GetCurrentUnixTimeStamp() - date.GetUnixTimeStamp() >= yearSecond)
// {
// str = "1年前";
// }
// else
// {
// // 如果不在同一年
// if (now.Year != date.Year)
// {
// str = date.ToString("yyyy-MM-dd");// date.Year.ToString() + "." + date.Month.ToString() + "." + date.Day.ToString() + " " + date.Hour.ToString() + ":" + date.Minute.ToString();
// }
// // 如果在同一年
// else
// {
// // 如果在同一天
// if (now.Month == date.Month && now.Day == date.Day)
// {
// if (now.Hour == date.Hour)
// {
// int minutes = now.Minute - date.Minute;
// if (minutes <= 5)
// {
// str = "刚刚";
// }
// else
// {
// str = minutes.ToString() + "分钟前";
// }
// }
// else
// {
// int hours = now.Hour - date.Hour;
// str = hours.ToString() + "小时前";
// }
// }
// // 如果不在同一天
// else
// {
// str = date.ToString("yyyy-MM-dd"); //date.Month.ToString() + "." + date.Day.ToString() + " " + date.Hour.ToString() + ":" + date.Minute.ToString();
// }
// }
// }
// }
// return str;
//}
///
///
///
///
///
/// 物理攻击
/// 法术强度
///
public static string ResolutionSkillDesc(string source, int curLeve, int AD, int AP)
{
Regex reg = new Regex(@"(?is)(?<=\()[^\)]+(?=\))");
string finish = source;
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
string xx = m.Value;
string[] arr = xx.Split('+');
float result = 0;
foreach (string temp in arr)
{
if (temp.Contains("/"))
{
string[] vvv = temp.Split('/');
if (curLeve >= 1 && curLeve <= vvv.Length)
{
result += System.Convert.ToSingle(vvv[curLeve - 1]);
}
else
{
result += 0;
}
}
else if (temp.Contains("AD"))
{
string a = temp.Substring(0, temp.Length - 2);
result += (int)(AD * System.Convert.ToSingle(a));
}
else if (temp.Contains("AP"))
{
string a = temp.Substring(0, temp.Length - 2);
result += (int)(AP * System.Convert.ToSingle(a));
}
else
{
}
}
//Debug.LogError("________________" + result);
finish = finish.Replace(m.Value, result.ToString());
}
finish = finish.Replace("(", "");
finish = finish.Replace(")", "");
finish = finish.Trim();
return finish;
}
}
#region
// AudioTo:改变声音的音量和音调到指定的数值。
//AudioFrom:将声音的音量和音调从给的数值变化到原始的数值;
//AudioUpdate:类似于AudioTo,在Update()方法或循环环境中调用。提供每帧改变属性值的环境。不依赖于EasrType
//Stab:播放AudioClip一次,可以不用手动加载AudioSource组件
//通过iTween实现声音音量和音调的渐变效果
//二、基础属性
//基础属性比较简单直接上代码
//首先是AudioTo的
//[csharp] view plain copy 在CODE上查看代码片派生到我的代码片
//void Start () {
// //播放的声音对象
// AudioSource tempSource = gameObject.AddComponent();
// tempSource.loop = true;
// tempSource.clip = soundEnd;
// tempSource.volume = 1;
// tempSource.Play();
// //键值对儿的形式保存iTween所用到的参数
// Hashtable args = new Hashtable();
// //声音
// args.Add("audiosource", tempSource);
// //音量
// args.Add("volume", 0);
// //音调
// args.Add("pitch", 0);
// //变化的时间
// args.Add("time", 10f);
// //延迟执行时间
// args.Add("delay", 0.1f);
// //这里是设置类型,iTween的类型又很多种,在源码中的枚举EaseType中
// args.Add("easeType", iTween.EaseType.easeInOutExpo);
// //三个循环类型 none loop pingPong (一般 循环 来回)
// //args.Add("loopType", "none");
// //args.Add("loopType", "loop");
// args.Add("loopType", iTween.LoopType.pingPong);
// //处理播放过程中的事件。
// //开始播放时调用AnimationStart方法,5.0表示它的参数
// args.Add("onstart", "AnimationStart");
// args.Add("onstartparams", 5.0f);
// //设置接受方法的对象,默认是自身接受,这里也可以改成别的对象接受,
// //那么就得在接收对象的脚本中实现AnimationStart方法。
// args.Add("onstarttarget", gameObject);
// //播放结束时调用,参数和上面类似
// args.Add("oncomplete", "AnimationEnd");
// args.Add("oncompleteparams", "end");
// args.Add("oncompletetarget", gameObject);
// //播放中调用,参数和上面类似
// args.Add("onupdate", "AnimationUpdate");
// args.Add("onupdatetarget", gameObject);
// args.Add("onupdateparams", true);
// iTween.AudioTo(btnBegin, args);
//}
// //动画开始时调用
// void AnimationStart(float f)
// {
// Debug.Log("start :" + f);
// }
// //动画结束时调用
// void AnimationEnd(string f)
// {
// Debug.Log("end : " + f);
// }
// //动画中调用
// void AnimationUpdate(bool f)
// {
// Debug.Log("update :" + f);
// }
#endregion