- visual update on riftraids - ability unlock system through ability tomes - (possible) bugfix sprite issue - player reputation level
82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using Kryz.CharacterStats.Examples;
|
|
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ExperienceBarUI : MonoBehaviour
|
|
{
|
|
[Header("Components:")]
|
|
[SerializeField] private TMP_Text level;
|
|
[SerializeField] private TMP_Text nextLevel;
|
|
[SerializeField] private TMP_Text experienceBar;
|
|
[SerializeField] private Image experienceBarFill;
|
|
[Header("Listeners:")]
|
|
[SerializeField] private GameEventListener_PhotonView onPlayerSpawned;
|
|
public bool isRepBar = false;
|
|
|
|
PlayerCharacterStats player;
|
|
|
|
float startingWidth;
|
|
|
|
float currentFill;
|
|
|
|
RectTransform rectFill;
|
|
RectMask2D mask;
|
|
|
|
Vector4 sizeFill = new Vector4();
|
|
|
|
private void Awake()
|
|
{
|
|
onPlayerSpawned.Response.AddListener(DependancyInjection);
|
|
|
|
rectFill = experienceBarFill.GetComponent<RectTransform>();
|
|
mask = experienceBarFill.GetComponent<RectMask2D>();
|
|
startingWidth = rectFill.rect.width;
|
|
}
|
|
|
|
private void DependancyInjection(PhotonView spawnedPlayer)
|
|
{
|
|
if (!spawnedPlayer.IsMine) return;
|
|
|
|
player = ((RiftPlayer)spawnedPlayer.Owner.TagObject).GetComponent<PlayerCharacterStats>();
|
|
if(isRepBar)
|
|
{
|
|
player.reputationLevel.OnLevelUpEvent.AddListener(UpdateLevelText);
|
|
player.reputationLevel.OnExperienceChanged.AddListener(UpdateLevelText);
|
|
}
|
|
else
|
|
{
|
|
player.level.OnLevelUpEvent.AddListener(UpdateLevelText);
|
|
player.level.OnExperienceChanged.AddListener(UpdateLevelText);
|
|
}
|
|
|
|
UpdateLevelText();
|
|
|
|
|
|
}
|
|
|
|
|
|
public void UpdateLevelText()
|
|
{
|
|
level.text = isRepBar ? player.reputationLevel.currentLevel.ToString() : player.level.currentLevel.ToString();
|
|
nextLevel.text = isRepBar ? (player.reputationLevel.currentLevel + 1).ToString() : (player.level.currentLevel + 1).ToString();
|
|
experienceBar.text = isRepBar ? $"{player.reputationLevel.GetCurrentExperience().ToString("F1")}/{player.reputationLevel.FinalExperienceThreshold.ToString("F1")}" : $"{player.level.GetCurrentExperience().ToString("F1")}/{player.level.FinalExperienceThreshold.ToString("F1")}";
|
|
SetCurrentFill();
|
|
}
|
|
|
|
private void SetCurrentFill()
|
|
{
|
|
currentFill = isRepBar ? player.reputationLevel.GetCurrentExperience() / player.reputationLevel.FinalExperienceThreshold : player.level.GetCurrentExperience() / player.level.FinalExperienceThreshold;
|
|
|
|
sizeFill.x = 0;
|
|
sizeFill.y = 0;
|
|
sizeFill.z = startingWidth - (currentFill * startingWidth);
|
|
sizeFill.w = 0;
|
|
|
|
mask.padding = sizeFill;
|
|
}
|
|
}
|