Skip to content

Latest commit

 

History

History
355 lines (271 loc) · 14.3 KB

File metadata and controls

355 lines (271 loc) · 14.3 KB

vFrame Unity Component Library

vFrame Made with Unity License

This library mainly provides a series of components inherited from Unity MonoBehaviour, serving as supplements to the official components.

Table of Contents

AnimationPlayer

Feature Introduction

AnimationPlayer is a component for playing animations. It can retrieve animation clips based on specified animation names and provides various methods for playing animations, including direct play, play until the end, fade in and out, etc. The biggest difference from Animation is that it can use custom animation names to bind with AnimationClip, without using the AnimationClip names to control animations.

Interface Description

  1. Retrieve the animation clip with the specified name
public AnimationClip GetAnimation(string animationName)
  1. Play the animation clip with the specified name
public bool Play(string animationName)
  1. Play the animation clip with the specified name until the animation is finished
public IEnumerator PlayUntilFinished(string animationName)
  1. Play the specified animation clip to the end
public void ForwardToEnd(string animationName)
  1. Crossfade animation with the specified name
public void CrossFade(string animationName)
  1. Crossfade animation with the specified name until the animation is finished
public IEnumerator CrossFadeUntilFinished(string animationName)

AnimatorEx

Feature Introduction

AnimatorEx is a Unity component designed to extend the functionality of the standard Animator component, supporting dynamic adjustment of animation playback speed and time scaling.

Interface Description

  1. Time scaling property
public float TimeScale { get; set; }

Allows getting or setting the time scale value. This value affects the playback speed of the animation and determines the final animation playback speed in conjunction with the Speed property.

  1. Speed property
public float Speed { get; set; }

Allows getting or setting the playback speed of the animation. This value multiplies with the TimeScale property value to determine the final animation playback speed.

AudioPlayer

Feature Introduction

AudioPlayer is a Unity component designed to simplify the process of audio playback. It provides a series of methods for controlling audio playback, pause, stop, mute, and setting audio clips and volume. This class also supports triggering a callback function after audio playback is complete, making it simple and straightforward to perform specific operations once the audio has finished playing.

Interface Description

  1. Get the pause status
public bool IsPause { get; }
  1. Get and set volume
public float Volume { get; set; }
  1. Check if audio is playing
public bool IsPlaying { get; }
  1. Get the audio source component
public AudioSource Source { get; }
  1. Reset the audio source state
public void ResetAudioSource()
  1. Pause audio playback
public void Pause()
  1. Continue audio playback
public void UnPause()
  1. Mute audio
public void Mute()
  1. Unmute audio
public void UnMute()
  1. Set the audio clip to play
public void SetClip(AudioClip clip)
  1. Stop audio playback
public void Stop()
  1. Play audio
public void Play()
  1. Play audio (with parameters)
public void Play(bool loop, float volume, Action onPlayFinished = null)
  1. Play audio and optionally destroy on completion
public void Play(bool loop, float volume, bool destroyWhenFinished)
  1. Play a specified audio clip
public void Play(AudioClip clip, bool loop, float volume, Action onPlayFinished = null)

TrailRendererEx

Feature Introduction

TrailRendererEx is a Unity component that enhances the functionality of the standard TrailRenderer component. It provides the ability to pause and resume trail effects and allows dynamic adjustment of the trail's time scale.

Interface Description

  1. Time scale property
public float TimeScale { get; set; }

Allows getting or setting the time scale value. This value affects the duration of the trail effect, and the trail is automatically paused and resumed when the time scale is set to apply the new value.

  1. Pause trail effect
public void Pause()

Pauses the trail effect, so it no longer updates when the game is paused or when it's necessary to stop the trail.

  1. Resume trail effect
public void UnPause()

Resumes the paused trail effect and continues updating the trail according to the time scale value.

  1. Check if paused
public bool IsPaused()

Returns a boolean value indicating whether the trail effect is paused.

  1. Clear trail effect
public void Clear()

Immediately clears the current trail effect and resets the trail's time in the next frame to begin drawing the trail effect anew.

MethodInvoker

Feature Introduction

MethodInvoker is a Unity component specifically used for invoking methods at runtime, performing delayed calls, looping calls, etc. It utilizes coroutines to implement these features and provides a convenient way to handle method calls with different parameters. By using MethodInvoker, developers can easily implement complex timing control and method scheduling in their games, such as executing tasks at set times or repeating tasks until a certain condition is met.

Interface Description

  1. Time scale property
public float TimeScale { get; set; }

Allows getting or setting the time scale value, which affects the timing intervals of delayed and looping calls.

  1. Stop all coroutines
public void Stop()

Stops all coroutines currently executing on the MethodInvoker component.

  1. Invoke a method
public Coroutine Invoke(Func<IEnumerator> action)

Starts a coroutine to invoke the specified method.

  1. Delayed method invocation
public Coroutine DelayInvoke(float time, Action action)

Invokes a method after a specified delay time.

  1. Looping method invocation
public Coroutine LoopInvoke(float interval, Func<bool> action, bool invokeImmediately = true)

Repeats the invocation of a method at specified intervals. The looping stops when the method returns true or the coroutine is stopped.

MethodInvoker also provides several overloaded versions of Invoke, DelayInvoke, and LoopInvoke methods to support different numbers and types of parameters. These overloaded methods allow developers to pass parameters to the invoked methods as needed, adding flexibility to the invocations.

