1
This commit is contained in:
@@ -54,7 +54,7 @@ namespace BITKit.UX
|
||||
{
|
||||
Clear();
|
||||
style.flexDirection = FlexDirection.Row;
|
||||
style.justifyContent = Justify.SpaceAround;
|
||||
style.justifyContent = Justify.FlexStart;
|
||||
instanceColumns.Clear();
|
||||
|
||||
if (string.IsNullOrEmpty(Json)) return;
|
||||
@@ -64,7 +64,9 @@ namespace BITKit.UX
|
||||
var rowLength = jArray.Count;
|
||||
for (var i = 0; i < colLength; i++)
|
||||
{
|
||||
instanceColumns.Add(this.Create<VisualElement>());
|
||||
var newContainer = this.Create<VisualElement>();
|
||||
newContainer.name = $"{nameof(VisualElement)}-{i}";
|
||||
instanceColumns.Add(newContainer);
|
||||
}
|
||||
for (var y = 0; y < rowLength; y++)
|
||||
{
|
||||
|
84
Assets/BITKit/Unity/Scripts/UX/Library/ProgressBlock.cs
Normal file
84
Assets/BITKit/Unity/Scripts/UX/Library/ProgressBlock.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class ProgressBlock : VisualElement
|
||||
{
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits
|
||||
{
|
||||
private readonly UxmlIntAttributeDescription m_ValueAttribute = new ()
|
||||
{
|
||||
name = "Value",defaultValue = 50
|
||||
};
|
||||
private readonly UxmlIntAttributeDescription m_SeparateAttribute = new ()
|
||||
{
|
||||
name = "Separate",defaultValue = 5
|
||||
};
|
||||
|
||||
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
|
||||
{
|
||||
base.Init(ve, bag, cc);
|
||||
var x = (ProgressBlock)ve;
|
||||
x.Value = m_ValueAttribute.GetValueFromBag(bag, cc);
|
||||
x.Separate = m_SeparateAttribute.GetValueFromBag(bag, cc);
|
||||
}
|
||||
}
|
||||
public ProgressBlock() : base()
|
||||
{
|
||||
|
||||
}
|
||||
public new class UxmlFactory : UxmlFactory<ProgressBlock, UxmlTraits> { }
|
||||
/// <summary>
|
||||
/// 值,默认50,范围0-100
|
||||
/// </summary>
|
||||
public int Value
|
||||
{
|
||||
get => value;
|
||||
set
|
||||
{
|
||||
this.value = value;
|
||||
Rebuild();
|
||||
}
|
||||
}
|
||||
private int value;
|
||||
/// <summary>
|
||||
/// 分割线,默认5
|
||||
/// </summary>
|
||||
public int Separate
|
||||
{
|
||||
get => separate;
|
||||
set
|
||||
{
|
||||
this.separate = value;
|
||||
Rebuild();
|
||||
}
|
||||
}
|
||||
private int separate;
|
||||
private void Rebuild()
|
||||
{
|
||||
Clear();
|
||||
//if value is 58
|
||||
for (var i = 1; i <= Separate; i++)
|
||||
{
|
||||
var block = this.Create<VisualElement>();
|
||||
block.style.flexGrow = 1;
|
||||
|
||||
if (i * 10 < Value)
|
||||
{
|
||||
block.style.opacity = 1;
|
||||
}else if ((i + 1) * 10 > value)
|
||||
{
|
||||
block.style.opacity = 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
block.style.opacity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user