Skip to content

uranuno/UnityUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnityUtils

Tag and Layer Attribute

Assets/Utils/TagAttribute.cs
Assets/Utils/LayerAttribute.cs

[Tag]
public string targetTag;

[Layer]
public int targetLayer;

Tag And Layer Attribute

Tag And Layer Attribute - Tag Tag And Layer Attribute - Layer

Min Max

Assets/Utils/MinMax.cs

// [Range(0,10f)]
// public float otherValue;

[SerializeField, MinMaxRange(0,10f)]
MinMax randomDelayRange;

float delay;
float accum;

void Update () {
	accum += Time.deltaTime;

	if (accum >= delay) {
		Debug.Log ("Fire!");
		accum = 0;
		delay = randomDelayRange.randomValue;
	}
}

Min Max Range Attribute

PlayerPrefs Data

Assets/Utils/PlayerPrefsData.cs

Helper for saving objects with PlayerPrefs.

// Custom Class to save with PlayerPrefs
public class AudioSettings
{
	public float bgmVolume = 1f;
	public float seVolume  = 1f;
}
void LoadData ()
{
	var data = PlayerPrefsData<AudioSettings>.Load (
		// Default Value
		new AudioSettings ()
	);

	m_BgmVolumeSlider.value = data.bgmVolume;
	m_SeVolumeSlider.value = data.seVolume;
}

void SaveData ()
{
	var data = new AudioSettings ();
	data.bgmVolume = m_BgmVolumeSlider.value;
	data.seVolume = m_SeVolumeSlider.value;

	PlayerPrefsData<AudioSettings>.Save (data);
}

void ResetData ()
{
	PlayerPrefsData<AudioSettings>.Delete ();
	// Reload
	LoadData ();
}

PlayerPrefs Data

Releases

No releases published

Packages

No packages published

Languages