Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stuff I use a lot, and a simple AnimationCurve-based tweening interface

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
NotificationsYou must be signed in to change notification settings

williamrjackson/UnityScriptingUtilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PathTrail
Stuff I use a lot, and a simple AnimationCurve-based tweening interface.

Add to projects using Package Manager git url:

https://github.com/williamrjackson/UnityScriptingUtilities.git#v1.6.16

OR

https://github.com/williamrjackson/UnityScriptingUtilities.git#v1.6

MapToCurve

Provides values as plotted on an Animation Curve. Used a lot like Mathf.Lerp, except not linear.

Includes a bunch of functions to manipulate transforms/audio over time. For example, the following will scale, move and rotate a transfrom into a position over 5 seconds. The target position is defined by a sibling transfrom.

Presets for common ease curves fromhttps://github.com/aureliendrouet/EasingCurvePresets are included

Wrj.Utils.MapToCurve.Ease.MatchSibling(transform,targetTransform,5f);//                       ^        ^          ^            ^           ^//                     curve   function   affected   destination   duration

Manipulation Functions

ScaleMove (local space)MoveWorld (world space)MoveAlongPathRotateFadeAudioCrossfadeAudio (smoothly transitions between two audio sources)FadeAlphaChangeColorMatchSibling

Arguments & Common Modifiers

tForm             - Transform to affectto                - Target destination/rotation/volume/etc.duration          - Length of time in seconds for the manipulation to complete.                     Applies to a single loop/pingPong iteration.mirrorCurve       - Swap the in/out curve shapes.                     Get EaseOut by combining the EaseIn curve  with this flag.repeatStyle       - Loop the manipulation.                  - PingPong: repeat the manipulation forward, then backward.                  - MirrorPingPong: pingPong, but inverts the curve when performing backward manipulations.repeatIterations  - Repeat this many times. Use -1 for infinite.useTimeScale      - Set this to false to ignore global time scalingshortestPath      - In the case of manipulations that include rotation, this will cause minimal                    possible rotation to get to the target. Without this, a rotation difference > 360                     will result in a full positive rotation before reaching the target.onDone            - Specify a function to call when the operation completes

There are simplified GameObject and Transform Extension Methods for linear and ease manipulations:

transform.Move(destination, duration);transform.EaseMove(destination, duration);transform.Rotate(targetRotation, duration);transform.EaseRotate(targetRotation, duration);transform.Scale(targetScale, duration);transform.EaseScale(TargetScale, duration);transform.SnapToSibling(targetSibling, duration);transform.EaseSnapToSibling(targetSibling, duration);transform.Color(desiredColor, duration);transform.Alpha(desiredAlpha, duration);

Tweening

Test Bed Example

floatduration=4.0f// Black CubeVector3blackTargetPos=blackTransform.localPosition+Vector3.up*5+Vector3.right*-1.5f;Vector3blackTargetRot=Vector3.up*135;Wrj.Utils.MapToCurve.Linear.Move(blackTransform,linTargetPos,duration,pingPong:10);Wrj.Utils.MapToCurve.Linear.Rotate(blackTransform,blackTargetRot,duration,shortestPath:false,pingPong:10);Wrj.Utils.MapToCurve.Ease.ChangeColor(blackTransform,Color.black,duration,pingPong:10);// Red CubeVector3redTargetPos=redTransform.localPosition+Vector3.up*5+Vector3.right*.5f;Vector3redTargetRot=Vector3.up*-360;Wrj.Utils.MapToCurve.EaseIn.Move(redTransform,redTargetPos,duration,mirrorCurve:false,pingPong:10);Wrj.Utils.MapToCurve.EaseIn.Rotate(redTransform,redTargetRot,duration,shortestPath:false,pingPong:10);Wrj.Utils.MapToCurve.Ease.ChangeColor(redTransform,Color.red,duration,pingPong:10);// Blue CubeVector3blueTargetPos=blueTransform.localPosition+Vector3.up*5+Vector3.right*-.5f;Vector3blueTargetRot=Vector3.forward*-720;Wrj.Utils.MapToCurve.EaseIn.Move(blueTransform,blueTargetPos,duration,mirrorCurve:true,pingPong:10);Wrj.Utils.MapToCurve.EaseIn.Rotate(blueTransform,blueTargetRot,duration,shortestPath:false,mirrorPingPong:10);Wrj.Utils.MapToCurve.Ease.ChangeColor(blueTransform,Color.blue,duration,pingPong:10);// Purple CubeWrj.Utils.MapToCurve.Ease.MatchSibling(purpleTransform,targetTransform,duration,pingPong:10);Wrj.Utils.MapToCurve.Ease.ChangeColor(purpleTransform,Color.magenta,duration,pingPong:10);// Purple Cube's TargetWrj.Utils.MapToCurve.Ease.FadeAlpha(targetTransform,0,duration,pingPong:10);

