移动 前端 Python Android Java

Unity 小技巧积累

2017-09-01  本文已影响92人  zcwfeng
NetworkReachability网络可达性
NetworkReachability.ReachableViaCarrierDataNetwork 通过运营商数据网络可达
NetworkReachability.ReachableViaLocalAreaNetwork 通过局域网络可达(wifi)

//判断当前的网络是否是wifi或者有线连接

if(Application.internetReachability != NetworkReachability.NotReachable){

    xxxx;

}
    [AddComponentMenu("UI/Slidershow", 39)]          //添加菜单
    [ExecuteInEditMode]                             //编辑模式下可执行
    [DisallowMultipleComponent]                     //不可重复
    [RequireComponent(typeof(RectTransform))]       //依赖于RectTransform组件
同一个物体上的脚本,后添加上去的脚本先执行
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);  
    }  
} 
        [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;
SceneManager.LoadScene("model");  
  1. 弹出提示框退出
      void OnApplicationQuit(){
        GameManager.instance = null;
    }
  1. 退出
        void OnApplicationQuit(){
        GameManager.instance = null;
    }
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);

    }

上一篇 下一篇

猜你喜欢

热点阅读