StansAssets / com.stansassets.foundation

Collection of utility methods, design patterns, and extensions for Unity.
https://stansassets.com/
MIT License
129 stars 12 forks source link

TransformExtensions code review #101

Closed soraphis closed 1 year ago

soraphis commented 2 years ago

https://github.com/StansAssets/com.stansassets.foundation/blob/b3332055c35bb65162e22570b14c06d59ff4155e/Runtime/Extensions/UnityEngine/TransformExtensions.cs#L53-L67

using GetComponent is kinda inefficient. you can do this:

for(int i = transform.childCount-1; i >= 0; --i){
    Object.DestroyImmediate(transform.GetChild(i));
}

https://github.com/StansAssets/com.stansassets.foundation/blob/b3332055c35bb65162e22570b14c06d59ff4155e/Runtime/Extensions/UnityEngine/TransformExtensions.cs#L80-L81

if you'd use part.SetParent(transform, false) you could skip the part.Reset() call.

alexey-yaremenko commented 1 year ago

Done in #108