91 lines
2.0 KiB
C#
91 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
public class Lighting_tip : MonoBehaviour
|
|
{
|
|
|
|
public string num;
|
|
public string name;
|
|
|
|
|
|
string str = "unity调用JS";
|
|
// 声明导入的JavaScript函数
|
|
[DllImport("Internal")]
|
|
private static extern void OpenWebPanel(string str);
|
|
|
|
/// <summary>
|
|
/// 跟随 UI提示出现的位置
|
|
/// </summary>
|
|
public Transform m_FollowObj;
|
|
/// <summary>
|
|
/// 偏移
|
|
/// </summary>
|
|
public Vector3 m_Offset;
|
|
/// <summary>
|
|
/// 移动点
|
|
/// </summary>
|
|
public Transform _movePos;
|
|
|
|
private void Start()
|
|
{
|
|
GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
Debug.Log("点击");
|
|
//#if !UNITY_EDITOR
|
|
// // 在按钮点击时调用JavaScript函数
|
|
// OpenWebPanel(num);
|
|
//#endif
|
|
print("调用前端方法" + name);
|
|
Application.ExternalCall("OnButtonClick",name);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
public void OnButtonClick()
|
|
{
|
|
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
if (m_FollowObj != null)
|
|
{
|
|
Vector3 screenPos = Camera.main.WorldToScreenPoint(m_FollowObj.position);
|
|
if (screenPos.z > 0)
|
|
{
|
|
screenPos.z = 0;
|
|
transform.position = screenPos + m_Offset;
|
|
|
|
}
|
|
else
|
|
{
|
|
transform.position = new Vector3(8888, 8888, 8888);
|
|
}
|
|
//if (GameManager.Instance)
|
|
//{
|
|
|
|
|
|
// float distance = Vector3.Distance(m_FollowObj.transform.position, Camera.main.transform.position);
|
|
// if (distance > 15 && GameManager.Instance.isShowUI)//Ui显示隐藏
|
|
// {
|
|
// transform.localScale = Vector3.one * 2.1f;
|
|
// }
|
|
// else
|
|
// {
|
|
// transform.localScale = Vector3.zero;
|
|
// }
|
|
//}
|
|
|
|
}
|
|
}
|
|
|
|
}
|