301 lines
13 KiB
C#
301 lines
13 KiB
C#
// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved.
|
|
// This code can only be used under the standard Unity Asset Store End User License Agreement
|
|
// A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms
|
|
|
|
using System.Collections.Generic;
|
|
using Doozy.Editor.Common.Utils;
|
|
using Doozy.Editor.EditorUI;
|
|
using Doozy.Editor.EditorUI.Components;
|
|
using Doozy.Editor.EditorUI.Components.Internal;
|
|
using Doozy.Editor.EditorUI.ScriptableObjects.Colors;
|
|
using Doozy.Editor.EditorUI.Utils;
|
|
using Doozy.Editor.Interfaces;
|
|
using Doozy.Runtime.UIElements.Extensions;
|
|
using Doozy.Runtime.UIManager.Input;
|
|
using Doozy.Runtime.UIManager.ScriptableObjects;
|
|
using UnityEditor;
|
|
using UnityEditor.UIElements;
|
|
using UnityEngine;
|
|
// ReSharper disable RedundantUsingDirective
|
|
using UnityEngine.UIElements; //leave this here to avoid errors in newer versions of Unity (THANKS UNITY)!!! - they moved IntegerField and FloatField to the UnityEngine.UIElements namespace
|
|
// ReSharper restore RedundantUsingDirective
|
|
using ObjectNames = Doozy.Runtime.Common.Utils.ObjectNames;
|
|
|
|
namespace Doozy.Editor.UIManager.Layouts.Settings
|
|
{
|
|
public sealed class InputSettingsWindowLayout : FluidWindowLayout, IDashboardSettingsWindowLayout
|
|
{
|
|
public int order => 0;
|
|
|
|
public override string layoutName => "Input Settings";
|
|
public override List<Texture2D> animatedIconTextures => EditorSpriteSheets.UIManager.Icons.KeyMapper;
|
|
public override Color accentColor => EditorColors.Default.SettingsComponent;
|
|
public override EditorSelectableColorInfo selectableAccentColor => EditorSelectableColors.Default.SettingsComponent;
|
|
|
|
private SerializedObject serializedObject { get; set; }
|
|
private SerializedProperty propertyDefaultPlayerIndex { get; set; }
|
|
private SerializedProperty propertyMultiplayerMode { get; set; }
|
|
private SerializedProperty propertyBackButtonCooldown { get; set; }
|
|
|
|
private SerializedProperty propertyBackButtonVirtualButtonName { get; set; }
|
|
|
|
private IntegerField defaultPlayerIndexIntegerField { get; set; }
|
|
private FluidToggleSwitch multiplayerModeSwitch { get; set; }
|
|
private FloatField backButtonCooldownFloatField { get; set; }
|
|
|
|
private TextField backButtonVirtualButtonNameTextField { get; set; }
|
|
|
|
private static IEnumerable<Texture2D> resetTextures => EditorSpriteSheets.EditorUI.Icons.Reset;
|
|
private FluidButton resetPlayerIndexButton { get; set; }
|
|
private FluidButton resetMultiplayerModeButton { get; set; }
|
|
private FluidButton resetBackButtonCooldownButton { get; set; }
|
|
private FluidButton saveButton { get; set; }
|
|
|
|
private FluidField playerIndexField { get; set; }
|
|
private FluidField playerMultiplayerMode { get; set; }
|
|
private FluidField playerBackButtonCooldown { get; set; }
|
|
private FluidField backButtonVirtualButtonName { get; set; }
|
|
|
|
private FluidToggleButtonTab inputSystemPackageTabButton { get; set; }
|
|
private FluidToggleButtonTab legacyInputManagerTabButton { get; set; }
|
|
private FluidToggleButtonTab customInputTabButton { get; set; }
|
|
|
|
public override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
multiplayerModeSwitch?.Recycle();
|
|
playerIndexField?.Recycle();
|
|
playerMultiplayerMode?.Recycle();
|
|
playerBackButtonCooldown?.Recycle();
|
|
backButtonVirtualButtonName?.Recycle();
|
|
resetPlayerIndexButton?.Recycle();
|
|
resetBackButtonCooldownButton?.Recycle();
|
|
resetMultiplayerModeButton?.Recycle();
|
|
saveButton?.Recycle();
|
|
|
|
inputSystemPackageTabButton?.Recycle();
|
|
legacyInputManagerTabButton?.Recycle();
|
|
customInputTabButton?.Recycle();
|
|
}
|
|
|
|
public InputSettingsWindowLayout()
|
|
{
|
|
AddHeader("Input Settings", "Runtime Global Settings", animatedIconTextures);
|
|
sideMenu.Dispose(); //remove side menu
|
|
FindProperties();
|
|
Initialize();
|
|
Compose();
|
|
}
|
|
|
|
private void FindProperties()
|
|
{
|
|
serializedObject = new SerializedObject(UIManagerInputSettings.instance);
|
|
propertyDefaultPlayerIndex = serializedObject.FindProperty("DefaultPlayerIndex");
|
|
propertyMultiplayerMode = serializedObject.FindProperty("MultiplayerMode");
|
|
propertyBackButtonCooldown = serializedObject.FindProperty("BackButtonCooldown");
|
|
propertyBackButtonVirtualButtonName = serializedObject.FindProperty("BackButtonVirtualButtonName");
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
defaultPlayerIndexIntegerField =
|
|
DesignUtils.NewIntegerField(propertyDefaultPlayerIndex)
|
|
.SetTooltip("Default player index value (used for global user)")
|
|
.SetStyleWidth(60);
|
|
|
|
multiplayerModeSwitch =
|
|
FluidToggleSwitch.Get()
|
|
.SetTooltip("True if Multiplayer Mode is enabled")
|
|
.SetToggleAccentColor(selectableAccentColor)
|
|
.BindToProperty(propertyMultiplayerMode);
|
|
|
|
backButtonCooldownFloatField =
|
|
DesignUtils.NewFloatField(propertyBackButtonCooldown)
|
|
.SetTooltip("Cooldown after the 'Back' button was fired (to prevent spamming and accidental double execution)")
|
|
.SetStyleWidth(60);
|
|
|
|
resetPlayerIndexButton =
|
|
DesignUtils.SystemButton(resetTextures)
|
|
.SetTooltip("Reset")
|
|
.SetOnClick(() =>
|
|
{
|
|
propertyDefaultPlayerIndex.intValue = -UIManagerInputSettings.k_LifeTheUniverseAndEverything;
|
|
serializedObject.ApplyModifiedProperties();
|
|
});
|
|
|
|
resetMultiplayerModeButton =
|
|
DesignUtils.SystemButton(resetTextures)
|
|
.SetTooltip("Reset")
|
|
.SetOnClick(() =>
|
|
{
|
|
propertyMultiplayerMode.boolValue = false;
|
|
serializedObject.ApplyModifiedProperties();
|
|
});
|
|
|
|
resetBackButtonCooldownButton =
|
|
DesignUtils.SystemButton(resetTextures)
|
|
.SetTooltip("Reset")
|
|
.SetOnClick(() =>
|
|
{
|
|
propertyBackButtonCooldown.floatValue = UIManagerInputSettings.k_BackButtonCooldown;
|
|
serializedObject.ApplyModifiedProperties();
|
|
});
|
|
|
|
playerIndexField =
|
|
FluidField.Get()
|
|
.SetStyleFlexGrow(0)
|
|
.SetElementSize(ElementSize.Normal)
|
|
.SetLabelText("Default Player Index")
|
|
.AddFieldContent
|
|
(
|
|
DesignUtils.row
|
|
.AddFlexibleSpace()
|
|
.AddChild(defaultPlayerIndexIntegerField.DisableElement())
|
|
.AddSpaceBlock()
|
|
.AddChild(resetPlayerIndexButton)
|
|
);
|
|
|
|
playerMultiplayerMode =
|
|
FluidField.Get()
|
|
.SetStyleFlexGrow(0)
|
|
.SetElementSize(ElementSize.Normal)
|
|
.SetLabelText("Multiplayer Mode")
|
|
.AddFieldContent
|
|
(
|
|
DesignUtils.row
|
|
.AddFlexibleSpace()
|
|
.AddChild(multiplayerModeSwitch)
|
|
.AddSpaceBlock()
|
|
.AddChild(resetMultiplayerModeButton)
|
|
);
|
|
|
|
playerBackButtonCooldown =
|
|
FluidField.Get()
|
|
.SetStyleFlexGrow(0)
|
|
.SetElementSize(ElementSize.Normal)
|
|
.SetLabelText("'Back' button cooldown")
|
|
.AddFieldContent
|
|
(
|
|
DesignUtils.row
|
|
.AddFlexibleSpace()
|
|
.AddChild(backButtonCooldownFloatField)
|
|
.AddSpaceBlock()
|
|
.AddChild(resetBackButtonCooldownButton)
|
|
);
|
|
|
|
saveButton =
|
|
FluidButton.Get()
|
|
.SetButtonStyle(ButtonStyle.Contained)
|
|
.SetElementSize(ElementSize.Small)
|
|
.SetLabelText("Save")
|
|
.SetIcon(EditorSpriteSheets.EditorUI.Icons.Save)
|
|
.SetOnClick(() =>
|
|
{
|
|
EditorUtility.SetDirty(UIManagerInputSettings.instance);
|
|
AssetDatabase.SaveAssets();
|
|
});
|
|
|
|
backButtonVirtualButtonNameTextField =
|
|
DesignUtils.NewTextField(propertyBackButtonVirtualButtonName)
|
|
.SetTooltip("Name of the virtual button that will be used as 'Back' button")
|
|
.SetStyleWidth(120);
|
|
|
|
backButtonVirtualButtonName =
|
|
FluidField.Get()
|
|
.SetStyleFlexGrow(0)
|
|
.SetElementSize(ElementSize.Normal)
|
|
.SetLabelText("'Back' button virtual button name")
|
|
.AddFieldContent
|
|
(
|
|
DesignUtils.row
|
|
.AddFlexibleSpace()
|
|
.AddChild(backButtonVirtualButtonNameTextField)
|
|
);
|
|
|
|
FluidToggleButtonTab GetTab() =>
|
|
FluidToggleButtonTab.Get()
|
|
.SetToggleAccentColor(selectableAccentColor)
|
|
.SetContainerColorOff(DesignUtils.tabButtonColorOff);
|
|
|
|
inputSystemPackageTabButton =
|
|
GetTab()
|
|
.SetLabelText($"{ObjectNames.NicifyVariableName(InputHandling.InputSystemPackage.ToString())}")
|
|
.SetTabPosition(TabPosition.TabOnLeft)
|
|
.SetOnClick(() =>
|
|
{
|
|
DefineSymbolsUtils.RemoveGlobalDefine("LEGACY_INPUT_MANAGER");
|
|
DefineSymbolsUtils.AddGlobalDefine("INPUT_SYSTEM_PACKAGE");
|
|
legacyInputManagerTabButton.isOn = false;
|
|
customInputTabButton.isOn = false;
|
|
});
|
|
|
|
legacyInputManagerTabButton =
|
|
GetTab()
|
|
.SetLabelText($"{ObjectNames.NicifyVariableName(InputHandling.LegacyInputManager.ToString())}")
|
|
.SetTabPosition(TabPosition.TabInCenter)
|
|
.SetOnClick(() =>
|
|
{
|
|
DefineSymbolsUtils.RemoveGlobalDefine("INPUT_SYSTEM_PACKAGE");
|
|
DefineSymbolsUtils.AddGlobalDefine("LEGACY_INPUT_MANAGER");
|
|
inputSystemPackageTabButton.isOn = false;
|
|
customInputTabButton.isOn = false;
|
|
});
|
|
|
|
customInputTabButton =
|
|
GetTab()
|
|
.SetLabelText($"{ObjectNames.NicifyVariableName(InputHandling.CustomInput.ToString())}")
|
|
.SetTabPosition(TabPosition.TabOnRight)
|
|
.SetOnClick(() =>
|
|
{
|
|
DefineSymbolsUtils.RemoveGlobalDefine("INPUT_SYSTEM_PACKAGE");
|
|
DefineSymbolsUtils.RemoveGlobalDefine("LEGACY_INPUT_MANAGER");
|
|
inputSystemPackageTabButton.isOn = false;
|
|
legacyInputManagerTabButton.isOn = false;
|
|
});
|
|
|
|
inputSystemPackageTabButton.isOn = UIManagerInputSettings.k_InputHandling == InputHandling.InputSystemPackage;
|
|
legacyInputManagerTabButton.isOn = UIManagerInputSettings.k_InputHandling == InputHandling.LegacyInputManager;
|
|
customInputTabButton.isOn = UIManagerInputSettings.k_InputHandling == InputHandling.CustomInput;
|
|
|
|
content.Bind(serializedObject);
|
|
}
|
|
|
|
private void Compose()
|
|
{
|
|
content
|
|
.AddChild
|
|
(
|
|
DesignUtils.row
|
|
.SetStyleFlexGrow(0)
|
|
.AddFlexibleSpace()
|
|
.AddChild(inputSystemPackageTabButton)
|
|
.AddSpace(1, 1)
|
|
.AddChild(legacyInputManagerTabButton)
|
|
.AddSpace(1, 1)
|
|
.AddChild(customInputTabButton)
|
|
.AddFlexibleSpace()
|
|
)
|
|
.AddSpaceBlock(4)
|
|
.AddChild(playerIndexField)
|
|
.AddSpaceBlock()
|
|
.AddChild(playerMultiplayerMode)
|
|
.AddSpaceBlock(2)
|
|
.AddChild(playerBackButtonCooldown)
|
|
.AddSpaceBlock(2);
|
|
|
|
#if LEGACY_INPUT_MANAGER
|
|
content.AddChild(backButtonVirtualButtonName)
|
|
.AddSpaceBlock(2);
|
|
#endif
|
|
|
|
content.AddChild
|
|
(
|
|
DesignUtils.row
|
|
.SetStyleFlexGrow(0)
|
|
.AddFlexibleSpace()
|
|
.AddChild(saveButton)
|
|
);
|
|
}
|
|
}
|
|
}
|