浏览代码

Add healthbar logic

/UI
uChema 4 年前
当前提交
d1f0a9e1
共有 15 个文件被更改,包括 687 次插入6 次删除
  1. 121
      UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab
  2. 2
      UOP1_Project/Assets/Scripts/.DS_Store
  3. 4
      UOP1_Project/Assets/Scripts/Quests/QuestManagerSO.cs
  4. 394
      UOP1_Project/Assets/Prefabs/UI/UIHealthbar.prefab
  5. 7
      UOP1_Project/Assets/Prefabs/UI/UIHealthbar.prefab.meta
  6. 8
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar.meta
  7. 77
      UOP1_Project/Assets/UIHealthBarManager.cs
  8. 11
      UOP1_Project/Assets/UIHealthBarManager.cs.meta
  9. 15
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/InflictDamageEvent.asset
  10. 8
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/InflictDamageEvent.asset.meta
  11. 15
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/RestoreHealthEvent.asset
  12. 8
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/RestoreHealthEvent.asset.meta
  13. 15
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/SetHealthbarEvent.asset
  14. 8
      UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/SetHealthbarEvent.asset.meta

121
UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab


type: 2}
_openInventoryChannel: {fileID: 11400000, guid: 30f6db2122a30480b996908173e1c7d7,
type: 2}
_closeInventoryChannel: {fileID: 11400000, guid: f6f7aad2f09f04ebf8d89aa6f52a6102,
type: 2}
--- !u!114 &6243045328629046901
MonoBehaviour:
m_ObjectHideFlags: 0

type: 3}
m_PrefabInstance: {fileID: 4298710388100857161}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &5225872683286218120
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 928224351994020785}
m_Modifications:
- target: {fileID: 2815881603653157998, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_Name
value: UIHealthbar
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_SizeDelta.x
value: 100
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_SizeDelta.y
value: 20
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalPosition.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalRotation.w
value: 0.026469946
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalRotation.x
value: 0.011508226
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalRotation.y
value: -0.9995812
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalRotation.z
value: 0.00209032
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_AnchoredPosition.x
value: -0.01
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0.28
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6352810064952983069, guid: 8f80078235ba241aaa576eba63c44a25,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8f80078235ba241aaa576eba63c44a25, type: 3}
--- !u!1001 &5431934865371800706
PrefabInstance:
m_ObjectHideFlags: 0

2
UOP1_Project/Assets/Scripts/.DS_Store
文件差异内容过多而无法显示
查看文件

4
UOP1_Project/Assets/Scripts/Quests/QuestManagerSO.cs


}
public DialogueDataSO InteractWithCharacter(ActorSO actor, bool isCheckValidity, bool isValid)
{
Debug.Log("current quest" + _currentQuest);
if (_currentQuest == null)
{ if (_currentQuest == null)
{
if (CheckQuestlineForQuestWithActor(actor))
{

394
UOP1_Project/Assets/Prefabs/UI/UIHealthbar.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &129456778788504016
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4477411494155732534}
- component: {fileID: 8675558951552184746}
m_Layer: 9
m_Name: SliderHealth
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4477411494155732534
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 129456778788504016}
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_Children:
- {fileID: 3377568230114908328}
- {fileID: 7579906292151165910}
m_Father: {fileID: 6352810064952983069}
m_RootOrder: 0
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!114 &8675558951552184746
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 129456778788504016}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 67db9e8f0e2ae9c40bc1e2b64352a6b4, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
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}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 0}
m_FillRect: {fileID: 9168795744388526357}
m_HandleRect: {fileID: 0}
m_Direction: 0
m_MinValue: 0
m_MaxValue: 1
m_WholeNumbers: 0
m_Value: 0.558
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
--- !u!1 &2717470933152208211
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7579906292151165910}
m_Layer: 9
m_Name: Fill Area
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &7579906292151165910
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2717470933152208211}
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_Children:
- {fileID: 9168795744388526357}
m_Father: {fileID: 4477411494155732534}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.25}
m_AnchorMax: {x: 1, y: 0.75}
m_AnchoredPosition: {x: -5, y: 0}
m_SizeDelta: {x: -20, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &2770995023073704661
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3377568230114908328}
- component: {fileID: 3660815796988947421}
- component: {fileID: 3283600458638593579}
m_Layer: 9
m_Name: Background
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &3377568230114908328
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2770995023073704661}
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_Children: []
m_Father: {fileID: 4477411494155732534}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.25}
m_AnchorMax: {x: 1, y: 0.75}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3660815796988947421
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2770995023073704661}
m_CullTransparentMesh: 1
--- !u!114 &3283600458638593579
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2770995023073704661}
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: 1, g: 1, b: 1, 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: 10907, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
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!1 &2815881603653157998
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6352810064952983069}
- component: {fileID: 6395593152779691077}
- component: {fileID: 7686382842736750647}
- component: {fileID: 4731765889197187948}
- component: {fileID: 7057594148529581253}
m_Layer: 9
m_Name: UIHealthbar
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6352810064952983069
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2815881603653157998}
m_LocalRotation: {x: 0.011508226, y: -0.9995812, z: 0.00209032, w: 0.026469946}
m_LocalPosition: {x: 0, y: 0, z: -0}
m_LocalScale: {x: 0.015, y: 0.015, z: 1}
m_Children:
- {fileID: 4477411494155732534}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: -0.01, y: 0.28}
m_SizeDelta: {x: 100, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &6395593152779691077
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2815881603653157998}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 2
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &7686382842736750647
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2815881603653157998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 1
--- !u!114 &4731765889197187948
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2815881603653157998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &7057594148529581253
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2815881603653157998}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f8dfad91156ef4bff806fff3c3f9eacd, type: 3}
m_Name:
m_EditorClassIdentifier:
_healthBar: {fileID: 8675558951552184746}
_setHealthBar: {fileID: 11400000, guid: de4a39f85969d44cba990125224ff7ef, type: 2}
_inflictDamage: {fileID: 11400000, guid: be921b398c68d450e9e3c55dde697149, type: 2}
_restoreHealth: {fileID: 11400000, guid: 22e3f27f002de44b4948988138dd9377, type: 2}
--- !u!1 &8076465948275431472
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9168795744388526357}
- component: {fileID: 6388844992306058055}
- component: {fileID: 8967380021000610061}
m_Layer: 9
m_Name: Fill
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &9168795744388526357
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8076465948275431472}
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_Children: []
m_Father: {fileID: 7579906292151165910}
m_RootOrder: 0
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: 0}
m_SizeDelta: {x: 10, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &6388844992306058055
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8076465948275431472}
m_CullTransparentMesh: 1
--- !u!114 &8967380021000610061
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8076465948275431472}
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: 1, g: 1, b: 1, 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: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1

7
UOP1_Project/Assets/Prefabs/UI/UIHealthbar.prefab.meta


fileFormatVersion: 2
guid: 8f80078235ba241aaa576eba63c44a25
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar.meta


fileFormatVersion: 2
guid: 4847ec491583f43db9ae3cf2340ec4ee
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

77
UOP1_Project/Assets/UIHealthBarManager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIHealthBarManager : MonoBehaviour
{
Transform target;
int maxHealth=0;
int currentHealth=0;
[SerializeField] private Slider _healthBar = default;
[Header("Listening to")]
[SerializeField] private IntEventChannelSO _setHealthBar = default;
[SerializeField] private IntEventChannelSO _inflictDamage = default;
[SerializeField] private IntEventChannelSO _restoreHealth = default;
private void OnEnable()
{
if((GetComponent<Canvas>()!=null)&&(Camera.main!=null))
{
GetComponent<Canvas>().worldCamera = Camera.main;
target = Camera.main.transform;
}
}
private void Start()
{
if (_setHealthBar != null)
{
_setHealthBar.OnEventRaised += SetHealthBar;
}
if (_inflictDamage != null)
{
_inflictDamage.OnEventRaised += InflictDamage;
}
if (_restoreHealth != null)
{
_restoreHealth.OnEventRaised += RestoreHealth;
}
}
public void SetHealthBar(int _maxHealth)
{
maxHealth = _maxHealth;
currentHealth = _maxHealth;
setSlider();
}
public void InflictDamage(int _damage)
{
currentHealth -= _damage;
setSlider();
}
public void RestoreHealth(int _healthToAdd)
{
currentHealth += _healthToAdd;
setSlider();
}
void setSlider()
{
//clamp current value
currentHealth = Mathf.Clamp(currentHealth, 0, maxHealth);
//find new slider value
float sliderValue = 0;
sliderValue = currentHealth / maxHealth;
_healthBar.value = sliderValue;
}
private void Update()
{
if (target != null)
transform.LookAt(target, Vector3.down);
}
}

11
UOP1_Project/Assets/UIHealthBarManager.cs.meta


fileFormatVersion: 2
guid: f8dfad91156ef4bff806fff3c3f9eacd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/InflictDamageEvent.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 696142ab7e0adf0478f66a5c9e06a168, type: 3}
m_Name: InflictDamageEvent
m_EditorClassIdentifier:
description:

8
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/InflictDamageEvent.asset.meta


fileFormatVersion: 2
guid: be921b398c68d450e9e3c55dde697149
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/RestoreHealthEvent.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 696142ab7e0adf0478f66a5c9e06a168, type: 3}
m_Name: RestoreHealthEvent
m_EditorClassIdentifier:
description:

8
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/RestoreHealthEvent.asset.meta


fileFormatVersion: 2
guid: de4a39f85969d44cba990125224ff7ef
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/SetHealthbarEvent.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 696142ab7e0adf0478f66a5c9e06a168, type: 3}
m_Name: SetHealthbarEvent
m_EditorClassIdentifier:
description:

8
UOP1_Project/Assets/ScriptableObjects/Events/Healthbar/SetHealthbarEvent.asset.meta


fileFormatVersion: 2
guid: 22e3f27f002de44b4948988138dd9377
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存