56 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
		
		
			
		
	
	
			56 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
|  | using UnrealSharp.Engine; | ||
|  | using UI.Level.Controllers; | ||
|  | using UnrealSharp.Attributes; | ||
|  | using UnrealSharp.BusyRabbit; | ||
|  | using UnrealSharp; | ||
|  | 
 | ||
|  | namespace UI.Level.StateBar; | ||
|  | 
 | ||
|  | [UClass] | ||
|  | public class UBusyWidgetStateBar : UPW_MinimalWidget | ||
|  | { | ||
|  |     protected UBusyWidgetHealthBar? WBP_HealthBar { get { return GetWidget("WBP_HealthBar") as UBusyWidgetHealthBar; } } | ||
|  |     protected UBusyWidgetSatietyBar? WBP_SatietyBar { get { return GetWidget("WBP_SatietyBar") as UBusyWidgetSatietyBar; } } | ||
|  | 
 | ||
|  |     protected UBusyRoleStateController? UIController; | ||
|  | 
 | ||
|  | 
 | ||
|  |     public override void Construct() | ||
|  |     { | ||
|  |         base.Construct(); | ||
|  |         WBP_SatietyBar.SetSatietyConfig(100, 200); | ||
|  | 
 | ||
|  |         UIController = UUIFunctionLibrary.GetUIController(this, "RoleState") as UBusyRoleStateController; | ||
|  | 
 | ||
|  |         InitRoleAttribute(); | ||
|  |         UIController.OnAttributeChangeDelegate += OnAttributeChanged; | ||
|  | 
 | ||
|  |     } | ||
|  | 
 | ||
|  |     public void InitRoleAttribute() | ||
|  |     { | ||
|  |         float CurHealth = UIController.GetControlledAttribute("Health"); | ||
|  |         float MaxHealth = UIController.GetControlledAttribute("MaxHealth"); | ||
|  |         float CurSatiety = UIController.GetControlledAttribute("Hunger"); | ||
|  |         float MaxSatiety = UIController.GetControlledAttribute("MaxHunger"); | ||
|  |         WBP_HealthBar.SetHpConfig(CurHealth, MaxHealth); | ||
|  |         WBP_SatietyBar.SetSatietyConfig(CurSatiety, MaxSatiety); | ||
|  |     } | ||
|  | 
 | ||
|  |     public override void Destruct() | ||
|  |     { | ||
|  |         base.Destruct(); | ||
|  |         UIController.OnAttributeChangeDelegate -= OnAttributeChanged; | ||
|  |     } | ||
|  | 
 | ||
|  | 
 | ||
|  |     [UFunction()] | ||
|  |     protected void OnAttributeChanged(FName AttributeName, float NewValue, float OldValue) | ||
|  |     { | ||
|  |         if (AttributeName == "Hunger") | ||
|  |         { | ||
|  |             WBP_SatietyBar.OnSatietyChanged(NewValue); | ||
|  |         } | ||
|  |     } | ||
|  | } |