Initial Unity project commit
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using Test_2022.LightsControl;
|
||||
|
||||
[CustomEditor(typeof(LightsControlController))]
|
||||
[CanEditMultipleObjects]
|
||||
public sealed class LightsControlControllerEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
|
||||
{
|
||||
EditorGUILayout.LabelField("Tools", EditorStyles.boldLabel);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Add Selected"))
|
||||
AddSelectedLights(false);
|
||||
|
||||
if (GUILayout.Button("Add Selected (+Children)"))
|
||||
AddSelectedLights(true);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Find All (Clear)"))
|
||||
FindAll(true);
|
||||
|
||||
if (GUILayout.Button("Find All (Append)"))
|
||||
FindAll(false);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Remove Nulls"))
|
||||
RemoveNulls();
|
||||
|
||||
if (GUILayout.Button("Clear List"))
|
||||
ClearList();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
|
||||
{
|
||||
EditorGUILayout.LabelField("Runtime", EditorStyles.boldLabel);
|
||||
|
||||
if (!Application.isPlaying)
|
||||
EditorGUILayout.HelpBox("进入 Play 模式后才会执行闪烁/定时协程。也可以在组件上启用 Auto Start On Enable 自动开始。", MessageType.Info);
|
||||
|
||||
using (new EditorGUI.DisabledScope(!Application.isPlaying))
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
if (GUILayout.Button("Start"))
|
||||
StartControl();
|
||||
|
||||
if (GUILayout.Button("Stop (Restore)"))
|
||||
StopControl(true);
|
||||
|
||||
if (GUILayout.Button("Stop (No Restore)"))
|
||||
StopControl(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddSelectedLights(bool includeChildren)
|
||||
{
|
||||
var selected = Selection.gameObjects;
|
||||
if (selected == null || selected.Length == 0)
|
||||
return;
|
||||
|
||||
var toAdd = new List<Light>();
|
||||
for (var i = 0; i < selected.Length; i++)
|
||||
{
|
||||
var go = selected[i];
|
||||
if (go == null)
|
||||
continue;
|
||||
|
||||
if (includeChildren)
|
||||
toAdd.AddRange(go.GetComponentsInChildren<Light>(true));
|
||||
else
|
||||
{
|
||||
var l = go.GetComponent<Light>();
|
||||
if (l != null)
|
||||
toAdd.Add(l);
|
||||
}
|
||||
}
|
||||
|
||||
if (toAdd.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var t in targets)
|
||||
{
|
||||
var c = (LightsControlController)t;
|
||||
Undo.RecordObject(c, "Add Lights");
|
||||
c.AddLights(toAdd);
|
||||
EditorUtility.SetDirty(c);
|
||||
MarkSceneDirty(c);
|
||||
}
|
||||
}
|
||||
|
||||
void FindAll(bool clearFirst)
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
var c = (LightsControlController)t;
|
||||
Undo.RecordObject(c, "Find Lights In Scene");
|
||||
c.FindAllLightsInScene(clearFirst);
|
||||
EditorUtility.SetDirty(c);
|
||||
MarkSceneDirty(c);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveNulls()
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
var c = (LightsControlController)t;
|
||||
Undo.RecordObject(c, "Remove Null Lights");
|
||||
c.RemoveNullLights();
|
||||
EditorUtility.SetDirty(c);
|
||||
MarkSceneDirty(c);
|
||||
}
|
||||
}
|
||||
|
||||
void ClearList()
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
var c = (LightsControlController)t;
|
||||
Undo.RecordObject(c, "Clear Lights");
|
||||
c.ClearLights();
|
||||
EditorUtility.SetDirty(c);
|
||||
MarkSceneDirty(c);
|
||||
}
|
||||
}
|
||||
|
||||
void StartControl()
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
var c = (LightsControlController)t;
|
||||
c.StartControl();
|
||||
}
|
||||
}
|
||||
|
||||
void StopControl(bool restoreBaseState)
|
||||
{
|
||||
foreach (var t in targets)
|
||||
{
|
||||
var c = (LightsControlController)t;
|
||||
c.StopControl(restoreBaseState);
|
||||
}
|
||||
}
|
||||
|
||||
static void MarkSceneDirty(LightsControlController c)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
return;
|
||||
if (!c.gameObject.scene.IsValid())
|
||||
return;
|
||||
EditorSceneManager.MarkSceneDirty(c.gameObject.scene);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1896a40637d32a44f80533164ded9c8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user