LiuQilin 8 سال پیش
والد
کامیت
5c11e523fd

BIN
Assets/Resources/Prefab/PrefabUI/AwardItem.prefab


+ 8 - 0
Assets/Resources/Prefab/PrefabUI/AwardItem.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 63aedf1e71ba0ae419cd55ae1dde1241
+timeCreated: 1489664129
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Resources/Prefab/PrefabUI/DateItem.prefab


+ 8 - 0
Assets/Resources/Prefab/PrefabUI/DateItem.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: aefbbfee089a9964e9b377589692f48c
+timeCreated: 1489664166
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Resources/Prefab/PrefabUI/FlowerCardItem.prefab


+ 8 - 0
Assets/Resources/Prefab/PrefabUI/FlowerCardItem.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: bda8a034985500243845dc4b804f9f25
+timeCreated: 1489664004
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Resources/Prefab/PrefabUI/FlowerHouseItem.prefab


+ 8 - 0
Assets/Resources/Prefab/PrefabUI/FlowerHouseItem.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: e719f06d55a7db842abdc96b01c32ae1
+timeCreated: 1489664063
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Resources/Prefab/PrefabUI/SkillItem.prefab


+ 8 - 0
Assets/Resources/Prefab/PrefabUI/SkillItem.prefab.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: e94e1c2506968d14ba9792fb79e31e39
+timeCreated: 1489663921
+licenseType: Pro
+NativeFormatImporter:
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 73 - 0
Assets/Script/Tool/Anim/MoveScrr.cs

@@ -0,0 +1,73 @@
+using UnityEngine;
+
+using System.Collections;
+using UnityEngine.Events;
+using UnityEngine.UI;
+
+public class MoveScrr : Move
+{
+    #region 变量
+
+    protected float Timer;
+    protected float Duration;
+    protected float Delta;
+    protected float Origin;
+    protected float Destination;
+    protected ScrollRect Target;
+
+    protected CurveFunctionF Func;
+
+    #endregion
+
+    public MoveScrr(ScrollRect target)
+    {
+        Target = target;
+    }
+
+
+    public override bool DoMove()
+    {
+        if (Timer > Duration)
+        {
+            Target.horizontalNormalizedPosition = Destination;
+
+            Timer = 0;
+
+            ManaAnim.MoveList.Remove(this);
+
+            if (OnFinish != null)
+            {
+                OnFinish.Invoke();
+            }
+
+            return true;
+        }
+        else
+        {
+            Target.horizontalNormalizedPosition = Func(Timer, Duration, Origin, Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+
+    public void StartMove(float destination, float duration, Curve curve)
+    {
+        Finish = false;
+
+        Delta = destination - Target.horizontalNormalizedPosition;
+        Origin = Target.horizontalNormalizedPosition;
+        Duration = duration;
+        Destination = destination;
+
+        Func = ManaAnim.FunctionDicF[curve];
+
+        if (OnStart != null)
+        {
+            OnStart.Invoke();
+        }
+
+        ManaAnim.MoveList.Add(this);
+    }
+}

+ 12 - 0
Assets/Script/Tool/Anim/MoveScrr.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: a5556dbc0ca92564d9abc5ec2055564f
+timeCreated: 1489626180
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 74 - 0
Assets/Script/Tool/Anim/MoveVec.cs

@@ -0,0 +1,74 @@
+using UnityEngine;
+using UnityEngine.Events;
+
+using System;
+using System.Collections;
+
+public class MoveVec : Move
+{
+    #region 变量
+
+    protected float Timer;
+    protected float Duration;
+    protected Vector3 Delta;
+    protected Vector3 Origin;
+    protected Vector3 Destination;
+    protected Transform Target;
+
+    protected CurveFunctionV Func;
+
+    #endregion
+
+    public MoveVec(Transform target)
+    {
+        Target = target;
+    }
+
+
+    public override bool DoMove()
+    {
+        if (Timer > Duration)
+        {
+            Target.position = Destination;
+
+            Timer = 0;
+
+            ManaAnim.MoveList.Remove(this);
+
+            if (OnFinish != null)
+            {
+                OnFinish.Invoke();
+            }
+
+            return true;
+        }
+        else
+        {
+            Target.position = Func(Timer, Duration, Origin, Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+
+    public void StartMove(Vector3 destination, float duration, Curve curve)
+    {
+        Finish = false;
+        destination.z = Target.position.z;
+
+        Delta = destination - Target.position;
+        Origin = Target.position;
+        Duration = duration;
+        Destination = destination;
+
+        Func = ManaAnim.FunctionDicV[curve];
+
+        if (OnStart != null)
+        {
+            OnStart.Invoke();
+        }
+
+        ManaAnim.MoveList.Add(this);
+    }
+}

+ 12 - 0
Assets/Script/Tool/Anim/MoveVec.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 15d25b48775dc7c4dbc614ce0c80df93
+timeCreated: 1488182161
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 97 - 0
Assets/Script/Tool/Anim/TweenGra.cs

@@ -0,0 +1,97 @@
+using UnityEngine;
+using UnityEngine.UI;
+
+using System.Collections;
+
+public class TweenGra : Tween 
+{
+    #region 变量
+
+    protected Color Delta;
+    protected Color Origin;
+    protected Color Destination;
+    protected Graphic Target;
+    protected CurveFunctionC Func;
+    
+    #endregion
+
+    public TweenGra(Graphic target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve)
+    {
+        Target = target;
+        Duration = duration;
+        DestActive = destActive;
+        OriginActive = originActive;
+
+        Delta = destination - origin;
+        Origin = origin;
+        Destination = destination;
+        
+        OnForwardStart += () =>
+        {
+            Target.SetActive(true);
+        };
+
+        OnForwardFinish += () =>
+        {
+            Target.SetActive(DestActive);
+        };
+
+        OnBackwardStart += () =>
+        {
+            Target.SetActive(true);
+        };
+
+        OnBackwardFinish += () =>
+        {
+            Target.SetActive(OriginActive);
+        };
+
+        Func = ManaAnim.FunctionDicC[curve];
+    }
+
+    public override bool DoForward()
+    {
+        if (Timer > Duration)
+        {
+            Target.color = Destination;
+
+            Timer = 0;
+            IsBackwardFinish = true;
+            OnForwardFinish.Invoke();
+
+            ManaAnim.TweenForList.Remove(this);
+            return true;
+        }
+        else
+        {
+            Target.color = Func(Timer, Duration, Origin, Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+
+    public override bool DoBackward()
+    {
+        if (Timer > Duration)
+        {
+            Target.color = Origin;
+
+            Timer = 0;
+            IsForwardFinish = true;
+            OnBackwardFinish.Invoke();
+
+            ManaAnim.TweenBacList.Remove(this);
+            return true;
+        }
+        else
+        {
+            Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a));
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+}

+ 12 - 0
Assets/Script/Tool/Anim/TweenGra.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0d8f57befd4ee794fb717f8d2edd57de
+timeCreated: 1489287555
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 135 - 0
Assets/Script/Tool/Anim/TweenScale.cs

@@ -0,0 +1,135 @@
+using UnityEngine;
+
+using System.Collections;
+
+public class TweenScale : Tween 
+{
+    #region
+
+    protected Vector3 Delta;
+    protected Vector3 Origin;
+    protected Vector3 Destination;
+    protected Transform Target;
+    protected CanvasGroup CanvasGroup;
+    protected CurveFunctionV Func;
+
+    #endregion
+
+    public TweenScale(Transform target, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve)
+    {
+        Target = target;
+        Duration = duration;
+        DestActive = destActive;
+        OriginActive = originActive;
+
+        Delta = destination - origin;
+        Origin = origin;
+        Destination = destination;
+
+        CanvasGroup = Target.GetComponent<CanvasGroup>();
+
+        OnForwardStart += () =>
+        {
+            Target.SetActive(true);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = false;
+            }
+        };
+
+        OnForwardFinish += () =>
+        {
+            Target.SetActive(DestActive);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = DestActive;
+            }
+        };
+
+        OnBackwardStart += () =>
+        {
+            Target.SetActive(true);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = false;
+            }
+        };
+
+        OnBackwardFinish += () =>
+        {
+            Target.SetActive(OriginActive);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = OriginActive;
+            }
+        };
+
+        Func = ManaAnim.FunctionDicV[curve];
+    }
+
+
+    public override void StartForward()
+    {
+        base.StartForward();
+
+        //Timer = (Target.localScale.x - Origin.x/Delta.x)*Duration;
+    }
+
+    public override void StartBackward()
+    {
+        base.StartForward();
+
+        //Timer = (Target.localScale.x - Destination.x / Delta.x) * Duration;
+    }
+
+    public override bool DoForward()
+    {
+        if (Timer > Duration)
+        {
+            Target.localScale = Destination;
+
+            Timer = 0;
+            IsForwardFinish = true;
+            OnForwardFinish.Invoke();
+
+            ManaAnim.TweenForList.Remove(this);
+
+            return true;
+        }
+        else
+        {
+            Target.localScale = Func(Timer, Duration, Origin, Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+
+    public override bool DoBackward()
+    {
+        if (Timer > Duration)
+        {
+            Target.localScale = Origin;
+
+            Timer = 0;
+            IsBackwardFinish = true;
+            OnBackwardFinish.Invoke();
+
+            ManaAnim.TweenBacList.Remove(this);
+            return true;
+        }
+        else
+        {
+            Target.localScale = Func(Timer, Duration, Destination, -Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+}

+ 12 - 0
Assets/Script/Tool/Anim/TweenScale.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 6e49a5c05fab1af44b49dfd16e15e764
+timeCreated: 1489693296
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 122 - 0
Assets/Script/Tool/Anim/TweenVec.cs

@@ -0,0 +1,122 @@
+using UnityEngine;
+
+using System;
+using System.Collections;
+
+public class TweenVec : Tween
+{
+    #region
+
+    protected Vector3 Delta;
+    protected Vector3 Origin;
+    protected Vector3 Destination;
+    protected Transform Target;
+    protected CanvasGroup CanvasGroup;
+    protected CurveFunctionV Func;
+
+    #endregion
+
+    public TweenVec(Transform target, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve)
+    {
+        Target = target;
+        Duration = duration;
+        DestActive = destActive;
+        OriginActive = originActive;
+
+        Delta = destination - origin;
+        Origin = origin;
+        Destination = destination;
+
+        CanvasGroup = Target.GetComponent<CanvasGroup>();
+
+        OnForwardStart += () =>
+        {
+            Target.SetActive(true);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = false;
+            }
+        };
+
+        OnForwardFinish += () =>
+        {
+            Target.SetActive(DestActive);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = DestActive;
+            }
+        };
+
+        OnBackwardStart += () =>
+        {
+            Target.SetActive(true);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = false;
+            }
+        };
+
+        OnBackwardFinish += () =>
+        {
+            Target.SetActive(OriginActive);
+
+            if (CanvasGroup != null)
+            {
+                CanvasGroup.interactable = OriginActive;
+            }
+        };
+
+        Func = ManaAnim.FunctionDicV[curve];
+    }
+
+
+    public override bool DoForward()
+    {
+        if (Timer > Duration)
+        {
+            Target.position = Destination;
+
+            Timer = 0;
+            IsForwardFinish = true;
+            OnForwardFinish.Invoke();
+
+            ManaAnim.TweenForList.Remove(this);
+
+            return true;
+        }
+        else
+        {
+            Target.position = Func(Timer, Duration, Origin, Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+
+    public override bool DoBackward()
+    {
+        if (Timer > Duration)
+        {
+            Target.position = Origin;
+
+            Timer = 0;
+            IsBackwardFinish = true;
+            OnBackwardFinish.Invoke();
+
+            ManaAnim.TweenBacList.Remove(this);
+            return true;
+        }
+        else
+        {
+            Target.position = Func(Timer, Duration, Destination, -Delta);
+
+            Timer += Time.fixedDeltaTime;
+
+            return false;
+        }
+    }
+}

+ 12 - 0
Assets/Script/Tool/Anim/TweenVec.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: aad4411c8b9e9c74c916ad5bf7230ca5
+timeCreated: 1487475733
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 328 - 0
Assets/Script/Tool/DateUtil.cs

@@ -0,0 +1,328 @@
+using System;
+using System.Globalization;
+
+public class DateUtil
+{
+    private static DateTime startStandardTime;
+    private static DateTime pauseStandardTime = new DateTime(1970, 1, 1);
+    private static DateTime localStandardTime;
+
+    //如果12月31号与下一年的1月1好在同一个星期则算下一年的第一周
+    public static int GetWeekIndex(DateTime dTime)
+    {
+        try
+        {
+            //确定此时间在一年中的位置
+            var dayOfYear = dTime.DayOfYear;
+            //当年第一天
+            var tempDate = new DateTime(dTime.Year, 1, 1);
+            //确定当年第一天
+            var tempDayOfWeek = (int)tempDate.DayOfWeek;
+            tempDayOfWeek = tempDayOfWeek == 0 ? 7 : tempDayOfWeek;
+            //确定星期几
+            var index = (int)dTime.DayOfWeek;
+            index = index == 0 ? 7 : index;
+            //当前周的范围
+            DateTime retStartDay = dTime.AddDays(-(index - 1));
+            DateTime retEndDay = dTime.AddDays(7 - index);
+            //确定当前是第几周
+            var weekIndex = (int)Math.Ceiling(((double)dayOfYear + tempDayOfWeek - 1) / 7);
+            if (retStartDay.Year < retEndDay.Year)
+            {
+                weekIndex = 1;
+            }
+
+            return weekIndex;
+        }
+        catch (Exception ex)
+        {
+            throw new Exception(ex.Message);
+        }
+    }
+
+
+    public static int GetWeekIndex(string strDate)
+    {
+        try
+        {
+            //需要判断的时间
+            DateTime dTime = Convert.ToDateTime(strDate);
+            return GetWeekIndex(dTime);
+        }
+        catch (Exception ex)
+        {
+            throw new Exception(ex.Message);
+        }
+
+    }
+
+    /// <summary>
+    /// 用年份和第几周来获得一周开始和结束的时间,这里用星期一做开始。
+    /// </summary>
+    public static void GetWeek(int year, int weekNum, out DateTime weekStart, out DateTime weekeEnd)
+    {
+        var dateTime = new DateTime(year, 1, 1);
+        dateTime = dateTime.AddDays(7 * weekNum);
+        weekStart = dateTime.AddDays(-(int)dateTime.DayOfWeek + (int)DayOfWeek.Monday);
+        weekeEnd = dateTime.AddDays((int)DayOfWeek.Saturday - (int)dateTime.DayOfWeek + 1);
+    }
+
+    /// <summary> 求某年有多少周
+    /// </summary>
+    public static int GetYearWeekCount(int year)
+    {
+        var dateTime = DateTime.Parse(year + "-01-01");
+        var firstDayOfWeek = Convert.ToInt32(dateTime.DayOfWeek);//得到该年的第一天是周几 
+        if (firstDayOfWeek == 1)
+        {
+            var countDay = dateTime.AddYears(1).AddDays(-1).DayOfYear;
+            var countWeek = countDay / 7 + 1;
+            return countWeek;
+        }
+        else
+        {
+            var countDay = dateTime.AddYears(1).AddDays(-1).DayOfYear;
+            var countWeek = countDay / 7 + 2;
+            return countWeek;
+        }
+    }
+
+    /// <summary>
+    /// 求当前日期是一年的中第几周
+    /// </summary>
+    public static int WeekOfYear(DateTime todayTime)
+    {
+        var firstdayofweek = Convert.ToInt32(Convert.ToDateTime(todayTime.Year.ToString(CultureInfo.InvariantCulture) + "- " + "1-1 ").DayOfWeek);
+        var days = todayTime.DayOfYear;
+        var daysOutOneWeek = days - (7 - firstdayofweek);
+        if (daysOutOneWeek <= 0)
+        {
+            return 1;
+        }
+        var weeks = daysOutOneWeek / 7;
+        if (daysOutOneWeek % 7 != 0)
+            weeks++;
+        return weeks + 1;
+    }
+
+    /// <summary>
+    /// 当前月有多少天
+    /// </summary>
+    public static int HowMonthDay(int year, int month)
+    {
+        int next_month;
+        int next_year;
+        if (month < 12)
+        {
+            next_month = month + 1;
+            next_year = year;
+        }
+        else
+        {
+            next_month = 1;
+            next_year = year + 1;
+        }
+        DateTime dt1 = Convert.ToDateTime(year + "-" + month + "-1");
+        DateTime dt2 = Convert.ToDateTime(next_year + "-" + next_month + "-1");
+        TimeSpan diff = dt2 - dt1;
+        return diff.Days;
+    }
+
+    //get day in week by hashcode
+    private static Array dayOfWeekArr = Enum.GetValues(typeof(DayOfWeek));
+    public static DayOfWeek GetDayOfWeekByHashCode(int code)
+    {
+        return (DayOfWeek)dayOfWeekArr.GetValue(code);
+    }
+
+    /// <summary>
+    /// 时间戳转为C#格式时间
+    /// </summary>
+    /// <param name="timeStamp">Unix时间戳格式</param>
+    /// <returns>C#格式时间</returns>
+    public static DateTime GetTime(string timeStamp)
+    {
+        DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
+        long lTime = long.Parse(timeStamp + "0000000");
+        TimeSpan toNow = new TimeSpan(lTime);
+        return dtStart.Add(toNow);
+    }
+
+    /// <summary>
+    /// DateTime时间格式转换为Unix时间戳格式
+    /// </summary>
+    /// <param name="time"> DateTime时间格式</param>
+    /// <returns>Unix时间戳格式</returns>
+    public static int ConvertDateTimeInt(System.DateTime time)
+    {
+        System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
+        return (int)(time - startTime).TotalSeconds;
+    }
+
+    /// <summary>
+    /// 从标准服务器获取当前正确时间,如果获取失败,则获取本地时间,并存在startStandardTime
+    /// </summary>
+    /// <param name="timeZone">时区</param>
+    /// <returns>DateTime时间格式</returns>
+    public static DateTime GetStandardTime(int timeZone = 8)
+    {
+        DateTime dt;
+
+        //返回国际标准时间
+        //只使用的时间服务器的IP地址,未使用域名
+        try
+        {
+            string[,] timeServer = new string[14, 2];
+            int[] searchOrder = new int[] { 3, 2, 4, 8, 9, 6, 11, 5, 10, 0, 1, 7, 12 };
+            timeServer[0, 0] = "time-a.nist.gov";
+            timeServer[0, 1] = "129.6.15.28";
+            timeServer[1, 0] = "time-b.nist.gov";
+            timeServer[1, 1] = "129.6.15.29";
+            timeServer[2, 0] = "time-a.timefreq.bldrdoc.gov";
+            timeServer[2, 1] = "132.163.4.101";
+            timeServer[3, 0] = "time-b.timefreq.bldrdoc.gov";
+            timeServer[3, 1] = "132.163.4.102";
+            timeServer[4, 0] = "time-c.timefreq.bldrdoc.gov";
+            timeServer[4, 1] = "132.163.4.103";
+            timeServer[5, 0] = "utcnist.colorado.edu";
+            timeServer[5, 1] = "128.138.140.44";
+            timeServer[6, 0] = "time.nist.gov";
+            timeServer[6, 1] = "192.43.244.18";
+            timeServer[7, 0] = "time-nw.nist.gov";
+            timeServer[7, 1] = "131.107.1.10";
+            timeServer[8, 0] = "nist1.symmetricom.com";
+            timeServer[8, 1] = "69.25.96.13";
+            timeServer[9, 0] = "nist1-dc.glassey.com";
+            timeServer[9, 1] = "216.200.93.8";
+            timeServer[10, 0] = "nist1-ny.glassey.com";
+            timeServer[10, 1] = "208.184.49.9";
+            timeServer[11, 0] = "nist1-sj.glassey.com";
+            timeServer[11, 1] = "207.126.98.204";
+            timeServer[12, 0] = "nist1.aol-ca.truetime.com";
+            timeServer[12, 1] = "207.200.81.113";
+            timeServer[13, 0] = "nist1.aol-va.truetime.com";
+            timeServer[13, 1] = "64.236.96.53";
+            int portNum = 13;
+            string hostName;
+            byte[] bytes = new byte[1024];
+            int bytesRead = 0;
+            System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
+            for (int i = 0; i < 13; i++)
+            {
+                hostName = timeServer[searchOrder[i], 1];
+                try
+                {
+                    client.Connect(hostName, portNum);
+                    System.Net.Sockets.NetworkStream ns = client.GetStream();
+                    bytesRead = ns.Read(bytes, 0, bytes.Length);
+                    client.Close();
+                    break;
+                }
+                catch (System.Exception)
+                {
+                }
+            }
+            char[] sp = new char[1];
+            sp[0] = ' ';
+            dt = new DateTime();
+            string str1;
+            str1 = System.Text.Encoding.ASCII.GetString(bytes, 0, bytesRead);
+
+            string[] s;
+            s = str1.Split(sp);
+            dt = DateTime.Parse(s[1] + " " + s[2]);//得到标准时间
+            dt = dt.AddHours(timeZone);
+        }
+        catch (Exception)
+        {
+            dt = DateTime.Parse("1970-1-1");
+        }
+
+        if ((dt.ToString() != "1970-1-1 0:00:00"))
+            startStandardTime = dt;
+        else
+        {
+            Debuger.LogError("Can not get server time, use local instead!");
+            startStandardTime = DateTime.Now;
+        }
+
+        localStandardTime = DateTime.Now;
+        //Debuger.LogWarning("[Server Standard Time]" + standardTime);
+        return dt;
+    }
+
+    /// <summary>
+    /// 按照当前时间重新设置起始时间
+    /// </summary>
+    /// <param name="interval">设置可重置的时间差,单位为秒</param>
+    public static void ResetStandardTime(int interval)
+    {
+        if(GetCurrentTimeByStandardTime() - ConvertDateTimeInt(pauseStandardTime) > interval && pauseStandardTime != new DateTime(1970, 1, 1))
+        {
+            startStandardTime = GetCurrenTimeByStandardTimeUseDateTime();
+            pauseStandardTime = new DateTime(1970, 1, 1);
+        }
+    }
+
+    /// <summary>
+    /// 设置暂停时的时间
+    /// </summary>
+    public static void SetPauseStandardTime()
+    {
+        pauseStandardTime = GetCurrenTimeByStandardTimeUseDateTime();
+    }
+
+    /// <summary>
+    /// 从打开游戏到当前所经历的秒数
+    /// </summary>
+    /// <returns>单位为秒</returns>
+    public static int GetRealTimeSinceStart()
+    {
+        return ConvertDateTimeInt(DateTime.Now) - ConvertDateTimeInt(localStandardTime);
+    }
+
+    /// <summary>
+    /// 获取当前标准时间的时间戳
+    /// </summary>
+    /// <returns>返回时间戳</returns>
+    public static int GetCurrentTimeByStandardTime()
+    {
+        return GetRealTimeSinceStart() + ConvertDateTimeInt(startStandardTime);
+    }
+
+    /// <summary>
+    /// 获取当前标准时间
+    /// </summary>
+    /// <returns>返回DateTime时间格式</returns>
+    public static DateTime GetCurrenTimeByStandardTimeUseDateTime()
+    {
+        return GetTime(GetCurrentTimeByStandardTime().ToString());
+    }
+
+    /// <summary>
+    /// 设置当前标准时间
+    /// </summary>
+    /// <param name="dateTime"></param>
+    public static void SetStandardTime(DateTime dateTime)
+    {
+        startStandardTime = dateTime;
+        localStandardTime = DateTime.Now;
+    }
+
+    /// <summary>
+    /// 获取当前标准时间
+    /// </summary>
+    public static DateTime GetStandardTimeExist()
+    {
+        return startStandardTime; //todo 删掉这句 取消注释
+        //if (startStandardTime != null) 
+        //    return startStandardTime;
+        //else
+        //    return DateTime.Now;
+    }
+
+    public static int GetStandardTimeExistByTimeStamp()
+    {
+        return ConvertDateTimeInt(GetStandardTimeExist());
+    }
+}

+ 12 - 0
Assets/Script/Tool/DateUtil.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 68ad82aba2e083d4f8e86ed3e36292d2
+timeCreated: 1489645107
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: