目录
- Scene面板
- 拓展布局(Editor模式)
- 效果
- 源码
- 绘制标识(非Editor模式)
- 效果
- 源码
- 禁用在Scene中选中对象(Editor模式)
- 源码
- SelectionBase(Scene视图上的对象选中标识)(非Editor模式)
- 效果
- 源码
- Game面板(非Editor模式)
- 拓展效果
- 源码
Scene面板
拓展布局(Editor模式)
效果
源码
// 常驻Scene辅助UI
[InitializeOnLoadMethod]
static void InitializeOnLoadMethod01()
{
SceneView.duringSceneGui += view =>
{
Handles.BeginGUI();
GUI.Label(new Rect(0f, 0f, 50f, 15f), "标题");
GUI.Button(new Rect(0f, 20f, 50f, 50f),
AssetDatabase.LoadAssetAtPath<Texture>("Assets/unity.png"));
Handles.EndGUI();
};
}
绘制标识(非Editor模式)
效果
源码
public class ExpandScene : MonoBehaviour
{
// 选择后绘制
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
// 画线 【当前游戏对象坐标点 向 (0,0,0)点 画线】
Gizmos.DrawLine(transform.position, Vector3.zero);
// 立方体 【以(0,0,0)点为原点绘制(0.5f,0.5f,0.5f)的立方体】
Gizmos.DrawCube(Vector3.zero, new Vector3(0.5f, 0.5f, 0.5f));
}
// 默认绘制
private void OnDrawGizmos()
{
Gizmos.DrawSphere(transform.position, 0.6f);
}
}
禁用在Scene中选中对象(Editor模式)
源码
// 禁用在Scene中选中对象(或者锁定图层,那么锁定的图层将不可选中)
[InitializeOnLoadMethod]
static void InitializeOnLoadMethod02()
{
SceneView.duringSceneGui += view =>
{
if (Event.current != null)
{
// FocusType.Passive 表示禁止接收控制焦点,获取它的 controllID 后, 即可禁止将点击事件穿透下去
int controlID = GUIUtility.GetControlID(FocusType.Passive);
if (Event.current.type == EventType.Layout)
HandleUtility.AddDefaultControl(controlID);
}
};
}
SelectionBase(Scene视图上的对象选中标识)(非Editor模式)
SelectionBase 在Scene视图中选中绑定此脚本游戏对象的子对象时,自动选择到绑定此脚本的游戏对象上
效果
源码
// SelectionBase 在Scene视图中选中绑定此脚本游戏对象的子对象时,自动选择到绑定此脚本的游戏对象上
[SelectionBase]
public class ExpandScene : MonoBehaviour { }
Game面板(非Editor模式)
拓展效果
源码
using UnityEngine;
namespace Scripts_03
{
// 拓展Game视图 绑定到任意游戏对象上均可 UNITY_EDITOR:发布时剔除
#if
[ExecuteInEditMode]
public class ExpandGame : MonoBehaviour
{
private void OnGUI()
{
GUILayout.Button("Button");
GUILayout.Label("Hello Lee!");
}
}
#endif
}