Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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 29 30 31
Archives
Today
Total
관리 메뉴

게임 프로그래밍

[Unity] Custom Editor Undo 본문

프로그래밍/유니티

[Unity] Custom Editor Undo

Junwe 2020. 3. 14. 14:40

유니티에 툴을 제작할려고 Custom Eidtor를 만들때 Undo 기능이 필요할때가 있습니다. 유니티는 이를 간단하게 제공하고 있습니다.

 

Undo.RecordObject (myGameObject.transform, "Zero Transform Position");
myGameObject.transform.position = Vector3.zero;

이런 코드가 있을때 zero 포지션에 갔던 Object를 Undo시키면 원래있던 자리로 가게 될것입니다. 

 

Adding a component:
Undo.AddComponent<RigidBody>(myGameObject);

Creating a new game object:
var go = new GameObject();
Undo.RegisterCreatedObjectUndo (go, "Created go");

Destroying a game object or component:
Undo.DestroyObjectImmediate (myGameObject);

Changing transform parenting:
Undo.SetTransformParent (myGameObject.transform, newTransformParent, "Set new parent");

 

그밖에도 오브젝트 삭제를 Undo.DestroyObjectImmediate 를 이용하거나 새로 생성된 오브젝트에 Undo.RegisterCreatedObjectUndo로등록하면Undo가 가능합니다.

https://docs.unity3d.com/ScriptReference/Undo.html

Comments