You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
62 lines
1.3 KiB
3 years ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using AX.MessageSystem;
|
||
|
|
||
|
public struct CameraFocusData
|
||
|
{
|
||
|
public float distance;
|
||
|
public float x;
|
||
|
public float y;
|
||
|
public GameObject obj;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 车辆头顶图标处理
|
||
|
/// </summary>
|
||
|
public class CarHeadImg : MonoBehaviour {
|
||
|
|
||
|
public GameObject carObj;
|
||
|
|
||
|
public float distance = 20f;
|
||
|
public float x = 180.0f;
|
||
|
public float y = 20.0f;
|
||
|
|
||
|
// Use this for initialization
|
||
|
void Start () {
|
||
|
GetComponent<Button>().onClick.AddListener(CameraFocusCarObj);
|
||
|
}
|
||
|
|
||
|
private void CameraFocusCarObj()
|
||
|
{
|
||
|
CameraFocusData data = new CameraFocusData();
|
||
|
data.distance = distance;
|
||
|
data.x = x;
|
||
|
data.y = y;
|
||
|
data.obj = carObj;
|
||
|
|
||
|
MessageDispatcher.SendMessage("CAMERA_FOCUS_CAROBJ", data);
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update () {
|
||
|
|
||
|
UIFollow();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 车辆头顶UI图标跟随车辆模型
|
||
|
/// </summary>
|
||
|
private void UIFollow()
|
||
|
{
|
||
|
transform.GetComponent<RectTransform>().position = Camera.main.WorldToScreenPoint(carObj.transform.position);
|
||
|
}
|
||
|
|
||
|
private void OnDestroy()
|
||
|
{
|
||
|
GetComponent<Button>().onClick.RemoveListener(CameraFocusCarObj);
|
||
|
}
|
||
|
}
|