A collection of small, handy components for unity. All CC0

gwen 35c9ce06ba added vec3 to vec2 swizzles. I may add vec 3-to-3 later but unless i find some metaprogramming trickery this won't scale forever lol 1 year ago
C04U 35c9ce06ba added vec3 to vec2 swizzles. I may add vec 3-to-3 later but unless i find some metaprogramming trickery this won't scale forever lol 1 year ago
.gitignore ffb6a25ec4 added metas so we can use this as a package 2 years ago
C04U.meta ffb6a25ec4 added metas so we can use this as a package 2 years ago
LICENSE 3af2ceaf95 indents 3 years ago
LICENSE.meta ffb6a25ec4 added metas so we can use this as a package 2 years ago
README.md e6842b5a90 Update 'README.md' 2 years ago
README.md.meta ffb6a25ec4 added metas so we can use this as a package 2 years ago
c0mp0nent-logo.pixil bfbe58299c logo! 3 years ago
c0mp0nent-logo.pixil.meta ffb6a25ec4 added metas so we can use this as a package 2 years ago
c0mp0nent-logo.png bfbe58299c logo! 3 years ago
c0mp0nent-logo.png.meta ffb6a25ec4 added metas so we can use this as a package 2 years ago
package.json 0d8dab53d1 bump version? 2 years ago
package.json.meta b74761e633 added more metas 2 years ago

README.md

c0mp0nents-for-unity

A collection of small, handy components for unity. License as CC0 so you (or more realistically just me) can use them basically anywhere and anyway you see fit.

Design Principles

Modularity

The library is highly modular. Almost all scripts can simply be removed if they are not needed or wanted. Namespaces can always be deleted wholesale, that is C04U.UGUI will not break if C04U.Events is removed and so on.

Minimal Dependencies

The library will have as few dependencies as possible, and scripts that rely on a dependency will be easily excised. Dependencies will not be bundled with the library, it is on the user to install them correctly.

The only dependency right now is on JSON .NET for Unity if you are in pre-2020LTS. After 2020 Unity packages in the Newtonsoft JSON DLL by default, removing this requirement. This dependency can be removed by deleting C04U/SaveData

Events

A few short scripts that just expose public UnityEvents so you can tie simple actions to an object without haveing to actually write a script. A good rule of thumb is if you need to do a thing in a monobehaviour event BUT you dont need an if statement or anything, then these components are for you.

Files:

  • OnDisableEvent.cs
  • OnEnableEvent.cs
  • OnApplicationQuitEvent.cs

Example

Examples for things you may not know about or will forget easily

Files:

  • AnimationCurvePlotter.cs
    • example snippet to shot how to abuse unity's AnimationCurve to plot values over time
  • RunOnStartWithoutAMonobehavior.cs
    • example snippet to have code run 'on start' without needing a monobehavior/game object
  • SwipeMovementRoutine.cs
    • An example of a swipe coroutine

Input

Currently only the InputTweak class which lets you design exclusively for touch interaction and have mouse interaction map through that.

Files:

  • InputTweak.cs
    • a child of Input that will translate mouse events into touch events so you can standardize on touch

SaveData

This is a partial class that allows to create complex save states without an enormous hassle. This part relies on JSONForUnity. Either install that from the asset store or delete this portion

Files:

  • SaveData.cs
    • this is the core part DO NOT modify it directly
    • will spawn a GameObject at runtime to manage autosaving
    • Has reflective functions for Getting and Setting properties by name
  • AutoSave.cs
    • monobehavior that will save the file at regular intervals.
    • the savedata itself has a value _AUTOSAVE_WAIT which will set the interval in seconds
    • There is an editor script which will enable and disable the autosave. This setting persists across restarts
  • SaveData.Example.cs
    • this is an example of how you should extend savedata to add values.
    • note the partial class and the namespace declaration
    • note the Setup function declaration
    • you should probably delete this file in production
  • ExampleDataUser.cs
    • example of how to use the data in SaveData
    • you should probably delete this file in production
  • SetInSaveData.cs
    • a Monobehaviour you can attach to objects like buttons to update the SaveData from a UnityEvent without a dedicated script
  • SetInSaveData2.cs, SetInSaveData3.cs
    • derived but unmodified classes of SetInSaveData. Useful if you need to set multiple values from the same button.

Tween

Tweening tools for use inside of coroutines (the only place you should ever be tweening anyway)

Files:

  • VectorTween.cs
    • An IEnumerator that will tween a vector from it's current value to a new one over a given duration

UGUI

Handy parts for working with UGUI items

Files:

  • EventSelector.cs
    • The is the base for many of the UGUI components. It basically just lets them reuse the part where they need to selet what monobehaviour event should trigger thier public Set() function
  • RectTransformViewer.cs
    • Displays all the actual unmodified properties of the RectTransform of the GameObject it is on
    • make sure to set it's TriggerOn to Update
  • SetButtonAlphaThreshold.cs
    • set the button alpha threshold. there is no reason I should ever write that
  • SetSibling
    • sets the transform to a particular sibling position
    • it will use the SetAsFirstSibling, SetAsLastSibling if the Postion option is set that way
    • it will (carefully) use SetSiblingIndex otherwise
  • Stretch
    • basically a "stretch to fit height" or "stretch to fit width"
    • sets the RectTransform to make sure it preserves the aspect ratio of the original sprite on whatever side you want to keep.
    • can manually set coparison sprite, or it can try to auto-find an Image component