OldBlueWater/BlueWater/Assets/02.Scripts/OceanUi.cs

64 lines
1.7 KiB
C#
Raw Normal View History

using System;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.UI;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
[Serializable]
public class ProcessBar
{
[field: SerializeField] public GameObject Obj { get; set; }
[field: SerializeField] public Image Fill { get; set; }
public ProcessBar(GameObject obj, Image fill)
{
Obj = obj;
Fill = fill;
SetFillAmount(0f);
}
public void SetActive(bool value) => Obj.SetActive(value);
public void SetPosition(Vector3 value) => Obj.transform.position = value;
public void SetFillAmount(float value) => Fill.fillAmount = value;
}
public class OceanUi : MonoBehaviour
{
[field: SerializeField] public ProcessBar ProcessBar { get; set; }
private Canvas canvas;
private void Awake()
{
UiManager.Inst.OceanUi = this;
ProcessBar.SetActive(false);
}
private void Update()
{
if (ProcessBar.Obj.activeSelf)
{
var mousePos = Input.mousePosition;
ProcessBar.SetPosition(mousePos);
}
}
[Button("셋팅 초기화")]
private void Init()
{
canvas = GetComponent<Canvas>();
if (!canvas)
{
Debug.LogError("canvas is null error");
return;
}
var processBar = canvas.transform.Find("ProcessBar").gameObject;
var fill = processBar.transform.Find("Fill").GetComponent<Image>();
ProcessBar = new ProcessBar(processBar, fill);
}
}
}