Action Bar (WIP)
Refactor item instance to use DatabaseLink Labels now pop up when aiming at loot Yeeted HUD trigger group UI into the abyss Created rebindable action bar (missing: assigning actions) Created Consumable Items Refactored behaviors to work on consumable items Implemented Velocity Conversion Behavior
This commit is contained in:
parent
282035dd25
commit
4489b18452
217 changed files with 5105 additions and 5703 deletions
115
Assets/Plugins/LayoutElementFitParent.cs
Normal file
115
Assets/Plugins/LayoutElementFitParent.cs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
|
||||
[ExecuteInEditMode]
|
||||
public class LayoutElementFitParent : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float aspectRatio = 1;
|
||||
|
||||
[SerializeField] private bool updateMin = false;
|
||||
[SerializeField] private bool updatePreferred = false;
|
||||
|
||||
private bool isDirty = false;
|
||||
private Vector2 lastParentSize;
|
||||
|
||||
private new RectTransform transform;
|
||||
private LayoutElement layoutElement;
|
||||
|
||||
public float AspectRatio
|
||||
{
|
||||
get { return aspectRatio; }
|
||||
set
|
||||
{
|
||||
aspectRatio = value;
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateMin
|
||||
{
|
||||
get { return updateMin; }
|
||||
set
|
||||
{
|
||||
updateMin = value;
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdatePreferred
|
||||
{
|
||||
get { return updatePreferred; }
|
||||
set
|
||||
{
|
||||
updatePreferred = value;
|
||||
isDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
transform = GetComponent<RectTransform>();
|
||||
layoutElement = GetComponent<LayoutElement>();
|
||||
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector2 parentSize = GetParentSize();
|
||||
|
||||
// Mark as dirty if parent's size changes
|
||||
if (lastParentSize != parentSize)
|
||||
{
|
||||
lastParentSize = parentSize;
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
// Only recalculate layout size if something has changed
|
||||
if (!isDirty) return;
|
||||
isDirty = false;
|
||||
|
||||
float neededWidth = parentSize.y * aspectRatio;
|
||||
float neededHeight = parentSize.x / aspectRatio;
|
||||
|
||||
// Is height the limiting factor?
|
||||
if (neededWidth <= parentSize.x)
|
||||
{
|
||||
// Scale to match parent's height
|
||||
SetSizes(neededWidth, parentSize.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Scale to match parent's width
|
||||
SetSizes(parentSize.x, neededHeight);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
// Inspector fields have changed, mark as dirty
|
||||
isDirty = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
private void SetSizes(float x, float y)
|
||||
{
|
||||
if (updateMin)
|
||||
{
|
||||
layoutElement.minWidth = x;
|
||||
layoutElement.minHeight = y;
|
||||
}
|
||||
if (updatePreferred)
|
||||
{
|
||||
layoutElement.preferredWidth = x;
|
||||
layoutElement.preferredHeight = y;
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 GetParentSize()
|
||||
{
|
||||
var parent = transform.parent as RectTransform;
|
||||
return parent == null ? Vector2.zero : parent.rect.size;
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/LayoutElementFitParent.cs.meta
Normal file
11
Assets/Plugins/LayoutElementFitParent.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a588f4b3f3e229540a82e5f976b08e2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue