Unity 编辑器开发实战【Editor Window】- BlendShape调试工具
【摘要】
Skin Mesh Renderer组件编辑器本身包含BlendShape的调试滑动条,但是当数量较多想要重置时较为麻烦,下面介绍的工具添加了这些调试滑动条的同时,增加了一键重置的功能:
代码如下:
using UnityEngine;using UnityEditor; namespace SK.Framework{ ...
Skin Mesh Renderer组件编辑器本身包含BlendShape的调试滑动条,但是当数量较多想要重置时较为麻烦,下面介绍的工具添加了这些调试滑动条的同时,增加了一键重置的功能:
代码如下:
-
using UnityEngine;
-
using UnityEditor;
-
-
namespace SK.Framework
-
{
-
/// <summary>
-
/// BlendShape调试工具
-
/// </summary>
-
public class BlendShapesPreviewer : EditorWindow
-
{
-
//菜单
-
[MenuItem("SKFramework/Tools/BlendShapes Previewer")]
-
private static void Open()
-
{
-
GetWindow<BlendShapesPreviewer>("BlendShapes Previewer").Show();
-
}
-
-
private Vector2 scroll = Vector2.zero;
-
-
private void OnGUI()
-
{
-
if (Selection.activeGameObject == null)
-
{
-
EditorGUILayout.HelpBox("未选中任何物体", MessageType.Info);
-
return;
-
}
-
SkinnedMeshRenderer smr = Selection.activeGameObject.GetComponent<SkinnedMeshRenderer>();
-
if (smr == null)
-
{
-
EditorGUILayout.HelpBox("物体不包含SkinnedMeshRenderer组件", MessageType.Info);
-
return;
-
}
-
Mesh mesh = smr.sharedMesh;
-
if(mesh == null)
-
{
-
EditorGUILayout.HelpBox("Mesh为空", MessageType.Info);
-
return;
-
}
-
int count = mesh.blendShapeCount;
-
if (count == 0)
-
{
-
EditorGUILayout.HelpBox("BlendShape Count: 0", MessageType.Info);
-
return;
-
}
-
scroll = EditorGUILayout.BeginScrollView(scroll);
-
{
-
for (int i = 0; i < count; i++)
-
{
-
//水平布局
-
GUILayout.BeginHorizontal();
-
//BlendShape名称
-
GUILayout.Label(mesh.GetBlendShapeName(i), GUILayout.Width(150f));
-
//滑动条
-
float newValue = EditorGUILayout.Slider(smr.GetBlendShapeWeight(i), 0f, 100f);
-
if (newValue != smr.GetBlendShapeWeight(i))
-
{
-
smr.SetBlendShapeWeight(i, newValue);
-
}
-
GUILayout.EndHorizontal();
-
}
-
}
-
EditorGUILayout.EndScrollView();
-
-
GUILayout.FlexibleSpace();
-
//重置按钮 点击时将所有BlendShape值设为0
-
if (GUILayout.Button("Reset"))
-
{
-
for (int i = 0; i < count; i++)
-
{
-
smr.SetBlendShapeWeight(i, 0);
-
}
-
}
-
}
-
//选择的物体变更时调用重新绘制方法
-
private void OnSelectionChange()
-
{
-
Repaint();
-
}
-
}
-
}
文章来源: coderz.blog.csdn.net,作者:CoderZ1010,版权归原作者所有,如需转载,请联系作者。
原文链接:coderz.blog.csdn.net/article/details/123496037
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)