| | 1 | | using UnityEngine; |
| | 2 | | using System; |
| | 3 | |
|
| | 4 | | namespace Builder.Gizmos |
| | 5 | | { |
| | 6 | | public class DCLBuilderGizmoAxis : MonoBehaviour |
| | 7 | | { |
| | 8 | | public Color defaultColor; |
| | 9 | | public Color highLightColor; |
| | 10 | | public Renderer objectRenderer; |
| | 11 | |
|
| | 12 | | MaterialPropertyBlock props; |
| | 13 | |
|
| | 14 | | static int colorPropertyID; |
| | 15 | | static bool isColorPropertyIdSet = false; |
| | 16 | |
|
| | 17 | | private DCLBuilderGizmo gizmo = null; |
| | 18 | |
|
| 0 | 19 | | public void SetGizmo(DCLBuilderGizmo parentGizmo) { gizmo = parentGizmo; } |
| | 20 | |
|
| 0 | 21 | | public DCLBuilderGizmo GetGizmo() { return gizmo; } |
| | 22 | |
|
| | 23 | | public void SetColorHighlight() |
| | 24 | | { |
| 0 | 25 | | if (props == null) |
| 0 | 26 | | return; |
| | 27 | |
|
| 0 | 28 | | objectRenderer.GetPropertyBlock(props); |
| 0 | 29 | | props.SetColor(colorPropertyID, highLightColor); |
| 0 | 30 | | objectRenderer.SetPropertyBlock(props); |
| | 31 | |
|
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | public void SetColorDefault() |
| | 35 | | { |
| 0 | 36 | | if (props == null) |
| 0 | 37 | | return; |
| | 38 | |
|
| 0 | 39 | | objectRenderer.GetPropertyBlock(props); |
| 0 | 40 | | props.SetColor(colorPropertyID, defaultColor); |
| 0 | 41 | | objectRenderer.SetPropertyBlock(props); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | private void Awake() |
| | 45 | | { |
| 0 | 46 | | if (!isColorPropertyIdSet) |
| | 47 | | { |
| 0 | 48 | | isColorPropertyIdSet = true; |
| 0 | 49 | | colorPropertyID = Shader.PropertyToID("_BaseColor"); |
| | 50 | | } |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | private void Start() |
| | 54 | | { |
| 0 | 55 | | props = new MaterialPropertyBlock(); |
| 0 | 56 | | objectRenderer.GetPropertyBlock(props); |
| 0 | 57 | | props.SetColor(colorPropertyID, defaultColor); |
| 0 | 58 | | objectRenderer.SetPropertyBlock(props); |
| 0 | 59 | | } |
| | 60 | | } |
| | 61 | | } |