|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
3 | 3 | using System.Collections.Generic;
|
| 4 | +using System.Linq; |
4 | 5 |
|
5 | 6 | namespace Straitjacket.Subnautica.Mods.SnapBuilder.ExtensionMethods
|
6 | 7 | {
|
@@ -67,7 +68,24 @@ public static void Render(this Collider collider, Material material, float scale
|
67 | 68 | /// <returns></returns>
|
68 | 69 | public static Transform GetOptimalTransform(this RaycastHit hit) => Builder.GetSurfaceType(hit.normal) switch
|
69 | 70 | {
|
70 |
| - SurfaceType.Ground => hit.transform.parent ?? hit.transform, |
| 71 | + SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root |
| 72 | + && root.GetComponent<BaseCell>() is BaseCell => root, |
| 73 | + SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root |
| 74 | + && root.GetComponent<Base>() is Base => hit.transform, |
| 75 | + SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root |
| 76 | + && new float[] { 1, 0, 1 / Mathf.Sqrt(2) } |
| 77 | + .Any(dot => Mathf.Approximately(dot, Mathf.Abs(Vector3.Dot(root.forward, hit.transform.forward)))) |
| 78 | + => root, |
| 79 | + |
| 80 | + SurfaceType.Ground when hit.transform.parent is Transform parent |
| 81 | + && parent.GetComponent<BaseCell>() is BaseCell => parent, |
| 82 | + SurfaceType.Ground when hit.transform.parent is Transform parent |
| 83 | + && parent.GetComponent<Base>() is Base => hit.transform, |
| 84 | + SurfaceType.Ground when hit.transform.parent is Transform parent |
| 85 | + && new float[] { 1, 0, 1 / Mathf.Sqrt(2) } |
| 86 | + .Any(dot => Mathf.Approximately(dot, Mathf.Abs(Vector3.Dot(parent.forward, hit.transform.forward)))) |
| 87 | + => parent, |
| 88 | + |
71 | 89 | _ => hit.transform
|
72 | 90 | };
|
73 | 91 |
|
|
0 commit comments