Move third party assets to ThirdParty folder
This commit is contained in:
36
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrDelayedDestroy.cs
vendored
Normal file
36
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrDelayedDestroy.cs
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrDelayedDestroy.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Core.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to destroy the <see cref="GameObject" /> it is attached to after a variable amount of seconds
|
||||
/// </summary>
|
||||
public class UxrDelayedDestroy : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private float _seconds;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Programs the object destruction.
|
||||
/// </summary>
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
Destroy(gameObject, _seconds);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
13
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrDelayedDestroy.cs.meta
vendored
Normal file
13
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrDelayedDestroy.cs.meta
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af3a08495f6a01846a24adb624144bb7
|
||||
timeCreated: 1534242279
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
313
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectBlink.cs
vendored
Normal file
313
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectBlink.cs
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrObjectBlink.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Core;
|
||||
using UltimateXR.Core.Components;
|
||||
using UltimateXR.Extensions.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to make objects blink using their material's emission channel.
|
||||
/// </summary>
|
||||
public class UxrObjectBlink : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private MeshRenderer _renderer;
|
||||
[SerializeField] private int _materialSlot = -1;
|
||||
[SerializeField] private Color _colorNormal = Color.black;
|
||||
[SerializeField] private Color _colorHighlight = Color.white;
|
||||
[SerializeField] private float _blinksPerSec = 4.0f;
|
||||
[SerializeField] private float _durationSeconds = -1.0f;
|
||||
[SerializeField] private bool _useUnscaledTime;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the object is currently blinking.
|
||||
/// </summary>
|
||||
public bool IsBlinking { get; private set; } = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Starts a blinking animation using the emission material of an object.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The GameObject to blink</param>
|
||||
/// <param name="emissionColor">The emission color</param>
|
||||
/// <param name="blinksPerSec">The blink frequency</param>
|
||||
/// <param name="durationSeconds">Total duration of the blinking animation</param>
|
||||
/// <param name="materialSlot">
|
||||
/// -1 to target all renderer materials if there is more than one. An index between [0, materialCount
|
||||
/// - 1] to target a specific material only.
|
||||
/// </param>
|
||||
/// <param name="useUnscaledTime">
|
||||
/// Whether to use unscaled time (<see cref="Time.unscaledTime" />) or not (
|
||||
/// <see cref="Time.time" />).
|
||||
/// </param>
|
||||
/// <returns>Animation component</returns>
|
||||
public static UxrObjectBlink StartBlinking(GameObject gameObject, Color emissionColor, float blinksPerSec, float durationSeconds, int materialSlot = -1, bool useUnscaledTime = false)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
UxrObjectBlink blinkComponent = gameObject.GetOrAddComponent<UxrObjectBlink>();
|
||||
|
||||
blinkComponent.CheckInitialize();
|
||||
blinkComponent.StartBlinkingInternal(emissionColor, blinksPerSec, durationSeconds, materialSlot, useUnscaledTime);
|
||||
|
||||
return blinkComponent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops a blinking animation on an object if it has any.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">GameObject to stop the animation from</param>
|
||||
public static void StopBlinking(GameObject gameObject)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameObject.TryGetComponent<UxrObjectBlink>(out var blinkComponent))
|
||||
{
|
||||
blinkComponent.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the given GameObject has any blinking animation running.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">GameObject to check</param>
|
||||
/// <returns>Whether the given GameObject has any blinking animation running</returns>
|
||||
public static bool CheckBlinking(GameObject gameObject)
|
||||
{
|
||||
if (gameObject == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
UxrObjectBlink blinkComponent = gameObject.GetComponent<UxrObjectBlink>();
|
||||
|
||||
return blinkComponent != null && blinkComponent.IsBlinking;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the blinking animation parameters.
|
||||
/// </summary>
|
||||
/// <param name="renderer">Renderer whose material will be animated</param>
|
||||
/// <param name="colorNormal">The emission color when it is not blinking</param>
|
||||
/// <param name="colorHighlight">The fully blinking color</param>
|
||||
/// <param name="blinksPerSec">The blinking frequency</param>
|
||||
/// <param name="durationSeconds">The total duration of the animation in seconds</param>
|
||||
/// <param name="materialSlot">
|
||||
/// -1 to target all renderer materials if there is more than one. An index between [0, materialCount
|
||||
/// - 1] to target a specific material only.
|
||||
/// </param>
|
||||
/// <param name="useUnscaledTime">
|
||||
/// Whether to use unscaled time (<see cref="Time.unscaledTime" />) or not (
|
||||
/// <see cref="Time.time" />).
|
||||
/// </param>
|
||||
public void Setup(MeshRenderer renderer, Color colorNormal, Color colorHighlight, float blinksPerSec = 4.0f, float durationSeconds = -1.0f, int materialSlot = -1, bool useUnscaledTime = false)
|
||||
{
|
||||
_renderer = renderer;
|
||||
_colorNormal = colorNormal;
|
||||
_colorHighlight = colorHighlight;
|
||||
_blinksPerSec = blinksPerSec;
|
||||
_durationSeconds = durationSeconds;
|
||||
_materialSlot = materialSlot;
|
||||
_useUnscaledTime = useUnscaledTime;
|
||||
IsBlinking = false;
|
||||
IsInitialized = false;
|
||||
CheckInitialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts or restarts the blinking animation using the current parameters.
|
||||
/// </summary>
|
||||
public void StartBlinkingWithCurrentParameters()
|
||||
{
|
||||
CheckInitialize();
|
||||
StartBlinkingInternal(_colorHighlight, _blinksPerSec, _durationSeconds, _materialSlot, _useUnscaledTime);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the component.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
CheckInitialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When re-enabled, starts blinking again with the current parameters.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
StartBlinkingWithCurrentParameters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops blinking.
|
||||
/// </summary>
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
StopBlinkingInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the blinking animation if active.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
if (IsBlinking && _renderer != null)
|
||||
{
|
||||
float timer = CurrentTime - _blinkStartTime;
|
||||
|
||||
if (_durationSeconds >= 0.0f && timer >= _durationSeconds)
|
||||
{
|
||||
StopBlinkingInternal();
|
||||
}
|
||||
else
|
||||
{
|
||||
float blend = (Mathf.Sin(timer * Mathf.PI * _blinksPerSec * 2.0f) + 1.0f) * 0.5f;
|
||||
|
||||
Material[] materials = _renderer.materials;
|
||||
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
if (i == _materialSlot || _materialSlot < 0)
|
||||
{
|
||||
materials[i].SetColor(UxrConstants.Shaders.EmissionColorVarName, Color.Lerp(_colorNormal, _colorHighlight, blend));
|
||||
}
|
||||
}
|
||||
|
||||
_renderer.materials = materials;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the component if necessary.
|
||||
/// </summary>
|
||||
private void CheckInitialize()
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
if (_renderer == null)
|
||||
{
|
||||
_renderer = GetComponent<MeshRenderer>();
|
||||
}
|
||||
|
||||
if (_renderer != null)
|
||||
{
|
||||
_originalMaterials = _renderer.sharedMaterials;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts blinking.
|
||||
/// </summary>
|
||||
/// <param name="emissionColor">Emission color</param>
|
||||
/// <param name="blinksPerSec">Blinking frequency</param>
|
||||
/// <param name="durationSeconds">Total duration in seconds</param>
|
||||
/// <param name="materialSlot">The material(s) to target</param>
|
||||
/// <param name="useUnscaledTime">Whether to use unscaled time or not</param>
|
||||
private void StartBlinkingInternal(Color emissionColor, float blinksPerSec, float durationSeconds, int materialSlot, bool useUnscaledTime)
|
||||
{
|
||||
if (_renderer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_useUnscaledTime = useUnscaledTime;
|
||||
_blinkStartTime = CurrentTime;
|
||||
_colorHighlight = emissionColor;
|
||||
_blinksPerSec = blinksPerSec;
|
||||
_durationSeconds = durationSeconds;
|
||||
_materialSlot = materialSlot;
|
||||
|
||||
Material[] materials = _renderer.materials;
|
||||
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
if (i == _materialSlot || _materialSlot < 0)
|
||||
{
|
||||
materials[i].EnableKeyword(UxrConstants.Shaders.EmissionKeyword);
|
||||
}
|
||||
}
|
||||
|
||||
_renderer.materials = materials;
|
||||
IsBlinking = true;
|
||||
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops blinking.
|
||||
/// </summary>
|
||||
private void StopBlinkingInternal()
|
||||
{
|
||||
if (_renderer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsBlinking = false;
|
||||
|
||||
RestoreOriginalSharedMaterial();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the original (shared) material.
|
||||
/// </summary>
|
||||
private void RestoreOriginalSharedMaterial()
|
||||
{
|
||||
if (_renderer)
|
||||
{
|
||||
_renderer.sharedMaterials = _originalMaterials;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private float CurrentTime => _useUnscaledTime ? Time.unscaledTime : Time.time;
|
||||
|
||||
private bool IsInitialized { get; set; }
|
||||
|
||||
private float _blinkStartTime;
|
||||
private Material[] _originalMaterials;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectBlink.cs.meta
vendored
Normal file
12
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectBlink.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6cff78ce55139e48a3e08257187ea94
|
||||
timeCreated: 1504781678
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrObjectFade.ObjectEntry.MaterialEntry.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
public partial class UxrObjectFade
|
||||
{
|
||||
#region Private Types & Data
|
||||
|
||||
private partial class ObjectEntry
|
||||
{
|
||||
#region Private Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Stores information of a material in a fade animation.
|
||||
/// </summary>
|
||||
private struct MaterialEntry
|
||||
{
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the initial material color.
|
||||
/// </summary>
|
||||
public Color StartColor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the shader transparency was enabled.
|
||||
/// </summary>
|
||||
public bool ShaderChanged { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e51e06febf0347f899cb77675622506d
|
||||
timeCreated: 1643744815
|
||||
123
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectFade.ObjectEntry.cs
vendored
Normal file
123
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectFade.ObjectEntry.cs
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrObjectFade.ObjectEntry.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Core;
|
||||
using UltimateXR.Extensions.System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
public partial class UxrObjectFade
|
||||
{
|
||||
#region Private Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Stores information about an object in a fade animation.
|
||||
/// </summary>
|
||||
private partial class ObjectEntry
|
||||
{
|
||||
#region Constructors & Finalizer
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
/// <param name="renderer">Renderer component</param>
|
||||
public ObjectEntry(Renderer renderer)
|
||||
{
|
||||
Renderer = renderer;
|
||||
SharedMaterials = renderer.sharedMaterials;
|
||||
Materials = renderer.materials;
|
||||
MaterialEntries = new MaterialEntry[Materials.Length];
|
||||
|
||||
for (int i = 0; i < Materials.Length; ++i)
|
||||
{
|
||||
MaterialEntries[i].StartColor = Materials[i].color;
|
||||
MaterialEntries[i].ShaderChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Changes the material transparency.
|
||||
/// </summary>
|
||||
/// <param name="startQuantity">Start alpha</param>
|
||||
/// <param name="endQuantity">End alpha</param>
|
||||
/// <param name="fadeT">Interpolation factor [0.0, 1.0]</param>
|
||||
public void Fade(float startQuantity, float endQuantity, float fadeT)
|
||||
{
|
||||
for (int i = 0; i < Materials.Length; ++i)
|
||||
{
|
||||
if (!MaterialEntries[i].ShaderChanged)
|
||||
{
|
||||
ChangeStandardMaterialRenderMode(Materials[i]);
|
||||
MaterialEntries[i].ShaderChanged = true;
|
||||
}
|
||||
|
||||
Color color = MaterialEntries[i].StartColor;
|
||||
color.a *= Mathf.Lerp(startQuantity, endQuantity, fadeT);
|
||||
Materials[i].color = color;
|
||||
}
|
||||
|
||||
Renderer.materials = Materials;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the original material(s).
|
||||
/// </summary>
|
||||
public void Restore()
|
||||
{
|
||||
Renderer.sharedMaterials = SharedMaterials;
|
||||
MaterialEntries.ForEach(m => m.ShaderChanged = false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Enables transparency on a material.
|
||||
/// </summary>
|
||||
/// <param name="material">Material to enable transparency on</param>
|
||||
private void ChangeStandardMaterialRenderMode(Material material)
|
||||
{
|
||||
if (material.HasProperty(UxrConstants.Shaders.SurfaceModeVarName))
|
||||
{
|
||||
// Universal render pipeline
|
||||
material.SetInt(UxrConstants.Shaders.SurfaceModeVarName, UxrConstants.Shaders.SurfaceModeTransparent);
|
||||
material.SetInt(UxrConstants.Shaders.BlendModeVarName, UxrConstants.Shaders.BlendModeAlpha);
|
||||
material.renderQueue = (int)RenderQueue.Transparent;
|
||||
}
|
||||
else if (material.IsKeywordEnabled(UxrConstants.Shaders.AlphaBlendOnKeyword) == false)
|
||||
{
|
||||
// Built-in render pipeline
|
||||
material.SetInt(UxrConstants.Shaders.SrcBlendVarName, (int)BlendMode.SrcAlpha);
|
||||
material.SetInt(UxrConstants.Shaders.DstBlendVarName, (int)BlendMode.OneMinusSrcAlpha);
|
||||
material.SetInt(UxrConstants.Shaders.ZWriteVarName, 0);
|
||||
material.DisableKeyword(UxrConstants.Shaders.AlphaTestOnKeyword);
|
||||
material.EnableKeyword(UxrConstants.Shaders.AlphaBlendOnKeyword);
|
||||
material.DisableKeyword(UxrConstants.Shaders.AlphaPremultiplyOnKeyword);
|
||||
material.renderQueue = (int)RenderQueue.Transparent;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private MaterialEntry[] MaterialEntries { get; }
|
||||
private Renderer Renderer { get; }
|
||||
private Material[] Materials { get; }
|
||||
private Material[] SharedMaterials { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edc5622f479147cd8ef96832732a9ff0
|
||||
timeCreated: 1644846685
|
||||
175
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectFade.cs
vendored
Normal file
175
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectFade.cs
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrObjectFade.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UltimateXR.Core.Components;
|
||||
using UltimateXR.Extensions.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to fade an object out by making the material progressively more transparent.
|
||||
/// </summary>
|
||||
public partial class UxrObjectFade : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private bool _recursively = true;
|
||||
[SerializeField] private float _delaySeconds;
|
||||
[SerializeField] private float _duration = 1.0f;
|
||||
[SerializeField] private float _startQuantity = 1.0f;
|
||||
[SerializeField] private float _endQuantity;
|
||||
[SerializeField] private bool _useUnscaledTime;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Starts a fade animation.
|
||||
/// </summary>
|
||||
/// <param name="gameObject">GameObject whose material transparency will be enabled and animated.</param>
|
||||
/// <param name="startAlphaQuantity">Start alpha</param>
|
||||
/// <param name="endFadeQuantity">End alpha</param>
|
||||
/// <param name="delaySeconds">Seconds to wait before the animation starts</param>
|
||||
/// <param name="durationSeconds">Fade duration in seconds</param>
|
||||
/// <param name="recursively">Whether to also process all other child objects in the hierarchy</param>
|
||||
/// <param name="useUnscaledTime">
|
||||
/// Whether to use unscaled time (<see cref="Time.unscaledTime" />) or not (
|
||||
/// <see cref="Time.time" />)
|
||||
/// </param>
|
||||
/// <param name="finishedCallback">Optional callback executed when the animation finished</param>
|
||||
/// <returns>Animation component</returns>
|
||||
public static UxrObjectFade Fade(GameObject gameObject,
|
||||
float startAlphaQuantity,
|
||||
float endFadeQuantity,
|
||||
float delaySeconds,
|
||||
float durationSeconds,
|
||||
bool recursively = true,
|
||||
bool useUnscaledTime = false,
|
||||
Action finishedCallback = null)
|
||||
{
|
||||
UxrObjectFade objectFade = gameObject.GetOrAddComponent<UxrObjectFade>();
|
||||
|
||||
objectFade._startQuantity = startAlphaQuantity;
|
||||
objectFade._endQuantity = endFadeQuantity;
|
||||
objectFade._delaySeconds = delaySeconds;
|
||||
objectFade._duration = durationSeconds;
|
||||
objectFade._recursively = recursively;
|
||||
objectFade._useUnscaledTime = useUnscaledTime;
|
||||
objectFade._finishedCallback = finishedCallback;
|
||||
|
||||
objectFade.CheckInitialize(true);
|
||||
|
||||
return objectFade;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the component.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
CheckInitialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts or re-starts the animation.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
_fadeStartTime = CurrentTime;
|
||||
_finished = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the animation and restores the material.
|
||||
/// </summary>
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
|
||||
foreach (ObjectEntry objectEntry in _objects)
|
||||
{
|
||||
objectEntry.Restore();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the animation.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
if (_finished)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float fadeTime = CurrentTime - _fadeStartTime - _delaySeconds;
|
||||
|
||||
if (fadeTime <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float fadeT = Mathf.Clamp01(fadeTime / _duration);
|
||||
|
||||
foreach (ObjectEntry entry in _objects)
|
||||
{
|
||||
entry.Fade(_startQuantity, _endQuantity, fadeT);
|
||||
}
|
||||
|
||||
if (fadeTime > _duration)
|
||||
{
|
||||
_finishedCallback?.Invoke();
|
||||
_finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the component if necessary.
|
||||
/// </summary>
|
||||
/// <param name="forceInitialize">Forces initializing the component even if it already may have been initialized</param>
|
||||
private void CheckInitialize(bool forceInitialize = false)
|
||||
{
|
||||
if (_objects.Count == 0 || forceInitialize)
|
||||
{
|
||||
Renderer[] objectRenderers = _recursively ? gameObject.GetComponentsInChildren<Renderer>() : new[] { gameObject.GetComponent<Renderer>() };
|
||||
|
||||
foreach (Renderer renderer in objectRenderers)
|
||||
{
|
||||
_objects.Add(new ObjectEntry(renderer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private float CurrentTime => _useUnscaledTime ? Time.unscaledTime : Time.time;
|
||||
|
||||
private readonly List<ObjectEntry> _objects = new List<ObjectEntry>();
|
||||
|
||||
private float _fadeStartTime;
|
||||
private bool _finished;
|
||||
private Action _finishedCallback;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
12
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectFade.cs.meta
vendored
Normal file
12
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrObjectFade.cs.meta
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 832e898c6d705a84692abd8a162a48e0
|
||||
timeCreated: 1505585796
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
87
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrToggleObject.cs
vendored
Normal file
87
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrToggleObject.cs
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrToggleObject.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using UltimateXR.Core.Components;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to toggle <see cref="GameObject" /> active state back and forth at random times.
|
||||
/// </summary>
|
||||
public class UxrToggleObject : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private GameObject _gameObject;
|
||||
[SerializeField] private float _enabledDurationMin;
|
||||
[SerializeField] private float _enabledDurationMax;
|
||||
[SerializeField] private float _disabledDurationMin;
|
||||
[SerializeField] private float _disabledDurationMax;
|
||||
[SerializeField] private bool _useUnscaledTime;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Called each time the component is enabled. Sets up the next toggle time.
|
||||
/// </summary>
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
_startTime = _useUnscaledTime ? Time.unscaledTime : Time.time;
|
||||
_nextToggleTime = GetNextRelativeToggleTime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on each update. Checks if it is time to toggle the GameObjects.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
float time = (_useUnscaledTime ? Time.unscaledTime : Time.time) - _startTime;
|
||||
|
||||
if (time > _nextToggleTime)
|
||||
{
|
||||
_gameObject.SetActive(!_gameObject.activeSelf);
|
||||
|
||||
_startTime = _useUnscaledTime ? Time.unscaledTime : Time.time;
|
||||
_nextToggleTime = GetNextRelativeToggleTime();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next time the objects will be toggled.
|
||||
/// </summary>
|
||||
/// <returns>Next toggle time in seconds relative to the current time</returns>
|
||||
private float GetNextRelativeToggleTime()
|
||||
{
|
||||
if (_gameObject && _gameObject.activeSelf)
|
||||
{
|
||||
return Random.Range(_enabledDurationMin, _enabledDurationMax);
|
||||
}
|
||||
if (_gameObject && !_gameObject.activeSelf)
|
||||
{
|
||||
return Random.Range(_disabledDurationMin, _disabledDurationMax);
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private float _startTime;
|
||||
private float _nextToggleTime;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
13
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrToggleObject.cs.meta
vendored
Normal file
13
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrToggleObject.cs.meta
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 161147edff113284a819edef7ac1d57c
|
||||
timeCreated: 1522850574
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
149
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrToggleObjectsUsingButtons.cs
vendored
Normal file
149
Assets/ThirdParty/UltimateXR/Runtime/Scripts/Animation/GameObjects/UxrToggleObjectsUsingButtons.cs
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="UxrToggleObjectsUsingButtons.cs" company="VRMADA">
|
||||
// Copyright (c) VRMADA, All rights reserved.
|
||||
// </copyright>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
using UltimateXR.Avatar;
|
||||
using UltimateXR.Core;
|
||||
using UltimateXR.Core.Components;
|
||||
using UltimateXR.Devices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UltimateXR.Animation.GameObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Component that allows to enable/disable GameObjects based on input from the VR controller buttons.
|
||||
/// </summary>
|
||||
public class UxrToggleObjectsUsingButtons : UxrComponent
|
||||
{
|
||||
#region Inspector Properties/Serialized Fields
|
||||
|
||||
[SerializeField] private List<GameObject> _objectList;
|
||||
[SerializeField] private bool _startEnabled = true;
|
||||
[SerializeField] private UxrHandSide _controllerHand = UxrHandSide.Left;
|
||||
[SerializeField] private UxrInputButtons _buttonsEnable = UxrInputButtons.Button1;
|
||||
[SerializeField] private UxrButtonEventType _buttonsEventEnable = UxrButtonEventType.PressDown;
|
||||
[SerializeField] private UxrInputButtons _buttonsDisable = UxrInputButtons.Button1;
|
||||
[SerializeField] private UxrButtonEventType _buttonsEventsDisable = UxrButtonEventType.TouchDown;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Types & Data
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the object list to enable/disable.
|
||||
/// </summary>
|
||||
public List<GameObject> ObjectList
|
||||
{
|
||||
get => _objectList;
|
||||
set => _objectList = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets which controller hand is responsible for the input.
|
||||
/// </summary>
|
||||
public UxrHandSide ControllerHand
|
||||
{
|
||||
get => _controllerHand;
|
||||
set => _controllerHand = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the button(s) used to enable.
|
||||
/// </summary>
|
||||
public UxrInputButtons ButtonsToEnable
|
||||
{
|
||||
get => _buttonsEnable;
|
||||
set => _buttonsEnable = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the button event to enable.
|
||||
/// </summary>
|
||||
public UxrButtonEventType EnableButtonEvent
|
||||
{
|
||||
get => _buttonsEventEnable;
|
||||
set => _buttonsEventEnable = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the button(s) to disable.
|
||||
/// </summary>
|
||||
public UxrInputButtons ButtonsToDisable
|
||||
{
|
||||
get => _buttonsDisable;
|
||||
set => _buttonsDisable = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the button event to disable.
|
||||
/// </summary>
|
||||
public UxrButtonEventType DisableButtonEvent
|
||||
{
|
||||
get => _buttonsEventsDisable;
|
||||
set => _buttonsEventsDisable = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity
|
||||
|
||||
/// <summary>
|
||||
/// Called at the beginning. Sets the object initial state.
|
||||
/// </summary>
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
_state = _startEnabled;
|
||||
SetObjectsState(_startEnabled);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame. Checks for VR controller button events and toggles states.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
if (!UxrAvatar.LocalAvatar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_state == false && UxrAvatar.LocalAvatarInput.GetButtonsEvent(ControllerHand, ButtonsToEnable, EnableButtonEvent))
|
||||
{
|
||||
SetObjectsState(true);
|
||||
}
|
||||
else if (_state && UxrAvatar.LocalAvatarInput.GetButtonsEvent(ControllerHand, ButtonsToDisable, DisableButtonEvent))
|
||||
{
|
||||
SetObjectsState(false);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Sets the object state of the list of objects in this component.
|
||||
/// </summary>
|
||||
/// <param name="value">State they should be changed to</param>
|
||||
private void SetObjectsState(bool value)
|
||||
{
|
||||
_state = value;
|
||||
|
||||
foreach (GameObject obj in ObjectList)
|
||||
{
|
||||
obj.SetActive(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Types & Data
|
||||
|
||||
private bool _state;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29eb44ed5f72f6d4f8341d2397b451a1
|
||||
timeCreated: 1522133718
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user