原生Transform编辑器,这个两个脚本能直接更改检视窗口的Tranform的显示
//**********************************************************************
// 文件名(File Name): TransformInspector.cs
// 作者(Author): 钱何飞
// 创建时间(CreateTime): 5/13/2019
// **********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;namespace FrameWork.IEditor
{[CustomEditor(typeof(Transform))][CanEditMultipleObjects]public class TransformInspector : Editor{private class Contents{public GUIContent positionContent = new GUIContent(LocalizationDatabase.GetLocalizedString("Position"), LocalizationDatabase.GetLocalizedString("The local position of this Game Object relative to the parent."));public GUIContent scaleContent = new GUIContent(LocalizationDatabase.GetLocalizedString("Scale"), LocalizationDatabase.GetLocalizedString("The local scaling of this Game Object relative to the parent."));public string floatingPointWarning = LocalizationDatabase.GetLocalizedString("Due to floating-point precision limitations, it is recommended to bring the world coordinates of the GameObject within a smaller range.");}private SerializedProperty m_Position;private SerializedProperty m_Scale;//private SerializedProperty m_Rotation;private TransformRotationGUI m_RotationGUI;private static Contents s_Contents;public void OnEnable(){m_Position = base.serializedObject.FindProperty("m_LocalPosition");m_Scale = base.serializedObject.FindProperty("m_LocalScale");//m_Rotation = base.serializedObject.FindProperty("m_LocalRotation");if (m_RotationGUI == null){m_RotationGUI = new TransformRotationGUI();}m_RotationGUI.OnEnable(base.serializedObject.FindProperty("m_LocalRotation"), new GUIContent(LocalizationDatabase.GetLocalizedString("Rotation")));}Transform transform;public override void OnInspectorGUI(){if (s_Contents == null){s_Contents = new Contents();}if (!EditorGUIUtility.wideMode){EditorGUIUtility.wideMode = true;EditorGUIUtility.labelWidth = EditorGUIUtility.currentViewWidth - 212f;}base.serializedObject.Update();Inspector3D();transform = base.target as Transform;Vector3 position = transform.position;if (Mathf.Abs(position.x) > 100000f || Mathf.Abs(position.y) > 100000f || Mathf.Abs(position.z) > 100000f){EditorGUILayout.HelpBox(s_Contents.floatingPointWarning, MessageType.Warning);}base.serializedObject.ApplyModifiedProperties();}private void Inspector3D(){GUILayoutOption width = GUILayout.Width(23);EditorGUILayout.BeginHorizontal("box");if (GUILayout.Button(new GUIContent("x0.2", "时间加速按钮"))){Time.timeScale = 0.2f;}if (GUILayout.Button("x0.4")){Time.timeScale = 0.4f;}if (GUILayout.Button("x0.8")){Time.timeScale = 0.8f;}if (GUILayout.Button("x1.0")){Time.timeScale = 1f;}if (GUILayout.Button("x2.0")){Time.timeScale = 2f;}if (GUILayout.Button("x4.0")){Time.timeScale = 4f;}if (GUILayout.Button("x6.0")){Time.timeScale = 6f;}if (GUILayout.Button("x8.0")){Time.timeScale = 8f;}EditorGUILayout.EndHorizontal();EditorGUILayout.BeginHorizontal("box");if (GUILayout.Button("W", "button", width)){string value = string.Format("new Vector3({0}f,{1}f,{2}f)", transform.position.x, transform.position.y, transform.position.z);Copy(value);}EditorGUILayout.PropertyField(m_Position, s_Contents.positionContent, GUILayout.ExpandWidth(true));if (GUILayout.Button("L", "button", width)){string value = string.Format("new Vector3({0}f,{1}f,{2}f)", transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);Copy(value);}EditorGUILayout.EndHorizontal();EditorGUILayout.BeginHorizontal("box");if (GUILayout.Button("W", "button", width)){string value = string.Format("new Vector3({0}f,{1}f,{2}f)", transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);Copy(value);}m_RotationGUI.RotationField();if (GUILayout.Button("L", "button", width)){string value = string.Format("new Vector3({0}f,{1}f,{2}f)", transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z);Copy(value);}EditorGUILayout.EndHorizontal();EditorGUILayout.BeginHorizontal("box");if (GUILayout.Button("L", "button", width)){string value = string.Format("new Vector3({0}f,{1}f,{2}f)", transform.localScale.x, transform.localScale.y, transform.localScale.z);Copy(value);}EditorGUILayout.PropertyField(m_Scale, s_Contents.scaleContent);EditorGUILayout.EndHorizontal();}public void Copy(string value){TextEditor textEditor = new TextEditor();textEditor.text = value;textEditor.Copy();Debug.Log("Copy " + textEditor.text);}}}
//**********************************************************************
// 文件名(File Name): TransformRotation.cs
// 作者(Author): 钱何飞
// 创建时间(CreateTime): 5/13/2019
// **********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEditor;
using System.Reflection;namespace FrameWork.IEditor
{internal enum RotationOrder{OrderXYZ,OrderXZY,OrderYZX,OrderYXZ,OrderZXY,OrderZYX}[Serializable]internal class TransformRotationGUI{private GUIContent rotationContent = new GUIContent("Rotation", "The local rotation of this Game Object relative to the parent.");private Vector3 m_EulerAngles;private Vector3 m_OldEulerAngles = new Vector3(1000000f, 1E+07f, 1000000f);private int m_OldRotationOrder = (int)RotationOrder.OrderZXY;private SerializedProperty m_Rotation;private UnityEngine.Object[] targets;private static int s_FoldoutHash = "Foldout".GetHashCode();public void OnEnable(SerializedProperty m_Rotation, GUIContent label){this.m_Rotation = m_Rotation;targets = m_Rotation.serializedObject.targetObjects;Transform item = (targets[0] as Transform);PropertyInfo rotationOrder = typeof(Transform).GetProperty("rotationOrder", BindingFlags.Instance | BindingFlags.NonPublic);m_OldRotationOrder = (int)rotationOrder.GetValue(item, null);rotationContent = label;}public void RotationField(){RotationField(disabled: false);}public void RotationField(bool disabled){Transform transform = targets[0] as Transform;MethodInfo methodInfo = transform.GetType().GetMethod("GetLocalEulerAngles", BindingFlags.Instance | BindingFlags.NonPublic);PropertyInfo propertyInfo = typeof(Transform).GetProperty("rotationOrder", BindingFlags.Instance | BindingFlags.NonPublic);int rotationOrder = (int)propertyInfo.GetValue(transform, null);Vector3 localEulerAngles = (Vector3)methodInfo.Invoke(transform, new object[] { rotationOrder });if (m_OldEulerAngles.x != localEulerAngles.x || m_OldEulerAngles.y != localEulerAngles.y || m_OldEulerAngles.z != localEulerAngles.z || m_OldRotationOrder != rotationOrder){rotationOrder = (int)propertyInfo.GetValue(transform, null);m_EulerAngles = (Vector3)methodInfo.Invoke(transform, new object[] { rotationOrder });m_OldRotationOrder = rotationOrder;}bool flag = false;bool flag2 = false;for (int i = 1; i < targets.Length; i++){Transform transform2 = targets[i] as Transform;int rotationOrder2 = (int)propertyInfo.GetValue(transform2, null);Vector3 localEulerAngles2 = (Vector3)methodInfo.Invoke(transform2, new object[] { rotationOrder });flag |= (localEulerAngles2.x != localEulerAngles.x || localEulerAngles2.y != localEulerAngles.y || localEulerAngles2.z != localEulerAngles.z);flag2 |= (rotationOrder2 != rotationOrder);}Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * (float)(EditorGUIUtility.wideMode ? 1 : 2));GUIContent gUIContent = EditorGUI.BeginProperty(controlRect, rotationContent, m_Rotation);EditorGUI.showMixedValue = flag;EditorGUI.BeginChangeCheck();int controlID = GUIUtility.GetControlID(s_FoldoutHash, FocusType.Keyboard, controlRect);string text = "";if (AnimationMode.InAnimationMode() && rotationOrder != (int)RotationOrder.OrderZXY){if (flag2){text = "Mixed";}else{text = rotationOrder.ToString();text = text.Substring(text.Length - 3);}gUIContent.text = gUIContent.text + " (" + text + ")";}MethodInfo EditorGUI_MultiFieldPrefixLabel = typeof(EditorGUI).GetMethod("MultiFieldPrefixLabel", BindingFlags.Static | BindingFlags.NonPublic);controlRect = (Rect)EditorGUI_MultiFieldPrefixLabel.Invoke(null, new object[] { controlRect, controlID, gUIContent, 3 });controlRect.height = EditorGUIUtility.singleLineHeight;using (new EditorGUI.DisabledScope(disabled)){m_EulerAngles = EditorGUI.Vector3Field(controlRect, GUIContent.none, m_EulerAngles);}if (EditorGUI.EndChangeCheck()){Undo.RecordObjects(targets, "Inspector");UnityEngine.Object[] array = targets;for (int j = 0; j < array.Length; j++){Transform transform3 = (Transform)array[j];MethodInfo SetLocalEulerAngles = typeof(Transform).GetMethod("SetLocalEulerAngles", BindingFlags.Instance | BindingFlags.NonPublic);int rotationOrder3 = (int)propertyInfo.GetValue(transform3, null);SetLocalEulerAngles.Invoke(transform3, new object[] { m_EulerAngles, rotationOrder3 });if (transform3.parent != null){MethodInfo SendTransformChangedScale = typeof(Transform).GetMethod("SendTransformChangedScale", BindingFlags.Instance | BindingFlags.NonPublic);SendTransformChangedScale.Invoke(transform3, null);}}m_Rotation.serializedObject.SetIsDifferentCacheDirty();}EditorGUI.showMixedValue = false;if (flag2){EditorGUILayout.HelpBox("Transforms have different rotation orders, keyframes saved will have the same value but not the same local rotation", MessageType.Warning);}EditorGUI.EndProperty();}}
}
原生Transform编辑器,这个两个脚本能直接更改检视窗口的Tranform的显示相关推荐
- Unity3D Editor 编辑器扩展2 选取物体、撤销操作和窗口小部件的显示
环境:Unity2017.2 语言:C# 总起: 今天主要介绍以下内容: 1.通过MenuCommand.Selection获取选中对象: 2.通过Undo编写可撤销的命令: 3.窗口小部件的显示. ...
- Unity3D Editor 编辑器扩展3 Editor脚本
Unity3D Editor 编辑器扩展3 Editor脚本 环境:Unity2017.2 语言:C# 总起: 在编辑Unity项目的时候,总不可能避免的接触到Unity自身自带的Inspector参 ...
- 第五节 红帽认证培训 重要的环境变量+Vim编辑器与Shell命令脚本(4.1-4.2)
第五节 红帽认证培训 重要的环境变量+Vim编辑器与Shell命令脚本(4.1-4.2) 文章目录 重要的环境变量 4.1 Vim文本编辑器(Vi加强版:着色) 4.2编写Shell脚本 1.编写简单 ...
- Linux基础(3) Vim编辑器与Shell命令脚本
1.VIM文本编辑器 VIM编辑器的三大模式 命令模式: 控制光标移动,可对文本进行复制.粘贴和查找等工作 输入模式: 正常的文本录入. 末行模式: 保存或退出文档,以及设置编辑环境 三种模式的切换: ...
- 卷毛崽|Linux自学|Vim 编辑器与 Shell 命令脚本
Vim编辑器与 Shell 命令脚本 1.Vim 文本编辑器: (1) vim常见命令 (2) vim 更改主机名(RHCSA考题) (3)vim 配置网卡ip(RHCSA考题) (4) vim配置y ...
- 两个脚本解决打开安卓模拟器时会显示黑框cmd的问题
先上vbs代码 Set ws = CreateObject("Wscript.Shell") ws.run "cmd /c android8.0.bat",0 ...
- Unity实现一个物体调用两个脚本
ㅤㅤㅤ 提要: 事情是这样的,我写了个脚本包含UI和摄像机的切换,进行一个主物体与多个物体进行互动. ㅤㅤㅤ 讲解部分: 原本我是这样写的 if (y == 1) {cameraOff (); } e ...
- 第六节 红帽认证培训 Vim编辑器与Shell命令脚本(4.3-4.4)
第六节 红帽认证培训 Vim编辑器与Shell命令脚本(4.3-4.4) 文章目录 4.3 流程控制语句 1.if条件测试语句 2.for条件循环语句 3.while条件循环语句 4.case条件测试 ...
- 树莓派gpu调用_关于检测树莓派的 CPU 和 GPU 温度,网上流传的两段脚本为何不同?...
目前网络上流传的检测树莓派 CPU 和 GPU 的温度主要是两个脚本,例子在这里(树莓派-GPIO.CPU.温度.内存 和 用Python小程序获取树莓派的CPU和GPU温度) 我分别认真读了两段脚本 ...
最新文章
- python刷新cdn_api 刷新是什么-和api 刷新相关的问题-阿里云开发者社区
- 安装adobe acrobat导致回滚
- 借款人死亡后,贷款必须由家属偿还吗?
- 程序员犯的非技术错误(Top 5)
- 视频人脸检测——Dlib版(六)
- 如何在RTSP/RTMP直播过程中加入SEI扩展数据发送和接收解析
- 1.RABBITMQ 入门 - WINDOWS - 获取,安装,配置
- SFML 与 VS2015 的安装配置
- ajax怎么模拟请求,如何模拟AJAX请求?
- linux nginx php7,linux nginx配置php7
- java设计模式--基础思想总结--抽象类与架构设计思想
- C++编程语言中接收用户输入参数的方法
- 九度OJ 1175:打牌 (模式匹配)
- cocos2d笔记 (3)cocos2d四个基本概念
- 一位五年工作经验架构师的感悟
- C#读取MP3文件的专辑图片和ID3V2Tag信息(带代码)
- css钢铁侠视角,css练习制作钢铁侠胸口的小型核反应堆
- 文明与征服阵容搭配,文明与征服阵容推荐
- vue3 ts 挂载全局vscode volar使用飘红
- http header