XDracam / unity-corelibrary

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

`myVector.With(x: 5, y:3)` and Color analogues #31

Closed XDracam closed 5 years ago

XDracam commented 5 years ago

The goal is to design a generic version for the already present Vector3.WithFoo methods. These do not add any real benefit, however they do provide alternatives to the developer to maximize expressability:

// -- before
Vector3 target;
transform.position = target.WithY(transform.position.y);

// -- after
Vector3 target;
transform.position = transform.position.With(x: target.x, z: target.z);

While the benefits for vectors are marginal, the whole thing becomes much better with colors:

// -- before (other planned feature)
Color color = Color.red;
material.color = color.WithG(0.5f).WithA(0.5f);

// -- after
Color color = Color.red;
material.color = color.With(g: 0.5f, a: 0.5f);