暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

GridPaintingState.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEditor.EditorTools;
  6. using UnityEditor.ShortcutManagement;
  7. using UnityEngine;
  8. namespace UnityEditor.Tilemaps
  9. {
  10. /// <summary>
  11. /// GridPaintingState controls the state of objects for painting with a Tile Palette.
  12. /// </summary>
  13. /// <remarks>
  14. /// Utilize this class to get and set the current painting target and brush for painting
  15. /// with the Tile Palette.
  16. /// </remarks>
  17. public class GridPaintingState : ScriptableSingleton<GridPaintingState>
  18. {
  19. [SerializeField] private GameObject m_EditModeScenePaintTarget; // Which GameObject in scene was the last painting target in EditMode
  20. [SerializeField] private GameObject m_ScenePaintTarget; // Which GameObject in scene is considered as painting target
  21. [SerializeField] private EditorTool[] m_BrushTools;
  22. [SerializeField] private GridBrushBase m_Brush; // Which brush will handle painting callbacks
  23. [SerializeField] private PaintableGrid m_ActiveGrid; // Grid that has painting focus (can be palette, too)
  24. [SerializeField] private PaintableGrid m_LastActiveGrid; // Grid that last had painting focus (can be palette, too)
  25. [SerializeField] private HashSet<System.Object> m_InterestedPainters = new HashSet<System.Object>(); // A list of objects that can paint using the GridPaintingState
  26. [SerializeField] private GameObject m_Palette;
  27. [SerializeField] private bool m_DrawGridGizmo = true;
  28. [SerializeField] private bool m_DrawGizmos;
  29. [SerializeField] private bool m_IsEditing;
  30. private GameObject[] m_CachedPaintTargets;
  31. private bool m_FlushPaintTargetCache;
  32. private Editor m_CachedEditor;
  33. private bool m_SavingPalette;
  34. private float m_BrushToolbarSize;
  35. private GridBrushEditorBase m_PreviousToolActivatedEditor;
  36. private GridBrushBase.Tool m_PreviousToolActivated;
  37. private PaintableSceneViewGrid m_PaintableSceneViewGrid;
  38. /// <summary>
  39. /// Callback when the Tile Palette's active target has changed
  40. /// </summary>
  41. public static event Action<GameObject> scenePaintTargetChanged;
  42. /// <summary>
  43. /// Callback when the Tile Palette's active brush has changed.
  44. /// </summary>
  45. public static event Action<GridBrushBase> brushChanged;
  46. /// <summary>
  47. /// Callback when the Tile Palette's active brush tools have changed.
  48. /// </summary>
  49. public static event Action brushToolsChanged;
  50. /// <summary>
  51. /// Callback before the Tile Palette's active palette GameObject has changed.
  52. /// </summary>
  53. public static event Action beforePaletteChanged;
  54. /// <summary>
  55. /// Callback when the Tile Palette's active palette GameObject has changed.
  56. /// </summary>
  57. public static event Action<GameObject> paletteChanged;
  58. /// <summary>
  59. /// Callback when the Tile Palette's list of palettes has changed
  60. /// </summary>
  61. public static event Action palettesChanged;
  62. /// <summary>
  63. /// Callback when the Tile Palette's valid targets has changed.
  64. /// </summary>
  65. public static event Action validTargetsChanged;
  66. /// <summary>
  67. /// Callback when Tile Palette edit mode has changed.
  68. /// </summary>
  69. public static event Action editModeChanged;
  70. private static readonly string k_TilemapLastPaletteEditorPref = "TilemapLastPalette";
  71. private string lastTilemapPalette
  72. {
  73. get
  74. {
  75. return EditorPrefs.GetString(k_TilemapLastPaletteEditorPref, "");
  76. }
  77. set
  78. {
  79. EditorPrefs.SetString(k_TilemapLastPaletteEditorPref, value);
  80. }
  81. }
  82. readonly TilemapEditorTool.ShortcutContext m_ShortcutContext = new TilemapEditorTool.ShortcutContext { active = true };
  83. private void OnEnable()
  84. {
  85. EditorApplication.hierarchyChanged += HierarchyChanged;
  86. EditorApplication.playModeStateChanged += PlayModeStateChanged;
  87. Selection.selectionChanged += OnSelectionChange;
  88. m_FlushPaintTargetCache = true;
  89. }
  90. private void OnDisable()
  91. {
  92. m_InterestedPainters.Clear();
  93. EditorApplication.hierarchyChanged -= HierarchyChanged;
  94. EditorApplication.playModeStateChanged -= PlayModeStateChanged;
  95. Selection.selectionChanged -= OnSelectionChange;
  96. FlushCache();
  97. }
  98. private void OnEditEnable()
  99. {
  100. isEditing = true;
  101. if (palette == null && !String.IsNullOrEmpty(lastTilemapPalette))
  102. {
  103. var lastPalette = GridPalettes.palettes
  104. .Where((paletteInList, _) => (AssetDatabase.GetAssetPath(paletteInList) == lastTilemapPalette))
  105. .FirstOrDefault();
  106. if (lastPalette != null)
  107. palette = lastPalette;
  108. }
  109. if (palette == null && GridPalettes.palettes.Count > 0)
  110. {
  111. palette = GridPalettes.palettes[0];
  112. }
  113. if (m_PaintableSceneViewGrid == null)
  114. {
  115. m_PaintableSceneViewGrid = CreateInstance<PaintableSceneViewGrid>();
  116. m_PaintableSceneViewGrid.hideFlags = HideFlags.HideAndDontSave;
  117. }
  118. m_FlushPaintTargetCache = true;
  119. GridPaletteBrushes.FlushCache();
  120. GridPalettes.palettesChanged += PalettesChanged;
  121. ShortcutIntegration.instance.profileManager.shortcutBindingChanged += UpdateTooltips;
  122. scenePaintTargetChanged += TilemapFocusModeUtility.OnScenePaintTargetChanged;
  123. brushChanged += TilemapFocusModeUtility.OnBrushChanged;
  124. paletteChanged += PaletteChanged;
  125. SceneView.duringSceneGui += TilemapFocusModeUtility.OnSceneViewGUI;
  126. ToolManager.activeToolChanged += ActiveToolChanged;
  127. ToolManager.activeToolChanging += ActiveToolChanging;
  128. AssetPreview.SetPreviewTextureCacheSize(256, GetInstanceID());
  129. ShortcutIntegration.instance.contextManager.RegisterToolContext(m_ShortcutContext);
  130. }
  131. private void PaletteChanged(GameObject obj)
  132. {
  133. lastTilemapPalette = AssetDatabase.GetAssetPath(palette);
  134. }
  135. private void PalettesChanged()
  136. {
  137. palettesChanged?.Invoke();
  138. }
  139. private void OnEditDisable()
  140. {
  141. TilemapFocusModeUtility.SetFocusMode(TilemapFocusModeUtility.TilemapFocusMode.None);
  142. CallOnToolDeactivated();
  143. gridBrush = null;
  144. DestroyImmediate(m_PaintableSceneViewGrid);
  145. if (PaintableGrid.InGridEditMode())
  146. {
  147. // Set Editor Tool to an always available Tool, as Tile Palette Tools are not available any more
  148. ToolManager.SetActiveTool<ViewModeTool>();
  149. }
  150. ShortcutIntegration.instance.profileManager.shortcutBindingChanged -= UpdateTooltips;
  151. ToolManager.activeToolChanged -= ActiveToolChanged;
  152. ToolManager.activeToolChanging -= ActiveToolChanging;
  153. SceneView.duringSceneGui -= TilemapFocusModeUtility.OnSceneViewGUI;
  154. brushChanged -= TilemapFocusModeUtility.OnBrushChanged;
  155. paletteChanged -= PaletteChanged;
  156. GridPalettes.palettesChanged -= PalettesChanged;
  157. ShortcutIntegration.instance.contextManager.DeregisterToolContext(m_ShortcutContext);
  158. isEditing = false;
  159. }
  160. private void ActiveToolChanged()
  161. {
  162. if (gridBrush != null && PaintableGrid.InGridEditMode() && activeBrushEditor != null)
  163. {
  164. GridBrushBase.Tool tool = PaintableGrid.EditTypeToBrushTool(ToolManager.activeToolType);
  165. activeBrushEditor.OnToolActivated(tool);
  166. m_PreviousToolActivatedEditor = activeBrushEditor;
  167. m_PreviousToolActivated = tool;
  168. for (int i = 0; i < TilePaletteMouseCursorUtility.MouseStyles.sceneViewEditModes.Length; ++i)
  169. {
  170. if (TilePaletteMouseCursorUtility.MouseStyles.sceneViewEditModes[i] == tool)
  171. {
  172. Cursor.SetCursor(TilePaletteMouseCursorUtility.MouseStyles.mouseCursorTextures[i],
  173. TilePaletteMouseCursorUtility.MouseStyles.mouseCursorTextures[i] != null ? TilePaletteMouseCursorUtility.MouseStyles.mouseCursorOSHotspot[(int)SystemInfo.operatingSystemFamily] : Vector2.zero,
  174. CursorMode.Auto);
  175. break;
  176. }
  177. }
  178. }
  179. else
  180. {
  181. Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
  182. }
  183. }
  184. private void ActiveToolChanging()
  185. {
  186. if (GridSelection.active
  187. && !TilemapEditorTool.IsActive(typeof(MoveTool))
  188. && !TilemapEditorTool.IsActive(typeof(SelectTool))
  189. && !ToolManager.activeToolType.IsSubclassOf(typeof(GridSelectionTool)))
  190. {
  191. GridSelection.Clear();
  192. }
  193. CallOnToolDeactivated();
  194. }
  195. private void CallOnToolDeactivated()
  196. {
  197. if (gridBrush != null && m_PreviousToolActivatedEditor != null)
  198. {
  199. m_PreviousToolActivatedEditor.OnToolDeactivated(m_PreviousToolActivated);
  200. m_PreviousToolActivatedEditor = null;
  201. if (!PaintableGrid.InGridEditMode())
  202. Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
  203. }
  204. }
  205. private void OnSelectionChange()
  206. {
  207. if (!hasInterestedPainters)
  208. return;
  209. var selectedObject = Selection.activeGameObject;
  210. if (ValidatePaintTarget(selectedObject))
  211. {
  212. scenePaintTarget = selectedObject;
  213. }
  214. if (selectedObject != null)
  215. {
  216. bool isPrefab = EditorUtility.IsPersistent(selectedObject) || (selectedObject.hideFlags & HideFlags.NotEditable) != 0;
  217. if (isPrefab)
  218. {
  219. var assetPath = AssetDatabase.GetAssetPath(selectedObject);
  220. var allAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
  221. foreach (var asset in allAssets)
  222. {
  223. if (asset != null && asset.GetType() == typeof(GridPalette))
  224. {
  225. var targetPalette = (GameObject)AssetDatabase.LoadMainAssetAtPath(assetPath);
  226. if (targetPalette != palette)
  227. palette = targetPalette;
  228. break;
  229. }
  230. }
  231. }
  232. }
  233. }
  234. private void PlayModeStateChanged(PlayModeStateChange state)
  235. {
  236. if (state == PlayModeStateChange.ExitingEditMode)
  237. {
  238. m_EditModeScenePaintTarget = scenePaintTarget;
  239. }
  240. else if (state == PlayModeStateChange.EnteredEditMode)
  241. {
  242. if (GridPaintActiveTargetsPreferences.restoreEditModeSelection && m_EditModeScenePaintTarget != null)
  243. {
  244. scenePaintTarget = m_EditModeScenePaintTarget;
  245. }
  246. }
  247. }
  248. private void HierarchyChanged()
  249. {
  250. if (hasInterestedPainters)
  251. {
  252. m_FlushPaintTargetCache = true;
  253. if (validTargets == null || validTargets.Length == 0 || !validTargets.Contains(scenePaintTarget))
  254. {
  255. // case 1102618: Try to use current Selection as scene paint target if possible
  256. if (Selection.activeGameObject != null && hasInterestedPainters && ValidatePaintTarget(Selection.activeGameObject))
  257. {
  258. scenePaintTarget = Selection.activeGameObject;
  259. }
  260. else
  261. {
  262. AutoSelectPaintTarget();
  263. }
  264. }
  265. }
  266. }
  267. private GameObject[] GetValidTargets()
  268. {
  269. if (m_FlushPaintTargetCache)
  270. {
  271. m_CachedPaintTargets = null;
  272. if (activeBrushEditor != null)
  273. m_CachedPaintTargets = activeBrushEditor.validTargets;
  274. if (m_CachedPaintTargets == null || m_CachedPaintTargets.Length == 0)
  275. scenePaintTarget = null;
  276. else
  277. {
  278. var comparer = GridPaintActiveTargetsPreferences.GetTargetComparer();
  279. if (comparer != null)
  280. Array.Sort(m_CachedPaintTargets, comparer);
  281. }
  282. m_FlushPaintTargetCache = false;
  283. validTargetsChanged?.Invoke();
  284. }
  285. return m_CachedPaintTargets;
  286. }
  287. private static void UpdateTooltips(IShortcutProfileManager obj, Identifier identifier, ShortcutBinding oldBinding, ShortcutBinding newBinding)
  288. {
  289. TilemapEditorTool.UpdateTooltips();
  290. }
  291. internal static void RegisterShortcutContext()
  292. {
  293. // ShortcutIntegration instance is recreated after LoadLayout which wipes the OnEnable registration
  294. ShortcutIntegration.instance.contextManager.RegisterToolContext(instance.m_ShortcutContext);
  295. }
  296. internal static void AutoSelectPaintTarget()
  297. {
  298. if (activeBrushEditor != null)
  299. {
  300. if (validTargets != null && validTargets.Length > 0)
  301. {
  302. scenePaintTarget = validTargets[0];
  303. }
  304. }
  305. }
  306. /// <summary>
  307. /// The currently active target for the Tile Palette
  308. /// </summary>
  309. public static GameObject scenePaintTarget
  310. {
  311. get { return instance.m_ScenePaintTarget; }
  312. set
  313. {
  314. if (value != instance.m_ScenePaintTarget)
  315. {
  316. instance.m_ScenePaintTarget = value;
  317. if (scenePaintTargetChanged != null)
  318. scenePaintTargetChanged(instance.m_ScenePaintTarget);
  319. RepaintGridPaintPaletteWindow();
  320. }
  321. }
  322. }
  323. /// <summary>
  324. /// The currently active brush for the Tile Palette
  325. /// </summary>
  326. public static GridBrushBase gridBrush
  327. {
  328. get
  329. {
  330. if (instance.m_Brush == null)
  331. {
  332. instance.m_Brush = GridPaletteBrushes.instance.GetLastUsedBrush();
  333. UpdateBrushToolbar();
  334. }
  335. return instance.m_Brush;
  336. }
  337. set
  338. {
  339. if (instance.m_Brush != value)
  340. {
  341. instance.m_Brush = value;
  342. instance.m_FlushPaintTargetCache = true;
  343. if (value != null)
  344. {
  345. GridPaletteBrushes.instance.StoreLastUsedBrush(value);
  346. UpdateBrushToolbar();
  347. }
  348. // Ensure that current scenePaintTarget is still a valid target after a brush change
  349. if (scenePaintTarget != null && !ValidatePaintTarget(scenePaintTarget))
  350. scenePaintTarget = null;
  351. // Use Selection if previous scenePaintTarget was not valid
  352. if (scenePaintTarget == null)
  353. scenePaintTarget = ValidatePaintTarget(Selection.activeGameObject) ? Selection.activeGameObject : null;
  354. // Auto select a valid target if there is still no scenePaintTarget
  355. if (scenePaintTarget == null)
  356. AutoSelectPaintTarget();
  357. if (null != brushChanged)
  358. brushChanged(value);
  359. RepaintGridPaintPaletteWindow();
  360. }
  361. }
  362. }
  363. /// <summary>
  364. /// Returns all available brushes for the Tile Palette
  365. /// </summary>
  366. public static IList<GridBrushBase> brushes
  367. {
  368. get { return GridPaletteBrushes.brushes; }
  369. }
  370. internal static GridBrush defaultBrush
  371. {
  372. get { return gridBrush as GridBrush; }
  373. set { gridBrush = value; }
  374. }
  375. /// <summary>
  376. /// The currently active palette GameObject for the Tile Palette
  377. /// </summary>
  378. public static GameObject palette
  379. {
  380. get
  381. {
  382. return instance.m_Palette;
  383. }
  384. set
  385. {
  386. if (value == null || !GridPalettes.palettes.Contains(value))
  387. throw new ArgumentException(L10n.Tr("Unable to set invalid palette"));
  388. if (instance.m_Palette != value)
  389. {
  390. OnBeforePaletteChanged();
  391. instance.m_Palette = value;
  392. OnPaletteChanged(instance.m_Palette);
  393. }
  394. }
  395. }
  396. /// <summary>
  397. /// Checks if target GameObject is part of the active Palette.
  398. /// </summary>
  399. /// <param name="target">GameObject to check.</param>
  400. /// <returns>True if the target GameObject is part of the active palette. False if not.</returns>
  401. public static bool IsPartOfActivePalette(GameObject target)
  402. {
  403. foreach (var clipboard in GridPaintPaletteClipboard.instances)
  404. {
  405. if (target == clipboard.paletteInstance)
  406. return true;
  407. }
  408. if (target == palette)
  409. return true;
  410. var parent = target.transform.parent;
  411. return parent != null && IsPartOfActivePalette(parent.gameObject);
  412. }
  413. /// <summary>
  414. /// Returns all available Palette GameObjects for the Tile Palette
  415. /// </summary>
  416. public static IList<GameObject> palettes
  417. {
  418. get { return GridPalettes.palettes; }
  419. }
  420. /// <summary>
  421. /// The currently active editor for the active brush for the Tile Palette
  422. /// </summary>
  423. public static GridBrushEditorBase activeBrushEditor
  424. {
  425. get
  426. {
  427. Editor.CreateCachedEditor(gridBrush, null, ref instance.m_CachedEditor);
  428. GridBrushEditorBase baseEditor = instance.m_CachedEditor as GridBrushEditorBase;
  429. return baseEditor;
  430. }
  431. }
  432. internal static Editor fallbackEditor
  433. {
  434. get
  435. {
  436. Editor.CreateCachedEditor(gridBrush, null, ref instance.m_CachedEditor);
  437. return instance.m_CachedEditor;
  438. }
  439. }
  440. internal static PaintableGrid activeGrid
  441. {
  442. get { return instance.m_ActiveGrid; }
  443. set
  444. {
  445. instance.m_ActiveGrid = value;
  446. if (instance.m_ActiveGrid != null)
  447. instance.m_LastActiveGrid = value;
  448. }
  449. }
  450. internal static PaintableGrid lastActiveGrid
  451. {
  452. get { return instance.m_LastActiveGrid; }
  453. }
  454. internal static PaintableSceneViewGrid paintableSceneViewGrid
  455. {
  456. get => instance.m_PaintableSceneViewGrid;
  457. }
  458. /// <summary>
  459. /// The last active mouse position on the `SceneView`
  460. /// when the `GridPaintingState` is active.
  461. /// </summary>
  462. public static Vector2 lastSceneViewMousePosition
  463. {
  464. get => paintableSceneViewGrid.mousePosition;
  465. }
  466. /// <summary>
  467. /// The last active grid position on the `SceneView`
  468. /// when the `GridPaintingState` is active.
  469. /// </summary>
  470. public static Vector3Int lastSceneViewGridPosition
  471. {
  472. get => new Vector3Int(paintableSceneViewGrid.mouseGridPosition.x
  473. , paintableSceneViewGrid.mouseGridPosition.y
  474. , paintableSceneViewGrid.zPosition);
  475. }
  476. internal static EditorTool[] activeBrushTools
  477. {
  478. get { return instance.m_BrushTools; }
  479. set
  480. {
  481. instance.m_BrushTools = value;
  482. brushToolsChanged?.Invoke();
  483. }
  484. }
  485. internal static float activeBrushToolbarSize
  486. {
  487. get
  488. {
  489. if (instance.m_BrushToolbarSize == 0.0f)
  490. CalculateToolbarSize();
  491. return instance.m_BrushToolbarSize;
  492. }
  493. set { instance.m_BrushToolbarSize = value; }
  494. }
  495. internal static bool drawGridGizmo
  496. {
  497. get => instance.m_DrawGridGizmo;
  498. set => instance.m_DrawGridGizmo = value;
  499. }
  500. internal static bool drawGizmos
  501. {
  502. get => instance.m_DrawGizmos;
  503. set => instance.m_DrawGizmos = value;
  504. }
  505. /// <summary>
  506. /// Returns whether GridPaintingState is active for editing.
  507. /// </summary>
  508. public static bool isEditing
  509. {
  510. get => instance.m_IsEditing;
  511. internal set
  512. {
  513. if (value != instance.m_IsEditing)
  514. {
  515. instance.m_IsEditing = value;
  516. editModeChanged?.Invoke();
  517. }
  518. }
  519. }
  520. private static void CalculateToolbarSize()
  521. {
  522. GUIStyle toolbarStyle = "Command";
  523. activeBrushToolbarSize = activeBrushTools.Sum(x => toolbarStyle.CalcSize(x.toolbarIcon).x);
  524. }
  525. internal static void SetBrushTools(EditorTool[] editorTools)
  526. {
  527. activeBrushTools = editorTools;
  528. activeBrushToolbarSize = 0.0f;
  529. }
  530. private static bool ValidatePaintTarget(GameObject candidate)
  531. {
  532. if (candidate == null)
  533. return false;
  534. // Case 1327021: Do not allow disabled GameObjects as a paint target
  535. if (!candidate.activeInHierarchy)
  536. return false;
  537. if (candidate.GetComponentInParent<Grid>() == null && candidate.GetComponent<Grid>() == null)
  538. return false;
  539. if (validTargets != null && validTargets.Length > 0 && !validTargets.Contains(candidate))
  540. return false;
  541. if (PrefabUtility.IsPartOfPrefabAsset(candidate))
  542. return false;
  543. return true;
  544. }
  545. internal static void FlushCache()
  546. {
  547. if (instance.m_CachedEditor != null)
  548. {
  549. DestroyImmediate(instance.m_CachedEditor);
  550. instance.m_CachedEditor = null;
  551. }
  552. instance.m_FlushPaintTargetCache = true;
  553. }
  554. /// <summary>
  555. /// A list of all valid targets that can be set as an active target for the Tile Palette
  556. /// </summary>
  557. public static GameObject[] validTargets
  558. {
  559. get { return instance.GetValidTargets(); }
  560. }
  561. internal static bool savingPalette
  562. {
  563. get { return instance.m_SavingPalette; }
  564. set { instance.m_SavingPalette = value; }
  565. }
  566. internal static void OnBeforePaletteChanged()
  567. {
  568. if (null != beforePaletteChanged)
  569. beforePaletteChanged();
  570. }
  571. internal static void OnPaletteChanged(GameObject changedPalette)
  572. {
  573. if (null != paletteChanged)
  574. paletteChanged(changedPalette);
  575. }
  576. internal static void UpdateBrushToolbar()
  577. {
  578. BrushToolsAttribute toolAttribute = null;
  579. if (instance.m_Brush != null)
  580. toolAttribute = (BrushToolsAttribute)instance.m_Brush.GetType().GetCustomAttribute(typeof(BrushToolsAttribute), false);
  581. TilemapEditorTool.UpdateEditorTools(toolAttribute);
  582. }
  583. internal static void UpdateActiveGridPalette()
  584. {
  585. foreach (var clipboard in GridPaintPaletteClipboard.instances)
  586. {
  587. clipboard.DelayedResetPreviewInstance();
  588. }
  589. }
  590. internal static void RepaintGridPaintPaletteWindow()
  591. {
  592. foreach (var clipboard in GridPaintPaletteClipboard.instances)
  593. {
  594. clipboard.Repaint();
  595. }
  596. }
  597. internal static void UnlockGridPaintPaletteClipboardForEditing()
  598. {
  599. foreach (var clipboard in GridPaintPaletteClipboard.instances)
  600. {
  601. clipboard.UnlockAndEdit();
  602. }
  603. }
  604. internal static void RegisterPainterInterest(System.Object painter)
  605. {
  606. var added = instance.m_InterestedPainters.Add(painter);
  607. if (added && instance.m_InterestedPainters.Count == 1)
  608. instance.OnEditEnable();
  609. }
  610. internal static void UnregisterPainterInterest(System.Object painter)
  611. {
  612. var removed = instance.m_InterestedPainters.Remove(painter);
  613. if (removed && instance.m_InterestedPainters.Count == 0)
  614. instance.OnEditDisable();
  615. }
  616. internal static bool hasInterestedPainters
  617. {
  618. get { return instance != null && instance.m_InterestedPainters.Count > 0; }
  619. }
  620. }
  621. }