ハートメーター対応
This commit is contained in:
parent
5efae97edd
commit
803cc79ba0
|
|
@ -191,7 +191,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastTarget: 0
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
|
|
@ -200,8 +200,8 @@ MonoBehaviour:
|
|||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillMethod: 0
|
||||
m_FillAmount: 0.107
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
|
|
@ -298,7 +298,7 @@ MonoBehaviour:
|
|||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Transition: 0
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
|
|
@ -318,7 +318,7 @@ MonoBehaviour:
|
|||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_Interactable: 0
|
||||
m_TargetGraphic: {fileID: 0}
|
||||
m_FillRect: {fileID: 137127162547959670}
|
||||
m_HandleRect: {fileID: 0}
|
||||
|
|
@ -326,7 +326,7 @@ MonoBehaviour:
|
|||
m_MinValue: 0
|
||||
m_MaxValue: 1
|
||||
m_WholeNumbers: 0
|
||||
m_Value: 1
|
||||
m_Value: 0.531
|
||||
m_OnValueChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
|
|
@ -885,8 +885,7 @@ GameObject:
|
|||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 137127164255914078}
|
||||
- component: {fileID: 137127164255914076}
|
||||
- component: {fileID: 137127164255914079}
|
||||
- component: {fileID: 1931931293542164419}
|
||||
m_Layer: 5
|
||||
m_Name: MeterHeart
|
||||
m_TagString: Untagged
|
||||
|
|
@ -915,16 +914,8 @@ RectTransform:
|
|||
m_AnchorMax: {x: 0.5, y: 1}
|
||||
m_AnchoredPosition: {x: 0, y: -77.60156}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &137127164255914076
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 137127164255914073}
|
||||
m_CullTransparentMesh: 0
|
||||
--- !u!114 &137127164255914079
|
||||
m_Pivot: {x: 0.5, y: 1}
|
||||
--- !u!114 &1931931293542164419
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
|
|
@ -933,26 +924,11 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 137127164255914073}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Script: {fileID: 11500000, guid: c08102b0ec474c8b9e6dac7813ebc803, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
slider: {fileID: 137127162796222319}
|
||||
heartLevel: {fileID: 137127163584464916}
|
||||
--- !u!1 &137127164258565650
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HeartMeter : SingletonMonoBehaviour<HeartMeter>
|
||||
{
|
||||
[SerializeField] private Slider slider;
|
||||
[SerializeField] private TextMeshProUGUI heartLevel;
|
||||
|
||||
private List<int> levelList = new List<int>();
|
||||
private int currentHeartCount;
|
||||
private Coroutine coroutine;
|
||||
|
||||
public void Initialize(List<int> list)
|
||||
{
|
||||
levelList = list;
|
||||
}
|
||||
|
||||
public void SetHeart(int heartCount)
|
||||
{
|
||||
currentHeartCount = heartCount;
|
||||
SetView(currentHeartCount);
|
||||
}
|
||||
|
||||
private void SetView(float heartCount)
|
||||
{
|
||||
var index = GetNextLevel(Mathf.FloorToInt(heartCount));
|
||||
SetLevelView(index);
|
||||
SetMeterView(heartCount, index);
|
||||
}
|
||||
|
||||
private void SetLevelView(int level)
|
||||
{
|
||||
heartLevel.text = $"{level}";
|
||||
}
|
||||
|
||||
private void SetMeterView(float heartCount, int index)
|
||||
{
|
||||
|
||||
slider.value = (heartCount - levelList[index - 1]) / (levelList[index] - levelList[index - 1]);
|
||||
// Debug.Log($"heart:{heartCount}, i:{index}, val:{slider.value}");
|
||||
}
|
||||
|
||||
private int GetNextLevel(int heartCount)
|
||||
{
|
||||
var index = levelList.FindIndex(x => x > heartCount);
|
||||
if (levelList.Last() < heartCount)
|
||||
{
|
||||
index = levelList.Count - 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public void AddHeart(int value)
|
||||
{
|
||||
this.SafeStopCoroutine(coroutine);
|
||||
var tmpHeart = currentHeartCount;
|
||||
currentHeartCount += value;
|
||||
coroutine = this.CallLerp(1f, f =>
|
||||
{
|
||||
var heart = tmpHeart + Mathf.Lerp(0, value, f);
|
||||
SetView(heart);
|
||||
}, () =>
|
||||
{
|
||||
SetHeart(currentHeartCount);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c08102b0ec474c8b9e6dac7813ebc803
|
||||
timeCreated: 1630033097
|
||||
Loading…
Reference in New Issue