I’ve made both and I need your opinion witch one you would prefer using and why?
First I did structure I love them
using UnityEngine;
using System.Collections;
public struct MenuLabels {
/// Changes Both Min&Max changes dinamically
public static void DinamicHorizontalSliderF(string Name, ref float Value, ref float SliderMinValue, ref float SliderMaxValue, float GuiWidth){
GUILayout.BeginHorizontal();
GUILayout.Label(Name + Value);
HorizontalSlider(ref Value, SliderMinValue, SliderMaxValue, GuiWidth);
GUILayout.EndHorizontal();
ChangeMinSlider(Value, ref SliderMinValue);
ChangeMaxSlider(Value, ref SliderMaxValue);
}
/// Changes from MinValue to dinamic MaxValue
public static void DinamicPositiveHorizontalSliderF(string Name, ref float Value, float SliderMinValue, ref float SliderMaxValue, float GuiWidth){
GUILayout.BeginHorizontal();
GUILayout.Label(Name + Value);
HorizontalSlider(ref Value, SliderMinValue, SliderMaxValue, GuiWidth);
GUILayout.EndHorizontal();
ChangeMaxSlider(Value, ref SliderMaxValue);
}
private static void HorizontalSlider(ref float Value, float SliderMinValue, float SliderMaxValue, float GuiWidth){
Value = GUILayout.HorizontalScrollbar((Value), 0.01f, SliderMinValue, SliderMaxValue, GUILayout.Width(50) );
}
private static void ChangeMinSlider(float Value, ref float SliderMinValue){
if (SliderMinValue >= Value){
SliderMinValue --;
}
else if (SliderMinValue <= Value-5){
SliderMinValue ++;
}
}
private static void ChangeMaxSlider(float Value, ref float SliderMaxValue){
if (SliderMaxValue <= Value+1){
SliderMaxValue ++;
}
else if (SliderMaxValue >= Value+6){
SliderMaxValue --;
}
}
}
Called with:
using System;
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour {
float TestValue = 5;
private float HallWaySliderMin = 0;
private float HallWaySliderMax = 10;
void OnGUI(){
MenuLabels.DinamicPositiveHorizontalSliderF("% to make fake ", ref TestValue, HallWaySliderMin, ref HallWaySliderMax, 50);
}
I didn’t like bunch of stuff in the MainMenu code so I did this:
but ended with same stuff in MainMenu
using UnityEngine;
using System.Collections;
public class Slider {
private string _Name;
private float _Value;
private bool[] _Dinamic;
private float _SliderMin;
private float _SliderMinValue;
private float _SliderMax;
private float _SliderMaxValue;
private float _GuiWidth;
/***** START CONSTRUCTORS *****/
public Slider(string Name, float Value, bool DinamicMinSlider, float SliderMinValue, bool DinamicMaxSlider, float SliderMaxValue, float GuiWidth){
_Name = Name;
_Value = Value;
_Dinamic = new bool[2] { DinamicMinSlider, DinamicMaxSlider };
_SliderMin = SliderMinValue;
if (_Dinamic[0]) {_SliderMinValue = Value * 0.9f;}
else {_SliderMinValue = _SliderMin;}
_SliderMax = SliderMaxValue;
if (_Dinamic[1]) {_SliderMaxValue = _Value * 1.1f;}
else {_SliderMaxValue = _SliderMax;}
_GuiWidth = GuiWidth;
}
/***** END CONSTRUCTORS *****/
public float HorizontalSlider(float Value){
GUILayout.BeginHorizontal();
GUILayout.Label(_Name + Value);
_Value = GUILayout.HorizontalScrollbar(Value, 0.01f, _SliderMinValue, _SliderMaxValue, GUILayout.Width( _GuiWidth ) );
GUILayout.EndHorizontal();
if (_Dinamic[0]){
if (_SliderMinValue >= _Value){
_SliderMinValue --;
}
else if (_SliderMinValue <= _Value-5){
_SliderMinValue ++;
}
}
if (_Dinamic[1]){
if (_SliderMaxValue <= _Value+1){
_SliderMaxValue ++;
}
else if (_SliderMaxValue >= _Value+6){
_SliderMaxValue --;
}
}
return _Value;
}
}
and I call it with:
using System;
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour {
Slider Test;
float TestValue = 5;
void Awake(){
Test = new Slider("% to make fake ", TestValue, true, 0f, true, 5f, 50f);
}
void OnGUI(){
TestValue = Test.HorizontalSlider(TestValue);
}
I want your honest opinion witch way would you choose and why.
thanks in advance