// Update is called once per frame
void Update()
{
if (sandboxSurface != Helper.GetMostImmediateParentVoxeme(sandboxSurface))
{
sandboxSurface = Helper.GetMostImmediateParentVoxeme(sandboxSurface);
}
if (placementState == PlacementState.Delete)
{
if (Input.GetMouseButtonDown(0))
{
if (Helper.PointOutsideMaskedAreas(
new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y),
new Rect[] {
new Rect(Screen.width - (15 + (int)(110 * fontSizeModifier / 3)) + 38 * fontSizeModifier - 60,
Screen.height - (35 + (int)(20 * fontSizeModifier)),
60, 20 * fontSizeModifier)
}))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Casts the ray and get the first game object hit
Physics.Raycast(ray, out selectRayhit);
if (selectRayhit.collider != null)
{
if (selectRayhit.collider.gameObject.transform.root.gameObject == selectedObject)
{
DeleteVoxeme(selectedObject);
actionButtonText = "Add Object";
placementState = PlacementState.Add;
selected = -1;
cameraControl.allowRotation = true;
}
}
}
}
}
else if (placementState == PlacementState.Place)
{
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Casts the ray and get the first game object hit
Physics.Raycast(ray, out selectRayhit);
if (selectRayhit.collider != null)
{
if (selectRayhit.collider.gameObject.transform.root.gameObject == sandboxSurface)
{
Debug.Log(selectRayhit.point.y);
if (Mathf.Abs(selectRayhit.point.y - preds.ON(new object[] { sandboxSurface }).y) <=
Constants.EPSILON)
{
if ((Mathf.Abs(selectRayhit.point.x - Helper.GetObjectWorldSize(sandboxSurface).min.x) >=
Helper.GetObjectWorldSize(selectedObject).extents.x) &&
(Mathf.Abs(selectRayhit.point.x - Helper.GetObjectWorldSize(sandboxSurface).max.x) >=
Helper.GetObjectWorldSize(selectedObject).extents.x) &&
(Mathf.Abs(selectRayhit.point.z - Helper.GetObjectWorldSize(sandboxSurface).min.z) >=
Helper.GetObjectWorldSize(selectedObject).extents.z) &&
(Mathf.Abs(selectRayhit.point.z - Helper.GetObjectWorldSize(sandboxSurface).max.z) >=
Helper.GetObjectWorldSize(selectedObject).extents.z))
{
selectedObject.transform.position = new Vector3(selectRayhit.point.x,
preds.ON(new object[] { sandboxSurface }).y + surfacePlacementOffset,
selectRayhit.point.z);
Voxeme voxComponent = selectedObject.GetComponent <Voxeme>();
voxComponent.targetPosition = selectedObject.transform.position;
foreach (Voxeme child in voxComponent.children)
{
if (child.isActiveAndEnabled)
{
if (child.gameObject != voxComponent.gameObject)
{
child.transform.localPosition =
voxComponent.parentToChildPositionOffset[child.gameObject];
child.targetPosition = child.transform.position;
}
}
}
}
}
}
}
}
if (Input.GetKeyDown(KeyCode.Return))
{
actionButtonText = "Add Object";
placementState = PlacementState.Add;
selected = -1;
cameraControl.allowRotation = true;
selectedObject.GetComponent <Rigging>().ActivatePhysics(true);
SetShader(selectedObject, ShaderType.Default);
}
}
else if (placementState == PlacementState.Add)
{
if (Input.GetMouseButton(0))
{
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// Casts the ray and get the first game object hit
Physics.Raycast(ray, out selectRayhit);
if (selectRayhit.collider != null)
{
if (Helper.IsSupportedBy(selectRayhit.collider.gameObject.transform.root.gameObject,
sandboxSurface))
{
if (selectRayhit.collider.gameObject.transform.root.gameObject.GetComponent <Voxeme>() !=
null)
{
selectedObject = selectRayhit.collider.gameObject.transform.root.gameObject;
surfacePlacementOffset =
(Helper.GetObjectWorldSize(selectedObject.gameObject).center.y -
Helper.GetObjectWorldSize(selectedObject.gameObject).min.y) +
(selectedObject.gameObject.transform.position.y -
Helper.GetObjectWorldSize(selectedObject.gameObject).center.y);
SetShader(selectedObject, ShaderType.Highlight);
actionButtonText = "Place";
placementState = PlacementState.Place;
cameraControl.allowRotation = false;
if (selectedObject != null)
{
selectedObject.GetComponent <Rigging>().ActivatePhysics(false);
}
}
}
}
}
}
}
}