一些函数与功能(不定时更新)
1:byte数组转string输出
byte[] result=new byte[]{1,2,3,4};
string vstr = "{" + string.Join(",", result) + "}";
Debug.Log(vstr);
2:sbyte转byte
sbyte[] temp = new sbyte[]{ 8, -25, 7} ;
byte[] temp2 = new byte[temp.Length];
Buffer.BlockCopy(temp, 0, temp2, 0, temp.Length);
3:在脚本中实例化Button类型预制体并添加onclick()函数
public GameObject car;
GameObject Car = Instantiate(car).gameObject;
newCar.GetComponent<RectTransform>().SetParent(this.GetComponent<RectTransform>());
Car.GetComponent<Button>().onClick.AddListener(() => { run(); });
4:判断物体是第几个子物体
int index = this.transform.GetSiblingIndex();
5:依据name寻找子物体
string name = "Car";
GameObject obj = this.transform.Find(name).gameObject;
6:int转string
string name = Convert.ToString(index);
|