快速連結

2021年10月15日

[筆記]比較UTC時間

new Date是非常好用的語法,不管是給UTC時間、還是地區時間,都可以幫你無痛轉成UTC的時間。
比較也是很簡單!直接做比較運算子就好!

let nowDate: Date = new Date();  
let endDate: Date = new Date( "2021-10-15T12:00:00+00:00");
let myDate: Date = new Date( "2021-10-15T16:22:00");
console.log(nowDate);
console.log(endDate);
console.log(myDate);
if (nowDate > endDate){
    console.log("Bigger");
}else{
    console.log("Smaller");
}
if (nowDate > myDate){
    console.log("Bigger");
}else{
    console.log("Smaller");
}
結果:
[LOG]: nowDate: "2021-10-15T08:22:47.110Z" [LOG]: endDate: "2021-10-15T12:00:00.000Z" [LOG]: myDate: "2021-10-15T08:22:00.000Z" [LOG]: nowDate vs endDate => "Smaller" [LOG]: nowDate vs myDate => "Bigger"

2021年9月2日

[筆記]讓金幣依照菱形圖案去跳舞



        private List CoinPos = new List();
        private void CreateCoinPos()
        {
            Vector3 offset = new Vector3(0, 20, 0);
            CoinPos.Clear();
            int _Diameter = 4;
            int _Distance = 60;
            for (int x = -_Diameter; x < _Diameter + 1; x++)
            {
                int r = Math.Abs(x % 2);
                int dis = _Diameter - Math.Abs(x);
                for (int y = -dis; y < dis + 1; y++)
                {
                    int ry = Math.Abs(y % 2);
                    if (ry != r)
                        continue;

                    Vector3 _Pos = new Vector3(x * _Distance, y * _Distance, 0);
                    _Pos += offset;
                    CoinPos.Add(_Pos);
                }
            }
            CoinPos.Sort(delegate(Vector3 a, Vector3 b)
            {
                float ad = Vector3.Distance(a, Vector3.zero);
                float bd = Vector3.Distance(b, Vector3.zero);
                if (ad < bd) return -1;
                if (ad > bd) return 1;
                return 0;
            });
        }
        public void DropCoin(int Length)
        {

        }

在typeScript使用namespace

今天要來講解在cocosCreator中,使用TypeScript來做namespace的實例,以及我遇到的小狀況。 以下就是實際code:

2021年5月15日

渲染順序 Rendering order

最近有同事在研究NGUI與UGUI的渲染順序關係(假如用同一個camera下),不過今天不是想講這個議題,而是來講講渲染順序。
當然也是有參考一些網路上的文章,本文主要是我看完後吸收到的結論。

以下圖片是實作渲染順序,如果看不懂…請再跟我說。(以下皆使用2017.4.3f1)

2020年2月5日

[工具]替換Component(Script)小工具


終於抽出時間來做些方便的小工具,其實也是為了要幫助自己快速優化專案的東西。
功能:可以對所有物件上所指定的script 同時替換成另一個script。但是限制是繼承同一個script~(例如NGUISPritePlus(繼承NGUISprite)可以取代NGUISprite)

2019年7月4日

2019年4月15日

【筆記】Unity5.4.3取得Animator現在的執行動畫(AnimatorState)的播放影格/時間


Animator m_FirstAnim, m_SecondAnim;
m_FirstAnim.Play("Loop", 0, 0);
.....
.....
float myTime = 0;
AnimatorStateInfo animationState = m_FirstAnim.GetCurrentAnimatorStateInfo(0);
float newNormalIzedTime = animationState.normalizedTime - (float)System.Math.Truncate(animationState.normalizedTime);
AnimatorClipInfo[] targetAnimatorClip = m_FirstAnim.GetCurrentAnimatorClipInfo(0);
if (targetAnimatorClip.Length > 0)
{
  myTime = targetAnimatorClip[0].clip.length * newNormalIzedTime;
}
else
{
  myTime = newNormalIzedTime;
}
m_SecondAnim.Play("Loop", 0, myTime);

2018年5月17日

Inspecter 基本架構紀錄


[CustomEditor(typeof(Tool))]
public class ToolInspecter : Editor
{
  protected Tool m_Tool;
  /// 
  /// Component每一次顯示在Inspector上就會重新呼叫一次
  /// 
  private void OnEnable()
  {
     //DO init
     m_Tool = target as Tool;
  }

  /// 
  /// Component從Inspector上移除的瞬間執行
  /// 
  private void OnDestroy()
  {
     //Do origin
  }

  /// 
  /// 該Component每一次有改變就會呼叫一次
  /// 
  public override void OnInspectorGUI()
  {
     //Do Draw GUI
     DrawDefaultInspector();
  }