Unity3d 初探
1.Mathf.Abs(Screen.height * 1.0f / Screen.width - 3.0f / 4)-------Screen類下
2.string filePath = Application.persistentDataPath + "/picture.jpg";-------Application類下
3. WaiteForWWW("https://wx.qimengkeji.com.cn/ppg_server/xingwawa/notice.txt", (www) => ------WWW類
{
string s = www.text;
if (!showNoticed && !s.Equals(""))
{
//if (PlayerPrefs.GetString("notice") != s)
{
showNoticed = true;
PlayerPrefs.SetString("notice", s);
noticeUi.GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetComponent<Text>().text = s;
noticeUi.gameObject.SetActive(true);
}
}
});
4. if (File.Exists(filePath))
{
byte[] bytes = File.ReadAllBytes(filePath);
Texture2D texture = new Texture2D(128, 128);
texture.LoadImage(bytes);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
panel.transform.GetChild(1).GetChild(2).GetComponent<Image>().sprite = sprite;
}
5. Debug.Log(www.text) ------log輸出
6. PlayerPrefs.SetString("playerId", www.text);-------PlayerPrefs類,本地持久化
7. JsonData jsonData = JsonMapper.ToObject(WWW.UnEscapeURL(www.text));
8. this.LoadTexture(WxAuthorize.IconUrl(WWW.UnEscapeURL(s[1])), (texture2D) => {
Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), new Vector2(0, 0));
panel.transform.GetChild(1).GetChild(2).GetComponent<Image>().sprite = sprite;
string filePath = Application.persistentDataPath + "/picture.jpg";
//filePath = Application.dataPath + "/picture.jpg";
byte[] bytes = texture2D.EncodeToPNG();
File.WriteAllBytes(filePath, bytes);
});
9. AndroidJavaObject _ajc= new AndroidJavaObject("com.jing.unity.Unity2Android"); --------jni呼叫
bool success;
success = _ajc.Call<bool>("joinQQGroup","yu16-R4oVeHl8CBuwAiaBklC-qgDunel");
// success = _ajc.Call<bool>("openApp", "mqqopensdkapi://bizAgent/qm/qr?url=http://qm.qq.com/cgi-bin/qm/qr?from=app&p=android&k=yu16-R4oVeHl8CBuwAiaBklC-qgDunel");
Debug.Log("QQGroup");
10. SceneManager.LoadScene("start");----------------------SceneManager類
11.JsonData jsonData = new JsonData();
foreach (int i in Player.GetAnimals().Keys)
{
if(1==Player.GetAnimals()[i])
{
JsonData jsonData2 = new JsonData();
jsonData2["level"] = 1;
jsonData[Player.PetNameMap()[i]] = jsonData2;
}
}
string strJson = jsonData.ToJson();
string url = "https://wx.qimengkeji.com.cn/ppg_server/xingwawa/index.php?m=xingwawa&a=set_pet_info&id=" + PassParameter.playerId + "&pet_info=" + WWW.EscapeURL(strJson);
m.WaiteForWWW(url, (www) => Debug.Log(www.text));
Debug.Log(strJson);
12. if(!(Application.internetReachability == NetworkReachability.NotReachable)) -----------NetworkReachability類
13.col = GameObject.Find("groundInstance");
for (int i = 0; i < transform.childCount; i++) ---------------------------------Transform類
14. public void LateUpdate() { -----------------------監聽鍵盤輸入
base.LateUpdate(); if (Input.GetKey("a"))
15.transform.position和transform.localPosition區別
1. position是根據世界原點為中心
2. localPosition是根據父節點為中心,如果沒有父節點,localpositon和position是沒有區別的
16.virtual protected void OnCollisionEnter(Collision collision)==================碰撞檢測
{
Character c = collision.gameObject.GetComponent<Character>();
}
17.GetComponent<Rigidbody>()
18. GetComponent<Rigidbody>().AddForce(collisionDirection * global.instance.bumperForce * a);
19. string names = PlayerPrefs.GetString("names");=================PlayerPrefs類
20.//獲取到按鈕
btn = GameObject.Find(“Button”).GetComponent<Button> ();
//給按鈕新增監聽事件
btn.onClick .AddListener (BtnClick);
void BtnClick() { //按鈕響應事件
Debug.Log (“btn.onClick .AddListener ()”);
}
21.
Slider是滑動條,Slider的屬性如圖所示:
Slider slider ;
void Star t () {
//獲取到Slider元件
slider = GameObject.Find(“Slider ”).GetComponent<Slider> ();
//新增監聽事件
slider.onValueChanged.AddListener(SliderValueChange);
}
// 事件響應
public voidSliderValueChange (float value){
Debug.Log (“value = “+value);
}
22.
private void OnApplicationQuit()
{
SocketManager.Instance.Close();
}
private void OnApplicationFocus(bool focus)
{
if(focus)
{
print("OnApplicationFocus true");
}else
{
print("OnApplicationFocus false");
}
}
private void OnApplicationPause(bool pause)
{
if (pause)
{
print("OnApplicationPause true");
}
else
{
print("OnApplicationPause false");
}
}
23.
相關文章
- Unity3d 入門(一) 瞭解Unity3dUnity3D
- unity3d碰撞Unity3D
- unity3d sqliteUnity3DSQLite
- unity3D進階Unity3D
- Unity3d 陀螺儀Unity3D
- Unity3D入門Unity3D
- 幹掉Unity3DUnity3D
- Deno 初探
- ELK初探
- Nginx 初探Nginx
- Mobx 初探
- jQuery初探jQuery
- 初探IndexedDBIndex
- 初探PWA
- Puppeteer 初探
- Redis初探Redis
- 初探Firewalld
- Serverless初探Server
- Promise初探Promise
- Quantum 初探
- 初探TCPTCP
- ## RATreeView 初探View
- puppeteer初探
- Quartz初探quartz
- MapDB初探
- Vue初探Vue
- Docker初探Docker
- angr初探
- Gitee初探Gitee
- 初探canvasCanvas
- pointerEvent 初探
- websoctet初探Web
- RxJava 初探RxJava
- GoLang初探Golang
- Django初探Django
- orm初探ORM
- 初探 TypeScriptTypeScript
- ECharts 初探Echarts