add project files
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public AudioMixer mixer;
|
||||
|
||||
public AudioListener listener;
|
||||
|
||||
public string sfxVolumeParamName;
|
||||
|
||||
public string musicVolumeParamName;
|
||||
|
||||
private AudioSource _currentMusicSource;
|
||||
|
||||
private IEnumerator _crossFadeCoroutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
public void Setup(bool masterEnabled, bool sfxEnabled, bool musicEnabled)
|
||||
{
|
||||
SetMasterEnabled(masterEnabled);
|
||||
SetGroupEnabled(musicVolumeParamName, musicEnabled);
|
||||
SetGroupEnabled(sfxVolumeParamName, sfxEnabled);
|
||||
}
|
||||
|
||||
public void SetMasterEnabled(bool enabled)
|
||||
{
|
||||
if (listener != null)
|
||||
{
|
||||
listener.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMusicEnabled(bool enabled)
|
||||
{
|
||||
SetGroupEnabled(musicVolumeParamName, enabled);
|
||||
}
|
||||
|
||||
public void SetSFXEnabled(bool enabled)
|
||||
{
|
||||
SetGroupEnabled(sfxVolumeParamName, enabled);
|
||||
}
|
||||
|
||||
private void SetGroupEnabled(string paramName, bool enabled)
|
||||
{
|
||||
mixer.SetFloat(paramName, enabled ? 0f : -100f);
|
||||
}
|
||||
|
||||
public void StopCurrentMusic()
|
||||
{
|
||||
if (_currentMusicSource != null)
|
||||
{
|
||||
_currentMusicSource.Stop();
|
||||
_currentMusicSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMusic(AudioSource source)
|
||||
{
|
||||
StopCrossFade();
|
||||
StopCurrentMusic();
|
||||
if (source == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
source.volume = 1f;
|
||||
source.Play();
|
||||
_currentMusicSource = source;
|
||||
}
|
||||
|
||||
private void StopCrossFade()
|
||||
{
|
||||
if (_crossFadeCoroutine != null)
|
||||
{
|
||||
StopCoroutine(_crossFadeCoroutine);
|
||||
_crossFadeCoroutine = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void CrossFadeMusic(AudioSource newSource, float duration)
|
||||
{
|
||||
StopCrossFade();
|
||||
_crossFadeCoroutine = CrossFadeCoroutine(_currentMusicSource, newSource, duration);
|
||||
_currentMusicSource = newSource;
|
||||
StartCoroutine(_crossFadeCoroutine);
|
||||
}
|
||||
|
||||
private IEnumerator CrossFadeCoroutine(AudioSource prevSource, AudioSource newSource, float duration)
|
||||
{
|
||||
if (newSource != null)
|
||||
{
|
||||
newSource.Play();
|
||||
}
|
||||
for (float t = 0f; t < duration; t += Time.deltaTime)
|
||||
{
|
||||
float ratio = t / duration;
|
||||
if (prevSource != null)
|
||||
{
|
||||
prevSource.volume = 1f - ratio;
|
||||
}
|
||||
if (newSource != null)
|
||||
{
|
||||
newSource.volume = ratio;
|
||||
}
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
if (prevSource != null)
|
||||
{
|
||||
prevSource.Stop();
|
||||
}
|
||||
_crossFadeCoroutine = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e52e6de4149c29a602c52866024241e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class ComponentsUtils
|
||||
{
|
||||
public static bool GetRequiredComponentInChildren<ComponentToFind>(Component parent, ref ComponentToFind componentToFind)
|
||||
{
|
||||
if (!IsNull(componentToFind))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
componentToFind = parent.GetComponentInChildren<ComponentToFind>(true);
|
||||
return !IsNull(componentToFind);
|
||||
}
|
||||
|
||||
public static bool GetRequiredComponentInParent<ComponentToFind>(Component parent, ref ComponentToFind componentToFind)
|
||||
{
|
||||
if (!IsNull(componentToFind))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
componentToFind = parent.GetComponentInParent<ComponentToFind>();
|
||||
return !IsNull(componentToFind);
|
||||
}
|
||||
|
||||
public static bool GetRequiredComponent<ComponentToFind>(Component parent, ref ComponentToFind componentToFind)
|
||||
{
|
||||
if (!IsNull(componentToFind))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
componentToFind = parent.GetComponent<ComponentToFind>();
|
||||
return !IsNull(componentToFind);
|
||||
}
|
||||
|
||||
public static ComponentToFind GetRequiredComponent<ComponentToFind>(Component parent)
|
||||
{
|
||||
return parent.GetComponent<ComponentToFind>();
|
||||
}
|
||||
|
||||
private static bool IsNull<T>(T value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return value is UnityEngine.Object obj && obj == null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b86ee851c870f1cc8e1ec0b194b9055
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit.Pooling;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class DelayedDestroy : MonoBehaviour, PooledObjectListener
|
||||
{
|
||||
public float delay;
|
||||
|
||||
public bool unscaledTime;
|
||||
|
||||
private float _remainingDelay;
|
||||
|
||||
public void OnRelease()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
_remainingDelay = delay;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_remainingDelay = delay;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_remainingDelay -= (unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
|
||||
if (_remainingDelay <= 0f)
|
||||
{
|
||||
PoolsManager.ReleaseObject(base.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ca4b3590601b593d5b7dd313214dff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34695aee27e59ce4d8c66fafc03cc111
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.FSM
|
||||
{
|
||||
public class FiniteStateMachine<StateType> where StateType : StateBase<StateType>
|
||||
{
|
||||
private float _currentStateStartTime;
|
||||
|
||||
public StateType CurrentState { get; private set; }
|
||||
|
||||
public void SetState(StateType state)
|
||||
{
|
||||
if (state == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (CurrentState != null)
|
||||
{
|
||||
CurrentState.Leave();
|
||||
}
|
||||
_currentStateStartTime = Time.time;
|
||||
CurrentState = state;
|
||||
state.Enter();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (CurrentState == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CurrentState.Update();
|
||||
if (CurrentState == null || CurrentState.NextState == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (Time.time - _currentStateStartTime >= CurrentState.MaxDuration)
|
||||
{
|
||||
SetState(CurrentState.NextState as StateType);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetCurrentStateDuration()
|
||||
{
|
||||
return Time.time - _currentStateStartTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe38a94f0266a7f489a17d4ee5f664fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
|
||||
namespace OHM.UnityToolkit.FSM
|
||||
{
|
||||
public class StateBase<T> where T : StateBase<T>
|
||||
{
|
||||
public Action startAction;
|
||||
|
||||
public Action updateAction;
|
||||
|
||||
public Action leaveAction;
|
||||
|
||||
public float MaxDuration { get; private set; }
|
||||
|
||||
public StateBase<T> NextState { get; private set; }
|
||||
|
||||
public void SetAutoTransition(StateBase<T> nextState, float duration)
|
||||
{
|
||||
MaxDuration = duration;
|
||||
NextState = nextState;
|
||||
}
|
||||
|
||||
public void Enter()
|
||||
{
|
||||
if (startAction != null)
|
||||
{
|
||||
startAction();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (updateAction != null)
|
||||
{
|
||||
updateAction();
|
||||
}
|
||||
}
|
||||
|
||||
public void Leave()
|
||||
{
|
||||
if (leaveAction != null)
|
||||
{
|
||||
leaveAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fceeb876c34166646ba3b9dcda3bfa17
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit.Pooling;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class FX : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Animator animator;
|
||||
|
||||
[SerializeField]
|
||||
public ParticleSystem[] particlesArray;
|
||||
|
||||
[SerializeField]
|
||||
public SFX soundFx;
|
||||
|
||||
[SerializeField]
|
||||
public string cameraTrigger;
|
||||
|
||||
[SerializeField]
|
||||
public Transform defaultSpawningCont;
|
||||
|
||||
[SerializeField]
|
||||
public ParticleSystem particles;
|
||||
|
||||
public SFXInstance SfxInstance { get; set; }
|
||||
|
||||
public void PlayNow()
|
||||
{
|
||||
PlayInstance(null, null);
|
||||
}
|
||||
|
||||
public static void TryPlayInstance(FX fx, Transform spawnerObj, Transform otherParent)
|
||||
{
|
||||
if (fx != null)
|
||||
{
|
||||
fx.PlayInstance(spawnerObj, otherParent);
|
||||
}
|
||||
}
|
||||
|
||||
public FX PlayInstance(Transform spawnerObj, Transform otherParent)
|
||||
{
|
||||
Transform parent = ((otherParent != null) ? otherParent : defaultSpawningCont);
|
||||
FX instance = PoolsManager.InstantiatePrefab(this, parent, Vector3.zero, Quaternion.identity);
|
||||
instance.gameObject.SetActive(value: true);
|
||||
instance.PlayInternal();
|
||||
if (spawnerObj != null)
|
||||
{
|
||||
instance.transform.position = spawnerObj.position;
|
||||
instance.transform.rotation = spawnerObj.rotation;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected void PlayInternal()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetTrigger("Play");
|
||||
}
|
||||
PlayParticles();
|
||||
if (soundFx != null)
|
||||
{
|
||||
soundFx.Play(base.transform);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(cameraTrigger))
|
||||
{
|
||||
FXCamAnimator camAnimator = Camera.main.GetComponent<FXCamAnimator>();
|
||||
if (camAnimator != null)
|
||||
{
|
||||
camAnimator.Trigger(cameraTrigger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayParticles()
|
||||
{
|
||||
if (particles != null)
|
||||
{
|
||||
particles.Play();
|
||||
}
|
||||
if (particlesArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < particlesArray.Length; i++)
|
||||
{
|
||||
if (particlesArray[i] != null)
|
||||
{
|
||||
particlesArray[i].Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StopParticles()
|
||||
{
|
||||
if (particles != null)
|
||||
{
|
||||
particles.Stop();
|
||||
}
|
||||
if (particlesArray == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < particlesArray.Length; i++)
|
||||
{
|
||||
if (particlesArray[i] != null)
|
||||
{
|
||||
particlesArray[i].Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ccb88a1290bb6610976c8e18dd5ab15a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class FXCamAnimator : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("animator")]
|
||||
private Animator _animator;
|
||||
|
||||
public void Trigger(string trigger)
|
||||
{
|
||||
_animator.SetTrigger(trigger);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea9bf2427bf88d4dceee925367ebd4a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd93a8385f7e30b42adbdf0d956d9ec6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class Inventory<TUType> : SerializableDictionary<TUType, long>
|
||||
{
|
||||
public long GetCount(TUType type)
|
||||
{
|
||||
long count;
|
||||
TryGetValue(type, out count);
|
||||
return count;
|
||||
}
|
||||
|
||||
public void AddReward(TransactionUnit<TUType> tu)
|
||||
{
|
||||
AddReward(tu.type, tu.count);
|
||||
}
|
||||
|
||||
public void AddReward(TUType tuType, long count)
|
||||
{
|
||||
if (ContainsKey(tuType))
|
||||
{
|
||||
base[tuType] = base[tuType] + count;
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(tuType, count);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddRewards<T>(TransactionUnitList<T> rewards)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetCount(TUType type, long count)
|
||||
{
|
||||
base[type] = count;
|
||||
}
|
||||
|
||||
public bool HasCost(TransactionUnit<TUType> tu)
|
||||
{
|
||||
if (tu.count == 0L)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!ContainsKey(tu.type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return base[tu.type] >= tu.count;
|
||||
}
|
||||
|
||||
public bool PayCost(TransactionUnit<TUType> tu)
|
||||
{
|
||||
if (tu.count == 0L)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!HasCost(tu))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
base[tu.type] = base[tu.type] - tu.count;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e81f91e0ef1433fe7eb4db7e1c223d07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
public class TUTypeStrId<EnumType>
|
||||
{
|
||||
[SerializeField]
|
||||
public EnumType type;
|
||||
|
||||
[SerializeField]
|
||||
public string id;
|
||||
|
||||
public TUTypeStrId(EnumType type, string id)
|
||||
{
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return new { type, id }.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as TUTypeStrId<EnumType>);
|
||||
}
|
||||
|
||||
public bool Equals(TUTypeStrId<EnumType> obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!EqualityComparer<EnumType>.Default.Equals(type, obj.type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return obj.id == id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db5914e74cbdcc0a236f5d964c4ae678
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class TransactionUnitList<TUType>
|
||||
{
|
||||
[SerializeField]
|
||||
public List<TUType> content = new List<TUType>();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64bd80db38c5011668c87a46a676156e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class TransactionUnit<TUType>
|
||||
{
|
||||
public TUType type;
|
||||
|
||||
public long count;
|
||||
|
||||
public TransactionUnit(TUType type, long count)
|
||||
{
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4cd7a1d785b8f6e443ab5f6821ffc22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a1021beb768abe44b252480533a6c4f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
namespace OHM.UnityToolkit.Localization
|
||||
{
|
||||
[CreateAssetMenu(fileName = "locale_def", menuName = "OHM/Localization/New locale def")]
|
||||
public class LocaleDef : ScriptableObject
|
||||
{
|
||||
public SystemLanguage language;
|
||||
|
||||
public string languageCode;
|
||||
|
||||
public KeysDic keys;
|
||||
|
||||
public void Test()
|
||||
{
|
||||
LocalizationManager.Instance.TestLocale(this);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class KeysDic : SerializableDictionary<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6c6b3ccd7030f728464122b207409c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Localization
|
||||
{
|
||||
[CreateAssetMenu(fileName = "locale_list", menuName = "OHM/Localization/New locales list")]
|
||||
public class LocalesList : ScriptableObject
|
||||
{
|
||||
public List<LocaleDef> locales;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 051df8610b6a0ef645af7b1dfa7323d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
namespace OHM.UnityToolkit.Localization
|
||||
{
|
||||
public class LocalizationManager : UniqueInstance<LocalizationManager>
|
||||
{
|
||||
public LocalesList localesList;
|
||||
|
||||
public bool autoSetLang;
|
||||
|
||||
public UnityEvent OnLangChanged;
|
||||
|
||||
private bool _showDebug;
|
||||
|
||||
public LocaleDef CurrentLocale { get; private set; }
|
||||
|
||||
protected override void AwakeInstance()
|
||||
{
|
||||
if (autoSetLang)
|
||||
{
|
||||
SetLanguage(Application.systemLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLanguage(SystemLanguage lang)
|
||||
{
|
||||
CurrentLocale = null;
|
||||
if (localesList == null || localesList.locales == null || localesList.locales.Count < 1)
|
||||
{
|
||||
Debug.LogError("No locale defined");
|
||||
return;
|
||||
}
|
||||
if (lang == SystemLanguage.Unknown)
|
||||
{
|
||||
lang = Application.systemLanguage;
|
||||
}
|
||||
foreach (LocaleDef locale in localesList.locales)
|
||||
{
|
||||
if (locale.language == lang)
|
||||
{
|
||||
CurrentLocale = locale;
|
||||
}
|
||||
}
|
||||
if (CurrentLocale == null)
|
||||
{
|
||||
CurrentLocale = localesList.locales[0];
|
||||
Debug.Log("No specific locale found for language" + lang + ". Using default : " + CurrentLocale.language);
|
||||
}
|
||||
OnLangChanged.Invoke();
|
||||
}
|
||||
|
||||
public void TestLocale(LocaleDef locale)
|
||||
{
|
||||
CurrentLocale = locale;
|
||||
OnLangChanged.Invoke();
|
||||
}
|
||||
|
||||
public string Localize(string key)
|
||||
{
|
||||
return LocalizationUtils.Localize(CurrentLocale, key);
|
||||
}
|
||||
|
||||
public string LocalizeFormat(string key, object[] args)
|
||||
{
|
||||
string localized = LocalizationUtils.Localize(CurrentLocale, key);
|
||||
try
|
||||
{
|
||||
localized = string.Format(localized, args);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
Debug.LogWarningFormat("Locale key {0} does not match the required format", key);
|
||||
}
|
||||
return localized;
|
||||
}
|
||||
|
||||
public void DrawDebug()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f93e818a9e9afd02bfae28ab1a7cacd5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Localization
|
||||
{
|
||||
public static class LocalizationUtils
|
||||
{
|
||||
public static string Localize(LocaleDef locale, string key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (locale == null)
|
||||
{
|
||||
return "#####";
|
||||
}
|
||||
string value;
|
||||
if (locale.keys != null && locale.keys.TryGetValue(key, out value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return "#" + key + "#";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7346a71832c8bf33a4431c08bd186c3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OHM.UnityToolkit.Localization
|
||||
{
|
||||
public class LocalizedText : MonoBehaviour
|
||||
{
|
||||
public string key;
|
||||
|
||||
public TextWrapper text;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
text = GetComponent<TextWrapper>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ApplyLocalization();
|
||||
LocalizationManager.Instance.OnLangChanged.AddListener(ApplyLocalization);
|
||||
}
|
||||
|
||||
public void ChangeKey(string key)
|
||||
{
|
||||
this.key = key;
|
||||
ApplyLocalization();
|
||||
}
|
||||
|
||||
public void ApplyLocalization()
|
||||
{
|
||||
SetText(string.IsNullOrEmpty(key)
|
||||
? string.Empty
|
||||
: LocalizationUtils.Localize(LocalizationManager.Instance.CurrentLocale, key));
|
||||
}
|
||||
|
||||
private void SetText(string content)
|
||||
{
|
||||
if (text != null)
|
||||
{
|
||||
text.text = content;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff6de81a7eca14b7e2b51b3bb4f69d8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class PersitantDataUtils
|
||||
{
|
||||
public static string GetFullPersitantPath(string subPath)
|
||||
{
|
||||
return Application.persistentDataPath + "/" + subPath;
|
||||
}
|
||||
|
||||
public static bool LoadData<T>(string subPath, out T obj)
|
||||
{
|
||||
string path = GetFullPersitantPath(subPath);
|
||||
Debug.Log("Loading " + path);
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
obj = JsonUtility.FromJson<T>(File.ReadAllText(path));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
obj = default(T);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SaveData<T>(string subPath, T obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllText(GetFullPersitantPath(subPath), JsonUtility.ToJson(obj));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveData(string subPath)
|
||||
{
|
||||
if (File.Exists(GetFullPersitantPath(subPath)))
|
||||
{
|
||||
File.Delete(subPath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f93bbb98b0c7d0ef55e312e8489ad6dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public interface PooledObjectListener
|
||||
{
|
||||
public abstract void OnRelease();
|
||||
|
||||
public abstract void OnReset();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 583766e24c298de16656d8181de7d535
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d704c60890fcec419c36f567ae39dc9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Pooling
|
||||
{
|
||||
public class PooledObject : MonoBehaviour
|
||||
{
|
||||
private int poolId;
|
||||
|
||||
private bool _used;
|
||||
|
||||
public int PoolId => poolId;
|
||||
|
||||
public bool Used => _used;
|
||||
|
||||
public void Use()
|
||||
{
|
||||
_used = true;
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
_used = false;
|
||||
}
|
||||
|
||||
public void AddToPool(int poolId)
|
||||
{
|
||||
this.poolId = poolId;
|
||||
}
|
||||
|
||||
public void RemoveFromPool()
|
||||
{
|
||||
poolId = -1;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (poolId != -1)
|
||||
{
|
||||
Debug.LogWarning("Pooled object " + base.name
|
||||
+ "destroyed whereas not ready. You should not destroy a pooled , but use the PoolsManager");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59525edf21d054c959c2d7401e337332
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,267 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using OHM.UnityToolkit;
|
||||
|
||||
namespace OHM.UnityToolkit.Pooling
|
||||
{
|
||||
public class PoolsManager : UniqueInstance<PoolsManager>
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform poolsContainer;
|
||||
|
||||
[SerializeField]
|
||||
private List<PreloadPrefab> preloadPrefabs;
|
||||
|
||||
private Dictionary<int, Pool> pools;
|
||||
|
||||
public static T InstantiatePrefab<T>(T prefab, Transform parent, Vector3 position, Quaternion rotation, bool startActive = false) where T : Component
|
||||
{
|
||||
PooledObject pooledPrefab = prefab.GetComponent<PooledObject>();
|
||||
if (pooledPrefab != null && Instance != null)
|
||||
{
|
||||
PooledObject instance = Instance.GetObjectFromPrefab(pooledPrefab, parent, position, rotation, startActive);
|
||||
return (instance != null) ? instance.GetComponent<T>() : null;
|
||||
}
|
||||
|
||||
T plain = UnityEngine.Object.Instantiate(prefab, position, rotation, parent);
|
||||
plain.gameObject.SetActive(startActive);
|
||||
return plain;
|
||||
}
|
||||
|
||||
public static void ReleasePooledObject(PooledObject pooledObject)
|
||||
{
|
||||
if (pooledObject != null)
|
||||
{
|
||||
pooledObject.Release();
|
||||
UnityEngine.Object.Destroy(pooledObject.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReleaseObject(GameObject obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
UnityEngine.Object.Destroy(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerator DelayReleaseObject(GameObject go, float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
ReleaseObject(go);
|
||||
}
|
||||
|
||||
public static void ReleaseAllPooledChildren(Transform parent)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PooledObject[] pooled = parent.GetComponentsInChildren<PooledObject>(true);
|
||||
for (int i = 0; i < pooled.Length; i++)
|
||||
{
|
||||
ReleasePooledObject(pooled[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void AwakeInstance()
|
||||
{
|
||||
pools = new Dictionary<int, Pool>();
|
||||
if (preloadPrefabs == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (PreloadPrefab preload in preloadPrefabs)
|
||||
{
|
||||
Pool pool = GetPoolFromPrefab(preload.prefab);
|
||||
GrowPool(pool, preload.prefab, preload.preloadCount);
|
||||
}
|
||||
}
|
||||
|
||||
private int GetPrefabPoolId(PooledObject prefab)
|
||||
{
|
||||
return prefab.gameObject.GetInstanceID();
|
||||
}
|
||||
|
||||
private Pool GetPoolFromPrefab(PooledObject prefab)
|
||||
{
|
||||
int id = GetPrefabPoolId(prefab);
|
||||
Pool pool;
|
||||
if (!pools.TryGetValue(id, out pool))
|
||||
{
|
||||
pool = new Pool();
|
||||
pool.id = id;
|
||||
pool.prefab = prefab;
|
||||
pools[id] = pool;
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
|
||||
private Pool GetPoolId(int poolId)
|
||||
{
|
||||
Pool pool;
|
||||
pools.TryGetValue(poolId, out pool);
|
||||
return pool;
|
||||
}
|
||||
|
||||
private PooledObject GetObjectFromPrefab(PooledObject prefab, Transform parent, Vector3 position, Quaternion rotation, bool startActive = false)
|
||||
{
|
||||
Pool pool = GetPoolFromPrefab(prefab);
|
||||
PooledObject obj = null;
|
||||
if (pool.freeObjects.Count >= 1)
|
||||
{
|
||||
obj = pool.freeObjects[pool.freeObjects.Count - 1];
|
||||
pool.freeObjects.RemoveAt(pool.freeObjects.Count - 1);
|
||||
pool.usedObjets.Add(obj);
|
||||
obj.transform.SetParent(parent);
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
obj = InstantiateObjectForPool(pool, prefab, parent, startActive);
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
obj.transform.position = position;
|
||||
obj.transform.rotation = rotation;
|
||||
obj.gameObject.SetActive(startActive);
|
||||
obj.Use();
|
||||
return obj;
|
||||
}
|
||||
|
||||
private PooledObject InstantiateObjectForPool(Pool pool, PooledObject prefab, Transform parent, bool startActive = false)
|
||||
{
|
||||
bool wasActive = prefab.gameObject.activeSelf;
|
||||
if (wasActive)
|
||||
{
|
||||
prefab.gameObject.SetActive(false);
|
||||
}
|
||||
PooledObject obj = UnityEngine.Object.Instantiate(prefab, parent);
|
||||
if (wasActive)
|
||||
{
|
||||
prefab.gameObject.SetActive(true);
|
||||
}
|
||||
obj.AddToPool(pool.id);
|
||||
obj.name = prefab.name + "_" + pool.totalObjectsCount;
|
||||
pool.totalObjectsCount++;
|
||||
pool.usedObjets.Add(obj);
|
||||
if (startActive)
|
||||
{
|
||||
obj.gameObject.SetActive(true);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void GrowPool(Pool pool, PooledObject prefab, int num)
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
ReleaseObject(InstantiateObjectForPool(pool, prefab, poolsContainer));
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseObject(PooledObject pooledObject)
|
||||
{
|
||||
if (pooledObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!pooledObject.Used)
|
||||
{
|
||||
Debug.LogWarning("Releasing a non used object");
|
||||
return;
|
||||
}
|
||||
Pool pool = GetPoolId(pooledObject.PoolId);
|
||||
if (pool == null)
|
||||
{
|
||||
Debug.LogWarning("Releasing used object but no pool found");
|
||||
return;
|
||||
}
|
||||
if (pool.usedObjets.Contains(pooledObject))
|
||||
{
|
||||
pool.usedObjets.Remove(pooledObject);
|
||||
}
|
||||
pool.freeObjects.Add(pooledObject);
|
||||
pooledObject.Release();
|
||||
pooledObject.gameObject.SetActive(false);
|
||||
pooledObject.transform.SetParent(poolsContainer);
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
if (pools == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (KeyValuePair<int, Pool> entry in pools)
|
||||
{
|
||||
foreach (PooledObject free in entry.Value.freeObjects)
|
||||
{
|
||||
if (free != null)
|
||||
{
|
||||
free.RemoveFromPool();
|
||||
}
|
||||
}
|
||||
entry.Value.freeObjects.Clear();
|
||||
foreach (PooledObject used in entry.Value.usedObjets)
|
||||
{
|
||||
if (used != null)
|
||||
{
|
||||
used.RemoveFromPool();
|
||||
}
|
||||
}
|
||||
entry.Value.usedObjets.Clear();
|
||||
}
|
||||
pools.Clear();
|
||||
}
|
||||
|
||||
public void SaveCurrentToPreloading()
|
||||
{
|
||||
preloadPrefabs.Clear();
|
||||
foreach (KeyValuePair<int, Pool> entry in pools)
|
||||
{
|
||||
var preload = new PreloadPrefab();
|
||||
preload.prefab = entry.Value.prefab;
|
||||
preload.preloadCount = entry.Value.totalObjectsCount;
|
||||
preloadPrefabs.Add(preload);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PreloadPrefab
|
||||
{
|
||||
public PooledObject prefab;
|
||||
|
||||
public int preloadCount;
|
||||
|
||||
}
|
||||
|
||||
private class Pool
|
||||
{
|
||||
public int id = -1;
|
||||
|
||||
public PooledObject prefab;
|
||||
|
||||
public List<PooledObject> freeObjects = new List<PooledObject>();
|
||||
|
||||
public HashSet<PooledObject> usedObjets = new HashSet<PooledObject>();
|
||||
|
||||
public int totalObjectsCount;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70aed98ea9388773529f2508969a5d6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Random = System.Random;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class RandomExtensions
|
||||
{
|
||||
public static RandomState Save(Random random)
|
||||
{
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
new BinaryFormatter().Serialize(stream, random);
|
||||
return new RandomState(stream.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public static Random Restore(RandomState state)
|
||||
{
|
||||
using (MemoryStream stream = new MemoryStream(state.State))
|
||||
{
|
||||
return (Random)new BinaryFormatter().Deserialize(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Bool(Random random)
|
||||
{
|
||||
return random.NextDouble() >= 0.5;
|
||||
}
|
||||
|
||||
public static int MinMax(Random random, int n1, int n2)
|
||||
{
|
||||
if (n1 == n2)
|
||||
{
|
||||
return n1;
|
||||
}
|
||||
int lo = Mathf.Min(n1, n2);
|
||||
int hi = Mathf.Max(n1, n2);
|
||||
return lo + random.Next() % (hi - lo + 1);
|
||||
}
|
||||
|
||||
public static int ListIndex(Random random, int listCount)
|
||||
{
|
||||
return MinMax(random, 0, listCount - 1);
|
||||
}
|
||||
|
||||
public static int ListIndex(Random random, ICollection collection)
|
||||
{
|
||||
return ListIndex(random, collection.Count);
|
||||
}
|
||||
|
||||
public static T ListElem<T>(Random random, List<T> list)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public static float MinMax(Random random, float min, float max)
|
||||
{
|
||||
return (float)((double)(max - min) * random.NextDouble() + (double)min);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d310ec6536203e02d6d4fdc39822749e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
[Serializable]
|
||||
public class RandomPoolElement<T>
|
||||
{
|
||||
[SerializeField]
|
||||
public T element;
|
||||
|
||||
[SerializeField]
|
||||
public int weight;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd65c8950bb362c607f34f32303f3214
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Random = System.Random;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class RandomPoolUtils
|
||||
{
|
||||
private static int getPoolMaxValue<RET, ET>(List<RET> pool)
|
||||
{
|
||||
return default(int);
|
||||
}
|
||||
|
||||
public static ET DrawElementFromPool<RET, ET>(Random random, List<RET> pool)
|
||||
{
|
||||
return default(ET);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf317ebfbbf9f6ba3f2d072b2b383bfd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public struct RandomState
|
||||
{
|
||||
public readonly byte[] State;
|
||||
|
||||
public RandomState(byte[] state)
|
||||
{
|
||||
this = default(RandomState);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a630a4238c5fe51ac7455ce5168789da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
[Serializable]
|
||||
public class SFX
|
||||
{
|
||||
public SFXInstance customPrefab;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
public AudioMixerGroup group;
|
||||
|
||||
public SFXInstance Play(Transform parent)
|
||||
{
|
||||
if (customPrefab == null && clip == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SFXInstance instance = Instanciate(parent);
|
||||
if (instance.audioSource != null)
|
||||
{
|
||||
instance.audioSource.clip = clip;
|
||||
}
|
||||
if (group != null)
|
||||
{
|
||||
instance.audioSource.outputAudioMixerGroup = group;
|
||||
}
|
||||
instance.name = ((instance.audioSource.clip != null) ? ("SFX_" + instance.audioSource.clip.name) : "SFX_noclip");
|
||||
instance.audioSource.Play();
|
||||
return instance;
|
||||
}
|
||||
|
||||
private SFXInstance Instanciate(Transform parent)
|
||||
{
|
||||
SFXInstance prefab = ((customPrefab != null) ? customPrefab : createDefaultInstance());
|
||||
SFXInstance instance = UnityEngine.Object.Instantiate(prefab);
|
||||
instance.gameObject.transform.parent = parent;
|
||||
instance.gameObject.transform.localPosition = Vector3.zero;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private SFXInstance createDefaultInstance()
|
||||
{
|
||||
var go = new GameObject();
|
||||
AudioSource source = go.AddComponent<AudioSource>();
|
||||
source.spatialBlend = 0f;
|
||||
source.playOnAwake = true;
|
||||
SFXInstance instance = go.AddComponent<SFXInstance>();
|
||||
instance.autoDestroyOnEnd = true;
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39c02c58c6c675c7c4f3bfdc472f634f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class SFXInstance : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public bool autoDestroyOnEnd = true;
|
||||
[SerializeField]
|
||||
public AudioSource audioSource;
|
||||
|
||||
public static readonly int[] majorScale = { 2, 2, 1, 2, 2, 2, 1 };
|
||||
|
||||
public static readonly int[] majorScaleMirrored = { 2, 2, 1, 2, 2, 2, 1, -1, -2, -2, -2, -1, -2, -2 };
|
||||
|
||||
public static readonly int[] majorScaleLoop = { 2, 2, 1, 2, 2, 2, -13 };
|
||||
|
||||
public static readonly int[] test = { 2, 2, 1, -5, 0, 2, 2, 1, 2, -7 };
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
ComponentsUtils.GetRequiredComponent(this, ref audioSource);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!autoDestroyOnEnd)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (audioSource != null && audioSource.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
UnityEngine.Object.Destroy(base.gameObject);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (autoDestroyOnEnd)
|
||||
{
|
||||
UnityEngine.Object.Destroy(base.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void RisingPitchShiftingSemiTone(int semitoneCount)
|
||||
{
|
||||
audioSource.pitch = Mathf.Pow(1.06f, semitoneCount);
|
||||
}
|
||||
|
||||
public void RisingPitchShiftingScale(int[] scale, int count)
|
||||
{
|
||||
int semitones = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
semitones += scale[i % scale.Length];
|
||||
}
|
||||
RisingPitchShiftingSemiTone(semitones);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7123a75c22e0554f294bbeddcb0ff59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public abstract class SavedDataController<DataType> : MonoBehaviour
|
||||
{
|
||||
public UnityEvent onStoredPlayerDataUpdated;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("dataPath")]
|
||||
private string _dataPath;
|
||||
|
||||
private DataType _savedData;
|
||||
|
||||
public DataType SavedData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_savedData == null)
|
||||
{
|
||||
_savedData = LoadData();
|
||||
}
|
||||
return _savedData;
|
||||
}
|
||||
private set
|
||||
{
|
||||
_savedData = value;
|
||||
}
|
||||
}
|
||||
|
||||
private DataType LoadData()
|
||||
{
|
||||
DataType data;
|
||||
if (!PersitantDataUtils.LoadData(_dataPath, out data))
|
||||
{
|
||||
data = GetInitialData();
|
||||
_savedData = data;
|
||||
SaveData();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private DataType GetInitialData()
|
||||
{
|
||||
DataType initialData = Activator.CreateInstance<DataType>();
|
||||
FillInitialData(initialData);
|
||||
return initialData;
|
||||
}
|
||||
|
||||
protected abstract void FillInitialData(DataType initialData);
|
||||
|
||||
public void SaveData()
|
||||
{
|
||||
try
|
||||
{
|
||||
onStoredPlayerDataUpdated.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
PersitantDataUtils.SaveData(_dataPath, SavedData);
|
||||
}
|
||||
|
||||
public void ResetData()
|
||||
{
|
||||
_savedData = GetInitialData();
|
||||
SaveData();
|
||||
}
|
||||
|
||||
public void ClearData()
|
||||
{
|
||||
PersitantDataUtils.RemoveData(_dataPath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 319ee02cf6439a7026819a49d1c7a21b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
[Serializable]
|
||||
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("keys")]
|
||||
private List<TKey> _keys = new List<TKey>();
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("values")]
|
||||
private List<TValue> _values = new List<TValue>();
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
_keys.Clear();
|
||||
_values.Clear();
|
||||
foreach (KeyValuePair<TKey, TValue> pair in this)
|
||||
{
|
||||
_keys.Add(pair.Key);
|
||||
_values.Add(pair.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
Clear();
|
||||
if (_keys.Count != _values.Count)
|
||||
{
|
||||
throw new Exception(string.Format(
|
||||
"there are {0} _keys and {1} _values after deserialization. Make sure that both key and value"
|
||||
+ " types are serializable.", _keys.Count, _values.Count));
|
||||
}
|
||||
for (int i = 0; i < _keys.Count; i++)
|
||||
{
|
||||
Add(_keys[i], _values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f58afaf68ca73faada2b5e0b259e20c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40e4e078d9f3d884cac94572bd7b2e37
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using OHM.UnityToolkit.Localization;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UIIncrementableCounter : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public float delay;
|
||||
|
||||
[SerializeField]
|
||||
public float incDuration = 0.1f;
|
||||
[SerializeField]
|
||||
public Animator animator;
|
||||
|
||||
[SerializeField]
|
||||
public TextWrapper text;
|
||||
|
||||
[SerializeField]
|
||||
public bool localized;
|
||||
|
||||
[SerializeField]
|
||||
[TextArea]
|
||||
public string strFormat;
|
||||
|
||||
private long targetValue;
|
||||
|
||||
private float _lastTargetChangeTime;
|
||||
|
||||
private long _lastTargetChangeValue;
|
||||
|
||||
public long currentValue { get; set; }
|
||||
|
||||
public void Init(long value)
|
||||
{
|
||||
targetValue = value;
|
||||
SetCurrentValue(value);
|
||||
}
|
||||
|
||||
public void SetTargetValue(long value)
|
||||
{
|
||||
if (targetValue == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (animator != null && animator.gameObject.activeSelf)
|
||||
{
|
||||
if (value > targetValue)
|
||||
{
|
||||
animator.ResetTrigger("Decrement");
|
||||
animator.SetTrigger("Increment");
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.ResetTrigger("Increment");
|
||||
animator.SetTrigger("Decrement");
|
||||
}
|
||||
}
|
||||
_lastTargetChangeTime = Time.unscaledTime;
|
||||
_lastTargetChangeValue = currentValue;
|
||||
targetValue = value;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (currentValue == targetValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float t = (Time.unscaledTime - _lastTargetChangeTime - delay) / incDuration;
|
||||
if (t < 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (t >= 1f)
|
||||
{
|
||||
SetCurrentValue(targetValue);
|
||||
return;
|
||||
}
|
||||
SetCurrentValue((long)Mathf.Lerp(_lastTargetChangeValue, targetValue, t));
|
||||
}
|
||||
|
||||
private void SetCurrentValue(long value)
|
||||
{
|
||||
currentValue = value;
|
||||
string display;
|
||||
if (string.IsNullOrEmpty(strFormat))
|
||||
{
|
||||
display = value.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
string format = (localized ? LocalizationUtils.Localize(LocalizationManager.Instance.CurrentLocale, strFormat) : strFormat);
|
||||
display = string.Format(format, value);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.text = display;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2161e4642056bc06a65d4705d923b9c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,164 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UIIncrementableGauge : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float incSpeed = 1f;
|
||||
[SerializeField]
|
||||
private float decSpeed = 1f;
|
||||
[SerializeField]
|
||||
private float levelincSpeed = 1f;
|
||||
[SerializeField]
|
||||
public RectTransform gaugeRect;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("gaugeImage")]
|
||||
private Image _gaugeImage;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("imageMaxFillRatio")]
|
||||
private float _imageMaxFillRatio = 1f;
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("x")]
|
||||
private bool _x;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("y")]
|
||||
private bool _y;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("smoothLevelUp")]
|
||||
private bool _smoothLevelUp;
|
||||
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("smoothLevelDown")]
|
||||
private bool _smoothLevelDown;
|
||||
|
||||
private int currentLevel;
|
||||
|
||||
private int _targetLevel;
|
||||
|
||||
private float _targetValue;
|
||||
|
||||
public float CurrentValue { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
currentLevel = 0;
|
||||
CurrentValue = 0f;
|
||||
_targetValue = 0f;
|
||||
SetRawValue(0f);
|
||||
}
|
||||
|
||||
public void SetTargetValue(float value, int level)
|
||||
{
|
||||
if (_targetValue == value && _targetLevel == level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_targetValue = Mathf.Clamp01(value);
|
||||
_targetLevel = level;
|
||||
}
|
||||
|
||||
public void QuickResetToLevel(int level, float value = 0, bool force = false)
|
||||
{
|
||||
_targetValue = value;
|
||||
currentLevel = level;
|
||||
_targetLevel = level;
|
||||
if (force)
|
||||
{
|
||||
CurrentValue = value;
|
||||
}
|
||||
SetRawValue(value);
|
||||
}
|
||||
|
||||
private bool IncValueToTarget(float target, float speed)
|
||||
{
|
||||
float current = CurrentValue;
|
||||
bool rising = target - current >= 0f;
|
||||
float next = current + (rising ? Time.deltaTime : (0f - Time.deltaTime)) * speed;
|
||||
bool reached;
|
||||
if (rising)
|
||||
{
|
||||
reached = next >= target;
|
||||
if (reached)
|
||||
{
|
||||
next = target;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reached = next <= target;
|
||||
if (reached)
|
||||
{
|
||||
next = target;
|
||||
}
|
||||
}
|
||||
SetRawValue(next);
|
||||
return reached;
|
||||
}
|
||||
|
||||
private void LevelTransition(bool smooth, int deltaLevel, float target, float afterValue)
|
||||
{
|
||||
if (!smooth)
|
||||
{
|
||||
currentLevel += deltaLevel;
|
||||
SetRawValue(_targetValue);
|
||||
return;
|
||||
}
|
||||
if (IncValueToTarget(target, levelincSpeed))
|
||||
{
|
||||
currentLevel += deltaLevel;
|
||||
SetRawValue(afterValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_targetLevel == currentLevel)
|
||||
{
|
||||
if (_targetValue > CurrentValue)
|
||||
{
|
||||
IncValueToTarget(_targetValue, incSpeed);
|
||||
}
|
||||
else if (_targetValue <= CurrentValue)
|
||||
{
|
||||
IncValueToTarget(_targetValue, decSpeed);
|
||||
}
|
||||
}
|
||||
else if (_targetLevel > currentLevel)
|
||||
{
|
||||
LevelTransition(_smoothLevelUp, 1, 1f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelTransition(_smoothLevelDown, -1, 0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetRawValue(float value)
|
||||
{
|
||||
CurrentValue = value;
|
||||
float ratio = Mathf.Clamp01(value);
|
||||
if (gaugeRect != null)
|
||||
{
|
||||
Vector2 anchorMax = gaugeRect.anchorMax;
|
||||
gaugeRect.anchorMax = new Vector2(_x ? ratio : anchorMax.x, _y ? ratio : anchorMax.y);
|
||||
}
|
||||
if (_gaugeImage != null)
|
||||
{
|
||||
_gaugeImage.fillAmount = ratio * _imageMaxFillRatio;
|
||||
}
|
||||
}
|
||||
|
||||
public void changeGaugeColor(Color color)
|
||||
{
|
||||
_gaugeImage.color = color;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 840746e70fee1eaead3c9e35da62c31f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UIMenuBase : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected Animator animator;
|
||||
|
||||
[SerializeField]
|
||||
protected GameObject toEnableOnShow;
|
||||
|
||||
[SerializeField]
|
||||
protected bool hideOnBack;
|
||||
|
||||
public UIMenuEvent onShow = new UIMenuEvent();
|
||||
public UIMenuEvent onHide = new UIMenuEvent();
|
||||
public UIMenuInteractionEvent onInteraction = new UIMenuInteractionEvent();
|
||||
protected UIMenusController menuController;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
internal void SetMenuController(UIMenusController menuController)
|
||||
{
|
||||
this.menuController = menuController;
|
||||
}
|
||||
|
||||
public virtual void Show()
|
||||
{
|
||||
base.gameObject.SetActive(value: true);
|
||||
if (toEnableOnShow != null)
|
||||
{
|
||||
toEnableOnShow.SetActive(value: true);
|
||||
}
|
||||
ResetTrigger("Hide");
|
||||
int? trigger = GetAnimParameter("Show");
|
||||
if (trigger.HasValue)
|
||||
{
|
||||
animator.SetTrigger(trigger.Value);
|
||||
}
|
||||
onShow.Invoke(base.name);
|
||||
if (menuController != null)
|
||||
{
|
||||
menuController.PushPopup(this);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Hide()
|
||||
{
|
||||
onHide.Invoke(base.name);
|
||||
if (menuController != null)
|
||||
{
|
||||
menuController.PopPopup(this);
|
||||
}
|
||||
ResetTrigger("Show");
|
||||
int? trigger = GetAnimParameter("Hide");
|
||||
if (trigger.HasValue)
|
||||
{
|
||||
animator.SetTrigger(trigger.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.gameObject.SetActive(value: false);
|
||||
}
|
||||
}
|
||||
|
||||
public void DisableNow()
|
||||
{
|
||||
base.gameObject.SetActive(value: false);
|
||||
}
|
||||
|
||||
protected void ResetTrigger(string id)
|
||||
{
|
||||
int? trigger = GetAnimParameter(id);
|
||||
if (trigger.HasValue)
|
||||
{
|
||||
animator.ResetTrigger(trigger.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected Nullable<int> GetAnimParameter(string name)
|
||||
{
|
||||
if (animator != null && animator.gameObject.activeSelf)
|
||||
{
|
||||
AnimatorControllerParameter[] parameters = animator.parameters;
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (parameters[i].name == name)
|
||||
{
|
||||
return parameters[i].nameHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void OnInteraction(string interactionId)
|
||||
{
|
||||
onInteraction.Invoke(base.name, interactionId);
|
||||
}
|
||||
|
||||
public virtual bool OnBack()
|
||||
{
|
||||
if (!hideOnBack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Hide();
|
||||
return true;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UIMenuEvent : UnityEvent<string>
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UIMenuInteractionEvent : UnityEvent<string, string>
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a12e645c9c64c5561bde3ff087a26ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UIMenusController : MonoBehaviour
|
||||
{
|
||||
public UIMenuBase defaultMenu;
|
||||
|
||||
private List<UIMenuBase> _popupStack = new List<UIMenuBase>();
|
||||
public UIMenuBase[] AllSubMenus { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitSubMenus();
|
||||
if (defaultMenu != null)
|
||||
{
|
||||
HideAllExcept(defaultMenu);
|
||||
}
|
||||
else
|
||||
{
|
||||
HideAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitSubMenus()
|
||||
{
|
||||
AllSubMenus = GetComponentsInChildren<UIMenuBase>(true);
|
||||
for (int i = 0; i < AllSubMenus.Length; i++)
|
||||
{
|
||||
InitSubMenu(AllSubMenus[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void InitSubMenu(UIMenuBase menu)
|
||||
{
|
||||
menu.SetMenuController(this);
|
||||
}
|
||||
|
||||
public void HideAll()
|
||||
{
|
||||
for (int i = 0; i < AllSubMenus.Length; i++)
|
||||
{
|
||||
AllSubMenus[i].Hide();
|
||||
}
|
||||
}
|
||||
|
||||
public void HideAllExcept(UIMenuBase except)
|
||||
{
|
||||
for (int i = 0; i < AllSubMenus.Length; i++)
|
||||
{
|
||||
UIMenuBase menu = AllSubMenus[i];
|
||||
if (menu != except)
|
||||
{
|
||||
menu.Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowDebug(bool state)
|
||||
{
|
||||
}
|
||||
|
||||
public void PushPopup(UIMenuBase popup)
|
||||
{
|
||||
_popupStack.Add(popup);
|
||||
}
|
||||
|
||||
public void PopPopup(UIMenuBase popup)
|
||||
{
|
||||
_popupStack.RemoveAll((UIMenuBase p) => p == popup);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!Input.GetKeyUp(KeyCode.Escape))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var stack = new List<UIMenuBase>(_popupStack);
|
||||
for (int i = stack.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (stack[i].OnBack())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 616d43cbcd2b2c9f08094843492913c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using OHM.UnityToolkit;
|
||||
using OHM.UnityToolkit.Pooling;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UIMoveToTarget : MonoBehaviour, PooledObjectListener
|
||||
{
|
||||
[SerializeField]
|
||||
private RectTransform rectTransform;
|
||||
|
||||
[SerializeField]
|
||||
public RectTransform target;
|
||||
|
||||
[SerializeField]
|
||||
public float initialDelay;
|
||||
|
||||
[SerializeField]
|
||||
public float animDuration;
|
||||
|
||||
[SerializeField]
|
||||
public AnimationCurve xCurve;
|
||||
|
||||
[SerializeField]
|
||||
public AnimationCurve yCurve;
|
||||
|
||||
[SerializeField]
|
||||
public bool autoStart = true;
|
||||
[SerializeField]
|
||||
public bool destroyOnEnd;
|
||||
|
||||
public UnityEvent onMoveDone = new UnityEvent();
|
||||
private void Start()
|
||||
{
|
||||
ComponentsUtils.GetRequiredComponent(this, ref rectTransform);
|
||||
if (autoStart)
|
||||
{
|
||||
StartCoroutine(MoveAnim());
|
||||
}
|
||||
}
|
||||
|
||||
public void StartMove()
|
||||
{
|
||||
StartCoroutine(MoveAnim());
|
||||
}
|
||||
|
||||
private IEnumerator MoveAnim()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
yield return new WaitForSeconds(initialDelay);
|
||||
Vector2 from = rectTransform.anchoredPosition;
|
||||
var delta = (Vector2)target.localPosition - from;
|
||||
for (float t = animDuration; t > 0f; t -= Time.deltaTime)
|
||||
{
|
||||
float ratio = 1f - t / animDuration;
|
||||
rectTransform.anchoredPosition = new Vector2(
|
||||
from.x + xCurve.Evaluate(ratio) * delta.x,
|
||||
from.y + yCurve.Evaluate(ratio) * delta.y);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
onMoveDone.Invoke();
|
||||
if (destroyOnEnd)
|
||||
{
|
||||
PoolsManager.ReleaseObject(base.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
StartCoroutine(MoveAnim());
|
||||
}
|
||||
|
||||
public void OnRelease()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92a9b3325dba89d6ab3eb8c111a45a60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OHM.UnityToolkit.UI
|
||||
{
|
||||
public class UITouchable : Graphic
|
||||
{
|
||||
public override bool Raycast(Vector2 sp, Camera eventCamera)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
vh.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eef9f966ce5bd70aad00e4025069964d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class UIInputBlocker : MonoBehaviour
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2eb36597c25cba982c032b32202c0d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
[RequireComponent(typeof(Toggle))]
|
||||
public class UIToggleOffGraphic : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
[FormerlySerializedAs("offGraphic")]
|
||||
private Graphic _offGraphic;
|
||||
|
||||
[SerializeField]
|
||||
private Toggle toggle;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
ComponentsUtils.GetRequiredComponent(base.transform, ref toggle);
|
||||
toggle.onValueChanged.AddListener(OnToggleChanged);
|
||||
}
|
||||
|
||||
private void OnToggleChanged(bool value)
|
||||
{
|
||||
if (_offGraphic != null)
|
||||
{
|
||||
_offGraphic.gameObject.SetActive(!toggle.isOn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f89041a0a0e824fe8c5e541cacc5fedf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class UIUtils
|
||||
{
|
||||
public static void AlignToWorldObject(Transform worldObject, RectTransform uiObjectToAlign)
|
||||
{
|
||||
if (worldObject != null)
|
||||
{
|
||||
AlignToWorldPosition(worldObject.position, uiObjectToAlign);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AlignToWorldPosition(Vector3 targetWorldPosition, RectTransform uiObjectToAlign)
|
||||
{
|
||||
Camera cam = Camera.main;
|
||||
if (cam == null || uiObjectToAlign == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Canvas canvas = uiObjectToAlign.GetComponentInParent<Canvas>();
|
||||
if (canvas == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
RectTransform canvasRect = canvas.GetComponent<RectTransform>();
|
||||
Vector3 viewport = cam.WorldToViewportPoint(targetWorldPosition);
|
||||
Vector2 canvasSize = canvasRect.sizeDelta;
|
||||
uiObjectToAlign.anchoredPosition = new Vector2(
|
||||
(viewport.x - canvasRect.pivot.x) * canvasSize.x,
|
||||
(viewport.y - canvasRect.pivot.y) * canvasSize.y);
|
||||
}
|
||||
|
||||
public static bool IsInputBlocked(Vector2 inputPos)
|
||||
{
|
||||
var pointer = new PointerEventData(EventSystem.current);
|
||||
pointer.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
|
||||
var results = new List<RaycastResult>();
|
||||
EventSystem.current.RaycastAll(pointer, results);
|
||||
for (int i = 0; i < results.Count; i++)
|
||||
{
|
||||
GameObject go = results[i].gameObject;
|
||||
if (go.GetComponent<Button>() != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (go.GetComponent<UIInputBlocker>() != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6501d1d7416951be20ab618916977d08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public class UniqueInstance<T> : MonoBehaviour
|
||||
{
|
||||
private static UniqueInstance<T> _instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return (_instance is T typed) ? typed : default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
if (_instance != null)
|
||||
{
|
||||
Debug.LogWarning("There is more than one _instance of type " + typeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
AwakeInstance();
|
||||
}
|
||||
|
||||
protected virtual void AwakeInstance()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 939f9f367c888eab00a988c166e7364a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
[CreateAssetMenu(fileName = "Version", menuName = "OHM/New Version Data")]
|
||||
public class VersionData : ScriptableObject
|
||||
{
|
||||
public int VersionMajor;
|
||||
|
||||
public int VersionMinor = 1;
|
||||
|
||||
public int VersionBuild = 1;
|
||||
|
||||
[Space]
|
||||
public int CloudBuildNumber;
|
||||
|
||||
public string Branch = "local";
|
||||
|
||||
public string CommitId = "unknown";
|
||||
|
||||
public int GetVersionCode()
|
||||
{
|
||||
return VersionMajor * 1000000 + VersionMinor * 1000 + VersionBuild;
|
||||
}
|
||||
|
||||
public string GetVersionLongName()
|
||||
{
|
||||
return string.Format("{0}.{1}.{2}", VersionMajor, VersionMinor, VersionBuild);
|
||||
}
|
||||
|
||||
public string GetVersionName()
|
||||
{
|
||||
return string.Format("{0}.{1}", VersionMajor, VersionMinor);
|
||||
}
|
||||
|
||||
public string GetSourceVersion()
|
||||
{
|
||||
return Branch + " " + CommitId;
|
||||
}
|
||||
|
||||
public string GetFullDebugVersion()
|
||||
{
|
||||
return GetVersionLongName() + " (" + CloudBuildNumber + ") " + GetSourceVersion();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a0caa27b9150d82f20ffcf323d406de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit
|
||||
{
|
||||
public static class VersionUtils
|
||||
{
|
||||
public static string VersionDataPath = "Version";
|
||||
public static VersionData GetVersionData()
|
||||
{
|
||||
return Resources.Load<VersionData>(VersionDataPath);
|
||||
}
|
||||
|
||||
public static void SaveVersionData(VersionData version)
|
||||
{
|
||||
Debug.Log("SaveVersionData should be called only in editor (nothing done outside editor)");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d6b32e17f852279b497fea26318fd4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe4cb9ad04810574dbc6f121a090a2ff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Vibration
|
||||
{
|
||||
public class VibrationManager : MonoBehaviour
|
||||
{
|
||||
public static bool Enabled = true;
|
||||
|
||||
public static float MinDelay = 0.1f;
|
||||
|
||||
public static long AndroidSmallLen = 25L;
|
||||
|
||||
public static int AndroidSmallAmplitude = 64;
|
||||
|
||||
public static long AndroidMediumLen = 100L;
|
||||
|
||||
public static int AndroidMediumAmplitude = 128;
|
||||
|
||||
public static long AndroidBigLen = 300L;
|
||||
|
||||
public static int AndroidBigAmplitude = -1;
|
||||
|
||||
public static bool LogEnabled = true;
|
||||
|
||||
private static float _lastVibrationFrameTime = -1f;
|
||||
|
||||
private static VibrationType _lastVibrationType;
|
||||
|
||||
public static void Vibrate(VibrationType type)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
if (LogEnabled)
|
||||
{
|
||||
Debug.Log("Vibration disabled");
|
||||
}
|
||||
return;
|
||||
}
|
||||
float sinceLast = Time.time - _lastVibrationFrameTime;
|
||||
if (sinceLast < MinDelay && _lastVibrationType >= type)
|
||||
{
|
||||
if (LogEnabled)
|
||||
{
|
||||
Debug.LogFormat("Vibration ignored (lower or equal type {0} / {1} and delay not done {2}) ",
|
||||
type.ToString(), _lastVibrationType.ToString(), sinceLast);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_lastVibrationFrameTime = Time.time;
|
||||
_lastVibrationType = type;
|
||||
long milliseconds;
|
||||
int amplitude;
|
||||
switch (type)
|
||||
{
|
||||
case VibrationType.BIG:
|
||||
milliseconds = AndroidBigLen;
|
||||
amplitude = AndroidBigAmplitude;
|
||||
break;
|
||||
case VibrationType.MEDIUM:
|
||||
milliseconds = AndroidMediumLen;
|
||||
amplitude = AndroidMediumAmplitude;
|
||||
break;
|
||||
case VibrationType.SMALL:
|
||||
milliseconds = AndroidSmallLen;
|
||||
amplitude = AndroidSmallAmplitude;
|
||||
break;
|
||||
default:
|
||||
milliseconds = 0L;
|
||||
amplitude = -1;
|
||||
break;
|
||||
}
|
||||
AndroidVibrationManager.CreateOneShot(milliseconds, amplitude);
|
||||
if (LogEnabled)
|
||||
{
|
||||
Debug.Log("Vibrate " + type.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public enum VibrationType
|
||||
{
|
||||
SMALL = 0,
|
||||
MEDIUM = 1,
|
||||
BIG = 2,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b714271ca74f5b8532fca6341477a4b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user