mirror of
https://github.com/originalnicodr/CinematicUnityExplorer.git
synced 2026-10-10 21:13:15 +08:00
Added a panel to spawn and control lights.
This commit is contained in:
@@ -31,7 +31,7 @@ namespace UnityExplorer.UI.Panels
|
||||
internal static Camera lastMainCamera;
|
||||
internal static FreeCamBehaviour freeCamScript;
|
||||
|
||||
internal static float desiredMoveSpeed = 10f;
|
||||
internal static float desiredMoveSpeed = 5f;
|
||||
|
||||
internal static Vector3 originalCameraPosition;
|
||||
internal static Quaternion originalCameraRotation;
|
||||
|
||||
+129
-65
@@ -1,6 +1,8 @@
|
||||
using UniverseLib.Input;
|
||||
using UniverseLib.UI;
|
||||
using UniverseLib.UI.Models;
|
||||
using UniverseLib.UI.Widgets;
|
||||
using UniverseLib.UI.Widgets.ScrollView;
|
||||
#if UNHOLLOWER
|
||||
using UnhollowerRuntimeLib;
|
||||
#endif
|
||||
@@ -21,120 +23,182 @@ namespace UnityExplorer.UI.Panels
|
||||
|
||||
public override string Name => "Lights Manager";
|
||||
public override UIManager.Panels PanelType => UIManager.Panels.LightsManager;
|
||||
public override int MinWidth => 400;
|
||||
public override int MinHeight => 320;
|
||||
public override int MinWidth => 500;
|
||||
public override int MinHeight => 500;
|
||||
public override Vector2 DefaultAnchorMin => new(0.4f, 0.4f);
|
||||
public override Vector2 DefaultAnchorMax => new(0.6f, 0.6f);
|
||||
public override bool NavButtonWanted => true;
|
||||
public override bool ShouldSaveActiveState => true;
|
||||
|
||||
static ButtonRef createLightButton;
|
||||
static ButtonRef createSpotLightButton;
|
||||
static ButtonRef createPointLightButton;
|
||||
List<UnityEngine.Light> vanillaGameLights = new List<UnityEngine.Light>();
|
||||
|
||||
List<GameObject> CreatedLights = new List<GameObject>();
|
||||
List<GameObject> UIElements = 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;
|
||||
|
||||
// ~~~~~~~~ UI construction / callbacks ~~~~~~~~
|
||||
|
||||
//private PostProcessVolume volume;
|
||||
//private UniverseLib.UnityEngine.Rendering.Fog fog;
|
||||
|
||||
protected override void ConstructPanelContent()
|
||||
{
|
||||
//var getVolume = GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessVolume>();
|
||||
//volume = getVolume;
|
||||
//volume.profile.TryGetSettings(out fog);
|
||||
GameObject horiGroup = UIFactory.CreateHorizontalGroup(ContentRoot, "MainOptions", false, false, true, true, 3,
|
||||
default, new Color(1, 1, 1, 0), TextAnchor.MiddleLeft);
|
||||
UIFactory.SetLayoutElement(horiGroup, minHeight: 25, flexibleWidth: 9999);
|
||||
//UIElements.Add(horiGroup);
|
||||
|
||||
createLightButton = UIFactory.CreateButton(ContentRoot, "ToggleButton", "Create Light");
|
||||
UIFactory.SetLayoutElement(createLightButton.GameObject, minWidth: 150, minHeight: 25, flexibleWidth: 9999);
|
||||
createLightButton.OnClick += CreateLight;
|
||||
//Create SpotLight
|
||||
createSpotLightButton = UIFactory.CreateButton(horiGroup, "ToggleButton", "Create SpotLight");
|
||||
UIFactory.SetLayoutElement(createSpotLightButton.GameObject, minWidth: 150, minHeight: 25);
|
||||
createSpotLightButton.OnClick += () => CreateLight(LightType.Spot);
|
||||
|
||||
//Create PointLight
|
||||
createPointLightButton = UIFactory.CreateButton(horiGroup, "ToggleButton", "Create PointLight");
|
||||
UIFactory.SetLayoutElement(createPointLightButton.GameObject, minWidth: 150, minHeight: 25);
|
||||
createPointLightButton.OnClick += () => CreateLight(LightType.Point);
|
||||
|
||||
//Turn off vanilla lights
|
||||
Toggle vanillaLightsToggle = new Toggle();
|
||||
GameObject toggleObj = UIFactory.CreateToggle(horiGroup, "Toggle Game Lights", out vanillaLightsToggle, out Text toggleText);
|
||||
UIFactory.SetLayoutElement(toggleObj, minHeight: 25, flexibleWidth: 9999);
|
||||
vanillaLightsToggle.onValueChanged.AddListener(ToggleGameLights);
|
||||
vanillaLightsToggle.isOn = true;
|
||||
toggleText.text = "Toggle Game Lights";
|
||||
|
||||
ListCreatedLights();
|
||||
}
|
||||
|
||||
private void ToggleGameLights(bool areLightsActive){
|
||||
//Update the list of game lights
|
||||
if (!areLightsActive){
|
||||
#if MONO
|
||||
var gameLights = GameObject.FindObjectsOfType<Light>();
|
||||
#else
|
||||
var gameLights = UnityEngine.Object.FindObjectsOfType(Il2CppType.Of<UnityEngine.Light>());
|
||||
#endif
|
||||
//ExplorerCore.LogWarning($"Found ligths: {gameLights.Length}");
|
||||
|
||||
foreach(UnityEngine.Light light in gameLights)
|
||||
{
|
||||
//We want to avoid grabbing our own lights
|
||||
if(!light.name.Contains("UE - Light")){
|
||||
vanillaGameLights.Add(light);
|
||||
light.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
foreach(UnityEngine.Light light in vanillaGameLights)
|
||||
{
|
||||
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){
|
||||
//Active
|
||||
Toggle useGameCameraToggle = new Toggle();
|
||||
GameObject horiGroup = UIFactory.CreateHorizontalGroup(UIRoot, "LightOptions", true, true, true, true, 4,
|
||||
default, new Color(1, 1, 1, 0), TextAnchor.MiddleLeft);
|
||||
UIFactory.SetLayoutElement(horiGroup, minHeight: 25, flexibleWidth: 9999);
|
||||
UIElements.Add(horiGroup);
|
||||
|
||||
GameObject toggleObj = UIFactory.CreateToggle(ContentRoot, "UseGameCameraToggle", out useGameCameraToggle, out Text toggleText);
|
||||
//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 = "Activate";
|
||||
toggleText.text = light.name;
|
||||
|
||||
AddSpacer(5);
|
||||
//Inspect GameObject
|
||||
ButtonRef inspectButton = UIFactory.CreateButton(horiGroup, "InspectButton", "Config");
|
||||
UIFactory.SetLayoutElement(inspectButton.GameObject, minWidth: 80, minHeight: 25, flexibleWidth: 9999);
|
||||
inspectButton.OnClick += () => {InspectorManager.Inspect(light.GetComponent<Light>());};
|
||||
|
||||
//Color
|
||||
//GameObject color = (new CacheObject.IValues.InteractiveColor()).CreateContent(light);
|
||||
InputFieldRef colorInput;
|
||||
//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);};
|
||||
|
||||
GameObject color = AddInputField("Color", "Color:", "eg. 1 1 1", out colorInput, (input) => { ColorInput_OnEndEdit(light, input); });
|
||||
//Attatch to Camera
|
||||
//TODO
|
||||
|
||||
AddSpacer(5);
|
||||
//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(){
|
||||
GameObject obj = new("UE - Light");
|
||||
private void CreateLight(LightType requestedType){
|
||||
GameObject obj = new($"UE - Light {lightCounter}");
|
||||
//DontDestroyOnLoad(obj);
|
||||
obj.hideFlags = HideFlags.HideAndDontSave;
|
||||
obj.AddComponent<UnityEngine.Light>();
|
||||
|
||||
Transform freeCamTransform = FreeCamTransform();
|
||||
obj.GetComponent<Light>().type = requestedType;
|
||||
|
||||
obj.transform.position = freeCamTransform.position;
|
||||
obj.transform.rotation = freeCamTransform.rotation;
|
||||
switch(requestedType){
|
||||
case LightType.Spot:
|
||||
obj.GetComponent<Light>().intensity = 200;
|
||||
obj.GetComponent<Light>().range = 1000;
|
||||
break;
|
||||
case LightType.Point:
|
||||
obj.GetComponent<Light>().intensity = 10;
|
||||
break;
|
||||
}
|
||||
|
||||
CopyFreeCamTransform(obj);
|
||||
|
||||
CreatedLights.Add(obj);
|
||||
ConstructPanelContent();
|
||||
ListCreatedLights();
|
||||
|
||||
lightCounter++;
|
||||
}
|
||||
|
||||
private Transform FreeCamTransform(){
|
||||
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) {
|
||||
return freeCam.transform;
|
||||
}
|
||||
else
|
||||
return new Transform();
|
||||
}
|
||||
obj.transform.position = freeCam.transform.position;
|
||||
obj.transform.rotation = freeCam.transform.rotation;
|
||||
|
||||
void AddSpacer(int height)
|
||||
{
|
||||
GameObject obj = UIFactory.CreateUIObject("Spacer", ContentRoot);
|
||||
UIFactory.SetLayoutElement(obj, minHeight: height, flexibleHeight: 0);
|
||||
}
|
||||
|
||||
GameObject AddInputField(string name, string labelText, string placeHolder, out InputFieldRef inputField, Action<string> onInputEndEdit)
|
||||
{
|
||||
GameObject row = UIFactory.CreateHorizontalGroup(ContentRoot, $"{name}_Group", false, false, true, true, 3, default, new(1, 1, 1, 0));
|
||||
|
||||
Text posLabel = UIFactory.CreateLabel(row, $"{name}_Label", labelText);
|
||||
UIFactory.SetLayoutElement(posLabel.gameObject, minWidth: 100, minHeight: 25);
|
||||
|
||||
inputField = UIFactory.CreateInputField(row, $"{name}_Input", placeHolder);
|
||||
UIFactory.SetLayoutElement(inputField.GameObject, minWidth: 125, minHeight: 25, flexibleWidth: 9999);
|
||||
inputField.Component.GetOnEndEdit().AddListener(onInputEndEdit);
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
|
||||
void ColorInput_OnEndEdit(GameObject ob, string input)
|
||||
{
|
||||
EventSystemHelper.SetSelectedGameObject(null);
|
||||
|
||||
if (!ParseUtility.TryParse(input, out Vector3 parsed, out Exception parseEx))
|
||||
{
|
||||
ExplorerCore.LogWarning($"Could not parse value: {parseEx.ReflectionExToString()}");
|
||||
//positionInput.Text = ParseUtility.ToStringForInput<Vector3>(lastSetCameraPosition);
|
||||
return;
|
||||
}
|
||||
|
||||
ob.GetComponent<Light>().color = new Color(parsed.x, parsed.y, parsed.z, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user