public bool Initialize(GameObject gameObject) { if (gameObject == null || _gameObject != null) { return(false); } Mesh mesh = gameObject.GetMesh(); Sprite sprite = gameObject.GetSprite(); if (mesh == null && sprite == null) { return(false); } bool useMesh = true; if (mesh == null) { useMesh = false; } RTMesh rtMesh = null; if (useMesh) { Renderer meshRenderer = gameObject.GetMeshRenderer(); if (meshRenderer == null || !meshRenderer.enabled) { useMesh = false; } rtMesh = RTMeshDb.Get.GetRTMesh(mesh); if (rtMesh == null) { useMesh = false; } } if (rtMesh == null && sprite == null) { return(false); } List <AABB> vertOverlapAABBs = BuildVertOverlapAABBs(gameObject, useMesh ? null : sprite, useMesh ? rtMesh : null); if (vertOverlapAABBs.Count == 0) { return(false); } AABB modelAABB = useMesh ? rtMesh.AABB : ObjectBounds.CalcSpriteModelAABB(gameObject); List <BoxFace> aabbFaces = BoxMath.AllBoxFaces; _gameObject = gameObject; if (useMesh) { foreach (BoxFace aabbFace in aabbFaces) { AABB overlapAABB = vertOverlapAABBs[(int)aabbFace]; List <Vector3> overlappedVerts = rtMesh.OverlapModelVerts(overlapAABB); Plane facePlane = BoxMath.CalcBoxFacePlane(modelAABB.Center, modelAABB.Size, Quaternion.identity, aabbFace); overlappedVerts = facePlane.ProjectAllPoints(overlappedVerts); _snapAreaBounds[(int)aabbFace] = new AABB(overlappedVerts); _snapAreaDesc[(int)aabbFace] = BoxMath.GetBoxFaceAreaDesc(_snapAreaBounds[(int)aabbFace].Size, aabbFace); } } else { foreach (BoxFace aabbFace in aabbFaces) { if (aabbFace != BoxFace.Front && aabbFace != BoxFace.Back) { AABB overlapAABB = vertOverlapAABBs[(int)aabbFace]; List <Vector3> overlappedVerts = ObjectVertexCollect.CollectModelSpriteVerts(sprite, overlapAABB); Plane facePlane = BoxMath.CalcBoxFacePlane(modelAABB.Center, modelAABB.Size, Quaternion.identity, aabbFace); overlappedVerts = facePlane.ProjectAllPoints(overlappedVerts); _snapAreaBounds[(int)aabbFace] = new AABB(overlappedVerts); _snapAreaDesc[(int)aabbFace] = BoxMath.GetBoxFaceAreaDesc(_snapAreaBounds[(int)aabbFace].Size, aabbFace); } else { _snapAreaBounds[(int)aabbFace] = AABB.GetInvalid(); _snapAreaDesc[(int)aabbFace] = BoxFaceAreaDesc.GetInvalid(); } } } return(true); }