Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Handles.ConeHandleCap

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method ConeHandleCap(controlID: int, position: Vector3, rotation: Quaternion, size: float, eventType: EventType): void;
public static void ConeHandleCap(int controlID, Vector3 position, Quaternion rotation, float size, EventType eventType);

Parameters

controlID The control ID for the handle.
position The position of the handle in the space of Handles.matrix.
rotation The rotation of the handle in the space of Handles.matrix.
size The size of the handle in the space of Handles.matrix. Use HandleUtility.GetHandleSize if you want a constant screen-space size.
eventType Event type for the handle to act upon. By design it handles EventType.Layout and EventType.Repaint events.

Description

Draw a cone handle. Pass this into handle functions.

On EventType.Layout event, calculates handle distance to mouse and calls HandleUtility.AddControl accordingly.

On EventType.Repaint event, draws the handle shape.

Cone Handle Cap in the Scene View.

Add the following script to your Assets folder as ConeExample.cs and add the ConeExample component to an object in a scene.

#pragma strict
public class ConeExample extends MonoBehaviour {
}
using UnityEngine;

public class ConeExample : MonoBehaviour {}

Add the following script to Assets/Editor as ConeExampleEditor.cs and select the object with the ConeExample component.

#pragma strict
@CustomEditor(ConeExample)
public class ConeExampleEditor extends Editor {
	var size: float = 1f;
	protected virtual function OnSceneGUI() {
		if (Event.current.type == EventType.Repaint) {
			var transform: Transform = (ConeExampletarget).transform;
			Handles.color = Handles.xAxisColor;
			Handles.ConeHandleCap(0, transform.position + new Vector3(3f, 0f, 0f), transform.rotation * Quaternion.LookRotation(Vector3.right), size, EventType.Repaint);
			Handles.color = Handles.yAxisColor;
			Handles.ConeHandleCap(0, transform.position + new Vector3(0f, 3f, 0f), transform.rotation * Quaternion.LookRotation(Vector3.up), size, EventType.Repaint);
			Handles.color = Handles.zAxisColor;
			Handles.ConeHandleCap(0, transform.position + new Vector3(0f, 0f, 3f), transform.rotation * Quaternion.LookRotation(Vector3.forward), size, EventType.Repaint);
		}
	}
}
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(ConeExample))] public class ConeExampleEditor : Editor { float size = 1f;

protected virtual void OnSceneGUI() { if (Event.current.type == EventType.Repaint) { Transform transform = ((ConeExample)target).transform; Handles.color = Handles.xAxisColor; Handles.ConeHandleCap( 0, transform.position + new Vector3(3f, 0f, 0f), transform.rotation * Quaternion.LookRotation(Vector3.right), size, EventType.Repaint ); Handles.color = Handles.yAxisColor; Handles.ConeHandleCap( 0, transform.position + new Vector3(0f, 3f, 0f), transform.rotation * Quaternion.LookRotation(Vector3.up), size, EventType.Repaint ); Handles.color = Handles.zAxisColor; Handles.ConeHandleCap( 0, transform.position + new Vector3(0f, 0f, 3f), transform.rotation * Quaternion.LookRotation(Vector3.forward), size, EventType.Repaint ); } } }
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答