WeightedElements

Also includes a Weighted Random Object class (demonstrated on the right in the gif above).

Contains a collection of objects with an int representing its weight. Higher weights are more likely for selection WhenweightedElements.GetRandom() is called.

Can also be initialized with a sourceList<T> and anAnimationCurve representing the desired weights.

publicTransformweight10;publicTransformweight5;publicTransformweight3;publicTransformweight1;WeightedElements<Transform>randomBumpObjects=newWeightedElements<Transform>();randomBumpObjects.Add(weight10,10);randomBumpObjects.Add(weight5,5);randomBumpObjects.Add(weight3,3);randomBumpObjects.Add(weight1,1);// This is most likely to scale object weight10. But it's fairly unlikely to scale weight1randomBumpObjects.GetRandom().localScale=Vector3.one*1.5f;

Utility Functions

  • EnsureComponent<T>(GameObject)
    • Returns a component instance by finding the one on the game object, or by adding one if not found.
  • DeferredExecution(delayTime, () => Method(withParams))
    • Issues a command after the specified delayTime elapses.
  • Switcheroo<T>(ref T a, ref T b)
    • Swap items
  • AffectGORecursively(GameObject, AnyFunctionThatTakesAGameObj)
    • Call AnyFunctionThatTakesAGameObj for GameObject and all of it's children.
  • GetPositiveAngle(float OR Vector3)
    • Ensure an angle in degrees is within 0 - 360
  • Remap(value, sourceMin, sourceMax, destMin, destMax)
    • Linearly remaps a value from a source range to a desired range
  • QuadraticBezierCurve(origin, influence, destination, pointCount)
    • Get an array of points representing a quadratic bezier curve.
  • CubicBezierCurve(origin, influenceA, influnceB, destination, pointCount)
    • Get an array of points representing a cubic bezier curve.
  • FromFeet(feet)
    • Convert feet into Unity Units. Because I'm a silly American that can only visualise space in US standard units.
  • FromInches(inches)
    • Convert inches into Unity Units.
  • String.PrependAn(capitalize)
    • Prepends either "A" or "An" depending on the word.
  • String.Pluralize(capitalize)
    • Appends "s" or "es" based on common rules. Uses dictionary of common outliers. "Puma" -> "Pumas"; "Fox" -> "Foxes"; "Index" -> "Indices"
  • List.GetRandom() andArray.GetRandom()
    • Returns a random element from an array or list.
  • CoinFlip
    • Returns true or false at random.

Bezier Path Editor

Editor scripts to create paths.MapToCurve includes a tween to follow paths over a duration using a speed curve.

Path

3D Layout Groups

Basic object distribution scripts that run in edit mode, dynamically adapting to changes in the child hierarchy. Similar to UI Layout Groups, but for 3D transforms. Offers flat grid distribution and curved grid distribution.

ObjectPool

Creates and enables game objects, recycling whenever possible.

AudioPool

Plays an AudioClip by cycling through multiple audio sources, preventing clicks and pops. Also includes RandomizedSoundEffect component that picks a random sample from a list, randomizing pitch and volume within a specified range.

CustomLog

UnityEngine.Debug.Log wrapper allowing you to subscribe to log updates, to change in-game Text for example. Inspired by the need to see the Debug.Log entries within a VR experience, without ruining the ability to doubleclick the item in the Unity Console. Also provides the ability to colorize in the Console. Usage:Wrj.CustomLog.Log("Test", Color.cyan). AddCustomLogTextUpdate component to an object containing aTMPro.TextMeshProUGUI,UnityEngine.UI.Text orTextMesh to update text each timeCustomLog.Log() is called.

Custom Script Creation Options

CustomCreationPrefs

  • Custom Script Path
    • New scripts created directly on GameObjects or in Assets root will automatically move to the Custom Script Path. Leave blank to disable.
  • Default Namespace
    • Automatically adds a default namespace to newly created scripts. Requires a custom monobehavior script in%EDITOR_PATH%\\Data\\Resources\\ScriptTemplates containing the variable#NAMESPACE#.

About

Stuff I use a lot, and a simple AnimationCurve-based tweening interface

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp