【AI教做人】UnityEditor扩展开发--关卡编辑器SceneView 面板入门代码

发布时间:2026/7/22 15:42:16
【AI教做人】UnityEditor扩展开发--关卡编辑器SceneView 面板入门代码 最终截图如下实现 SceneView 的扩展开发找了一个开源项目就一个代码------就好像ParticleSystem 可以做Scene View 的操作浮空面板https://github.com/unitycoder/OverlayWindowContainer但是我也不知道怎么用啊用AI写一个代码//需要用到上面的github 代码, //一直在Update 创建可能有些问题using UnityEditor; using UnityEngine; using Plugins.Editor; //需要用到上面的github 代码Container public class SceneViewOverlayWindow : EditorWindow { private OverlayWindowContainer infoOverlay; private OverlayWindowContainer toolsOverlay; private bool overlaysActive; private string infoText 暂无信息; private Color overlayColor Color.white; [MenuItem(Tools/SceneView Overlay 面板)] private static void Open() { var win GetWindowSceneViewOverlayWindow(SceneView Overlay); win.minSize new Vector2(360, 280); win.Show(); } private void OnEnable() { SceneView.duringSceneGui OnSceneGUI; } private void OnDisable() { SceneView.duringSceneGui - OnSceneGUI; overlaysActive false; } private void OnSceneGUI(SceneView sceneView) { if (!overlaysActive) return; // 第一个面板场景信息 if (infoOverlay null) { infoOverlay new OverlayWindowContainer( new GUIContent(场景信息), DrawInfoOverlay, 0, this, OverlayWindowContainer.WindowDisplayOption.OneWindowPerTitle); } infoOverlay.OnGUI(); // 第二个面板快捷工具 if (toolsOverlay null) { toolsOverlay new OverlayWindowContainer( new GUIContent(快捷工具), DrawToolsOverlay, 1, this, OverlayWindowContainer.WindowDisplayOption.OneWindowPerTitle); } toolsOverlay.OnGUI(); } private void DrawInfoOverlay(UnityEngine.Object target, SceneView sceneView) { var activeScene UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene(); EditorGUILayout.LabelField(场景, activeScene.name); EditorGUILayout.LabelField(根对象, activeScene.rootCount.ToString()); EditorGUILayout.LabelField(路径, activeScene.path); if (Selection.activeGameObject ! null) { EditorGUILayout.Space(4); EditorGUILayout.LabelField(选中, Selection.activeGameObject.name); EditorGUILayout.LabelField(位置, Selection.activeGameObject.transform.position.ToString(F2)); } } private void DrawToolsOverlay(UnityEngine.Object target, SceneView sceneView) { GUILayout.Label(快捷操作, EditorStyles.boldLabel); if (GUILayout.Button(创建空对象, EditorStyles.miniButton)) { var go new GameObject(GameObject); Undo.RegisterCreatedObjectUndo(go, Create GameObject); Selection.activeGameObject go; } if (GUILayout.Button(截图 SceneView, EditorStyles.miniButton)) { var path $Temp/SceneView_{System.DateTime.Now:HHmmss}.png; var tex CaptureSceneView(sceneView); if (tex ! null) { System.IO.File.WriteAllBytes(path, tex.EncodeToPNG()); Debug.Log($截图已保存: {path}); } } EditorGUILayout.Space(4); overlayColor EditorGUILayout.ColorField(颜色, overlayColor); } private Texture2D CaptureSceneView(SceneView sceneView) { var camera sceneView.camera; if (camera null) return null; var renderTexture camera.targetTexture; var currentRT RenderTexture.active; var rt new RenderTexture((int)sceneView.position.width, (int)sceneView.position.height, 24); camera.targetTexture rt; RenderTexture.active rt; camera.Render(); var tex new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply(); camera.targetTexture renderTexture; RenderTexture.active currentRT; Object.DestroyImmediate(rt); return tex; } private void OnGUI() { GUILayout.Space(8); EditorGUILayout.LabelField(SceneView Overlay 面板, EditorStyles.boldLabel); EditorGUILayout.HelpBox( 点击下方按钮在 SceneView 中显示/隐藏浮动面板。\n OverlayWindowContainer 通过反射调用 Unity 内部 SceneViewOverlay API。, MessageType.Info); GUILayout.Space(10); if (GUILayout.Button(overlaysActive ? 关闭 Overlay 面板 : 开启 Overlay 面板, GUILayout.Height(32))) { overlaysActive !overlaysActive; SceneView.RepaintAll(); } GUILayout.Space(8); if (overlaysActive) { EditorGUILayout.LabelField(状态, 已激活, EditorStyles.boldLabel); EditorGUILayout.LabelField(面板数量, 2 (场景信息 快捷工具)); } else { EditorGUILayout.LabelField(状态, 未激活, EditorStyles.boldLabel); } } }无厘头的参考。Net Framework正寻思个要不要再装个vs2015?左看右看vs2015好像最低支持.net framework 4啊难道要装个vs2010?我记得肯定用vs2015开发过插件呀微软这么正log4cat这种开源都编译不了的啊万一来个framework3.5的开源也跑不了都要重新安装对的环境吗微软二十年每年一个版本怎么才能装对啊。。。。反正最后搜到一句“xxxxxxxxxx就知道解决方法 了。net 天生不是开源的放弃了紧靠官方更新到猴年马月参考https://www.outsystems.com/blog/posts/migrating-from-net-framework-to-net-core/https://blog.csdn.net/weixin_40007175/article/details/111199573Docker Hub必须添加对程序集“netstandard, Version2.0.0.0, Cultureneutral, PublicKeyTokencc7b13ffcd2ddd51”的引用_hello_yajing的博客-CSDN博客_必须添加netstandard