public static float ClampRotaionY(float y)
{
while (y < 0)
{
y += 360;
}
while (y > 360)
{
y -= 360;
}
return y;
}
嗚嗚喔學習筆記
搜尋此網誌
2022年12月19日 星期一
C# Rotation to Positive , [C#] 旋轉角度轉正 不給負數
2022年12月14日 星期三
GIT .gitignore 刷新方式
我们用GIT提交版本的时候,忽略文件有可能并不是不变的。但是对于后来加入到.gitignore中的文件,GIT默认还是不理睬它们的。因为GIT有一个缓存的机制。
下面是解决办法:
1、使用命令工具Git Bash,进入需要修改的工作目录。如C:/est
则输入
cd c:/test
2、重置所有缓存(注意后面有个.)
git rm -r --cached .
3、重新添加(注意后面有个.)
git add .
4、提交
git commit -m ".gitignore is now working"
如需转载请标明出处:http://blog.csdn.net/itas109
————————————————
版权声明:本文为CSDN博主「itas109」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/itas109/article/details/48156805
2022年12月13日 星期二
C# Byte To 4 Bit 用4bit儲存資料 可以節省一半空間
public static class HalfByteArray
{
public static byte HalfByteAyGet(byte[] bAy, int idx)
{
int bIndex = idx / 2;
if (idx % 2 == 0)
{
return (byte)(bAy[bIndex] >> 4);
}
else
{
return (byte)(bAy[bIndex] & 0b0000_1111);
}
}
public static byte[] Byte2Half(byte[] og)
{
byte[] bAry = new byte[og.Length / 2];
for (int i = 0; i < og.Length; i += 2)
{
byte HLv0 = og[i];
byte HLv1 = og[i + 1];
byte b = (byte)((HLv0 << 4) + HLv1);
bAry[i / 2] = b;
}
return bAry;
}
public static void TestCase()
{
byte[] og = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] halfB = Byte2Half(og);
for (int i = 0; i < og.Length; i++)
{
byte back = HalfByteAyGet(halfB, i);
UnityEngine.Assertions.Assert.AreEqual(back, og[i]);
}
}
}
2022年7月6日 星期三
C# Switch case vs if else 效能分析
先說結論 : Switch case 再Case數量 > 5 之後比 if else 還快 ( 但快非常少 )
為什麼? 他經過什麼轉換?
Switch Case 是語法糖 所以他會經過轉換 基本上就是轉成 if else 的形式 只是會做一些優化處理
以下為轉換程式碼
如果 case 是數字常數時->會轉成樹狀查詢
int a = 100; |
轉成:
int num = 100; |
物件格式:
Object b = "100"; |
case 數量 >5 時 會先轉HashCode 所以能夠被樹狀查詢 ( 會比較快點 ) 轉成: |
object obj = "100"; |
結論: 當switch case 是數字常數時會比較快 or 非數字常數要超過5個以上才會優化
參考: