Ryle Radio 1.0.1
An open-source "radio" system for Unity, allowing tracks, tuning, broadcasters, and more!
Loading...
Searching...
No Matches
RadioUtils.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using UnityEngine;
6
7/// The entire package
8namespace RyleRadio
9{
10 // you can ignore this section- this is for namespace descriptions in documentation
11 // ------
12 /// Components to be placed on scene objects, e.g: Outputs, Broadcasters, Observers
13 namespace Components {
14 /// Base interfaces and classes for components, e.g: track accessors, output accessors
15 namespace Base { }
16 }
17 /// Editor scripts for classes and attributes, notably excluding MultiselectAttribute
18 namespace Editor { }
19 /// Tracks to be used on a radio- includes base classes
20 namespace Tracks { }
21 // ------
22
23
24 /// <summary>
25 /// Various utilities used throughout the project.
26 /// </summary>
27 static class RadioUtils
28 {
29 /// <summary>
30 /// Remaps a float between `[_from1 - _from2]` to `[_to1 - _to2]`
31 /// Preserves the float's position in the range.
32 /// </summary>
33 /// <param name="_value">A _value between `_from1` and `_from2`</param>
34 /// <returns>A _value between `_to1` and `_to2`</returns>
35 /// <example><code>
36 /// float _value = 1;
37 /// float output = _value.Remap(0, 5, 2, 15); // remap 1 from [0 - 2] to [5 - 15]
38 /// Debug.Log(output); // logs 10
39 /// </code></example>
40 public static float Remap(this float _value, float _from1, float _to1, float _from2, float _to2)
41 {
42 return (_value - _from1) / (_to1 - _from1) * (_to2 - _from2) + _from2;
43 }
44
45 /// <summary>
46 /// Gets the absolute value of all components of a vector at once
47 /// </summary>
48 /// <param name="_value">The vector to convert to absolute values</param>
49 /// <returns>The same vector, but any negative numbers have been flipped to positive</returns>
50 /// <example><code>
51 /// Vector3 mixed = new Vector3(-10, 3, 0);
52 /// Vector3 abs = mixed.Abs();
53 /// Debug.Log(abs); // logs Vector3(10, 3, 0)
54 /// </code></example>
55 public static Vector3 Abs(this Vector3 _value)
56 {
57 return new Vector3(
58 Mathf.Abs(_value.x),
59 Mathf.Abs(_value.y),
60 Mathf.Abs(_value.z)
61 );
62 }
63
64 /// <summary>
65 /// Gets all types derived from a given one. Does not include:<list eventType="bullet">
66 /// <item>Interfaces</item>
67 /// <item>Generic classes</item>
68 /// <item>Abstract classes</item></list>
69 /// </summary>
70 /// <param name="_baseType">The eventType to find derived types of</param>
71 /// <returns>An array of types that derive from \ref _baseType</returns>
72 public static Type[] FindDerivedTypes(Type _baseType)
73 {
74 // we use all assemblies here for ease of use to developers creating and testing new tracks
75
76 // get all assemblies used in the project
77 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
78 IEnumerable<Type> types = new List<Type>();
79
80 // search through every assembly applicable classes
81 foreach (Assembly assembly in assemblies)
82 types = types.Union(assembly.GetTypes().Where(t => // find classes that,
83 t != _baseType // aren't the given eventType
84 && _baseType.IsAssignableFrom(t) // inherit from the given eventType
85 && !t.IsInterface // aren't interfaces
86 && !t.IsGenericType // aren't generic
87 && !t.IsAbstract // aren't abstract
88 ));
89
90 // returns the types
91 return types.ToArray();
92 }
93 }
94
95}
Various utilities used throughout the project.
Definition RadioUtils.cs:28
static float Remap(this float _value, float _from1, float _to1, float _from2, float _to2)
Remaps a float between [_from1 - _from2] to [_to1 - _to2] Preserves the float's position in the range...
Definition RadioUtils.cs:40
static Vector3 Abs(this Vector3 _value)
Gets the absolute value of all components of a vector at once.
Definition RadioUtils.cs:55
static Type[] FindDerivedTypes(Type _baseType)
Gets all types derived from a given one. Does not include:Interfaces Generic classes Abstract classes
Definition RadioUtils.cs:72
Base interfaces and classes for components, e.g: track accessors, output accessors.
Components to be placed on scene objects, e.g: Outputs, Broadcasters, Observers.
Editor scripts for classes and attributes, notably excluding MultiselectAttribute.
Tracks to be used on a radio- includes base classes.
Definition RadioUtils.cs:20
The entire package.