123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- using UnityEngine;
- using System.Collections;
- using System;
- using System.Text.RegularExpressions;
- public class Sutil
- {
- /// <summary>
- /// 比较两个字符串中,是否包含与对方一样的字符 .
- /// 包含就行 返回true
- /// </summary>
- /// <param name="strA"></param>
- /// <param name="strB"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 获取字符串中的数字
- /// </summary>
- /// <param name="str">字符串</param>
- /// <returns>数字</returns>
- 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;
- }
- /// <summary>
- /// 获取事件串 x时x分x秒
- /// </summary>
- /// <returns></returns>
- 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;
- }
- ///// <summary>
- ///// 关于时间转换::最近日期的简易版(类似刚刚,几分钟前等)
- ///// </summary>
- ///// <param name="time"></param>
- ///// <returns></returns>
- //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;
- //}
- /// <summary>
- ///
- /// </summary>
- /// <param name="source"></param>
- /// <param name="curLeve"></param>
- /// <param name="AD">物理攻击</param>
- /// <param name="AP">法术强度</param>
- /// <returns></returns>
- 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<AudioSource>();
- // 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
|