CullingBehaviour

Feature Introduction

CullingBehaviour is an abstract Unity component for implementing view-based culling functionality. Using CullingGroup and BoundingSphere, it can determine whether objects should be rendered based on the camera's perspective and the set culling radius. This class is meant to be inherited, and its OnBecameVisible and OnBecameInvisible methods can be overridden to implement custom behaviors when objects become visible or invisible. This component is suitable for optimizing scene rendering performance, especially when dealing with a large number of objects' visibility.

Interface Description

  1. Set the culling camera
public Camera TargetCamera { set; get; }

Allows getting or setting the target camera for culling decisions. If not specified, the main camera will be used by default.

  1. Auto-update bounding box position
public bool AutoUpdate { set; get; }

Enables or disables the auto-update feature for the culling area. When enabled, the culling area is updated every frame based on the object's current position.

  1. Reset
public void Reset()

Resets and releases CullingGroup resources, clearing all related culling settings.

  1. Update culling group
public void UpdateCullingGroup()

Manually updates the culling area, typically called when the object's position changes or when a forced update of culling settings is needed.

  1. Update culling state
public void UpdateCullingState()

Updates the visibility state of the object based on the current culling area and the position of the target camera.

  1. Visibility change event
public event Action<bool> onCullingStateChanged;

An event triggered when the visibility state of the object changes. The parameter is true for the object becoming invisible and false for becoming visible.

This class also contains a series of protected virtual methods like OnBecameInvisible and OnBecameVisible, allowing for custom visibility change behaviors to be implemented in derived classes. Additionally, it provides an IsVisible method for checking the current visibility of the object.

ParticleCulling

Feature Introduction

ParticleCulling class inherits from CullingBehaviour, specifically for view culling of particle systems. It overrides the OnBecameVisible and OnBecameInvisible methods to automatically start or stop playing particle effects when the particle system enters or leaves the camera view. It also controls the enabled state of the related renderer, optimizing the performance of particle systems in the scene, especially when dealing with a large number of particle systems, significantly reducing unnecessary rendering overhead.

GameObjectSnapshot

GameObjectSnapshotBehaviour

Feature Introduction

GameObjectSnapshotBehaviour is a Unity component used for snapshotting and restoring the state of game objects. It enables developers to capture the current state of a game object at runtime and restore it to that state at any later point in time. This feature is particularly useful in scenarios where game object states need to be temporarily modified for testing or specific operations, and then later restored to their original state.

Interface Description

  1. Set and get snapshot settings
public GameObjectSnapshotSettings SnapshotSettings { get; set; }

Allows getting or setting the configuration for snapshots, including information on which component types need to have their states captured. Developers can customize the snapshot capturing functionality by inheriting from GameObjectSnapshot.

  1. Capture the current state
public void Take()

Captures the current state of the game object according to the rules defined in the snapshot settings and stores these states. If a snapshot already exists, it clears the old snapshot first.

  1. Restore to snapshot state
public void Restore()

Restores the game object to the state of the most recent snapshot taken. If no snapshot is available, this operation is ineffective.

  1. Clear all snapshots
public void Clear()

Clears all stored snapshot information and frees related resources. It is automatically called before taking a new snapshot and can also be manually called to ensure no old snapshot data is retained.

GameObjectSnapshotBehaviour implements the logic of capturing and restoring snapshots through internal methods TakeInternal and RestoreInternal. These methods use reflection to create and manipulate components inherited from GameObjectSnapshot to capture and restore the state of specific components. The design of this component allows developers to flexibly manage the state of game objects to accommodate various runtime state changes.

GameObjectSnapshotRecursiveBehaviour

Feature Introduction

GameObjectSnapshotRecursiveBehaviour is a Unity component that recursively snapshots and restores the state of game objects and all their children. It extends the functionality of GameObjectSnapshotBehaviour, not only allowing snapshots of individual game objects but also recursively capturing the state of all their children, thus implementing the state capture and restoration of an entire game object tree. This is highly useful for scenarios where the states of multiple game objects need to be managed simultaneously, such as restoring the entire state of a scene to a specific moment at once.

Interface Description

  1. Set and get snapshot settings
public GameObjectSnapshotSettings SnapshotSettings { get; set; }

Allows getting or setting the configuration for snapshots, including information on which component types need to have their states captured.

  1. Capture the current state
public void Take()

Captures the current state of the game object and all its children according to the rules defined in the snapshot settings and stores these states. If a snapshot already exists, it clears the old snapshot first.

  1. Restore to snapshot state
public void Restore()

Restores the game object and all its children to the state of the most recent snapshot taken. If no snapshot is available, this operation is ineffective.

  1. Clear all snapshots
public void Clear()

Clears all stored snapshot information and frees related resources. It is automatically called before taking a new snapshot and can also be manually called to ensure no old snapshot data is retained.

GameObjectSnapshotRecursiveBehaviour implements the logic for capturing snapshots of every object in the game object tree through the internal method TakeInternal. This method adds a GameObjectSnapshotBehaviour component to each game object and calls its Take method to capture the state. This recursive capturing approach ensures that the state of the entire game object tree can be comprehensively saved and restored, providing developers with powerful state management capabilities.

License

Apache License 2.0