123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// текст над маркером
- /// </summary>
- public class LabelObjectScript : MonoBehaviour
- {
- RectTransform canvasRect;
- GameObject text;
- Button button;
- public bool TrackMarker = true;
- public uint UserId;
- //public string NameUser;
- // Start is called before the first frame update
- void Start()
- {
- //text = Instantiate(Resources.Load("GameObjects/Capsule", typeof(GameObject))) as GameObject;
- cameraController = Camera.main.GetComponent<CameraController>();
- canvasRect = transform.GetChild(0).GetComponent<RectTransform>();
- text = transform.GetChild(0).GetChild(0).GetChild(0).gameObject;
- var player = PlayerController.instance;
- if (TrackMarker) {
- button = transform.GetChild(0).GetChild(0).GetChild(1).GetComponent<Button>();
- button.onClick.AddListener(() => player.BroadcastStart(UserId));
- }
- }
- // Update is called once per frame
- void Update()
- {
- // Offset position above object bbox (in world space)
- float offsetPosY = transform.position.y + 1.5f;
- // Final position of marker above GO in world space
- Vector3 offsetPos = new Vector3(transform.position.x, offsetPosY, transform.position.z);
- // Calculate *screen* position (note, not a canvas/recttransform position)
- Vector2 canvasPos;
- Vector2 screenPoint = Camera.main.WorldToScreenPoint(offsetPos);
- // Convert screen position to Canvas / RectTransform space <- leave camera null if Screen Space Overlay
- RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, null, out canvasPos);
- // Set
- //markerRtra.localPosition = canvasPos;
- //if(TrackMarker) text.transform.localPosition = canvasPos;
- //else
- text.transform.parent.transform.localPosition = canvasPos;
- }
- CameraController cameraController;
- void OnMouseDown()
- {
- if (TrackMarker)
- {
- cameraController.target = transform;
- cameraController.axes = CameraController.RotationAxes.TrackMarker;
-
- }
- }
- void BroadcastStart()
- {
- var player = PlayerController.instance;
- if (player.user_broadcast != UserId)
- {
- if (player.user_broadcast != null)
- {
- var client = Client.instance;
- client.ImageStreamStopSend(player.user_broadcast.Value);
- }
- player.user_broadcast = UserId;
- player.broadcast = true;
- }
- }
- }
|