private static Rect WallSectionItem(Facade facade, int x, int inverseY, bool isGround = false) { WallSection wallSection = !isGround?facade.GetBaseWallSection(x, inverseY) : facade.GetGroundWallSection(x); string wallSectionName = wallSection != null ? wallSection.name : ""; Undo.RecordObject(facade, "Add wall section to facade"); GUIContent texture; if (wallSection != null) { texture = new GUIContent(wallSection.previewTexture); } else { texture = new GUIContent(wallSectionName); } EditorGUILayout.BeginHorizontal("box", GUILayout.Width(SECTION_PREVIEW_SIZE), GUILayout.Height(SECTION_PREVIEW_SIZE)); EditorGUILayout.LabelField(texture, GUILayout.Width(SECTION_PREVIEW_SIZE), GUILayout.Height(SECTION_PREVIEW_SIZE)); EditorGUILayout.EndHorizontal(); Rect sectionRect = GUILayoutUtility.GetLastRect(); // facadeRects[x].Add(sectionRect); WallSection newSection = EditorGUI.ObjectField(sectionRect, wallSection, typeof(WallSection), false) as WallSection; if (newSection != wallSection) { if (!isGround) { facade.SetBaseWallSection(x, inverseY, newSection); } else { facade.SetGroundWallSection(x, newSection); } } EditorGUI.DrawPreviewTexture(sectionRect, EditorGUIUtility.whiteTexture); EditorGUI.LabelField(sectionRect, texture); EditorGUI.DropShadowLabel(sectionRect, wallSectionName, BuildingEditor.FacadeLabel); return(sectionRect); }
private static void BasePatternEditor(Facade facade) { EventType eventType = Event.current.type; // if (eventType == EventType.DragUpdated) // Debug.Log("DragUpdated"); // if (eventType == EventType.DragPerform) // Debug.Log("DragPerform"); List <List <Rect> > facadeRects = new List <List <Rect> >(); float calWidth = Mathf.Min((SECTION_PREVIEW_SIZE + 20) * facade.baseWidth, BuildingEditor.MAIN_GUI_WIDTH - SECTION_PREVIEW_SIZE); float calHeight = (SECTION_PREVIEW_SIZE + 30) * facade.baseHeight; SCROLL_POS = EditorGUILayout.BeginScrollView(SCROLL_POS, GUILayout.Width(calWidth), GUILayout.Height(calHeight)); EditorGUILayout.BeginHorizontal(GUILayout.Width(calWidth)); for (int x = 0; x < facade.baseWidth; x++) { facadeRects.Add(new List <Rect>()); EditorGUILayout.BeginVertical(GUILayout.Width(SECTION_PREVIEW_SIZE)); for (int y = 0; y < facade.baseHeight; y++) { int inverseY = facade.baseHeight - y - 1; Rect itemrect = WallSectionItem(facade, x, inverseY); facadeRects[x].Add(itemrect); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); WallSection output = null; // EventType eventType = Event.current.type; if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform) { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; Object[] objArray = DragAndDrop.objectReferences; if (objArray != null) { if (objArray[0].GetType() == typeof(WallSection)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (eventType == EventType.DragPerform) { output = (WallSection)objArray[0]; DragAndDrop.AcceptDrag(); Vector2 mousePos = Event.current.mousePosition; for (int x = 0; x < facade.baseWidth; x++) { for (int y = 0; y < facade.baseHeight; y++) { if (facadeRects[x][y].Contains(mousePos)) { int inverseY = facade.baseHeight - y - 1; WallSection wallSection = facade.GetBaseWallSection(x, inverseY); if (output != wallSection) { Undo.RecordObject(facade, "Add wall section to facade"); facade.SetBaseWallSection(x, inverseY, output); } } } } } } } } }