Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private static void GroundPatternEditor(Facade facade)
        {
            if (!facade.hasGroundFloorPattern)
            {
                return;
            }
            EventType eventType = Event.current.type;
//            if (eventType == EventType.DragUpdated)
//                Debug.Log("DragUpdated");
//            if (eventType == EventType.DragPerform)
//                Debug.Log("DragPerform");

            List <Rect> facadeRects = new List <Rect>();

            EditorGUILayout.BeginHorizontal();
            for (int x = 0; x < facade.baseWidth; x++)
            {
                Rect itemrect = WallSectionItem(facade, x, 0, true);
                facadeRects.Add(itemrect);

//                WallSection wallSection = facade.GetGroundWallSection(x);

                //                if(wallSection != null)
                //                {
                //                    EditorGUILayout.BeginHorizontal("box");
                //                    GUIContent texture = new GUIContent(wallSection.PreviewTexture());
                //                    EditorGUILayout.LabelField(texture, GUILayout.Width(SECTION_PREVIEW_SIZE), GUILayout.Height(SECTION_PREVIEW_SIZE));
                //                    EditorGUILayout.EndHorizontal();
                //                }
                //                else
                //                {
                //                    EditorGUILayout.BeginHorizontal("box");
                //                    EditorGUILayout.LabelField("", GUILayout.Width(SECTION_PREVIEW_SIZE), GUILayout.Height(SECTION_PREVIEW_SIZE));
                //                    EditorGUILayout.EndHorizontal();
                //                }
                //                facadeRects.Add(GUILayoutUtility.GetLastRect());
            }
            EditorGUILayout.EndHorizontal();

            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++)
                            {
                                if (facadeRects[x].Contains(mousePos))
                                {
                                    WallSection wallSection = facade.GetGroundWallSection(x);
                                    if (output != wallSection)
                                    {
                                        facade.SetGroundWallSection(x, output);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }