This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Vector3 AnchoredPositionToWorldPosition(Vector2 anchoredPosition) | |
{ | |
Vector2 canvasSize = canvasRectTransform.sizeDelta; | |
Vector2 viewportPosition = new Vector2( | |
(anchoredPosition.x + (canvasSize.x * 0.5f)) / canvasSize.x, | |
(anchoredPosition.y + (canvasSize.y * 0.5f)) / canvasSize.y | |
); | |
Vector3 worldPosition = CameraManager.GetInstance().GetUICamera().ViewportToWorldPoint(viewportPosition); | |
worldPosition.z = canvasRectTransform.position.z; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 pos = targetTransform.position; | |
Matrix4x4 vp = mainCamera.projectionMatrix * mainCamera.worldToCameraMatrix; | |
Vector4 porjPos = vp * new Vector4(pos.x, pos.y, pos.z, 1); | |
// projPos.xyz / projPos.w [-1, 1] in view frustum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rotation and transform a 2d array | |
// aniticlockwise 90 degree | |
Vector2[] tUV2 = new Vector2[tUV.Length]; | |
System.Array.Copy(tUV, 0, tUV2, 0, tUV.Length); | |
for (int pi = 0; pi < h; ++pi) | |
{ | |
for (int pj = 0; pj < w; ++pj) | |
{ | |
Vector2 pc = tUV2[pi * w + pj]; | |
tUV[(w - pj - 1) * w + pi] = pc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert tiling from UnityTerrain to CustomTerrain | |
material.SetTextureScale("_Splat0", new Vector2(1.0f / terrainLayer.tileSize.x * terrainData.size.x, 1.0f / terrainLayer.tileSize.y * terrainData.size.z)) |