예제 #1
0
        public override void OnInspectorGUI()
        {
            if (!Target.Tileset)
            {
                Tileset targetTileset = Target.transform.parent ? Target.transform.parent.GetComponent <Tileset>() : null;
                if (!targetTileset)
                {
                    EditorGUILayout.HelpBox("A Tileset component is required on the parent object.", MessageType.Warning);
                    return;
                }

                Target.Tileset = targetTileset;
            }

            base.OnInspectorGUI();
            TilesetFlagsMaskDrawer.DrawTilesetFlagsMask(new GUIContent("Tileset Flags"), Target.tilesetFlags, Target.Tileset, ref tilesetFlagsFoldout);
            if (GUI.changed)
            {
                EditorUtility.SetDirty(Target);
            }

            utilityFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(utilityFoldout, "Utilities");
            if (utilityFoldout)
            {
                if (GUILayout.Button("Size from bounds"))
                {
                    DoAll(t => t.SetBoundsFromChildren());
                }
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Rotate X"))
                {
                    DoAll(t => t.RotateWithoutChildren(Quaternion.Euler(new Vector3(90, 0, 0))));
                }
                if (GUILayout.Button("Rotate Y"))
                {
                    DoAll(t => t.RotateWithoutChildren(Quaternion.Euler(new Vector3(0, 90, 0))));
                }
                if (GUILayout.Button("Rotate Z"))
                {
                    DoAll(t => t.RotateWithoutChildren(Quaternion.Euler(new Vector3(0, 0, 90))));
                }
                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
        }
예제 #2
0
        private static void DoTileOverlayUI(UnityEngine.Object target, SceneView sceneView)
        {
            var Target = target as TilesetRenderer;

            if (Target.Mesh.selectedFaceCount >= 1)
            {
                var tile = Target.LookupTile(Target.Mesh.selectedFaceIndexes[0]);
                if (tile != null)
                {
                    var labelSize = EditorGUIUtility.labelWidth;
                    var fieldSize = EditorGUIUtility.fieldWidth;
                    EditorGUIUtility.labelWidth = 120f;
                    EditorGUIUtility.fieldWidth = 100f;
                    GUI.changed = false;
                    TilesetFlagsMaskDrawer.DrawTilesetFlagsMask(new GUIContent("Flags"), tile.tilesetFlags, Target.Tileset);
                    if (GUI.changed)
                    {
                        if (Target.Mesh.selectedFaceCount > 1)
                        {
                            for (int i = 1; i < Target.Mesh.selectedFaceCount; i++)
                            {
                                var t = Target.LookupTile(Target.Mesh.selectedFaceIndexes[i]);
                                if (t != null)
                                {
                                    t.tilesetFlags.Copy(tile.tilesetFlags);
                                }
                            }
                        }

                        Target.WriteTileFlagsToVertexColors();
                        Target.FullRefresh();
                    }
                    EditorGUIUtility.labelWidth = labelSize;
                    EditorGUIUtility.fieldWidth = fieldSize;
                }
            }
            else
            {
                GUILayout.Label("No tile selected");
            }
        }
예제 #3
0
        public override void OnInspectorGUI()
        {
            if (disabled)
            {
                if (Target.Mesh != null)
                {
                    disabled = false;
                    OnEnable();
                    return;
                }

                EditorGUILayout.HelpBox("Tileset Renderer requires a Pro Builder Mesh component. " +
                                        "Create a new Pro Builder Shape and attach a Tileset Renderer to the " +
                                        "resulting GameObject", MessageType.Error);
                return;
            }

            // Draw default inspector
            base.OnInspectorGUI();
            if (GUI.changed)
            {
                Target.FullRefresh();
            }

            // Draw selected tile section
            selectedTileFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(selectedTileFoldout, "Selected Tile");
            if (selectedTileFoldout)
            {
                if (Target.Mesh.selectedFaceCount == 1)
                {
                    EditorGUI.indentLevel++;
                    GUI.enabled = false;

                    var tile = Target.LookupTile(Target.Mesh.selectedFaceIndexes[0]);
                    if (tile != null)
                    {
                        EditorGUILayout.ObjectField("Tile Instance",
                                                    tile.matchedTileInstance != null ? tile.matchedTileInstance.instance : null,
                                                    typeof(GameObject),
                                                    false);

                        EditorGUILayout.Toggle("Flags Undefined", tile.tilesetFlags.IsUndefined);
                        GUI.enabled = true;

                        var foldout = true;
                        GUI.changed = false;
                        TilesetFlagsMaskDrawer.DrawTilesetFlagsMask(new GUIContent("Flags"), tile.tilesetFlags,
                                                                    Target.Tileset, ref foldout);
                        if (GUI.changed)
                        {
                            Target.WriteTileFlagsToVertexColors();
                        }
                    }

                    GUI.enabled = true;
                    EditorGUI.indentLevel--;
                }
                else
                {
                    EditorGUILayout.HelpBox("Select a face from the tile mesh", MessageType.Info);
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            // Draw visualization section
            visualizationFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(visualizationFoldout, "Visualization");
            if (visualizationFoldout)
            {
                DoVisualizationSettings();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            // Draw debug section
            debugFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(debugFoldout, "Debug");
            if (debugFoldout)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Clear Pool"))
                {
                    Target.TilePool.ReturnTiles();
                    Target.TilePool.ClearPool();
                }
                if (GUILayout.Button("Rebuild Pool"))
                {
                    Target.TilePool.RebuildPool();
                }
                if (GUILayout.Button("Full Refresh"))
                {
                    Target.FullRefresh();
                }

                // Toggle visibility
                var firstChild = Target.transform.childCount > 0 ? Target.transform.GetChild(0) : null;
                if (!firstChild)
                {
                    GUI.enabled = false;
                }
                var visible = firstChild ? firstChild.gameObject.hideFlags == HideFlags.None : false;
                if (GUILayout.Button((visible ? "Hide" : "Show") + " Tiles"))
                {
                    Target.SetTileVisibility(!visible);
                }
                GUI.enabled = true;

                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();
        }