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.挂载到游戏物体的一个脚本xxx.cs
其中:this指当前脚本。transform当前物体的transform组件。gameObject当前脚本所挂的物体