Version: 2022.2

Handles.DrawOutline

切换到手册
public static void DrawOutline (GameObject[] objects, Color parentNodeColor, Color childNodeColor, float fillOpacity);
public static void DrawOutline (GameObject[] objects, Color color, float fillOpacity);
public static void DrawOutline (List<GameObject> objects, Color parentNodeColor, Color childNodeColor, float fillOpacity);
public static void DrawOutline (List<GameObject> objects, Color color, float fillOpacity);
public static void DrawOutline (int[] parentRenderers, int[] childRenderers, Color parentNodeColor, Color childNodeColor, float fillOpacity);
public static void DrawOutline (int[] renderers, Color color, float fillOpacity);
public static void DrawOutline (Renderer[] renderers, Color parentNodeColor, Color childNodeColor, float fillOpacity);
public static void DrawOutline (Renderer[] renderers, Color color, float fillOpacity);

参数

objects The GameObjects to outline.
parentNodeColor The color of the outline of the GameObjects provided explicitly in the objects parameter and the parentRenderers parameters. The alpha value controls the intensity of the outline.
childNodeColor The color of the outline of the GameObjects which are children to the GameObjects in the objects parameter. The alpha value controls the intensity of the outline.
color The color of the outline for the objects and renderers.
parentRenderers The instance IDs of the first set of Renderers. If you provide GameObjects or Renderers as parameters, these Renderers belong to the GameObjects provided explicitly in the parameters.
childRenderers The instance IDs of the second set of Renderers. If you provide GameObjects or Renderers as parameters, these Renderers belong to the child GameObjects of the objects provided in the parameters.
fillOpacity The opacity of the Renderers within each outline.
renderers The Renderers to outline.

描述

Draws an outline around the specified GameObjects in the Scene View.

This only applies to GameObjects that have Renderer components. You can only use this during a EventType.Repaint event.

Instead of passing in GameObjects or Renderers, you can also use Renderer instance IDs. This improves performance because Unity doesn't need to get the instance IDs from the GameObjects or Renderers every time you call this function.

NOTE: Overloads that take GameObject[], Renderer[] or List<GameObject> as arguments are there for convenience, using them might result in additional allocations that cause additional garbage collection. To avoid performance or memory issues, use these overloads only when drawing a relatively small number of outlines (consider providing renderer instance IDs directly if the number of outlines exceeds 100).

The alpha values of parentNodeColor and childNodeColor control the intensity of the outline, 0 makes it completely transparent and 1 makes it fully opaque.

The fillOpacity controls the weight of the color multiplier for the Renderer. Higher fillOpacity values make the color more intense and leave the original object less visible.

See Also: Handles.DrawCamera.

using UnityEditor;
using UnityEngine;

namespace UnityEditor { [CustomEditor(typeof(GameObject))] public class CustomInspector : Editor { private GameObject[] objects;

public void OnEnable() { // Note: If you use FindGameObjectsWithTag in a Prefab Stage that you opened from a Scene, // it includes GameObjects from that Scene. Instead use: // var renderers = StageUtility.GetCurrentStage().FindComponentsOfType<Renderer>(); // to explicitly specify where to get the GameObjects from. objects = GameObject.FindGameObjectsWithTag("Player"); // populate the objects array with game objects }

public void OnSceneGUI() { // draw the outline with an alpha of 0.5 if (Event.current.type == EventType.Repaint) Handles.DrawOutline(objects, Color.yellow, Color.green, 0.1f); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961