This commit is contained in:
MuHua-123
2025-06-17 10:53:45 +08:00
parent c6d9b71e95
commit 5374616980
87 changed files with 2265 additions and 1019 deletions
@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using MuHua;
namespace MuHuaEditor {
/// <summary>
/// 定义对带有 `CustomLabelAttribute` 特性的字段的面板内容的绘制行为。
/// </summary>
[CustomPropertyDrawer(typeof(CustomLabelAttribute))]
public class CustomLabelDrawer : PropertyDrawer {
private GUIContent _label = null;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if (_label == null) {
string name = (attribute as CustomLabelAttribute).name;
_label = new GUIContent(name);
}
EditorGUI.PropertyField(position, property, _label);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc3616839f041cc4d929eb2fc85d09ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+18
View File
@@ -0,0 +1,18 @@
{
"name": "MuHuaEditor",
"rootNamespace": "",
"references": [
"GUID:b88cc9b1727cc3a45a42964e99e119c1"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 37896a819dacc814aaaa2b9e188161a0
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+70
View File
@@ -0,0 +1,70 @@
using UnityEditor;
using UnityEngine;
using MuHua;
namespace MuHuaEditor {
[CustomPropertyDrawer(typeof(SceneNameAttribute))]
public class SceneNameDrawer : PropertyDrawer {
int sceneIndex = -1;
GUIContent[] sceneNames;
readonly string[] scenePathSplit = { "/", ".unity" };
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if (EditorBuildSettings.scenes.Length == 0) return;
if (sceneIndex == -1)
GetSceneNameArray(property);
int oldIndex = sceneIndex;
sceneIndex = EditorGUI.Popup(position, label, sceneIndex, sceneNames);
if (oldIndex != sceneIndex)
property.stringValue = sceneNames[sceneIndex].text;
}
private void GetSceneNameArray(SerializedProperty property) {
var scenes = EditorBuildSettings.scenes;
//初始化数组
sceneNames = new GUIContent[scenes.Length];
for (int i = 0; i < sceneNames.Length; i++) {
string path = scenes[i].path;
string[] splitPath = path.Split(scenePathSplit, System.StringSplitOptions.RemoveEmptyEntries);
string sceneName = "";
if (splitPath.Length > 0) {
sceneName = splitPath[splitPath.Length - 1];
}
else {
sceneName = "(Deleted Scene)";
}
sceneNames[i] = new GUIContent(sceneName);
}
if (sceneNames.Length == 0) {
sceneNames = new[] { new GUIContent("Check Your Build Settings") };
}
if (!string.IsNullOrEmpty(property.stringValue)) {
bool nameFound = false;
for (int i = 0; i < sceneNames.Length; i++) {
if (sceneNames[i].text == property.stringValue) {
sceneIndex = i;
nameFound = true;
break;
}
}
if (nameFound == false)
sceneIndex = 0;
}
else {
sceneIndex = 0;
}
property.stringValue = sceneNames[sceneIndex].text;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7f8370bd97b1c943b8584a1dcb97445
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: