Initial commit
This commit is contained in:
commit
137cb2ce13
215 changed files with 659023 additions and 0 deletions
39
src/GameCult.Unity/Assets/Scripts/Attributes.cs
Normal file
39
src/GameCult.Unity/Assets/Scripts/Attributes.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
|
||||
[AttributeUsage(AttributeTargets.All, Inherited = false)]
|
||||
public class InspectableAttribute : Attribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public abstract class PreferredInspectorAttribute : InspectableAttribute { }
|
||||
|
||||
public class InspectableEnumValuesAttribute : PreferredInspectorAttribute
|
||||
{
|
||||
public Type EnumType;
|
||||
|
||||
public InspectableEnumValuesAttribute(Type enumType)
|
||||
{
|
||||
EnumType = enumType;
|
||||
}
|
||||
}
|
||||
|
||||
public class InspectableRangedFloatAttribute : PreferredInspectorAttribute
|
||||
{
|
||||
public readonly float Min, Max;
|
||||
|
||||
public InspectableRangedFloatAttribute(float min, float max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
}
|
||||
|
||||
public class InspectableRangedIntAttribute : PreferredInspectorAttribute
|
||||
{
|
||||
public readonly int Min, Max;
|
||||
|
||||
public InspectableRangedIntAttribute(int min, int max)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
}
|
||||
}
|
||||
118
src/GameCult.Unity/Assets/Scripts/Prototype.cs
Normal file
118
src/GameCult.Unity/Assets/Scripts/Prototype.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Convenience way to create objects in the hierarchy that are a bit like prefabs, except that they
|
||||
/// aren't. They exist in the scene, immediately deactivate themselves, then provide an easy way to
|
||||
/// instantiate a copy in the same place in the hierarchy.
|
||||
/// If you call ReturnToPool() once you're done with the instance, then it's returned
|
||||
/// to the original prototype to be reused if necessary instead of creating a brand new GameObject.
|
||||
/// </summary>
|
||||
public class Prototype : MonoBehaviour {
|
||||
|
||||
public event Action OnReturnToPool;
|
||||
|
||||
public bool isOriginalPrototype {
|
||||
get {
|
||||
return _originalPrototype == null;
|
||||
}
|
||||
}
|
||||
|
||||
public Prototype originalPrototype {
|
||||
get {
|
||||
return _originalPrototype;
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if( isOriginalPrototype )
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if( _instancePool != null )
|
||||
foreach(var inst in _instancePool)
|
||||
Destroy(inst);
|
||||
}
|
||||
|
||||
public T Instantiate<T>() where T : Component
|
||||
{
|
||||
Prototype instance = null;
|
||||
|
||||
// Re-use instance from pool
|
||||
if( _instancePool != null && _instancePool.Count > 0 ) {
|
||||
var instanceIdx = _instancePool.Count-1;
|
||||
instance = _instancePool[instanceIdx];
|
||||
_instancePool.RemoveAt(instanceIdx);
|
||||
instance.transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
// Instantiate fresh instance
|
||||
else {
|
||||
instance = UnityEngine.Object.Instantiate(this);
|
||||
|
||||
instance.transform.SetParent(transform.parent, worldPositionStays:false);
|
||||
|
||||
var protoRT = transform as RectTransform;
|
||||
if( protoRT ) {
|
||||
var instRT = instance.transform as RectTransform;
|
||||
instRT.anchorMin = protoRT.anchorMin;
|
||||
instRT.anchorMax = protoRT.anchorMax;
|
||||
instRT.pivot = protoRT.pivot;
|
||||
instRT.sizeDelta = protoRT.sizeDelta;
|
||||
}
|
||||
|
||||
instance.transform.localPosition = transform.localPosition;
|
||||
instance.transform.localRotation = transform.localRotation;
|
||||
instance.transform.localScale = transform.localScale;
|
||||
|
||||
instance._originalPrototype = this;
|
||||
}
|
||||
|
||||
instance.gameObject.SetActive(true);
|
||||
|
||||
return instance.GetComponent<T>();
|
||||
}
|
||||
|
||||
public void ReturnToPool()
|
||||
{
|
||||
if( isOriginalPrototype ) {
|
||||
Debug.LogError("Can't return to pool because the original prototype doesn't exist. Is this prototype the original?");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
transform.SetParent(_originalPrototype.transform.parent);
|
||||
_originalPrototype.AddToPool(this);
|
||||
OnReturnToPool = null;
|
||||
}
|
||||
|
||||
public T GetOriginal<T>()
|
||||
{
|
||||
if( isOriginalPrototype )
|
||||
return GetComponent<T>();
|
||||
else
|
||||
return originalPrototype.GetComponent<T>();
|
||||
}
|
||||
|
||||
void AddToPool(Prototype instancePrototype)
|
||||
{
|
||||
if( !isOriginalPrototype )
|
||||
Debug.LogError("Adding "+instancePrototype.name+" to prototype pool of "+this.name+" but this appears to be an instance itself?");
|
||||
|
||||
instancePrototype.gameObject.SetActive(false);
|
||||
|
||||
if( _instancePool == null ) _instancePool = new List<Prototype>();
|
||||
_instancePool.Add(instancePrototype);
|
||||
|
||||
if( instancePrototype.OnReturnToPool != null )
|
||||
instancePrototype.OnReturnToPool();
|
||||
}
|
||||
|
||||
Prototype _originalPrototype;
|
||||
|
||||
List<Prototype> _instancePool;
|
||||
}
|
||||
17
src/GameCult.Unity/Assets/Scripts/StringExtensions.cs
Normal file
17
src/GameCult.Unity/Assets/Scripts/StringExtensions.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string SplitCamelCase( this string str )
|
||||
{
|
||||
return Regex.Replace(
|
||||
Regex.Replace(
|
||||
str,
|
||||
@"(\P{Ll})(\P{Ll}\p{Ll})",
|
||||
"$1 $2"
|
||||
),
|
||||
@"(\p{Ll})(\P{Ll})",
|
||||
"$1 $2"
|
||||
);
|
||||
}
|
||||
}
|
||||
68
src/GameCult.Unity/Assets/Scripts/UI/ClickCatcher.cs
Normal file
68
src/GameCult.Unity/Assets/Scripts/UI/ClickCatcher.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using R3;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, /*IPointerUpHandler, */IPointerDownHandler, IPointerClickHandler
|
||||
{
|
||||
//public bool EnableMouse => PointerIsInside && !_catching;
|
||||
public bool PointerIsInside { get; private set; }
|
||||
public float DragDistance = 25f;
|
||||
|
||||
public Subject<PointerEventData> OnEnter = new Subject<PointerEventData>();
|
||||
public Subject<PointerEventData> OnExit = new Subject<PointerEventData>();
|
||||
public Subject<PointerEventData> OnClick = new Subject<PointerEventData>();
|
||||
public Subject<PointerEventData> OnDown = new Subject<PointerEventData>();
|
||||
|
||||
// private float downTime;
|
||||
|
||||
public static ClickCatcher Background
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_background == null)
|
||||
_background = GameObject.FindGameObjectWithTag("UIBackground").GetComponent<ClickCatcher>();
|
||||
return _background;
|
||||
}
|
||||
}
|
||||
|
||||
private static ClickCatcher _background;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
//Debug.Log("Pointer Entered");
|
||||
OnEnter.OnNext(eventData);
|
||||
PointerIsInside = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
//Debug.Log("Pointer Exited");
|
||||
OnExit.OnNext(eventData);
|
||||
PointerIsInside = false;
|
||||
}
|
||||
|
||||
// public void OnPointerUp(PointerEventData eventData)
|
||||
// {
|
||||
// if(Time.time - downTime < ClickTime)
|
||||
// OnClick?.Invoke(eventData);
|
||||
// }
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
OnDown.OnNext(eventData);
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if((eventData.pressPosition - eventData.position).sqrMagnitude < DragDistance)
|
||||
OnClick.OnNext(eventData);
|
||||
}
|
||||
}
|
||||
75
src/GameCult.Unity/Assets/Scripts/UI/ConfirmationDialog.cs
Normal file
75
src/GameCult.Unity/Assets/Scripts/UI/ConfirmationDialog.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using R3;
|
||||
|
||||
public class ConfirmationDialog : PropertiesPanel
|
||||
{
|
||||
public ClickCatcher CancelClickCatcher;
|
||||
public GameObject ButtonGroup;
|
||||
public Button Cancel;
|
||||
public Button Confirm;
|
||||
public TextMeshProUGUI ConfirmText;
|
||||
public TextMeshProUGUI CancelText;
|
||||
|
||||
public bool LockDialog { get; set; }
|
||||
|
||||
private Action _onCancel;
|
||||
private Action _onConfirm;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cancel.onClick.AddListener(() => End());
|
||||
Confirm.onClick.AddListener(() => End(true));
|
||||
if (CancelClickCatcher != null)
|
||||
CancelClickCatcher.OnClick.Subscribe(data =>
|
||||
{
|
||||
if (!LockDialog) End();
|
||||
});
|
||||
|
||||
OnPropertyAdded += go =>
|
||||
{
|
||||
go.SetActive(true);
|
||||
go.transform.SetSiblingIndex(Title.transform.GetSiblingIndex() + 1);
|
||||
};
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void End(bool success = false)
|
||||
{
|
||||
if(success) _onConfirm?.Invoke();
|
||||
else _onCancel?.Invoke();
|
||||
CancelClickCatcher?.gameObject.SetActive(false);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void MoveToCursor()
|
||||
{
|
||||
transform.position = Mouse.current.position.ReadValue();
|
||||
}
|
||||
|
||||
public void Show(Action onConfirm = null, Action onCancel = null, string confirmText = "OK", string cancelText = "Cancel")
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
_onConfirm = onConfirm;
|
||||
Confirm.gameObject.SetActive(onConfirm!=null);
|
||||
ConfirmText.text = confirmText;
|
||||
|
||||
_onCancel = onCancel;
|
||||
Cancel.gameObject.SetActive(onCancel!=null);
|
||||
CancelText.text = cancelText;
|
||||
|
||||
ButtonGroup.SetActive(onConfirm!=null || onCancel!=null);
|
||||
|
||||
CancelClickCatcher?.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
86
src/GameCult.Unity/Assets/Scripts/UI/DropdownMenu.cs
Normal file
86
src/GameCult.Unity/Assets/Scripts/UI/DropdownMenu.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using R3;
|
||||
|
||||
public class DropdownMenu : MonoBehaviour
|
||||
{
|
||||
public Canvas Canvas;
|
||||
public ClickCatcher CancelClickCatcher;
|
||||
public PropertyButton OptionPrefab;
|
||||
|
||||
public RectTransform ContentRoot;
|
||||
|
||||
public float OptionHeight;
|
||||
public float PaddingHeight;
|
||||
|
||||
private List<GameObject> _options = new List<GameObject>();
|
||||
private IDisposable _backgroundClickSubscription;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (CancelClickCatcher != null)
|
||||
_backgroundClickSubscription = CancelClickCatcher.OnClick.Subscribe(data =>
|
||||
{
|
||||
End();
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_backgroundClickSubscription?.Dispose();
|
||||
_backgroundClickSubscription = null;
|
||||
}
|
||||
|
||||
private void End()
|
||||
{
|
||||
CancelClickCatcher.gameObject.SetActive(false);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
// Destroy previous options
|
||||
foreach(var option in _options)
|
||||
Destroy(option);
|
||||
_options.Clear();
|
||||
}
|
||||
|
||||
public void AddOption(string text, Action action, bool selected = false, bool enabled = true)
|
||||
{
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.Label.text = text;
|
||||
optionButton.Button.onClick.AddListener(() =>
|
||||
{
|
||||
action();
|
||||
End();
|
||||
});
|
||||
optionButton.Button.interactable = enabled;
|
||||
//optionButton.Button..CurrentState = !enabled ? FlatButtonState.Disabled : selected ? FlatButtonState.Selected : FlatButtonState.Unselected;
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
|
||||
public void Show(RectTransform parent)
|
||||
{
|
||||
var rect = transform as RectTransform;
|
||||
var pivot = rect.pivot;
|
||||
pivot.x = 0;
|
||||
var scaleFactor = Canvas.scaleFactor;
|
||||
var corners = new Vector3[4];
|
||||
parent.GetWorldCorners(corners);
|
||||
var pivotTop = corners[0].y > (PaddingHeight + _options.Count * OptionHeight) * scaleFactor;
|
||||
pivot.y = pivotTop ? 1 : 0;
|
||||
rect.pivot = pivot;
|
||||
rect.sizeDelta = parent.sizeDelta;
|
||||
rect.position = pivotTop ? corners[0] : corners[1];
|
||||
CancelClickCatcher.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
189
src/GameCult.Unity/Assets/Scripts/UI/MainMenu.cs
Normal file
189
src/GameCult.Unity/Assets/Scripts/UI/MainMenu.cs
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using R3;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public ConfirmationDialog Dialog;
|
||||
public bool InGame;
|
||||
public Prototype PanelPrototype;
|
||||
public float FadeTime = .5f;
|
||||
public float FadeDistance = 512;
|
||||
public float FadeAlphaExponent = 2;
|
||||
public float FadePositionExponent = 2;
|
||||
|
||||
private (PropertiesPanel panel, CanvasGroup group) _currentMenu, _nextMenu;
|
||||
private bool _fadeFromRight;
|
||||
private float _fadeLerp;
|
||||
private bool _fading;
|
||||
private Vector3 _panelPosition;
|
||||
//private Task<DatabaseCache> _databaseLoad;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Start loading the database in the background 'cause it takes a few seconds
|
||||
//_databaseLoad = Task.Run(() => ActionGameManager.Database);
|
||||
|
||||
_panelPosition = PanelPrototype.transform.position;
|
||||
|
||||
var panel1 = PanelPrototype.Instantiate<PropertiesPanel>();
|
||||
_currentMenu = (panel1, panel1.GetComponent<CanvasGroup>());
|
||||
|
||||
var panel2 = PanelPrototype.Instantiate<PropertiesPanel>();
|
||||
_nextMenu = (panel2, panel2.GetComponent<CanvasGroup>());
|
||||
|
||||
_currentMenu.panel.gameObject.SetActive(false);
|
||||
//_saveDirectory = ActionGameManager.GameDataDirectory.CreateSubdirectory("Saves");
|
||||
|
||||
ShowMain();
|
||||
Fade(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_fading)
|
||||
{
|
||||
_fadeLerp += Time.deltaTime / FadeTime;
|
||||
|
||||
_currentMenu.panel.transform.position =
|
||||
_panelPosition + (_fadeFromRight ? Vector3.left : Vector3.right) * (FadeDistance * pow(_fadeLerp, FadePositionExponent));
|
||||
_nextMenu.panel.transform.position =
|
||||
_panelPosition + (_fadeFromRight ? Vector3.right : Vector3.left) * (FadeDistance * pow(1-_fadeLerp, FadePositionExponent));
|
||||
_currentMenu.group.alpha = pow(1 - _fadeLerp, FadeAlphaExponent);
|
||||
_nextMenu.group.alpha = pow(_fadeLerp, FadeAlphaExponent);
|
||||
|
||||
if (_fadeLerp > 1)
|
||||
{
|
||||
_fading = false;
|
||||
_currentMenu.panel.gameObject.SetActive(false);
|
||||
var temp = _currentMenu;
|
||||
_currentMenu = _nextMenu;
|
||||
_nextMenu = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string TitleSubtitle(string title, string subtitle) => $"{title}\n<smallcaps><size=50%>{subtitle}";
|
||||
|
||||
private void Fade(bool fromRight)
|
||||
{
|
||||
_nextMenu.panel.gameObject.SetActive(true);
|
||||
_nextMenu.group.alpha = 0;
|
||||
_fading = true;
|
||||
_fadeLerp = 0;
|
||||
_fadeFromRight = fromRight;
|
||||
}
|
||||
|
||||
private void ShowMain()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
_nextMenu.panel.Title.text = TitleSubtitle("aetheria", "terminus");
|
||||
_nextMenu.panel.AddButton("New Game",
|
||||
() =>
|
||||
{
|
||||
|
||||
});
|
||||
_nextMenu.panel.AddButton("Settings",
|
||||
() =>
|
||||
{
|
||||
ShowSettings();
|
||||
Fade(true);
|
||||
});
|
||||
_nextMenu.panel.AddButton("Quit", Application.Quit);
|
||||
}
|
||||
|
||||
private void ShowSettings()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
_nextMenu.panel.Title.text = "settings";
|
||||
_nextMenu.panel.AddButton("Gameplay",
|
||||
() =>
|
||||
{
|
||||
ShowGameplaySettings();
|
||||
Fade(true);
|
||||
});
|
||||
_nextMenu.panel.AddButton("Graphics",
|
||||
() =>
|
||||
{
|
||||
ShowGraphicsSettings();
|
||||
Fade(true);
|
||||
});
|
||||
_nextMenu.panel.AddButton("Input",
|
||||
() =>
|
||||
{
|
||||
ShowInputSettings();
|
||||
Fade(true);
|
||||
});
|
||||
_nextMenu.panel.AddButton("Audio",
|
||||
() =>
|
||||
{
|
||||
ShowAudioSettings();
|
||||
Fade(true);
|
||||
});
|
||||
_nextMenu.panel.AddButton("Back",
|
||||
() =>
|
||||
{
|
||||
ShowMain();
|
||||
Fade(false);
|
||||
});
|
||||
}
|
||||
|
||||
private void ShowGameplaySettings()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
_nextMenu.panel.Title.text = TitleSubtitle("gameplay", "settings");
|
||||
_nextMenu.panel.AddButton("Back",
|
||||
() =>
|
||||
{
|
||||
ShowSettings();
|
||||
Fade(false);
|
||||
});
|
||||
}
|
||||
|
||||
private void ShowGraphicsSettings()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
_nextMenu.panel.Title.text = TitleSubtitle("graphics", "settings");
|
||||
_nextMenu.panel.AddButton("Back",
|
||||
() =>
|
||||
{
|
||||
ShowSettings();
|
||||
Fade(false);
|
||||
});
|
||||
}
|
||||
|
||||
private void ShowInputSettings()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
_nextMenu.panel.Title.text = TitleSubtitle("input", "settings");
|
||||
_nextMenu.panel.AddButton("Back",
|
||||
() =>
|
||||
{
|
||||
ShowSettings();
|
||||
Fade(false);
|
||||
});
|
||||
}
|
||||
|
||||
private void ShowAudioSettings()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
_nextMenu.panel.Title.text = TitleSubtitle("audio", "settings");
|
||||
_nextMenu.panel.AddButton("Back",
|
||||
() =>
|
||||
{
|
||||
ShowSettings();
|
||||
Fade(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AttributeProperty : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Title;
|
||||
public TextMeshProUGUI LowLabel;
|
||||
public TextMeshProUGUI HighLabel;
|
||||
public Slider Slider;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BoolField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Toggle Toggle;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ButtonField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public TextMeshProUGUI ButtonLabel;
|
||||
public Button Button;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EnumField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Button Dropdown;
|
||||
public TextMeshProUGUI DropdownLabel;
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class IncrementField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public TextMeshProUGUI Value;
|
||||
public Button Increment;
|
||||
public Button Decrement;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class InputField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public TMP_InputField Field;
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PropertiesList : PropertiesPanel
|
||||
{
|
||||
public Image FoldoutIcon;
|
||||
public float FoldoutRotationDamping;
|
||||
public Button Button;
|
||||
public VerticalLayoutGroup LayoutGroup;
|
||||
public int FoldedPadding = -8;
|
||||
public int ExpandedPadding = 8;
|
||||
public event Action<bool> OnExpand;
|
||||
|
||||
private bool _expanded = false;
|
||||
private float _targetFoldoutRotation = 0;
|
||||
private float _foldoutRotation = 0;
|
||||
|
||||
public bool Expanded => _expanded;
|
||||
|
||||
public new void Awake()
|
||||
{
|
||||
Button.onClick.AddListener(ToggleExpand);
|
||||
OnPropertyAdded += go => go.SetActive(_expanded);
|
||||
//SetExpanded(true, true);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
RefreshValues();
|
||||
_foldoutRotation =
|
||||
Mathf.Lerp(_foldoutRotation, _targetFoldoutRotation, FoldoutRotationDamping * Time.deltaTime);
|
||||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
|
||||
public void ToggleExpand() => SetExpanded(!_expanded, false);
|
||||
|
||||
public void SetExpanded(bool expanded, bool force)
|
||||
{
|
||||
_expanded = expanded;
|
||||
var padding = LayoutGroup.padding;
|
||||
padding = new RectOffset(padding.left, padding.right, padding.top, _expanded ? ExpandedPadding : FoldedPadding);
|
||||
LayoutGroup.padding = padding;
|
||||
foreach (var property in Properties) property.SetActive(_expanded);
|
||||
_targetFoldoutRotation = _expanded ? -90 : 0;
|
||||
if (force)
|
||||
{
|
||||
_foldoutRotation = _targetFoldoutRotation;
|
||||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
OnExpand?.Invoke(_expanded);
|
||||
}
|
||||
|
||||
// public override PropertyLabel AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
|
||||
// {
|
||||
// var prop = base.AddProperty(name, read, onClick, radio);
|
||||
// prop.gameObject.SetActive(false);
|
||||
// return prop;
|
||||
// }
|
||||
//
|
||||
// public override PropertiesList AddList(string name)
|
||||
// {
|
||||
// var list = base.AddList(name);
|
||||
// list.gameObject.SetActive(false);
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// public override RectTransform AddSection(string name)
|
||||
// {
|
||||
// var section = base.AddSection(name);
|
||||
// section.gameObject.SetActive(false);
|
||||
// return section;
|
||||
// }
|
||||
//
|
||||
// public override PropertyButton AddButton(string name, Action<PointerEventData> onClick)
|
||||
// {
|
||||
// var button = base.AddButton(name, onClick);
|
||||
// button.gameObject.SetActive(false);
|
||||
// return button;
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,410 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using TMPro;
|
||||
using R3;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class PropertiesPanel : MonoBehaviour
|
||||
{
|
||||
public RectTransform Spacer;
|
||||
public DropdownMenu Dropdown;
|
||||
public TextMeshProUGUI Title;
|
||||
public RectTransform Section;
|
||||
public PropertiesList List;
|
||||
public Property Property;
|
||||
public PropertyLabel PropertyLabel;
|
||||
public AttributeProperty Attribute;
|
||||
public InputField InputField;
|
||||
public RangedFloatField RangedFloatField;
|
||||
public RangedFloatField ProgressField;
|
||||
public EnumField EnumField;
|
||||
public BoolField BoolField;
|
||||
public PropertyButton PropertyButton;
|
||||
public ButtonField ButtonField;
|
||||
public IncrementField IncrementField;
|
||||
public StatSheet StatSheet;
|
||||
public RectTransform Content;
|
||||
public RectTransform DragParent;
|
||||
|
||||
protected List<GameObject> Properties = new List<GameObject>();
|
||||
protected event Action RefreshPropertyValues;
|
||||
protected bool RadioSelection = false;
|
||||
|
||||
private RectTransform _dragObject;
|
||||
|
||||
|
||||
protected event Action<GameObject> OnPropertyAdded;
|
||||
protected Action OnPropertiesChanged;
|
||||
|
||||
public int Children => Properties.Count;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
OnPropertyAdded += go => go.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
RefreshValues();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
// private void OnDisable()
|
||||
// {
|
||||
// RemoveListener();
|
||||
// }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
//RemoveListener();
|
||||
foreach(var property in Properties)
|
||||
Destroy(property);
|
||||
Title.text = "Properties";
|
||||
Properties.Clear();
|
||||
RefreshPropertyValues = null;
|
||||
RadioSelection = false;
|
||||
}
|
||||
|
||||
public RectTransform AddSpacer()
|
||||
{
|
||||
var spacer = Instantiate(Spacer, Content ?? transform);
|
||||
Properties.Add(spacer.gameObject);
|
||||
OnPropertyAdded?.Invoke(spacer.gameObject);
|
||||
return spacer;
|
||||
}
|
||||
|
||||
public RectTransform AddSection(string name)
|
||||
{
|
||||
var section = Instantiate(Section, Content ?? transform);
|
||||
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
|
||||
Properties.Add(section.gameObject);
|
||||
OnPropertyAdded?.Invoke(section.gameObject);
|
||||
return section;
|
||||
}
|
||||
|
||||
public Property AddProperty(Func<string> read)
|
||||
{
|
||||
if (read == null) throw new ArgumentException("Attempted to add property with null read function!");
|
||||
|
||||
var property = Instantiate(Property, Content ?? transform);
|
||||
property.Label.text = read();
|
||||
|
||||
RefreshPropertyValues += () => property.Label.text = read();
|
||||
Properties.Add(property.gameObject);
|
||||
OnPropertyAdded?.Invoke(property.gameObject);
|
||||
return property;
|
||||
}
|
||||
|
||||
public Property AddProperty(string name, Func<string> read = null)
|
||||
{
|
||||
Property property;
|
||||
if(read != null)
|
||||
property = Instantiate(PropertyLabel, Content ?? transform);
|
||||
else
|
||||
property = Instantiate(Property, Content ?? transform);
|
||||
property.Label.text = name;
|
||||
|
||||
if (read != null)
|
||||
RefreshPropertyValues += () => ((PropertyLabel) property).Value.text = read.Invoke();
|
||||
Properties.Add(property.gameObject);
|
||||
OnPropertyAdded?.Invoke(property.gameObject);
|
||||
return property;
|
||||
}
|
||||
|
||||
public StatSheet AddStatSheet()
|
||||
{
|
||||
var sheet = Instantiate(StatSheet, Content ?? transform);
|
||||
Properties.Add(sheet.gameObject);
|
||||
OnPropertyAdded?.Invoke(sheet.gameObject);
|
||||
RefreshPropertyValues += () => sheet.RefreshValues();
|
||||
return sheet;
|
||||
}
|
||||
|
||||
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
|
||||
{
|
||||
var list = Instantiate(List, Content ?? transform);
|
||||
list.Dropdown = Dropdown;
|
||||
list.Title.text = name;
|
||||
// foreach (var element in elements)
|
||||
// {
|
||||
// var item = Instantiate(PropertyPrefab, list);
|
||||
// item.Name.text = element.Item1;
|
||||
// item.Value.text = element.Item2();
|
||||
// item.ValueFunction = element.Item2;
|
||||
// Properties.Add(item.gameObject);
|
||||
// }
|
||||
//RefreshPropertyValues += () => list.RefreshValues();
|
||||
Properties.Add(list.gameObject);
|
||||
OnPropertyAdded?.Invoke(list.gameObject);
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual PropertyButton AddButton(string name, Action onClick)
|
||||
{
|
||||
var button = Instantiate(PropertyButton, Content ?? transform);
|
||||
button.Label.text = name;
|
||||
button.Button.interactable = onClick != null;
|
||||
button.Button.onClick.AddListener(() => onClick());
|
||||
Properties.Add(button.gameObject);
|
||||
OnPropertyAdded?.Invoke(button.gameObject);
|
||||
return button;
|
||||
}
|
||||
|
||||
public void AddButton(string name, string label, Action onClick)
|
||||
{
|
||||
var button = Instantiate(ButtonField, Content ?? transform);
|
||||
button.Label.text = name;
|
||||
button.ButtonLabel.text = label;
|
||||
button.Button.interactable = onClick != null;
|
||||
button.Button.onClick.AddListener(() => onClick());
|
||||
Properties.Add(button.gameObject);
|
||||
OnPropertyAdded?.Invoke(button.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<string> read, Action<string> write)
|
||||
{
|
||||
var field = Instantiate(InputField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.Standard;
|
||||
field.Field.onValueChanged.AddListener(val => write(val));
|
||||
// field.Field.text = read();
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var s = read();
|
||||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ =>
|
||||
{
|
||||
if(field != null)
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
});
|
||||
}
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<float> read, Action<float> write)
|
||||
{
|
||||
var field = Instantiate(InputField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var s = read().ToString(CultureInfo.InvariantCulture);
|
||||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
|
||||
}
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write)
|
||||
{
|
||||
var field = Instantiate(InputField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var s = read().ToString(CultureInfo.InvariantCulture);
|
||||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
|
||||
}
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddIncrementField(string name, Func<int> read, Action<int> write, Func<int> min, Func<int> max)
|
||||
{
|
||||
var field = Instantiate(IncrementField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Increment.onClick.AddListener(() => write(read() + 1));
|
||||
field.Decrement.onClick.AddListener(() => write(read() - 1));
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var val = read();
|
||||
var minval = min();
|
||||
var maxval = max();
|
||||
if (val < minval || val > maxval)
|
||||
write(val = clamp(val, minval, maxval));
|
||||
field.Value.text = val.ToString(CultureInfo.InvariantCulture);
|
||||
field.Increment.interactable = val == maxval;
|
||||
field.Decrement.interactable = val == minval;
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<float> read, Action<float> write, float min, float max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = false;
|
||||
field.Slider.minValue = min;
|
||||
field.Slider.maxValue = max;
|
||||
field.Slider.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProgressField(string name, Func<float> read)
|
||||
{
|
||||
var field = Instantiate(ProgressField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = false;
|
||||
field.Slider.minValue = 0;
|
||||
field.Slider.maxValue = 1;
|
||||
//field.Slider.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write, int min, int max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = true;
|
||||
field.Slider.minValue = min;
|
||||
field.Slider.maxValue = max;
|
||||
field.Slider.onValueChanged.AddListener(val => write(Mathf.RoundToInt(val)));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<bool> read, Action<bool> write)
|
||||
{
|
||||
var field = Instantiate(BoolField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Toggle.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Toggle.isOn = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write, string[] enumOptions)
|
||||
{
|
||||
var field = Instantiate(EnumField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Dropdown.onClick.AddListener(() =>
|
||||
{
|
||||
var selected = read();
|
||||
Dropdown.gameObject.SetActive(true);
|
||||
Dropdown.Clear();
|
||||
for (int i = 0; i < enumOptions.Length; i++)
|
||||
{
|
||||
var index = i;
|
||||
Dropdown.AddOption(enumOptions[i], () => write(index), index == selected);
|
||||
}
|
||||
|
||||
Dropdown.Show((RectTransform) field.Dropdown.transform);
|
||||
});
|
||||
RefreshPropertyValues += () => field.DropdownLabel.text = enumOptions[read()];
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
|
||||
public void Inspect(object obj, bool inspectablesOnly = false, bool readWrite = false, bool topLevel = true)
|
||||
{
|
||||
var fields = obj.GetType().GetFields();
|
||||
foreach (var field in fields)
|
||||
Inspect(obj, field, inspectablesOnly, readWrite);
|
||||
|
||||
// if(topLevel)
|
||||
// foreach (var field in _propertyFields)
|
||||
// field.transform.SetSiblingIndex(_propertyFields.IndexOf(field));
|
||||
|
||||
RefreshValues();
|
||||
}
|
||||
|
||||
public void Inspect(object obj, FieldInfo field, bool inspectablesOnly = false, bool readWrite = false)
|
||||
{
|
||||
var inspectable = field.GetCustomAttribute<InspectableAttribute>();
|
||||
if (inspectable == null && inspectablesOnly) return;
|
||||
var type = field.FieldType;
|
||||
|
||||
if (type == typeof(float))
|
||||
{
|
||||
if (readWrite)
|
||||
{
|
||||
if (inspectable is InspectableRangedFloatAttribute ranged)
|
||||
AddField(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f),
|
||||
ranged.Min, ranged.Max);
|
||||
else
|
||||
AddField(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f));
|
||||
} else AddProperty(field.Name.SplitCamelCase(), () => ((float) field.GetValue(obj)).ToString("0.##"));
|
||||
}
|
||||
else if (type == typeof(int))
|
||||
{
|
||||
if (readWrite)
|
||||
{
|
||||
if (inspectable is InspectableRangedIntAttribute ranged)
|
||||
AddField(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f),
|
||||
ranged.Min, ranged.Max);
|
||||
else
|
||||
AddField(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f));
|
||||
} else AddProperty(field.Name.SplitCamelCase(), () => ((int) field.GetValue(obj)).ToString());
|
||||
}
|
||||
else if (type.IsEnum)
|
||||
{
|
||||
if (readWrite)
|
||||
AddField(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), i => field.SetValue(obj, i),
|
||||
Enum.GetNames(field.FieldType));
|
||||
else
|
||||
AddProperty(field.Name.SplitCamelCase(), () => Enum.GetName(type, field.GetValue(obj)).SplitCamelCase());
|
||||
}
|
||||
else if (type == typeof(string))
|
||||
{
|
||||
if (readWrite)
|
||||
AddField(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj), i => field.SetValue(obj, i));
|
||||
else
|
||||
AddProperty(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj));
|
||||
}
|
||||
//else if (field.FieldType == typeof(Color)) Inspect(field.Name, () => (Color) field.GetValue(obj), c => field.SetValue(obj, c));
|
||||
else if (field.FieldType == typeof(bool)) AddField(field.Name, () => (bool) field.GetValue(obj), b => field.SetValue(obj, b));
|
||||
else if (type.GetCustomAttribute<InspectableAttribute>() != null)
|
||||
{
|
||||
// if(!_propertyFields.Any() || !_propertyFields.Last().gameObject.name.ToUpper().Contains("DIVIDER"))
|
||||
// _propertyFields.Add(Divider.Instantiate<Prototype>());
|
||||
var list = AddList(field.Name);
|
||||
list.Inspect(field.GetValue(obj), inspectablesOnly, readWrite, false);
|
||||
}
|
||||
else
|
||||
Debug.Log($"Field \"{field.Name}\" has unknown type {field.FieldType.Name}. No inspector was generated.");
|
||||
}
|
||||
|
||||
public void RefreshValues()
|
||||
{
|
||||
RefreshPropertyValues?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Property : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PropertyButton : Property
|
||||
{
|
||||
public Button Button;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class PropertyLabel : Property
|
||||
{
|
||||
public TextMeshProUGUI Value;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RangedFloatField : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI Label;
|
||||
public Slider Slider;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StatSheet : MonoBehaviour
|
||||
{
|
||||
public PropertyLabel StatPrefab;
|
||||
|
||||
private List<(PropertyLabel property, Func<string> value)> _stats = new List<(PropertyLabel property, Func<string> value)>();
|
||||
|
||||
public void AddStat(string label, Func<string> value)
|
||||
{
|
||||
var instance = Instantiate(StatPrefab, transform);
|
||||
instance.Label.text = label;
|
||||
_stats.Add((instance, value));
|
||||
}
|
||||
|
||||
public void RefreshValues()
|
||||
{
|
||||
foreach(var stat in _stats)
|
||||
stat.property.Value.text = stat.value();
|
||||
}
|
||||
}
|
||||
35
src/GameCult.Unity/Assets/Scripts/UI/TextButton.cs
Normal file
35
src/GameCult.Unity/Assets/Scripts/UI/TextButton.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class TextButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public Button Button;
|
||||
public TextMeshProUGUI Label;
|
||||
public float AnimationDuration;
|
||||
public float HoverSpacing;
|
||||
|
||||
private float _lerp;
|
||||
private bool _hovering;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
_lerp = saturate(_lerp + Time.deltaTime / AnimationDuration * (Button.interactable && _hovering ? 1 : -1));
|
||||
Label.characterSpacing = HoverSpacing * _lerp;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
_hovering = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
_hovering = false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue