- 網(wǎng)絡(luò)判斷
NetworkReachability網(wǎng)絡(luò)可達(dá)性
NetworkReachability.ReachableViaCarrierDataNetwork 通過運營商數(shù)據(jù)網(wǎng)絡(luò)可達(dá)
NetworkReachability.ReachableViaLocalAreaNetwork 通過局域網(wǎng)絡(luò)可達(dá)(wifi)
//判斷當(dāng)前的網(wǎng)絡(luò)是否是wifi或者有線連接
if(Application.internetReachability != NetworkReachability.NotReachable){
xxxx;
}
掛載腳本后窑多,有的腳本左側(cè)有復(fù)選框,有的沒有。原因是沒有寫Start函數(shù)秒裕。這種腳本啟動不會自動調(diào)用。
Editor settings 的mode設(shè)置
最好設(shè)置成text類型而不是mix 二進(jìn)制類型钞啸。因為多人開發(fā)有可能這里沖突几蜻,二進(jìn)制導(dǎo)致無法解決查找二進(jìn)制文件的沖突喇潘。常見的幾種聲明腳本屬性方式
[AddComponentMenu("UI/Slidershow", 39)] //添加菜單
[ExecuteInEditMode] //編輯模式下可執(zhí)行
[DisallowMultipleComponent] //不可重復(fù)
[RequireComponent(typeof(RectTransform))] //依賴于RectTransform組件
- 腳本處理順序
同一個物體上的腳本,后添加上去的腳本先執(zhí)行
- 平臺預(yù)處理
using UnityEngine;
using System.Collections;
public class Recompile : MonoBehaviour
{
private string platform = string.Empty;
// Use this for initialization
void Start()
{
DebugPlatformMesaage();
}
void DebugPlatformMesaage()
{
#if UNITY_EDITOR
platform = "hi,大家好,我是在unity編輯模式下";
#elif UNITY_XBOX360
platform="hi梭稚,大家好,我在XBOX360平臺";
#elif UNITY_IPHONE
platform="hi颖低,大家好,我是IPHONE平臺";
#elif UNITY_ANDROID
platform="hi,大家好,我是ANDROID平臺";
#elif UNITY_STANDALONE_OSX
platform="hi弧烤,大家好,我是OSX平臺";
#elif UNITY_STANDALONE_WIN
platform="hi忱屑,大家好,我是Windows平臺";
#endif
Debug.Log("Current Platform:" + platform);
}
}
- 避免不小心修改腳本的變量和設(shè)置
如,項目里面聲明變量,這樣這些腳本的屬性值暇昂,就不會出現(xiàn)在面板中莺戒,隱藏掉
[HideInInspector] public int stars;
[HideInInspector] public bool goalAchieved = false;
[HideInInspector]public static int maxLevels = 40;
[HideInInspector]public static int maxPacks = 4;
[HideInInspector]public static bool soundEnabled;
[HideInInspector]public GameObject genericDialog;
[HideInInspector]public static int hintCount;
[HideInInspector]public static int rewardsCount = 0,rewardsLimit=3;
[HideInInspector]public static int ADMOB = 1, CHARTBOOST=2;
- GameManager
- DontDestroy
- Application
- QualitySettings
- SenceManager
場景跳轉(zhuǎn)
SceneManager.LoadScene("model");
- 退出應(yīng)用
- 彈出提示框退出
void OnApplicationQuit(){
GameManager.instance = null;
}
- 退出
void OnApplicationQuit(){
GameManager.instance = null;
}
- 跳轉(zhuǎn)google play 分享
void ShareLink() {
string bodyString = "";
string subjectString = "New Android Game";
//Refernece of AndroidJavaClass class for intent
AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
//Refernece of AndroidJavaObject class for intent
AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
//call setAction method of the Intent object created
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
//set the type of sharing that is happening
intentObject.Call<AndroidJavaObject>("setType", "text/plain");
//add data to be passed to the other activity i.e., the data to be sent
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subjectString);
bodyString = "I play this new cool puzzle game - https://play.google.com/store/apps/details?id=" +packageName;
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"),bodyString);
//get the current activity
AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
//start the activity by sending the intent data
currentActivity.Call ("startActivity", intentObject);
}