// PAINT METHOD: -------------------------------------------------------------------------- public static void Paint(GlobalID globalID) { switch (IS_EDITING) { case true: PaintEditing(globalID); break; case false: PaintNormal(globalID); break; } }
private static void PaintEditing(GlobalID globalID) { Rect rect = GUILayoutUtility.GetRect( 0f, 9999f, HEIGHT + PADDING, HEIGHT + PADDING ); Rect rectInfo = new Rect( rect.x, rect.y, INFO_WIDTH, HEIGHT ); Rect rectContent = new Rect( rectInfo.x + rectInfo.width, rectInfo.y, rect.width - INFO_WIDTH - EDIT_WIDTH, HEIGHT ); Rect rectEdit = new Rect( rectContent.x + rectContent.width, rectContent.y, EDIT_WIDTH, HEIGHT ); if (GUI.Button(rectInfo, "Regen", CoreGUIStyles.GetButtonLeft())) { if (EditorUtility.DisplayDialog(REGEN_1, REGEN_2, "Yes", "Cancel")) { string gid = Guid.NewGuid().ToString("D"); SetGID(globalID, gid); } } string prvGid = globalID.GetID(); string newGid = EditorGUI.TextField( rectContent, prvGid, CoreGUIStyles.GlobalIDText() ); if (prvGid != newGid) { SetGID(globalID, newGid); } if (GUI.Button(rectEdit, "Back", CoreGUIStyles.GetButtonRight())) { IS_EDITING = false; } }
// PRIVATE METHODS: ----------------------------------------------------------------------- private static void SetGID(GlobalID globalID, string gid) { SerializedObject soGID = new SerializedObject(globalID); soGID.ApplyModifiedProperties(); soGID.Update(); gid = ProcessGID(gid); soGID.FindProperty("gid").stringValue = gid; soGID.ApplyModifiedProperties(); soGID.Update(); }
private static void PaintNormal(GlobalID globalID) { Rect rect = GUILayoutUtility.GetRect( 0f, 9999f, HEIGHT + PADDING, HEIGHT + PADDING ); Rect rectInfo = new Rect( rect.x, rect.y, INFO_WIDTH, HEIGHT ); Rect rectContent = new Rect( rectInfo.x + rectInfo.width, rectInfo.y, rect.width - INFO_WIDTH - EDIT_WIDTH, HEIGHT ); Rect rectEdit = new Rect( rectContent.x + rectContent.width, rectContent.y, EDIT_WIDTH, HEIGHT ); GUI.enabled = false; EditorGUI.LabelField(rectInfo, "ID", CoreGUIStyles.GetButtonLeft()); GUI.enabled = true; GUI.enabled = false; EditorGUI.LabelField(rectContent, globalID.GetID(), CoreGUIStyles.GetButtonMid()); GUI.enabled = true; if (GUI.Button(rectEdit, "Edit", CoreGUIStyles.GetButtonRight())) { IS_EDITING = true; } }