Tanoda
pb_Gizmo.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using System.Linq;
4using Newtonsoft.Json;
6
7namespace GILES
8{
12 [pb_JsonIgnore]
13 [pb_EditorComponent]
14 public abstract class pb_Gizmo : MonoBehaviour
15 {
17 public Material icon;
18
20 protected Transform cam;
21
23 protected Transform trs;
24
26 protected Matrix4x4 cameraFacingMatrix { get { return _cameraFacingMatrix; }}
27 private Matrix4x4 _cameraFacingMatrix = Matrix4x4.identity;
28
29 public bool isSelected = false;
30
31 private static Mesh _mesh;
32 private static Mesh mesh
33 {
34 get
35 {
36 if(_mesh == null)
37 {
38 GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad);
39 _mesh = go.GetComponent<MeshFilter>().sharedMesh;
40 pb_ObjectUtility.Destroy(go);
41 }
42 return _mesh;
43 }
44 }
45
46 private void Awake()
47 {
48 cam = Camera.main.transform;
49 trs = transform;
50 }
51
55 public virtual void OnComponentModified()
56 {}
57
58 public bool CanEditType(Type t)
59 {
60 pb_GizmoAttribute attrib = this.GetType().GetCustomAttributes(true).FirstOrDefault(x => x is pb_GizmoAttribute) as pb_GizmoAttribute;
61
62 if(attrib != null)
63 return attrib.CanEditType(t);
64
65 return false;
66 }
67
68 public virtual void Update()
69 {
70 // To keep handle sizes consistent, uncomment this line
71 //_cameraFacingMatrix.SetTRS(trs.position, Quaternion.LookRotation(cam.forward, Vector3.up), Vector3.one * pb_HandleUtility.GetHandleSize(trs.position) * 100f );
72 _cameraFacingMatrix.SetTRS(trs.position, Quaternion.LookRotation(cam.forward, Vector3.up), Vector3.one );
73
74 Graphics.DrawMesh(mesh, _cameraFacingMatrix, icon, 0);
75 }
76 }
77}
virtual bool CanEditType(Type rhs)
Material icon
The icon to be rendered facing the camera at the position of this object.
Definition: pb_Gizmo.cs:17
Matrix4x4 cameraFacingMatrix
Matrix with a camera facing rotation, world position of parent transform, and scale of 1.
Definition: pb_Gizmo.cs:26
Transform trs
A reference to this object's transform.
Definition: pb_Gizmo.cs:23
bool CanEditType(Type t)
Definition: pb_Gizmo.cs:58
Transform cam
A reference to the main camera transform.
Definition: pb_Gizmo.cs:20
bool isSelected
Definition: pb_Gizmo.cs:29
virtual void OnComponentModified()
Definition: pb_Gizmo.cs:55
virtual void Update()
Definition: pb_Gizmo.cs:68