Unit World UI

master
Sascha 2023-05-16 10:34:03 +07:00
parent df3a9e3add
commit 5c0dd5b844
345 changed files with 9691 additions and 45875 deletions

@ -34,12 +34,13 @@ RectTransform:
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 220629097105182586}
- {fileID: 7784280617483512128}
m_Father: {fileID: 2266715941421909531}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 2}
m_AnchoredPosition: {x: 0.036, y: 2.032}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &8973440857211681844
@ -119,6 +120,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
actionPointsText: {fileID: 7200650202464231469}
unit: {fileID: 1762224036004953036}
healthBarImage: {fileID: 7501741253264082696}
healthSystem: {fileID: -3436836861493843007}
--- !u!114 &7690589944934352399
MonoBehaviour:
m_ObjectHideFlags: 0
@ -132,6 +135,174 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
invert: 1
--- !u!1 &4169618788585346426
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 204966530800471585}
- component: {fileID: 1804339895209020557}
- component: {fileID: 7501741253264082696}
m_Layer: 7
m_Name: Bar
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &204966530800471585
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4169618788585346426}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 7784280617483512128}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &1804339895209020557
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4169618788585346426}
m_CullTransparentMesh: 1
--- !u!114 &7501741253264082696
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4169618788585346426}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.6784314, g: 0.2627451, b: 0.27058825, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 127279d577f25ac4ea17dae3782e5074, type: 3}
m_Type: 3
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 0
m_FillAmount: 0.692
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &5404838907170991692
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6454921614034271923}
- component: {fileID: 7207494205102635592}
- component: {fileID: 2148841397682255794}
- component: {fileID: 3225463878417525295}
m_Layer: 7
m_Name: Background
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6454921614034271923
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5404838907170991692}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 7784280617483512128}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7207494205102635592
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5404838907170991692}
m_CullTransparentMesh: 1
--- !u!114 &2148841397682255794
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5404838907170991692}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 0.39215687}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
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
--- !u!114 &3225463878417525295
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5404838907170991692}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3}
m_Name:
m_EditorClassIdentifier:
m_EffectColor: {r: 0, g: 0, b: 0, a: 1}
m_EffectDistance: {x: 0.04, y: 0.04}
m_UseGraphicAlpha: 1
--- !u!1 &6811418269204574989
GameObject:
m_ObjectHideFlags: 0
@ -163,6 +334,44 @@ Transform:
m_Father: {fileID: 4322432214950709108}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &7018597050678859317
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7784280617483512128}
m_Layer: 7
m_Name: HealthBar
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7784280617483512128
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7018597050678859317}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 6454921614034271923}
- {fileID: 204966530800471585}
m_Father: {fileID: 4225202326264141909}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 1.2, y: 0.1}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &7515914176832744456
GameObject:
m_ObjectHideFlags: 0
@ -318,7 +527,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 336b2639ed64edc0a8d7b792b54a5575, type: 3}
m_Name:
m_EditorClassIdentifier:
health: 100
maxHealth: 100
--- !u!114 &6109206103003842800
MonoBehaviour:
m_ObjectHideFlags: 0
@ -369,7 +578,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: -0.008, y: 0.37}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5121494619036075576
@ -427,8 +636,8 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 0.5
m_fontSizeBase: 0.5
m_fontSize: 0.4
m_fontSizeBase: 0.4
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18

@ -1,15 +1,25 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
public class HealthSystem : MonoBehaviour {
[SerializeField] private int health = 100;
private int health;
[SerializeField] private int maxHealth = 100;
public float HealthNormalized => (float)health / maxHealth;
public event EventHandler OnDead;
public event EventHandler OnDamage;
private void Awake() => health = maxHealth;
public void Damage(int damageAmount) {
health -= damageAmount;
if (health < 0) health = 0;
if (health == 0) Die();
Debug.Log($"{gameObject.name} {health}");
OnDamage?.Invoke(this, EventArgs.Empty);
}
private void Die() => OnDead?.Invoke(this, EventArgs.Empty);
}

@ -1,6 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAtCamera : MonoBehaviour {

@ -1,19 +1,28 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace UI {
public class UnitWorldUI : MonoBehaviour {
[SerializeField] private TextMeshProUGUI actionPointsText;
[SerializeField] private Unit unit;
[SerializeField] private Image healthBarImage;
[SerializeField] private HealthSystem healthSystem;
private void Start() {
Unit.OnAnyActionPointsChanged += Unit_OnAnyActionPointsChanged;
healthSystem.OnDamage += HealthSystem_OnDamage;
UpdateActionPointsText();
UpdateHealthBar();
}
private void HealthSystem_OnDamage(object sender, EventArgs e) => UpdateHealthBar();
private void Unit_OnAnyActionPointsChanged(object sender, EventArgs e) => UpdateActionPointsText();
private void UpdateActionPointsText() => actionPointsText.text = unit.ActionPoints.ToString();
private void UpdateHealthBar() => healthBarImage.fillAmount = healthSystem.HealthNormalized;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Some files were not shown because too many files have changed in this diff Show More