Compare commits
1 Commits
main
...
ssl/250220
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc4a2a3234 |
@@ -15,7 +15,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!4 &4257723628152675382
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
123
Assets/Resources/Prefabs/PRF_SnapPoint.prefab
Normal file
123
Assets/Resources/Prefabs/PRF_SnapPoint.prefab
Normal file
@@ -0,0 +1,123 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &6849823355470127284
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5816802771913517320}
|
||||
- component: {fileID: 6122485136425333212}
|
||||
- component: {fileID: 2044656933811447541}
|
||||
- component: {fileID: 629700437578547089}
|
||||
- component: {fileID: 7066316665738235925}
|
||||
m_Layer: 9
|
||||
m_Name: PRF_SnapPoint
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5816802771913517320
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6849823355470127284}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0.5, y: 0.5, z: 0.5}
|
||||
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!33 &6122485136425333212
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6849823355470127284}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!23 &2044656933811447541
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6849823355470127284}
|
||||
m_Enabled: 0
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!65 &629700437578547089
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6849823355470127284}
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 511
|
||||
m_LayerOverridePriority: 0
|
||||
m_IsTrigger: 1
|
||||
m_ProvidesContacts: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &7066316665738235925
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6849823355470127284}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 27fe0faeff38d0148b50bf181c8d8f64, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
7
Assets/Resources/Prefabs/PRF_SnapPoint.prefab.meta
Normal file
7
Assets/Resources/Prefabs/PRF_SnapPoint.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c7b5be630a5eab4392b2166ad5f15c9
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -146,8 +146,8 @@ namespace XED.Asset
|
||||
selectedAssetData.RemoveTransform(selectedItem.transform);
|
||||
Destroy(selectedItem);
|
||||
}
|
||||
selectRenderObject.Deselect();
|
||||
selectedAssetData = null;
|
||||
selectRenderObject.Deselect();
|
||||
selectedAssetData = null;
|
||||
onAssetDropped?.Invoke();
|
||||
}
|
||||
public void OnSelectObjectFromHierarchy(List<HierarchyItem> selectedItems)
|
||||
@@ -214,29 +214,29 @@ namespace XED.Asset
|
||||
onSelectObjects?.Invoke(name, selectedObjects);
|
||||
}
|
||||
public void OnDragBoxSelect(Rect selectionBoxRect)
|
||||
{
|
||||
{
|
||||
List<ConnectedAsset> activeAssets = connectedAssets.FindAll(x => x.renderObject != null && x.renderObject.gameObject.activeSelf);
|
||||
if (activeAssets.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = "";
|
||||
List<GameObject> selectedObjects = new List<GameObject>();
|
||||
string name = "";
|
||||
List<HierarchyItem> selectedItems = new List<HierarchyItem>();
|
||||
renderObjectHandler.RemoveAllSelections();
|
||||
List<CustomAssetRenderObject> selectedRenderObjects = new List<CustomAssetRenderObject>();
|
||||
renderObjectHandler.RemoveAllSelections();
|
||||
for (int i = 0; i < activeAssets.Count; i++)
|
||||
{
|
||||
ConnectedAsset activeAsset = activeAssets[i];
|
||||
if (selectionBoxRect.Contains(Camera.main.WorldToScreenPoint(activeAsset.renderObject.transform.position)))
|
||||
{
|
||||
name = i == 0 ? activeAsset.hierarchyItem.name : name.Equals(activeAsset.hierarchyItem.name) ? activeAsset.hierarchyItem.name : "-";
|
||||
selectedItems.Add(activeAsset.hierarchyItem);
|
||||
selectedObjects.Add(activeAsset.renderObject.gameObject);
|
||||
renderObjectHandler.AddSelection(activeAsset.renderObject);
|
||||
selectedItems.Add(activeAsset.hierarchyItem);
|
||||
selectedRenderObjects.Add(activeAsset.renderObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
renderObjectHandler.AddSelection(selectedRenderObjects);
|
||||
componentScrollView.OnSelect(selectedItems);
|
||||
onSelectObjects?.Invoke(name, selectedObjects);
|
||||
onSelectObjects?.Invoke(name, selectedRenderObjects.Select(x=>x.gameObject).ToList());
|
||||
}
|
||||
public void OnRemoveObject(List<CustomAssetRenderObject> objects)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace XED.Util
|
||||
{
|
||||
objectRenderer = GetComponentInChildren<MeshRenderer>();
|
||||
snapPoints = GetComponentsInChildren<ObjectSnap>().Select(x => x.transform).ToList();
|
||||
boxCollider = GetComponent<BoxCollider>();
|
||||
boxCollider = GetComponent<BoxCollider>();
|
||||
matCubeShow = Resources.Load<Material>("Materials/Mat_CubeShow");
|
||||
matCubeSelected = Resources.Load<Material>("Materials/Mat_CubeSelected");
|
||||
matCubeCollided = Resources.Load<Material>("Materials/Mat_CubeCollided");
|
||||
@@ -205,5 +205,29 @@ namespace XED.Util
|
||||
renderObject = null;
|
||||
}
|
||||
}
|
||||
public Bounds GetBounds()
|
||||
{
|
||||
return boxCollider.bounds;
|
||||
}
|
||||
public List<Vector3> GetRenderObjectVertices()
|
||||
{
|
||||
MeshFilter[] meshFilters = renderObject.GetComponentsInChildren<MeshFilter>();
|
||||
List<Vector3> points = new List<Vector3>();
|
||||
for (int i = 0; i < meshFilters.Length; i++)
|
||||
{
|
||||
Vector3[] vertices = meshFilters[i].mesh.vertices;
|
||||
for (int k = 0; k < vertices.Length; k++)
|
||||
{
|
||||
Vector3 pt = renderObject.transform.TransformPoint(vertices[k]);
|
||||
points.Add(pt);
|
||||
}
|
||||
}
|
||||
return points;
|
||||
}
|
||||
public KDTree GetVertexPointKDTree()
|
||||
{
|
||||
if (renderObject == null) return null;
|
||||
return new KDTree(renderObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace XED.Util
|
||||
List<GameObject> selectedGameObjects = new List<GameObject>();
|
||||
CustomAssetRenderObject prevSelectedObject;
|
||||
RTGController rtgController;
|
||||
ConvexHullCalculator convexHullCalculator = new ConvexHullCalculator();
|
||||
Vector3 clickBeginPos;
|
||||
float clickLengthThreshold = 5.0f;
|
||||
int uiLayer;
|
||||
@@ -46,8 +47,20 @@ namespace XED.Util
|
||||
//var inputManager = FindSingle<UserInputManager>();
|
||||
|
||||
selectIndex = 0;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private bool ApproximatelyEqual(Vector3 a, Vector3 b, float epsilon = 1e-5f)
|
||||
{
|
||||
return Mathf.Abs(a.x - b.x) < epsilon &&
|
||||
Mathf.Abs(a.y - b.y) < epsilon &&
|
||||
Mathf.Abs(a.z - b.z) < epsilon;
|
||||
}
|
||||
private void OnMousePointerDown()
|
||||
{
|
||||
clickBeginPos = Input.mousePosition;
|
||||
@@ -65,13 +78,12 @@ namespace XED.Util
|
||||
onDragBegin?.Invoke(clickBeginPos);
|
||||
}
|
||||
private void OnMousePointerUp()
|
||||
{
|
||||
{
|
||||
//rtg 컨트롤러가 조작중일때 락을 건다.
|
||||
//rtg 컨트롤러 조작 후 포커스가 바뀌는 것을 방지하기 위한 용도
|
||||
if (lockHandler == true)
|
||||
{
|
||||
lockHandler = false;
|
||||
onDragForceEnd?.Invoke();
|
||||
return;
|
||||
}
|
||||
//ui를 선택했을 경우에는 오브젝트 선택을 멈춘다.
|
||||
@@ -85,7 +97,7 @@ namespace XED.Util
|
||||
{
|
||||
onDragForceEnd?.Invoke();
|
||||
return;
|
||||
}
|
||||
}
|
||||
//포인터 업 위치가 포인터 다운 위치에서 크게 벗어났을 경우는 클릭을 무시한다.
|
||||
if ((clickBeginPos - Input.mousePosition).magnitude > clickLengthThreshold)
|
||||
{
|
||||
@@ -168,6 +180,21 @@ namespace XED.Util
|
||||
selectedGameObjects.Add(item.gameObject);
|
||||
rtgController.SetGizmoTargetObjects(selectedGameObjects);
|
||||
}
|
||||
public void AddSelection(List<CustomAssetRenderObject> items)
|
||||
{
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
CustomAssetRenderObject item = items[i];
|
||||
if (selectedRenderObjects.Any(x => x == item))
|
||||
{
|
||||
return;
|
||||
}
|
||||
item.Select();
|
||||
selectedRenderObjects.Add(item);
|
||||
selectedGameObjects.Add(item.gameObject);
|
||||
}
|
||||
rtgController.SetGizmoTargetObjects(selectedGameObjects);
|
||||
}
|
||||
public void RemoveAllSelections()
|
||||
{
|
||||
for (int i = 0; i < selectedRenderObjects.Count; i++)
|
||||
@@ -213,6 +240,7 @@ namespace XED.Util
|
||||
{
|
||||
OnTransformChanged(transformObjects);
|
||||
onTransformChanged?.Invoke(selectedGameObjects);
|
||||
onDragForceEnd?.Invoke();
|
||||
}
|
||||
public void OnTransformChanged(List<GameObject> transformObjects)
|
||||
{
|
||||
@@ -305,6 +333,81 @@ namespace XED.Util
|
||||
});
|
||||
CommandManager.I.ExecuteCommand(command);
|
||||
}
|
||||
public void VertexSnap()
|
||||
{
|
||||
if (selectedRenderObjects.Count != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//가장 가까운 오브젝트에 붙여준다.
|
||||
//Transform.position이 가깝다고 오브젝트 사이 기리가 꼭 가장 가까운 것은 아니기 때문에
|
||||
//오버랩 박스에 충돌되는 모든 오브젝트의 버텍스로 KDTree를 구성해 볼까 하다가 관두었다.
|
||||
float minDist = float.MaxValue;
|
||||
CustomAssetRenderObject fromObject = selectedRenderObjects[0];
|
||||
CustomAssetRenderObject toObject = null;
|
||||
Bounds fromBounds = fromObject.GetBounds();
|
||||
Collider[] colliders = Physics.OverlapBox(fromBounds.center, fromBounds.size * 2.0f);
|
||||
foreach (Collider collider in colliders)
|
||||
{
|
||||
if (collider.gameObject == fromObject.gameObject) continue;
|
||||
CustomAssetRenderObject otherObject = collider.gameObject.GetComponent<CustomAssetRenderObject>();
|
||||
if (otherObject != null)
|
||||
{
|
||||
float dist = Vector3.Magnitude(fromObject.transform.position - otherObject.transform.position);
|
||||
if (dist < minDist)
|
||||
{
|
||||
minDist = dist;
|
||||
toObject = otherObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toObject != null)
|
||||
{
|
||||
//선택된 오브젝트의 ConvexHull 버텍스 점을 계산해준다.
|
||||
//이는 iteration하는 버텍스 수를 줄이기 위해 해주며,
|
||||
//만약 선택된 오브젝트도 TDTree로 Nearest 포인트 탐지할 경우 toObject의 센터에 가장 가까운 포인트만 탐지되기 때문에 가장 가까운 버텍스 점이 골라지지 않는 경우가 있다.
|
||||
List<Vector3> verts = new List<Vector3>();
|
||||
List<int> tris = new List<int>();
|
||||
List<Vector3> normals = new List<Vector3>();
|
||||
convexHullCalculator.GenerateHull(fromObject.GetRenderObjectVertices(), false, ref verts, ref tris, ref normals);
|
||||
KDTree toTree = toObject.GetVertexPointKDTree();
|
||||
Vector3 nearestPoint = Vector3.zero;
|
||||
Vector3 snapPoint = Vector3.zero;
|
||||
float minDistance = float.MaxValue;
|
||||
for (int i = 0; i < verts.Count; i++)
|
||||
{
|
||||
Vector3 ptNearest = verts[i];
|
||||
Vector3 ptSnap = toTree.FindNearest(ptNearest);
|
||||
float tempDist = Vector3.Magnitude(ptSnap - ptNearest);
|
||||
if (tempDist < minDistance)
|
||||
{
|
||||
minDistance = tempDist;
|
||||
nearestPoint = ptNearest;
|
||||
snapPoint = ptSnap;
|
||||
}
|
||||
}
|
||||
//Vector3 direction = snapPoint - nearestPoint;
|
||||
//fromObject.transform.position += direction;
|
||||
List<Vector3> dir = new List<Vector3>() { snapPoint - nearestPoint };
|
||||
if (dir[0].magnitude < 0.5f)
|
||||
{
|
||||
fromObject.transform.position += dir[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
ActionCommand command = new ActionCommand(
|
||||
() =>
|
||||
{
|
||||
fromObject.transform.position += dir[0];
|
||||
},
|
||||
() =>
|
||||
{
|
||||
fromObject.transform.position -= dir[0];
|
||||
});
|
||||
CommandManager.I.ExecuteCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputHandler myHandler;
|
||||
public void CurrentStatusEvent()
|
||||
@@ -329,6 +432,7 @@ namespace XED.Util
|
||||
getKeyActions.Add(KeyCode.W, SetRTGRotate);
|
||||
getKeyActions.Add(KeyCode.E, SetRTGScale);
|
||||
getKeyActions.Add(KeyCode.R, ResetRTG);
|
||||
getKeyActions.Add(KeyCode.V, VertexSnap);
|
||||
|
||||
var shortcutTable = new Dictionary<KeyCode, Dictionary<KeyCode, Action>>();
|
||||
#if UNITY_EDITOR
|
||||
|
||||
1221
Assets/Scripts/XED/Common/ConvexHullCalculator.cs
Normal file
1221
Assets/Scripts/XED/Common/ConvexHullCalculator.cs
Normal file
File diff suppressed because it is too large
Load Diff
2
Assets/Scripts/XED/Common/ConvexHullCalculator.cs.meta
Normal file
2
Assets/Scripts/XED/Common/ConvexHullCalculator.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f641992acc8b864bbd2a56cf7d61e13
|
||||
111
Assets/Scripts/XED/Common/KDTree.cs
Normal file
111
Assets/Scripts/XED/Common/KDTree.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XED.Util
|
||||
{
|
||||
public class KDTree
|
||||
{
|
||||
private class KDNode
|
||||
{
|
||||
public Vector3 point;
|
||||
public KDNode left, right;
|
||||
public int axis;
|
||||
}
|
||||
|
||||
private KDNode root;
|
||||
|
||||
public KDTree(Vector3[] points)
|
||||
{
|
||||
root = Build(points, 0);
|
||||
}
|
||||
public KDTree(GameObject gb)
|
||||
{
|
||||
MeshFilter[] meshFilters = gb.GetComponentsInChildren<MeshFilter>();
|
||||
HashSet<Vector3> listPoints = new HashSet<Vector3>();
|
||||
for (int i = 0; i < meshFilters.Length; i++)
|
||||
{
|
||||
Vector3[] vertices = meshFilters[i].mesh.vertices;
|
||||
for (int k = 0; k < vertices.Length; k++)
|
||||
{
|
||||
Vector3 pt = gb.transform.TransformPoint(vertices[k]);
|
||||
listPoints.Add(pt);
|
||||
}
|
||||
}
|
||||
root = Build(listPoints.ToArray(), 0);
|
||||
}
|
||||
|
||||
private KDNode Build(Vector3[] points, int depth)
|
||||
{
|
||||
if (points.Length == 0) return null;
|
||||
|
||||
int axis = depth % 3;
|
||||
System.Array.Sort(points, (a, b) => (a[axis] < b[axis]) ? -1 : (a[axis] > b[axis]) ? 1 : 0);
|
||||
//System.Array.Sort(points, (a, b) => a[axis].CompareTo(b[axis]));
|
||||
int median = points.Length / 2;
|
||||
|
||||
return new KDNode
|
||||
{
|
||||
point = points[median],
|
||||
axis = axis,
|
||||
left = Build(points[..median], depth + 1),
|
||||
right = Build(points[(median + 1)..], depth + 1)
|
||||
};
|
||||
}
|
||||
private Vector3[] RemoveDuplicates(Vector3[] points, float epsilon = 1e-5f)
|
||||
{
|
||||
if (points.Length == 0) return points;
|
||||
|
||||
List<Vector3> uniquePoints = new List<Vector3> { points[0] };
|
||||
|
||||
for (int i = 1; i < points.Length; i++)
|
||||
{
|
||||
if (!ApproximatelyEqual(points[i], points[i - 1], epsilon))
|
||||
{
|
||||
uniquePoints.Add(points[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return uniquePoints.ToArray();
|
||||
}
|
||||
|
||||
private bool ApproximatelyEqual(Vector3 a, Vector3 b, float epsilon = 1e-5f)
|
||||
{
|
||||
return Mathf.Abs(a.x - b.x) < epsilon &&
|
||||
Mathf.Abs(a.y - b.y) < epsilon &&
|
||||
Mathf.Abs(a.z - b.z) < epsilon;
|
||||
}
|
||||
public Vector3 FindNearest(Vector3 target)
|
||||
{
|
||||
return FindNearest(root, target, root.point, float.MaxValue);
|
||||
}
|
||||
|
||||
private Vector3 FindNearest(KDNode node, Vector3 target, Vector3 best, float bestDist)
|
||||
{
|
||||
if (node == null) return best;
|
||||
|
||||
float dist = Vector3.Distance(target, node.point);
|
||||
if (dist < bestDist)
|
||||
{
|
||||
bestDist = dist;
|
||||
best = node.point;
|
||||
}
|
||||
|
||||
bool searchLeft = target[node.axis] < node.point[node.axis];
|
||||
|
||||
KDNode first = searchLeft ? node.left : node.right;
|
||||
KDNode second = searchLeft ? node.right : node.left;
|
||||
|
||||
best = FindNearest(first, target, best, bestDist);
|
||||
bestDist = Vector3.Distance(target, best);
|
||||
|
||||
if (Mathf.Abs(target[node.axis] - node.point[node.axis]) < bestDist)
|
||||
{
|
||||
best = FindNearest(second, target, best, bestDist);
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/XED/Common/KDTree.cs.meta
Normal file
2
Assets/Scripts/XED/Common/KDTree.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 716a33e2eb3f24c4893f51d634f5f1f1
|
||||
@@ -50,6 +50,7 @@ namespace XED.UI
|
||||
}
|
||||
public void OnEndDrag(Vector3 position)
|
||||
{
|
||||
if (!selectionBoxImage.gameObject.activeSelf) return;
|
||||
selectionBoxImage.gameObject.SetActive(false);
|
||||
StopAllCoroutines();
|
||||
SetSelectionBoxSize(position);
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace XED.UI
|
||||
}
|
||||
}
|
||||
public void SetObjectInfo(string name, List<GameObject> selectedObjects)
|
||||
{
|
||||
{
|
||||
ResetObjectInfo();
|
||||
if (name == null || selectedObjects == null)
|
||||
{
|
||||
@@ -225,12 +225,17 @@ namespace XED.UI
|
||||
{
|
||||
return;
|
||||
}
|
||||
Text_Name.text = name;
|
||||
string append = "";
|
||||
if (!name.Equals("-"))
|
||||
{
|
||||
append = string.Format(" ({0})" ,selectedObjects.Count);
|
||||
}
|
||||
Text_Name.text = name + append;
|
||||
OnTransformChanged(selectedObjects);
|
||||
if (lastSelectedInputField.type != InputFieldType.none)
|
||||
{
|
||||
lastSelectedInputField = new SelectedInput(InputFieldType.none, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void ResetObjectInfo()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user