Ejemplo n.º 1
0
        private void OnGUI()
        {
            changed.Clear();
            if (roomName == "")
            {
                roomName = "Room Name";
            }

            GUILayout.Label("Room Properties", EditorStyles.boldLabel);
            roomName       = EditorGUILayout.TextField("Room Name", roomName, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            roomMusic      = (MusicData)EditorGUILayout.ObjectField("Room Music", roomMusic, typeof(MusicData), false, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            roomStage      = (StageData)EditorGUILayout.ObjectField("Room Stage", roomStage, typeof(StageData), false, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            roomBackground = (Sprite)EditorGUILayout.ObjectField("Room Background", roomBackground, typeof(Sprite), false, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            roomColor      = EditorGUILayout.ColorField("Room Color", roomColor, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            generateWall   = EditorGUILayout.Toggle("Generate Wall", generateWall, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            if (generateWall)
            {
                wallTile = (TileBase)EditorGUILayout.ObjectField("Wall Tile", wallTile, typeof(TileBase), false, GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f));
            }

            GUILayout.Label("Room Shape", EditorStyles.boldLabel);
            GUILayout.BeginVertical(GUILayout.MaxWidth(120f), GUILayout.MinWidth(120f));
            for (int i = 0; i < toggled.GetLength(0); i++)
            {
                GUILayout.BeginHorizontal(GUILayout.MaxWidth(120f), GUILayout.MinWidth(120f));
                for (int j = 0; j < toggled.GetLength(1); j++)
                {
                    toggled[i, j] = EditorGUILayout.Toggle(toggled[i, j]);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();

            for (int i = 0; i < toggled.GetLength(0); i++)
            {
                for (int j = 0; j < toggled.GetLength(1); j++)
                {
                    if (toggled[i, j] != oldToggled[i, j])
                    {
                        changed.Add(i * 5 + j);
                    }
                }
            }
            if (changed.Count > 0)
            {
                changedString = "";
            }
            for (int i = 0; i < changed.Count; i++)
            {
                changedString += "[" + changed[i] + "] ";
            }
            GUILayout.Label("Last Edited: " + changedString, EditorStyles.label);
            oldToggled = (bool[, ])toggled.Clone();

            nonrectangle  = CheckNonSquare();
            center        = new Vector2(minIdx.x + maxIdx.x, minIdx.y + maxIdx.y);
            center       /= 2;
            bgChunkSize.x = (maxIdx.x - minIdx.x + 1);
            bgChunkSize.y = (minIdx.y - maxIdx.y + 1);
            bgSize        = new Vector2(targetSize.width, targetSize.height);
            bgCenter      = bgSize;
            bgSize.x     *= bgChunkSize.x;
            bgSize.y     *= bgChunkSize.y;
            bgCenter.x   *= center.x;
            bgCenter.y   *= center.y;

            GUILayout.BeginHorizontal(GUILayout.MinWidth(300f), GUILayout.MaxWidth(300f));
            GUILayout.Label("MinPos: " + minIdx, EditorStyles.label, GUILayout.Width(150f));
            GUILayout.Label("MaxPos: " + maxIdx, EditorStyles.label, GUILayout.Width(150f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal(GUILayout.MinWidth(300f), GUILayout.MaxWidth(300f));
            GUILayout.Label("Center: " + center, EditorStyles.label, GUILayout.Width(150f));
            GUILayout.Label("RCenter: " + bgCenter, EditorStyles.label, GUILayout.Width(150f));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal(GUILayout.MinWidth(300f), GUILayout.MaxWidth(300f));
            GUILayout.Label("Size: " + bgChunkSize, EditorStyles.label, GUILayout.Width(150f));
            GUILayout.Label("RSize: " + Vector2Int.RoundToInt(bgSize), EditorStyles.label, GUILayout.Width(150f));
            GUILayout.EndHorizontal();

            using (new EditorGUI.DisabledGroupScope(nonrectangle)) {
                if (GUILayout.Button(nonrectangle ? "Non Rectangle Room" : "Create Room", GUILayout.MaxWidth(300f), GUILayout.MinWidth(300f)))
                {
                    string assetResultPath = assetPath + roomName + ".prefab";
                    if (AssetDatabase.LoadAssetAtPath(assetResultPath, typeof(GameObject)))
                    {
                        if (EditorUtility.DisplayDialog(
                                "Are you sure?",
                                "Room \"" + roomName + "\" already exists. Do you want to overwrite it?",
                                "Yes",
                                "No"))
                        {
                            BuildRoom(assetResultPath);
                        }
                    }
                    else
                    {
                        BuildRoom(assetResultPath);
                    }
                }
            }
        }