2020. 10. 5. 11:00
Unity/C#
gui색을 노란색으로 바꿈
GUILayout도 적용됨
GUI.backgroundColor = Color.yellow;
{
GUILayout.Box(nameof(gameclass.name), GUILayout.Width(50), GUILayout.Height(50));
}
GUI.backgroundColor = Color.white;
가로전환
GUILayout.BeginHorizontal();
{
}
GUILayout.EndHorizontal();
스크롤뷰(슬라이더)
Vector2 scrollPosition=Vector2.zero;
void OnGUI()
{
//scrollPosition=GUILayout.BeginScrollView(scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
scrollPosition=GUILayout.BeginScrollView(scrollPosition);
{
}
GUILayout.EndScrollView();
}
스크롤뷰(슬라이더) v2 (미완성)
Vector2 scrollPosition=Vector2.zero;
void OnGUI()
{
scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), scrollPosition, new Rect(0, 0, width:500, height:800));
{
}
GUI.EndScrollView();
}
마우스 대면 바뀌는 주석
if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
GUILayout.Label("Mouse over!");
else
GUILayout.Label("Mouse somewhere else");
버튼
if(GUILayout.Button("버튼"))
{
}
왼쪽으로 밀린 박스
var Texture2D = new Texture2D(1, 1);//삭제가 안되어 메모리릭을 유발하므로 전역에 생성해 두어야함
{
BoxBG.SetPixels(0,0,1,1, new Color[]{ Color.gray});
BoxBG.Apply();
var guiStyle = new GUIStyle();
guiStyle.alignment = TextAnchor.UpperLeft;
guiStyle.richText = true;
guiStyle.normal.background = BoxBG;
GUILayout.Box("내용",guiStyle);
}
인스펙터 변동사항이 있는지 검사한다
겸 드롭다운 샘플
EditorGUI.BeginChangeCheck();
{
index = EditorGUILayout.Popup("Index", index, new string[] { "1", "2" });
}
if (EditorGUI.EndChangeCheck())
{
Debug.Log("index값이 변경됨");
}
들여쓰기
EditorGUILayout계열만 적용됨
GUILayout은 안됨
EditorGUI.indentLevel++;
{
}
EditorGUI.indentLevel--;
스크립트오브젝트저장
//더티플래그
EditorUtility.SetDirty(scriptableObject);
var filePath = AssetDatabase.GetAssetPath(scriptableObject);
Debug.Log($"scriptableObject 저장됨, filePath: {filePath}");
//AssetDatabase.SaveAssets(); //이건 딱히 안 넣어도 되는듯
애니메이션 상태 저장
ImportAsset이 붙은 이유는 이래야 저장되더라
아마 위도 동일할듯 싶은데 나중에 해봐야지
여기서 사용함
UnityEditor.AssetDatabase.SaveAssetIfDirty(animationClip);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(animationClip));
패스 에디터
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(PayloadRace))]
public class PayloadRaceEditor : Editor
{
private Vector3 position = Vector3.zero;
void OnSceneGUI()
{
var payloadRace = (PayloadRace)target;
var tracksParent = payloadRace.tracksParent;
if (tracksParent)
{
var childs = new List<Transform>();
for (int i = 0; i < tracksParent.childCount; i++)
{
childs.Add(tracksParent.GetChild(i));
}
foreach (var child in childs)
{
if (Vector3.Distance(payloadRace.transform.position, child.position) < 1)
{
//너무 가까우면 최상위 조작이 불가하므로
continue;
}
var newPosition = UnityEditor.Handles.PositionHandle(child.position, child.rotation);
if (newPosition != child.position)
{
UnityEditor.Undo.RecordObject(child, "Move Transform");
child.position = newPosition;
}
}
}
}
}
#endif
public class PayloadRace : MonoBehaviour
{
public int team = 0;
public GameObject payload;
public Transform tracksParent;
#if UNITY_EDITOR_WIN
void OnDrawGizmos()
{
var color = Color.red;
if (team == 0)
{
color = Color.blue;
}
Gizmos.color = color;
{
Gizmos.DrawWireSphere(transform.position,5);
}
Gizmos.color = Color.white;
if (tracksParent)
{
var childs = new List<Transform>();
for (int i = 0; i < tracksParent.childCount; i++)
{
childs.Add(tracksParent.GetChild(i));
}
foreach (var child in childs)
{
Gizmos.DrawSphere(child.position,0.1f);
if (Vector3.Distance(transform.position, child.position)<1)
{
continue;
}
}
for (int i = 0; i < childs.Count-1; i++)
{
Gizmos.DrawLine(childs[i].position, childs[i + 1].position);
}
}
}
#endif
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
'Unity > C#' 카테고리의 다른 글
그래디언트효과 (0) | 2020.10.20 |
---|---|
failed to connect to localhost port 80: Connection (0) | 2020.09.01 |
c# MD5 (0) | 2020.08.25 |