/// <summary> /// Creates a new tile system using properties from the specified preset. /// </summary> /// <remarks> /// <para>This method does not automatically record the new game object with /// Unity's undo system. If undo functionality is desired then the callee should /// do this.</para> /// </remarks> /// <param name="preset">Tile system preset.</param> /// <returns> /// A new game object with an initialized <see cref="TileSystem"/>. /// </returns> /// <exception cref="System.ArgumentNullException"> /// If <paramref name="preset"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException"> /// <list type="bullet"> /// <item>If preset defines an invalid name for a tile system.</item> /// <item>If preset defines a tile system with less than one cell.</item> /// </list> /// </exception> public static GameObject CreateTileSystemFromPreset(TileSystemPreset preset) { if (preset == null) { throw new ArgumentNullException("preset"); } string name = preset.SystemName.Trim(); if (string.IsNullOrEmpty(name)) { throw new InvalidOperationException("Invalid name for tile system."); } if (preset.Rows < 1 || preset.Columns < 1) { throw new InvalidOperationException("Tile system must have at least one cell."); } // Create empty game object and add tile system component. var go = new GameObject(name); var tileSystem = go.AddComponent <TileSystem>(); tileSystem.CreateSystem(preset.TileWidth, preset.TileHeight, preset.TileDepth, preset.Rows, preset.Columns, preset.ChunkWidth, preset.ChunkHeight); TransformTileSystemUsingPreset(preset, go.transform); SetTileSystemPropertiesFromPreset(preset, tileSystem); // Place at end of the scene palette listing. tileSystem.sceneOrder = int.MaxValue; ToolUtility.RepaintScenePalette(); return(go); }
//!TODO: The following should be refactored so that the tile system is passed in // as the context object rather than using a closure. private EditorMenu BuildContextMenu(TileSystem system) { var contextMenu = new EditorMenu(); contextMenu.AddCommand(TileLang.ParticularText("Action", "Inspect")) .Action(() => { EditorInternalUtility.FocusInspectorWindow(); }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.ParticularText("Action", "Rename")) .Action(() => { this.BeginEditingName(system); }); contextMenu.AddCommand(TileLang.ParticularText("Action", "Lock")) .Checked(system.Locked) .Action(() => { Undo.RecordObject(system, system.Locked ? TileLang.ParticularText("Action", "Unlock Tile System") : TileLang.ParticularText("Action", "Lock Tile System")); system.Locked = !system.Locked; EditorUtility.SetDirty(system); ToolUtility.RepaintScenePalette(); }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Tiles"))) .Enabled(!system.Locked) .Action(() => { TileSystemCommands.Command_Refresh(system); }); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Repair Tiles"))) .Enabled(!system.Locked) .Action(() => { TileSystemCommands.Command_Repair(system); }); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Tiles"))) .Enabled(!system.Locked) .Action(() => { TileSystemCommands.Command_Clear(system); }); //contextMenu.AddSeparator(); //contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Plops"))) // .Enabled(!system.Locked) // .Action(() => { // TileSystemCommands.Command_RefreshPlops(system); // }); //contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Plops"))) // .Enabled(!system.Locked) // .Action(() => { // TileSystemCommands.Command_ClearPlops(system); // }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.ParticularText("Action", "Delete")) .Enabled(!system.Locked) .Action(() => { Undo.DestroyObjectImmediate(system.gameObject); }); contextMenu.AddSeparator(); contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Build Prefab"))) .Action(() => { TileSystemCommands.Command_BuildPrefab(system); }); return(contextMenu); }