Skip to content

FishingCactus/UnityCommonCode

Repository files navigation

FishingCactus - Unity Common Code.

Use this to format your tables: http://markdowntable.com/

đź“ť TODO: We could add some screenshots and put them in the notes column or below the tables (especially for editor tools)

Runtime scripts summary

Classes Static? Mono? Serializable? Notes
DebugTimeScaler X Scales time and fixed delta time with the exposed value
EnumDictionary<TEnum, TObject> X Serializable dictionary initialized with all the enum values as keys
FloatRange X Provides tools to handle min and max float values
FPSCounter X FPS counter with colors
GUIConsole X Runtime console to show Unity logs
GyroscopeHelper Gyroscope support
IntegerRange X Provides tools to handle min an max integer values
NetworkStatusChecker X
Optional X Wrapper to create optional values
SerializableInterface X Wrapper used to reference objects that implement a specific interface
SerializableDictionary<TKey, TValue> X Unity serialization support for dictionaries
Singleton X X Monobehaviour Singleton
TagLink X
TimeScaleManager X X Scales time with lerp and callback
Vector3Range X Provides tools to handle min and max Vector3 values
VersionNumber X Shows application version on start in console and on GUI

Animator

| Classes | Static? | Mono? | Serializable? | Notes | |--------------------------------|---------|-------|---- ---| | | AnimatorLayerController | | | X | | | BooleanAnimatorParameterLink | | | X | | | IntegerAnimatorParameterLink | | | X | | | FloatAnimatorParameterLink | | | X | | | TriggerAnimatorParameterLink | | | X | |

Attributes

Classes Target Notes
EnumFlagsAttributes Enum When is this useful? The field will already have a special drawer if the enum has the System.Flags attribute
ExposedScriptableObjectAttribute( bool it_must_display_object_selector = true ) ScriptableObject Displays the content of the referenced scriptable object
MaxAttribute( float max ) float Ensures that the value won't exceed the max
ReadOnlyAttribute Any The exposed value can't be modified
SubClassPickerAttribute With SerializeReference attribute You can choose a child class to initialize an object marked as SerializeReference
HideInCreateAssetDropdownAttribute ScriptableObject Scriptable object classes that define this attribute are hidden in the create asset dropdown from CreateAssetContextMenu (see PropertyContextMenus)

Coroutines

Still useful?

Extensions

AnimationCurve

Methods Notes
static float GetDuration( this AnimationCurve animation_curve )
static float GetStartTime( this AnimationCurve animation_curve )
static float GetStartValue( this AnimationCurve animation_curve )
static float GetEndTime( this AnimationCurve animation_curve )
static float GetEndValue( this AnimationCurve animation_curve )
static float GetMaximumValueKeyTime( this AnimationCurve animation_curve )

Animator

đź“ť TODO: Instead of still relying on strings (and thus not gaining any perf or ease of use), we could provide an enum value as the argument and internally cache the parameters' ids in a map. Either we generate that enum class according to the animator's parameters, or we just update it manually (it has to be in Samples to be editable)
Methods Notes
static bool HasParameter( this Animator animator, string parameter_name )
static bool HasParameter( this Animator animator, int parameter_hash_id )
static void ResetAllTriggerParameters( this Animator animator )
static void SetTriggerParameter( this Animator animator, string cached_parameter_name )
static void ResetTriggerParameter( this Animator animator, string cached_parameter_name )
static void GetBooleanParameter( this Animator animator, string cached_parameter_name )
static void SetBooleanParameter( this Animator animator, string cached_parameter_name, bool it_is_true )
static void GetFloatParameter( this Animator animator, string cached_parameter_name )
static void SetFloatParameter( this Animator animator, string cached_parameter_name, float value )
static void GetIntegerParameter( this Animator animator, string cached_parameter_name )
static void SetIntegerParameter( this Animator animator, string cached_parameter_name, int value )
static void ToggleBooleanParameter( this Animator animator, string cached_parameter_name )
static void ClearAllTransitions( this Animator animator )

Collections

Methods Notes
static T GetItemByIndexClamped<T>( this List<T> list, int index )
static T GetItemByIndexClamped<T>( this T[] array, int index )
static T GetRandomItem<T>( this List<T> list )
static T GetRandomItem<T>( this T[] array )
static T GetRandomItem<T>( this List<T> list, out int index )
static T GetRandomItem<T>( this T[] array, out int index )

GameObject

Methods Notes
static void SetParent( this GameObject game_object, Transform parent, bool reset_local_position = true, bool reset_local_rotation = true, bool reset_local_scale = false )
static T GetSafeComponent( this GameObject game_object ) obsolete
static T GetCheckedComponent( this GameObject game_object ) where T : MonoBehaviour
static T GetCheckedComponentInParent( this GameObject game_object ) where T : MonoBehaviour
static T GetCheckedComponentInChildren( this GameObject game_object ) where T : MonoBehaviour
static T GetOrAddComponent( this GameObject game_object ) where T : MonoBehaviour
static Component GetOrAddComponent( this GameObject game_object, System.Type component_type )
static void SafeDestroy( this GameObject game_object_instance )

IComparable

Methods Notes
static T Clamp( this T value, T min, T max ) where T : IComparable

List

Methods Notes
static T LastValue<T>( this List<T> list )
static void Shuffle<T>( this List<T> list )
static void MoveDown<T>( this List<T> list, int index )

MonoBehaviour

Methods Notes
static void SetParent( this MonoBehaviour mono_behaviour, Transform parent, bool reset_local_position = true, bool reset_local_rotation = true, bool reset_local_scale = false )
static void Invoke( this MonoBehaviour mono_behaviour, Action action, float time )
static void InvokeRepeating( this MonoBehaviour mono_behaviour, Action action, float time, float repeat_rate )
static T GetOrAddComponent<T>( this MonoBehaviour mono_behaviour ) where T : MonoBehaviour
static Component GetOrAddComponent( this MonoBehaviour mono_behaviour, Type component_type )

String

Methods Notes
static int CountOccurence( this string main, string pattern )
static string Capitalize( this string str )
static string SafeFormat( this string format, params object[] args )

Transform

Methods Notes
static void SetParent( this Transform transform, Transform parent, bool reset_local_position = true, bool reset_local_rotation = true, bool reset_local_scale = false )
static void SetX( this Transform transform, float x )
static void SetY( this Transform transform, float y )
static void SetZ( this Transform transform, float z )
static void SetLocalX( this Transform transform, float x )
static void SetLocalY( this Transform transform, float y )
static void SetLocalZ( this Transform transform, float z )
static void CopyTransform( this Transform transform, Transform source )
static void CopyLocalTransform( this Transform transform, Transform source )
static void Reset( this Transform transform )
static void ResetLocal( this Transform transform )
static void DestroyChildren( this Transform transform )
static void DestroyImmediateChildren( this Transform transform )

ULong

Methods Notes
static uint GetToggledFlagsCount( this ulong flags )

Vector3

Methods Notes
static float GetSquaredMagnitude( this Vector3 vector, Vector3 other_vector )
static float GetHorizontalMagnitude( this Vector3 vector, Vector3 other_vector )
static float GetSquaredHorizontalMagnitude( this Vector3 vector, Vector3 other_vector )
static float GetVerticalMagnitude( this Vector3 vector, Vector3 other_vector )
static float GetSquaredVerticalMagnitude( this Vector3 vector, Vector3 other_vector )

Utilities

Stateless static functions, shouldn't be extensions because too specific or can't be because not called on an instance

ArgumentUtils

For command line arguments

Methods Notes
static bool FindArg( out string value, string name )
static string GetArg( string name )
static bool HasArg( string name )

EnumUtils

Methods Notes
static T ParseEnum<T>( string value ) where T : Enum
static IEnumerable<string> GetValueTable<T>() where T : Enum
static T GetRandom<T>() where T : Enum
static T GetRandom<T>( T min_inclusive, T max_inclusive ) where T : Enum

MathUtils

Methods Notes
static Vector3 CatmulRomInterpolation( Vector3 point0, Vector3 point1, Vector3 point2, Vector3 point3, float percentage )
static bool SameSign( int first_value, int second_value )
static bool SameSign( float first_value, float second_value )
static int MathMod( int dividend, int modulus )

ReflectionUtils

Methods Notes
static bool IsStaticClass( Type type )
static bool TryGetEnumerableElementType( Type list_type, out Type element_type )
static bool IsAssignableToGenericType( Type type, Type generic_type )
static IEnumerable<Type> GetImplementations<TBase>( Func<Type, bool> implementation_delegate = null ) Gets all types that implement the given type and match the given delegate
static IEnumerable<Type> GetImplementations( Type base_type, Func<Type, bool> implementation_delegate = null ) Gets all types that implement the given type and match the given delegate
static IEnumerable<TBase> CreateInstances<TBase>( object[] parameters = null, Func<Type, bool> implementation_delegate = null ) where TBase : class Creates exactly one instance of each type that implements the given type and matches the given delegate

ThrowUtils

Methods Notes
static void ThrowIfArgumentNull( string name, object argument )
static void ThrowIfArgumentOutOfRange( string name, int index, int count )
static void ThrowIfArgumentOutOfRange( string name, int index, int start_index, int count )

TimeUtils

Methods Notes
static int GetMinutesFromSeconds( double seconds )
static int GetHoursFromSeconds( double seconds )
static string GetFormattedTimeFromSeconds( double seconds, bool show_hours = true, bool show_minutes = true, bool show_seconds = true )

ReadOnlyCollections

Provide readonly access to common collections types with garbage free enumerating and utility functions.

Classes Static? Mono? Notes
ReadOnlyDictionary<TKey, TValue>
ReadOnlyHashSet<T>
ReadOnlyList<T>
ReadOnlyQueue<T>
ReadOnlySerializableDictionary<TKey, TValue>
ReadOnlyStack<T>

UI

Classes Static? Mono? Notes
Wizard X Succession of WizardPanel navigable with buttons
WizardPanel X

Editor scripts summary

Classes Static? Notes
ApplySelectedPrefabs
AttributesDrawer
CreateNewPrefab
EditorUtils X
InternalEditorStyle X
ObjectToTerrain
PropertyDrawer
ScriptableObjectCreator X
CustomObjectField Used to draw customized object field with more functionality than EditorGUILayout.ObjectField

ContextMenus

PropertyContextMenus

Classes Notes
CreateAssetContextMenu Adds a context menu action to choose, create and reference an instance of an implemenation of the property type when right clicking on exposed properties deriving from ScriptableObject
PropertyContextMenuCallbackFetcher Utils script to fetch scripts that derive from IPropertyContextMenuCallback and add them automatically to property context menus. This is not meant to be used in project
VectorContextMenu Adds context menu actions to quickly set values of integer, floating-points and vectors values in inspector
MathematicsVectorContextMenu Same as VectorContextMenu but for Unity.Mathematics

Dropdowns

Classes Notes
SelectImplementationDropdown Dropdown that allows to search and select an implementation of a given type

Items

Classes Notes
TypeDropdownItem

DropHandlers

Classes Notes
HierarchyScriptDropHandler Allows people to drag and drop scripts inside a scene to quickly create empty game objects with the dragged script attached

Inspector

Classes Notes
ReorderableSubAssetList<TAsset> Used to draw a list of subassets in inspector from a serialized list on scriptable objects. Supports creating new subassets by selecting a specific implementation and delete existing subassets

PropertyDrawer

Classes Notes
AnimatorParameterLinkDrawer See AnimatorParameterLink child classes
EnumDictionaryPropertyDrawer See EnumDictionary
OptionalDrawer See Optional
RangeDrawer See Range child classes
TagLinkDrawer See TagLink

AttributesDrawer

See Attributes

Utilities

EditorUtils

Methods Notes
static void AddDefineIfNecessary( string define, BuildTargetGroup build_target_group )
static void RemoveDefineIfNecessary( string define, BuildTargetGroup build_target_group )
static bool IsDefined( string define, BuildTargetGroup build_target_group )

HierarchyUtils

Utility functions related to the scene hierarchy.

Methods Notes
static GameObject CreateAndRename( string default_name, Transform parent = null, bool active_object_is_default_parent = true )
static void Rename( GameObject game_object )

InspectorUtils

Utility functions related to drawing things in inspector.

Methods Notes
static Type GetPropertyType( SerializedProperty property )

WizzardUtils

Methods Notes
static string DisplayPathSelector( string original_path, string description, PanelMode panel_mode, string file_extension = "" )

About

No description, website, or topics provided.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages