using System;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
///
/// A SceneAnnotation component allows you to add a rich text display
/// to a GameObject and to align the scene camera to ths object for
/// tutorial purposes
///
[ExecuteInEditMode]
public class SceneAnnotation : MonoBehaviour, IComparable
{
public string headline = "Headline Goes Here";
public TextAsset textAsset;
public int id;
public void OnDrawGizmos()
{
#if UNITY_EDITOR
var xform = gameObject.transform;
Gizmos.DrawIcon(xform.position + Vector3.up, "Assets/TerrainToolsDemo/Scripts/Help_Icon.png", true);
Gizmos.matrix = xform.localToWorldMatrix;
Gizmos.DrawFrustum(Vector3.back, 90, 0.5f, 0.25f, 2);
Gizmos.DrawCube(Vector3.back, new Vector3(1, 0.5f, 0.5f));
#endif
}
public int CompareTo(SceneAnnotation other)
{
// Use the ID Value to sort scene objects for the inspector tool
// Add an extra check in case somebody got lazy and duplicated w/o changing IDs
var idx = id.CompareTo(other.id);
if (idx == 0) idx = string.Compare(headline, other.headline, StringComparison.Ordinal);
return idx;
}
}
#if UNITY_EDITOR
[InitializeOnLoad]
[CustomEditor(typeof(SceneAnnotation))]
public class SceneAnnotationEditor : Editor
{
private static readonly string UXMLPath = "SceneAnnotation";
public static bool isLoaded = false;
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
var visualTree = Resources.Load(UXMLPath);
VisualElement inspectorUI = visualTree.CloneTree();
root.Add(inspectorUI);
root.Q