版本: Unity 6 (6000.0)
语言English
  • C#

ToolManager.RefreshAvailableTools

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提出的每个建议的更改,并在适用情况下进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static void RefreshAvailableTools();

描述

调用 RefreshAvailableTools 以重建场景视图工具叠加层的内容。

当工具可以在选择和工具更改事件之外更改 EditorTool.IsAvailable 的值时,此方法很有用。

using System;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;

// An example of a tool that may be made available or unavailable in situations other than selection changes. [EditorTool("Conditional Tool", typeof(Transform))] class ConditionallyAvailable : EditorTool { bool m_IsAvailable; void OnEnable() => EditorApplication.update += UpdateAvailable; void OnDisable() => EditorApplication.update -= UpdateAvailable;

// This tool is enabled and disabled in 10 second intervals. void UpdateAvailable() { var time = DateTime.Now;

if (m_IsAvailable != ((time.Second / 10) % 2 == 0)) { m_IsAvailable = !m_IsAvailable; // Because the tool is changing availability arbitrarily, it is necessary to manually refresh the UI. ToolManager.RefreshAvailableTools(); } }

// When a tool is available, it is shown in the Tools Overlay. If not available, it is hidden. public override bool IsAvailable() => m_IsAvailable; }