mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2025-02-23 05:24:32 +01:00
60 lines
No EOL
2.2 KiB
C#
60 lines
No EOL
2.2 KiB
C#
// Copyright (c) 2015 Augie R. Maddox, Guavaman Enterprises. All rights reserved.
|
|
#pragma warning disable 0219
|
|
#pragma warning disable 0618
|
|
#pragma warning disable 0649
|
|
|
|
namespace Rewired.UI.ControlMapper {
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
|
|
[AddComponentMenu("")]
|
|
public class UIControlSet : MonoBehaviour {
|
|
|
|
[SerializeField]
|
|
private Text title;
|
|
|
|
private Dictionary<int, UIControl> _controls;
|
|
private Dictionary<int, UIControl> controls => _controls ?? (_controls = new Dictionary<int, UIControl>());
|
|
|
|
public void SetTitle(string text) {
|
|
if(title == null) return;
|
|
title.text = text;
|
|
}
|
|
|
|
public T GetControl<T>(int uniqueId) where T : UIControl {
|
|
UIControl control;
|
|
controls.TryGetValue(uniqueId, out control);
|
|
return control as T;
|
|
}
|
|
|
|
public UISliderControl CreateSlider(GameObject prefab, Sprite icon, float minValue, float maxValue, System.Action<int, float> valueChangedCallback, System.Action<int> cancelCallback) {
|
|
GameObject instance = (GameObject)Object.Instantiate(prefab);
|
|
UISliderControl control = instance.GetComponent<UISliderControl>();
|
|
if(control == null) {
|
|
Object.Destroy(instance);
|
|
Debug.LogError("Prefab missing UISliderControl component!");
|
|
return null;
|
|
}
|
|
|
|
instance.transform.SetParent(this.transform, false);
|
|
if(control.iconImage != null) {
|
|
control.iconImage.sprite = icon;
|
|
}
|
|
if(control.slider != null) {
|
|
control.slider.minValue = minValue;
|
|
control.slider.maxValue = maxValue;
|
|
if(valueChangedCallback != null) {
|
|
control.slider.onValueChanged.AddListener((float value) => { valueChangedCallback(control.id, value); });
|
|
}
|
|
if(cancelCallback != null) {
|
|
control.SetCancelCallback(() => { cancelCallback(control.id); });
|
|
}
|
|
}
|
|
controls.Add(control.id, control);
|
|
return control;
|
|
}
|
|
|
|
}
|
|
} |