Commit a0158467 authored by Bošániová Monika's avatar Bošániová Monika
Browse files

changing automate rotations (not working yet)

parent 97dfb482
......@@ -999,6 +999,84 @@ RectTransform:
m_AnchoredPosition: {x: 225, y: -49.946747}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &213162957
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 213162958}
- component: {fileID: 213162960}
- component: {fileID: 213162959}
m_Layer: 5
m_Name: Error Message
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &213162958
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 213162957}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 320450172}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 733.7, y: 27.68}
m_SizeDelta: {x: 386.87756, y: 45.844025}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &213162959
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 213162957}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.8862745}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 25
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text:
--- !u!222 &213162960
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 213162957}
m_CullTransparentMesh: 0
--- !u!1 &239965588
GameObject:
m_ObjectHideFlags: 0
......@@ -1372,7 +1450,7 @@ GameObject:
- component: {fileID: 273764826}
- component: {fileID: 273764825}
m_Layer: 5
m_Name: Panel
m_Name: Color Buttons
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -1420,6 +1498,7 @@ MonoBehaviour:
cube2DMap: {fileID: 981341155}
allButtons: {fileID: 273764823}
ClickableRotator: {fileID: 837318595}
errorTextOutput: {fileID: 213162959}
actualMaterial: {fileID: 2100000, guid: 5601add48eb7ebe4cb5c251dde8c8998, type: 2}
--- !u!114 &273764826
MonoBehaviour:
......@@ -1783,6 +1862,7 @@ RectTransform:
- {fileID: 62275332}
- {fileID: 578057746}
- {fileID: 273764824}
- {fileID: 213162958}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -9915,6 +9995,7 @@ MonoBehaviour:
cube2DMap: {fileID: 981341155}
allButtons: {fileID: 0}
ClickableRotator: {fileID: 0}
errorTextOutput: {fileID: 0}
actualMaterial: {fileID: 0}
--- !u!1 &1786435071
GameObject:
......
......@@ -26,6 +26,7 @@ public class Automate : MonoBehaviour
{
cubeState = FindObjectOfType<CubeState>();
cubeMap = CubeMapMatrix.CubeMatrix;
CubeState.started = true;
//readCube = FindObjectOfType<ReadCube>();
////update 2D Map
......@@ -126,7 +127,7 @@ public class Automate : MonoBehaviour
{
//readCube.ReadState();
CubeState.autoRotating = true;
cubeMap.callRotation(move);
//cubeMap.callRotation(move);
if (move == "U")
{
RotateSide(cubeState.up, -90);
......
......@@ -10,13 +10,16 @@ public class ColorButtons : MonoBehaviour
public GameObject cube2DMap;
public GameObject allButtons;
public GameObject ClickableRotator;
public Text errorTextOutput;
public Material actualMaterial;
private Colors beforeButtonColor;
private string errorMassage = "You can't recolor middle pieces!";
private void Start()
{
errorTextOutput = GameObject.Find("Error Message").GetComponent<Text>();
}
void Update()
......@@ -27,19 +30,25 @@ public class ColorButtons : MonoBehaviour
if (Physics.Raycast(ray, out RaycastHit hit))
{
Renderer mesh = hit.collider.GetComponent<Renderer>();
if((
if(mesh.tag == "Centre")
{
errorTextOutput.text = errorMassage;
}
else if(
mesh.name == "Front" ||
mesh.name == "Back" ||
mesh.name == "Up" ||
mesh.name == "Down" ||
mesh.name == "Right" ||
mesh.name == "Left"
) && mesh.tag != "Centre")
if (actualMaterial)
{
mesh.material = actualMaterial;
Rotator.Update2DMap(wholeCube, cube2DMap);
}
mesh.name == "Left")
{
if (actualMaterial)
{
mesh.material = actualMaterial;
Rotator.Update2DMap(wholeCube, cube2DMap);
}
}
}
}
......@@ -79,6 +88,7 @@ public class ColorButtons : MonoBehaviour
button.text = "Rotation";
removeLabels();
ClickableRotator.SetActive(true);
errorTextOutput.text = "";
allButtons.transform.Find("Editation Button").Find("Edit Image").gameObject.SetActive(false);
allButtons.transform.Find("Editation Button").Find("Rotate Image").gameObject.SetActive(true);
......
......@@ -4,46 +4,46 @@ using UnityEngine;
public class PivotRotation : MonoBehaviour
{
//private List<GameObject> activeSide;
//private Vector3 localForward;
//private Vector3 mouseRef;
//private bool dragging = false;
//private bool autoRotating = false;
//private float sensitivity = 0.4f;
//private float speed = 300f;
//private Vector3 rotation;
//private Quaternion targetQuaternion;
////private ReadCube readCube;
//private CubeState cubeState;
//// Start is called before the first frame update
//void Start()
//{
// //readCube = FindObjectOfType<ReadCube>();
// cubeState = FindObjectOfType<CubeState>();
//}
//// Late Update is called once per frame at the end
//void LateUpdate()
//{
// print("Pivot?" + dragging + autoRotating);
// if (dragging && !autoRotating)
// {
// SpinSide(activeSide);
// if (Input.GetMouseButtonUp(0))
// {
// dragging = false;
// RotateToRightAngle();
// }
// }
// if (autoRotating)
// {
// AutoRotate();
// }
//}
private List<GameObject> activeSide;
private Vector3 localForward;
private Vector3 mouseRef;
private bool dragging = false;
private bool autoRotating = false;
private float sensitivity = 0.4f;
private float speed = 300f;
private Vector3 rotation;
private Quaternion targetQuaternion;
//private ReadCube readCube;
private CubeState cubeState;
// Start is called before the first frame update
void Start()
{
//readCube = FindObjectOfType<ReadCube>();
cubeState = FindObjectOfType<CubeState>();
}
// Late Update is called once per frame at the end
void LateUpdate()
{
//print("Pivot?" + dragging + autoRotating);
//if (dragging && !autoRotating)
//{
// SpinSide(activeSide);
// if (Input.GetMouseButtonUp(0))
// {
// dragging = false;
// RotateToRightAngle();
// }
//}
if (autoRotating)
{
AutoRotate();
}
}
//private void SpinSide(List<GameObject> side)
//{
......@@ -53,11 +53,11 @@ public class PivotRotation : MonoBehaviour
// //current move position minus the last mouse position
// Vector3 mouseOffset = (Input.mousePosition - mouseRef);
// if(side == cubeState.front)
// if (side == cubeState.front)
// {
// rotation.x = (mouseOffset.x + mouseOffset.y) * -sensitivity;
// }
// if(side == cubeState.back)
// if (side == cubeState.back)
// {
// rotation.x = (mouseOffset.x + mouseOffset.y) * sensitivity;
// }
......@@ -87,53 +87,53 @@ public class PivotRotation : MonoBehaviour
// mouseRef = Input.mousePosition;
//}
//public void Rotate(List<GameObject> side)
//{
// activeSide = side;
// mouseRef = Input.mousePosition;
// dragging = true;
// //Create a vector to rotate around
// localForward = Vector3.zero - side[4].transform.parent.transform.localPosition;
//}
//public void StartAutoRotate(List<GameObject> side, float angle)
//{
// cubeState.PickUp(side);
// Vector3 localForward = Vector3.zero - side[4].transform.parent.transform.localPosition;
// targetQuaternion = Quaternion.AngleAxis(angle, localForward) * transform.localRotation;
// activeSide = side;
// autoRotating = true;
//}
//public void RotateToRightAngle()
//{
// Vector3 vec = transform.localEulerAngles;
// // round vec to nearest 90 degrees
// vec.x = Mathf.Round(vec.x / 90) * 90;
// vec.y = Mathf.Round(vec.y / 90) * 90;
// vec.z = Mathf.Round(vec.z / 90) * 90;
// targetQuaternion.eulerAngles = vec;
// autoRotating = true;
//}
//private void AutoRotate()
//{
// dragging = false;
// var step = speed * Time.deltaTime;
// transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetQuaternion, step);
// //if within one degree, set angle to target angle and end the rotation
// if(Quaternion.Angle(transform.localRotation, targetQuaternion) <= 1)
// {
// transform.localRotation = targetQuaternion;
// //unparent the little cubes
// cubeState.PutDown(activeSide, transform.parent);
// //readCube.ReadState();
// CubeState.autoRotating = false;
// autoRotating = false;
// dragging = false;
// }
//}
public void Rotate(List<GameObject> side)
{
activeSide = side;
mouseRef = Input.mousePosition;
dragging = true;
//Create a vector to rotate around
localForward = Vector3.zero - side[4].transform.parent.transform.localPosition;
}
public void StartAutoRotate(List<GameObject> side, float angle)
{
cubeState.PickUp(side);
Vector3 localForward = Vector3.zero - side[4].transform.parent.transform.localPosition;
targetQuaternion = Quaternion.AngleAxis(angle, localForward) * transform.localRotation;
activeSide = side;
autoRotating = true;
}
public void RotateToRightAngle()
{
Vector3 vec = transform.localEulerAngles;
// round vec to nearest 90 degrees
vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;
targetQuaternion.eulerAngles = vec;
autoRotating = true;
}
private void AutoRotate()
{
dragging = false;
var step = speed * Time.deltaTime;
transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetQuaternion, step);
//if within one degree, set angle to target angle and end the rotation
if (Quaternion.Angle(transform.localRotation, targetQuaternion) <= 1)
{
transform.localRotation = targetQuaternion;
//unparent the little cubes
cubeState.PutDown(activeSide, transform.parent);
//readCube.ReadState();
CubeState.autoRotating = false;
autoRotating = false;
dragging = false;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment