File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Assets/JCSUnity/Scripts/Util Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 66 * $Notice: See LICENSE.txt for modification and distribution information
77 * Copyright © 2023 by Shen, Jen-Chieh $
88 */
9+ using System ;
910using UnityEngine ;
1011
1112namespace JCSUnity
@@ -15,6 +16,12 @@ namespace JCSUnity
1516 /// </summary>
1617 public static class JCS_Time
1718 {
19+ /* Variables */
20+
21+ /* Setter & Getter */
22+
23+ /* Functions */
24+
1825 /// <summary>
1926 /// Get the delta time by type.
2027 /// </summary>
@@ -42,5 +49,29 @@ public static float DeltaTime(JCS_DeltaTimeType type)
4249
4350 return 0.0f ;
4451 }
52+
53+ /// <summary>
54+ /// Return the time similar to skill time.
55+ ///
56+ /// - For day: 1d
57+ /// - For hour: 2h
58+ /// - For minute: 3m
59+ /// - For second: 4s
60+ /// </summary>
61+ public static string Format ( float seconds )
62+ {
63+ TimeSpan time = TimeSpan . FromSeconds ( seconds ) ;
64+
65+ if ( time . Days > 0 )
66+ return $ "{ time . Days } d";
67+ if ( time . Hours > 0 )
68+ return $ "{ time . Hours } h";
69+ if ( time . Minutes > 0 )
70+ return $ "{ time . Minutes } m";
71+ if ( time . Seconds >= 0 )
72+ return $ "{ time . Seconds } s";
73+
74+ return "" ;
75+ }
4576 }
4677}
You can’t perform that action at this time.
0 commit comments