I'm working on a (free) asset package for Unity, which is basically a collection of extension methods (C#) to make life easier / faster for us devs. I'm asking the community for any extension methods you'd like to see included. If you have a common method in Unity (for example, setting the X value of a transform, or recursively setting a layer on an object and its children), please post here and I'll be happy to add it to the package, along with all appropriate acknowledgements. Thanks, Philip
Vector3.Add(Vector3 v); //Adds v to Vector3 Vector3.Add(float x,float y,float z) // Adda XYZ as a vector to Vector3. The following 3 could be put into a "FileFormatIO" class or similar A way to load WAV files from disk ( I have code for this if you need ) A way to load JPG files from disk ( I have code for this if you need ) A way to load DDS files from disk ( I have code for this if you need )
Well if you are working on a general solution here's a few that might be handy to have. - Method that finds transform(s) by name from transform hierarchy. Meaning if you have complex transform like car with ton of child transforms you'd be able to find all the transforms named "wheel" or just one. - Method that does the above but returns the specified component(s) e.g all WheelBehaviors from wheels. we have in-house methods for these and they have been really handy especially for user interface development where you are want to find certain labels, textboxes which are children of UI windows. Getting the distance between transforms quickly might be handy as well. Fairly simple to implement but fitting for general solution. - float transform.DistanceTo(Transform t); Doesn't the Vector3.Scale already do this?
Doesn't the vector class already work with + operator? I mean I find myself often using Code (CSharp): transform.position += direction * Time.deltaTime;
Here are a couple I wrote which I use a lot Code (CSharp): public static T GetInterface<T>(this GameObject go) where T : class { if(!typeof(T).IsInterface) { Debug.LogError(typeof(T).ToString() + " is not an interface"); return null; } return go.GetComponents<Component>().OfType<T>().FirstOrDefault(); } public static T GetInterfaceInChildren<T>(this GameObject go) where T : class { if(!typeof(T).IsInterface) { Debug.LogError(typeof(T).ToString() + " is not an interface"); return null; } return go.GetComponentsInChildren<Component>().OfType<T>().FirstOrDefault(); } public static IEnumerable<T> GetInterfaces<T>(this GameObject go) where T : class { if(!typeof(T).IsInterface) { Debug.LogError(typeof(T).ToString() + " is not an interface"); return Enumerable.Empty<T>(); } return go.GetComponents<Component>().OfType<T>(); } public static IEnumerable<T> GetInterfacesInChildren<T>(this GameObject go) where T : class { if(!typeof(T).IsInterface) { Debug.LogError(typeof(T).ToString() + " is not an interface"); return Enumerable.Empty<T>(); } return go.GetComponentsInChildren<Component>(true).OfType<T>(); }
Great. I have the V3 adds already. If you'd like to send me the FileFormatIO code via PM, I'll include it in the project. Thanks
That's very useful. I just had a hundred ideas of how to use this, immediately after seeing your code! I'm going to add this, too. Thank you