XDracam / unity-corelibrary

Collection of classes and extension methods that make life with Unity3D more comfortable
MIT License
15 stars 3 forks source link

Is<T>(out result, Search where) alternative #24

Closed Eregerog closed 5 years ago

Eregerog commented 5 years ago

Instead of writing

if(this.Is<Collider>(Search.InChildren)){
 var collider = this.As<Collider>(Search.InChildren);
 collider.trigger = true;
}

there could be an overload for all the Is methods, that is used like the following (in c#7 and updwards, a little less useful before)

if(this.Is<Collider>(out var result, Search.InChildren)){
  result.trigger = true;
}

Saves a line and an unneccesarry query, without really sacrificing readability. It kinda works like if(foo is MyClass asMyClass)

Eregerog commented 5 years ago

See Pull request: #25