mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2026-10-11 01:48:07 +08:00
Refactored the LightsManager to use a ScrollingPoll, and made the turn-off vanilla lights more robust regarding switching scenes with turned-off lights. Also renamed the "AnimatirUI" folder to "Cells".
This commit is contained in:
1 parent
467d5cf2d5
commit
147b846995
4 files changed
+151
-101
No files matched your search
+43
-101
@@ -15,7 +15,7 @@ using UnityEngine;
|
||||
|
||||
namespace UnityExplorer.UI.Panels
|
||||
{
|
||||
internal class LightsManager : UEPanel
|
||||
public class LightsManager : UEPanel, ICellPoolDataSource<LightCell>
|
||||
{
|
||||
public LightsManager(UIBase owner) : base(owner)
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace UnityExplorer.UI.Panels
|
||||
public override string Name => "Lights Manager";
|
||||
public override UIManager.Panels PanelType => UIManager.Panels.LightsManager;
|
||||
public override int MinWidth => 650;
|
||||
public override int MinHeight => 500;
|
||||
public override int MinHeight => 200;
|
||||
public override Vector2 DefaultAnchorMin => new(0.4f, 0.4f);
|
||||
public override Vector2 DefaultAnchorMax => new(0.6f, 0.6f);
|
||||
public override bool NavButtonWanted => true;
|
||||
@@ -34,12 +34,42 @@ namespace UnityExplorer.UI.Panels
|
||||
static ButtonRef createPointLightButton;
|
||||
List<UnityEngine.Light> vanillaGameLights = new List<UnityEngine.Light>();
|
||||
|
||||
List<GameObject> CreatedLights = new List<GameObject>();
|
||||
List<GameObject> UIElements = new List<GameObject>();
|
||||
public List<GameObject> CreatedLights = new List<GameObject>();
|
||||
//Declaring a counter instead of just using the length of the createdLight list in case we delete lights, so we don't end up with two lists with the same name.
|
||||
int lightCounter = 0;
|
||||
public int lightCounter = 0;
|
||||
float defaultIntensity = 10;
|
||||
|
||||
public ScrollPool<LightCell> lightsScrollPool;
|
||||
public int ItemCount => CreatedLights.Count;
|
||||
private static bool DoneScrollPoolInit;
|
||||
|
||||
public override void SetActive(bool active)
|
||||
{
|
||||
base.SetActive(active);
|
||||
if (active && !DoneScrollPoolInit)
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(this.Rect);
|
||||
lightsScrollPool.Initialize(this);
|
||||
DoneScrollPoolInit = true;
|
||||
}
|
||||
|
||||
lightsScrollPool.Refresh(true, false);
|
||||
}
|
||||
|
||||
public void OnCellBorrowed(LightCell cell) { }
|
||||
|
||||
public void SetCell(LightCell cell, int index){
|
||||
if (index >= CreatedLights.Count)
|
||||
{
|
||||
cell.Disable();
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject light = CreatedLights[index];
|
||||
cell.light = light;
|
||||
cell.label.text = light.name;
|
||||
}
|
||||
|
||||
// ~~~~~~~~ UI construction / callbacks ~~~~~~~~
|
||||
|
||||
protected override void ConstructPanelContent()
|
||||
@@ -69,13 +99,15 @@ namespace UnityExplorer.UI.Panels
|
||||
vanillaLightsToggle.isOn = true;
|
||||
toggleText.text = "Toggle Game Lights";
|
||||
|
||||
ListCreatedLights();
|
||||
lightsScrollPool = UIFactory.CreateScrollPool<LightCell>(ContentRoot, "NodeList", out GameObject scrollObj,
|
||||
out GameObject scrollContent, new Color(0.03f, 0.03f, 0.03f));
|
||||
UIFactory.SetLayoutElement(scrollObj, flexibleWidth: 9999, flexibleHeight: 9999);
|
||||
}
|
||||
|
||||
private void ToggleGameLights(bool areLightsActive){
|
||||
//Update the list of game lights
|
||||
if (!areLightsActive){
|
||||
var gameLights = RuntimeHelper.FindObjectsOfTypeAll<UnityEngine.Light>();
|
||||
var gameLights = RuntimeHelper.FindObjectsOfTypeAll<UnityEngine.Light>().Where(l => l.enabled);
|
||||
|
||||
//ExplorerCore.LogWarning($"Found ligths: {gameLights.Length}");
|
||||
|
||||
@@ -91,70 +123,13 @@ namespace UnityExplorer.UI.Panels
|
||||
else{
|
||||
foreach(UnityEngine.Light light in vanillaGameLights)
|
||||
{
|
||||
light.enabled = true;
|
||||
// In case the light was destroyed
|
||||
if (light != null) light.enabled = true;
|
||||
}
|
||||
vanillaGameLights.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void ListCreatedLights(){
|
||||
//Refresh list
|
||||
foreach (var comp in UIElements){
|
||||
UnityEngine.Object.Destroy(comp);
|
||||
//UIElements.Remove(comp);
|
||||
}
|
||||
|
||||
foreach (var light in CreatedLights) {
|
||||
DrawOptionsLights(light);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawOptionsLights(GameObject light){
|
||||
GameObject horiGroup = UIFactory.CreateHorizontalGroup(ContentRoot, "LightOptions", true, false, true, false, 4,
|
||||
default, new Color(1, 1, 1, 0), TextAnchor.MiddleLeft);
|
||||
UIFactory.SetLayoutElement(horiGroup, minHeight: 25, flexibleWidth: 9999);
|
||||
UIElements.Add(horiGroup);
|
||||
|
||||
//Active toggle
|
||||
Toggle useGameCameraToggle = new Toggle();
|
||||
GameObject toggleObj = UIFactory.CreateToggle(horiGroup, "UseGameCameraToggle", out useGameCameraToggle, out Text toggleText);
|
||||
UIFactory.SetLayoutElement(toggleObj, minHeight: 25, flexibleWidth: 9999);
|
||||
useGameCameraToggle.onValueChanged.AddListener(value => { light.SetActive(value); });
|
||||
useGameCameraToggle.isOn = true;
|
||||
toggleText.text = light.name;
|
||||
|
||||
//Toggle visualizer
|
||||
ButtonRef toggleVisualizerButton = UIFactory.CreateButton(horiGroup, "ToggleVisualizer", "Toggle Visualizer");
|
||||
UIFactory.SetLayoutElement(toggleVisualizerButton.GameObject, minWidth: 100, minHeight: 25, flexibleWidth: 9999);
|
||||
toggleVisualizerButton.OnClick += () => {ToggleVisualizer(light);};
|
||||
|
||||
//Inspect GameObject
|
||||
ButtonRef inspectButton = UIFactory.CreateButton(horiGroup, "InspectButton", "Config");
|
||||
UIFactory.SetLayoutElement(inspectButton.GameObject, minWidth: 80, minHeight: 25, flexibleWidth: 9999);
|
||||
inspectButton.OnClick += () => InspectorManager.InspectWithFilters(light.GetComponent<Light>(), "Light",
|
||||
UnityExplorer.Inspectors.MemberFilter.Property |
|
||||
UnityExplorer.Inspectors.MemberFilter.Field
|
||||
);
|
||||
|
||||
//Move to Camera
|
||||
ButtonRef moveToCameraButton = UIFactory.CreateButton(horiGroup, "MoveToCamera", "Move to Camera");
|
||||
UIFactory.SetLayoutElement(moveToCameraButton.GameObject, minWidth: 100, minHeight: 25, flexibleWidth: 9999);
|
||||
moveToCameraButton.OnClick += () => {CopyFreeCamTransform(light);};
|
||||
|
||||
//Attatch to Camera
|
||||
//TODO
|
||||
|
||||
//Copy
|
||||
ButtonRef copyButton = UIFactory.CreateButton(horiGroup, "Copy", "Copy");
|
||||
UIFactory.SetLayoutElement(copyButton.GameObject, minWidth: 50, minHeight: 25, flexibleWidth: 9999);
|
||||
copyButton.OnClick += () => {CopyLight(light);};
|
||||
|
||||
//Destroy Light
|
||||
ButtonRef destroyButton = UIFactory.CreateButton(horiGroup, "DestroyButton", "Destroy");
|
||||
UIFactory.SetLayoutElement(destroyButton.GameObject, minWidth: 80, minHeight: 25, flexibleWidth: 9999);
|
||||
destroyButton.OnClick += () => {DestroyLight(light);};
|
||||
}
|
||||
|
||||
private void CreateLight(LightType requestedType){
|
||||
GameObject obj = new($"UE - Light {lightCounter}");
|
||||
//DontDestroyOnLoad(obj);
|
||||
@@ -189,47 +164,14 @@ namespace UnityExplorer.UI.Panels
|
||||
break;
|
||||
}
|
||||
|
||||
CopyFreeCamTransform(obj);
|
||||
LightCell.CopyFreeCamTransform(obj);
|
||||
|
||||
CreatedLights.Add(obj);
|
||||
ListCreatedLights();
|
||||
lightsScrollPool.Refresh(true, false);
|
||||
|
||||
lightCounter++;
|
||||
}
|
||||
|
||||
private void ToggleVisualizer(GameObject light){
|
||||
GameObject visualizer = light.transform.GetChild(0).gameObject;
|
||||
visualizer.SetActive(!visualizer.activeSelf);
|
||||
}
|
||||
|
||||
private void CopyLight(GameObject light){
|
||||
GameObject newLight = UnityEngine.Object.Instantiate(light);
|
||||
CopyFreeCamTransform(newLight);
|
||||
newLight.name = $"UE - Light {lightCounter}";
|
||||
|
||||
CreatedLights.Add(newLight);
|
||||
ListCreatedLights();
|
||||
|
||||
lightCounter++;
|
||||
}
|
||||
|
||||
private void DestroyLight(GameObject light){
|
||||
CreatedLights.Remove(light);
|
||||
UnityEngine.Object.Destroy(light);
|
||||
ListCreatedLights();
|
||||
}
|
||||
|
||||
private void CopyFreeCamTransform(GameObject obj){
|
||||
Camera freeCam = FreeCamPanel.ourCamera;
|
||||
|
||||
if (freeCam != null) {
|
||||
obj.transform.position = freeCam.transform.position;
|
||||
obj.transform.rotation = freeCam.transform.rotation;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GameObject AddInputField(GameObject parent, string name, string labelText, string placeHolder, Action<string> onInputEndEdit)
|
||||
{
|
||||
Text posLabel = UIFactory.CreateLabel(parent, $"{name}_Label", labelText);
|
||||
|
||||
Reference in new issue
Block a user