Super Sexy Properties Panel
Properties panel now allows nested lists with foldouts, item selection and click callbacks Properties Panel UI has a new look Refactored lambdas in control module code into methods for readability
This commit is contained in:
parent
68473a84ab
commit
50a8059ed4
43 changed files with 894 additions and 916 deletions
68
Assets/Scripts/UI/PropertiesList.cs
Normal file
68
Assets/Scripts/UI/PropertiesList.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PropertiesList : ReadOnlyPropertiesPanel
|
||||
{
|
||||
public Image FoldoutIcon;
|
||||
public float FoldoutRotationDamping;
|
||||
public FlatFlatButton Button;
|
||||
public VerticalLayoutGroup LayoutGroup;
|
||||
public int FoldedPadding = -8;
|
||||
public int ExpandedPadding = 8;
|
||||
|
||||
private bool _expanded = false;
|
||||
private float _targetFoldoutRotation = 0;
|
||||
private float _foldoutRotation = 0;
|
||||
|
||||
public bool Expanded
|
||||
{
|
||||
set
|
||||
{
|
||||
_expanded = value;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Button.OnClick += ToggleExpand;
|
||||
}
|
||||
|
||||
public void ToggleExpand() => Expanded = !_expanded;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_foldoutRotation =
|
||||
Mathf.Lerp(_foldoutRotation, _targetFoldoutRotation, FoldoutRotationDamping * Time.deltaTime);
|
||||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
|
||||
public new PropertyLabel AddProperty(string name, Func<string> value = null, Action onClick = null)
|
||||
{
|
||||
var prop = base.AddProperty(name, value, onClick);
|
||||
prop.gameObject.SetActive(false);
|
||||
return prop;
|
||||
}
|
||||
|
||||
public new PropertiesList AddList(string name)
|
||||
{
|
||||
var list = base.AddList(name);
|
||||
list.gameObject.SetActive(false);
|
||||
return list;
|
||||
}
|
||||
|
||||
public new RectTransform AddSection(string name)
|
||||
{
|
||||
var section = base.AddSection(name);
|
||||
section.gameObject.SetActive(false);
|
||||
return section;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue