211 lines
5.1 KiB
C#
211 lines
5.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Runtime.InteropServices;
|
||
using UnityEngine;
|
||
|
||
public class H5Controller : MonoBehaviour
|
||
{
|
||
/// <summary>
|
||
/// JS库文件类
|
||
/// </summary>
|
||
public class JsLib
|
||
{
|
||
//[DllImport("__Internal")]
|
||
//public static extern void SetFullscreen();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern float GetPlatformType();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void LoadView(string data);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void HideView();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void Alert(string msg);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern bool IsBroswerSP();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern bool IsMobileBroswer();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern bool IsIOSBroswer();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern bool IsShowFPS();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern bool OpenUrl(string url);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void PlayBg(int index);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void PauseBackgroundMusic();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void ResumeBackgroundMusic();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void SetBackgroundMute();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void PlayAudio(string audioName);
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void StopAudio();
|
||
|
||
[DllImport("__Internal")]
|
||
public static extern void LoadVideo(string videoName, string videoTitle);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置全屏
|
||
/// </summary>
|
||
public static void SetFullscreen()
|
||
{
|
||
//JsLib.SetFullscreen();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取平台类型
|
||
/// </summary>
|
||
/// <returns>0:编辑器,1:非IOS,2:IOS</returns>
|
||
public static float GetPlatformType()
|
||
{
|
||
if (Application.isEditor)
|
||
return 0;
|
||
else
|
||
return JsLib.GetPlatformType();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载网页弹窗视图
|
||
/// </summary>
|
||
public static void LoadVideo(string videoName, string videoTitle)
|
||
{
|
||
JsLib.LoadVideo(videoName, videoTitle);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载网页弹窗视图
|
||
/// </summary>
|
||
/// <param name="data">JSON格式数据</param>
|
||
public static void LoadView(string data)
|
||
{
|
||
JsLib.LoadView(data);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隐藏网页弹窗视图
|
||
/// </summary>
|
||
public static void HideView()
|
||
{
|
||
JsLib.HideView();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是否坚屏
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool IsBroswerSP()
|
||
{
|
||
return JsLib.IsBroswerSP();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断移动端浏览器
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool IsMobileBroswer()
|
||
{
|
||
// return true;
|
||
if (Application.isEditor)
|
||
return false;
|
||
else
|
||
return JsLib.IsMobileBroswer();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断移动端浏览器
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool IsIOSBroswer()
|
||
{
|
||
if (Application.isEditor)
|
||
return false;
|
||
else
|
||
return JsLib.IsIOSBroswer();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断是否显示FPS
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool IsShowFPS()
|
||
{
|
||
if (Application.isEditor)
|
||
return false;
|
||
else
|
||
return JsLib.IsShowFPS();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载网页弹窗视图
|
||
/// </summary>
|
||
/// <param name="data">JSON格式数据</param>
|
||
public static void OpenUrl(string url)
|
||
{
|
||
if (Application.isEditor)
|
||
// System.Diagnostics.Process.Start(url);
|
||
Debug.Log(url);
|
||
else
|
||
JsLib.OpenUrl(url);
|
||
}
|
||
|
||
public static void PlayBg(int index)
|
||
{
|
||
if (Application.isEditor)
|
||
AudioManagerX.Instance.PlayBg(index);
|
||
else
|
||
JsLib.PlayBg(index);
|
||
}
|
||
public static void PauseBackgroundMusic()
|
||
{
|
||
if (Application.isEditor)
|
||
AudioManagerX.Instance.PauseBackgroundMusic();
|
||
else
|
||
JsLib.PauseBackgroundMusic();
|
||
}
|
||
public static void ResumeBackgroundMusic()
|
||
{
|
||
if (Application.isEditor)
|
||
AudioManagerX.Instance.ResumeBackgroundMusic();
|
||
else
|
||
JsLib.ResumeBackgroundMusic();
|
||
}
|
||
public static void SetBackgroundMute()
|
||
{
|
||
if (Application.isEditor)
|
||
AudioManagerX.Instance.SetBackgroundMute();
|
||
else
|
||
JsLib.SetBackgroundMute();
|
||
}
|
||
public static void PlayAudio(string auName)
|
||
{
|
||
if (Application.isEditor)
|
||
AudioManagerX.Instance.PlayAudio(auName);
|
||
else
|
||
JsLib.PlayAudio(auName);
|
||
}
|
||
public static void StopAudio()
|
||
{
|
||
if (Application.isEditor)
|
||
AudioManagerX.Instance.StopAudio();
|
||
else
|
||
JsLib.StopAudio();
|
||
}
|
||
} |