본문 바로가기
개발/Unity

Unity) 2D Curve Editor 샘플코드

by 테샤르 2020. 7. 29.

2D Curve Editor 샘플 코드

예전에 참고한 2D Curve의 샘플 코드를 작성했다.

2D로 베지어 곡선을 이용해서 포인트 포인트를 처리했고 

Edit의 형태로 나중에도 많이 사용이 가능할 거라는 생각이 들어서 작업했다.

간략하게 설명하면 Event를 받아서 Shift 버튼과 마우스 클릭을 하게 되면 (Button이 아닌 경우) 해당 path에 Segment를 한 개 추가한다. Undo.RecordObject는 해당 데이터를 Undo를 할 수 있도록 처리하는 기능이다.

void Input(){
        Event guiEvent = Event.current;
        Vector2 mousePos = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition).origin;
        if(guiEvent.type == EventType.MouseDown && guiEvent.button == 0 && guiEvent.shift){
            Undo.RecordObject(creator, "Add segment");
            path.AddSegment(mousePos);
        }
    }

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

 

Unity - Scripting API: Undo.RecordObject

Almost all property changes can be recorded with this function. The transform parent, AddComponent, object destruction can not be recorded with this function, for that you should use the dedicated functions. Internally this creates a temporary copy of the

docs.unity3d.com

에디터에서 플레이 영상은 다음과 같다.

모든 코드를 이해하진 못했지만 많이 참고해서 작업했다.

에디터를 만들어서 하는 많은 기능에 확장성 있게 사용이 가능하다.

 ★

 

반응형

댓글