mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Keep texture centered when extending pipes
(this will be important later)
This commit is contained in:
parent
46c068f4a7
commit
1ba8caa1ac
Binary file not shown.
@ -27,6 +27,12 @@ namespace Restock
|
|||||||
|
|
||||||
// initial scale of the pipe object, may not be 1
|
// initial scale of the pipe object, may not be 1
|
||||||
private float baseStretch;
|
private float baseStretch;
|
||||||
|
|
||||||
|
// scale vector for the material
|
||||||
|
private Vector2 texScale = Vector2.one;
|
||||||
|
|
||||||
|
// offset vector for the material
|
||||||
|
private Vector2 texOffset = Vector2.zero;
|
||||||
|
|
||||||
|
|
||||||
public override void OnStart(StartState state)
|
public override void OnStart(StartState state)
|
||||||
@ -76,15 +82,17 @@ namespace Restock
|
|||||||
// updates the texture stretch to match the pipe object's local scale
|
// updates the texture stretch to match the pipe object's local scale
|
||||||
private void UpdateStretch()
|
private void UpdateStretch()
|
||||||
{
|
{
|
||||||
var stretch = line.localScale.z;
|
var stretch = line.localScale.z / baseStretch;
|
||||||
var scaleVect = Vector2.one;
|
|
||||||
scaleVect[pipeStretchIndex] = stretch / baseStretch;
|
texScale[pipeStretchIndex] = stretch;
|
||||||
|
texOffset[pipeStretchIndex] = (1 - stretch) / 2;
|
||||||
|
|
||||||
foreach (var material in pipeMaterials)
|
foreach (var material in pipeMaterials)
|
||||||
{
|
{
|
||||||
foreach (var id in pipeMaterialIDs)
|
foreach (var id in pipeMaterialIDs)
|
||||||
{
|
{
|
||||||
material.SetTextureScale(id, scaleVect);
|
material.SetTextureScale(id, texScale);
|
||||||
|
material.SetTextureOffset(id, texOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user