Unity Custom Inspector 커스텀 인스펙터
Unity/찾아본것 2019. 7. 22. 16:141
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using UnityEngine;
public class Cube : MonoBehaviour
{
void Start()
{
GenerateColor();
}
public void GenerateColor()
{
this.GetComponent<Renderer>().sharedMaterial.color = Random.ColorHSV();
}
public void Reset()
{
this.GetComponent<Renderer>().sharedMaterial.color = Color.white;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | using UnityEngine; using UnityEditor; [CustomEditor(typeof(Cube))] public class CubeEditor : Editor { public override void OnInspectorGUI() { base.OnInspectorGUI(); Cube cube = (Cube)target; GUILayout.BeginHorizontal(); if (GUILayout.Button("GenerrateColor")) { cube.GenerateColor(); } if (GUILayout.Button("ResetColor")) { cube.Reset(); } GUILayout.EndHorizontal(); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class Sphere : MonoBehaviour { public float baseSize = 1f; void Update() { float anim = baseSize + Mathf.Sin(Time.time * 8f) * baseSize / 7f; transform.localScale = Vector3.one * anim; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | using UnityEngine; using UnityEditor; [CustomEditor(typeof(Sphere))] public class SphereEditor : Editor { public override void OnInspectorGUI() { base.OnInspectorGUI(); Sphere sphere = (Sphere)target; sphere.baseSize = EditorGUILayout.Slider(sphere.baseSize, .1f, 2f); sphere.transform.localScale = Vector3.one * sphere.baseSize; } } | cs |
왜 sphere..가 같이 색이 변하지 ( ? )
'Unity > 찾아본것' 카테고리의 다른 글
Unity Button Array onClick (0) | 2020.08.11 |
---|---|
Unity GameObject 부모 자식 관계 설정 (0) | 2020.08.11 |
<화면 나누기> ViewportRect사용 (0) | 2019.06.14 |
setdestination can only be called on an active agent that has been placed on a navmesh (0) | 2019.05.03 |
유니티 현재의 씬 다시 불러오기 (0) | 2019.05.02 |