Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
This diff is collapsed.
This diff is collapsed.
......@@ -37,7 +37,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 53, y: 2}
m_SizeDelta: {x: 30, y: 30}
m_SizeDelta: {x: 60, y: 60}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &5672974249124204919
CanvasRenderer:
......@@ -187,7 +187,7 @@ MonoBehaviour:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
......
This diff is collapsed.
......@@ -23,6 +23,8 @@ public class Constraint
public object Object1;
public object Object2;
public string name;
State state = State.unknown;
ConstraintType constraintType;
......@@ -40,6 +42,7 @@ public class Constraint
float length = (float)obj2;
l.setConstraint(this);
name = l.name + "=" + length.ToString();
break;
case ConstraintType.LineEqual:
Line l1 = (Line)obj1;
......@@ -47,6 +50,7 @@ public class Constraint
l1.setConstraint(this);
l2.setConstraint(this);
name = l1.name + "=" + l2.name;
break;
}
}
......
......@@ -9,12 +9,15 @@ public class Line
public Point point2;
public Vector3 direction;
public string name;
public State lineState = State.unknown;
public Line(Point p1, Point p2)
{
point1 = p1;
point2 = p2;
name = p1.name + p2.name;
direction = new Vector3(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z).normalized;
}
......
......@@ -11,6 +11,8 @@ public class CanvasManager3D : MonoBehaviour
List<Angle> angles;
List<Constraint> constraints;
public bool isFin = false;
public CanvasManager3D()
{
points = new Dictionary<string, Point>();
......@@ -147,6 +149,7 @@ public class CanvasManager3D : MonoBehaviour
}
PrintPoints();
isFin = true;
}
public string createPoint(string name = "")
......@@ -257,10 +260,11 @@ public class CanvasManager3D : MonoBehaviour
return tmp;
}
public void createConstraint(object obj1, object obj2, ConstraintType type)
public string createConstraint(object obj1, object obj2, ConstraintType type)
{
Constraint constraint = new Constraint(type, obj1, obj2);
constraints.Add(constraint);
return constraint.name;
}
void PrintPoints()
......
......@@ -7,11 +7,18 @@ public class UIManager : MonoBehaviour
{
List<GameObject> points;
List<GameObject> lines;
List<GameObject> constraints;
public GameObject constraintDropdown;
public GameObject constraintInput;
public Transform pointsParent;
public Transform linesParent;
public Transform constraintParent;
public GameObject button;
public GameObject line;
public GameObject constraint;
string chosen1 = "";
string chosen2 = "";
......@@ -21,7 +28,9 @@ public class UIManager : MonoBehaviour
enum UIState
{
none,
createLine
createLine,
linelength,
lineEqual
}
UIState state = UIState.none;
......@@ -31,6 +40,7 @@ public class UIManager : MonoBehaviour
{
points = new List<GameObject>();
lines = new List<GameObject>();
constraints = new List<GameObject>();
}
// Update is called once per frame
......@@ -46,6 +56,18 @@ public class UIManager : MonoBehaviour
createLine();
}
break;
case UIState.linelength:
if (!chosen1.Equals("") && !constraintInput.GetComponent<InputField>().text.Equals(""))
{
createConstraint();
}
break;
case UIState.lineEqual:
if (!chosen1.Equals("") && !chosen2.Equals(""))
{
createConstraint();
}
break;
}
}
......@@ -55,7 +77,7 @@ public class UIManager : MonoBehaviour
GameObject tmp = Instantiate(button);
tmp.transform.SetParent(pointsParent);
points.Add(tmp);
tmp.transform.localPosition = new Vector3(50 + 40 * (points.Count - 1), 0, 0);
tmp.transform.localPosition = new Vector3(100 + 70 * (points.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n;
tmp.GetComponent<Button>().onClick.AddListener(delegate(){ chooseObject(n); });
}
......@@ -73,17 +95,23 @@ public class UIManager : MonoBehaviour
GameObject tmp = Instantiate(line);
tmp.transform.SetParent(linesParent);
lines.Add(tmp);
tmp.transform.localPosition = new Vector3(50 + 40 * (lines.Count - 1), 0, 0);
tmp.transform.localPosition = new Vector3(100 + 70 * (lines.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n;
tmp.GetComponent<Button>().onClick.AddListener(delegate () { chooseObject(n); });
state = UIState.none;
}
public void chooseObject(string obj)
{
if(state != UIState.none)
{
if (chosen1.Equals(""))
chosen1 = obj;
if (!chosen1.Equals("") && !chosen1.Equals(obj) && chosen2.Equals(""))
chosen2 = obj;
Debug.Log(obj);
}
}
public void LineButton()
......@@ -93,4 +121,54 @@ public class UIManager : MonoBehaviour
}
}
public void createConstraintButton()
{
constraintDropdown.SetActive(true);
}
public void constraintDropdownChange()
{
string text = constraintDropdown.GetComponent<Dropdown>().captionText.text;
ConstraintType type = (ConstraintType)System.Enum.Parse(typeof(ConstraintType), text);
switch (type)
{
case ConstraintType.LineLength:
state = UIState.linelength;
constraintInput.SetActive(true);
break;
case ConstraintType.LineEqual:
state = UIState.lineEqual;
break;
}
}
void createConstraint()
{
string n = "";
switch (state)
{
case UIState.linelength:
Line l = CM.GetLine(chosen1);
float length = float.Parse(constraintInput.GetComponent<InputField>().text);
n = CM.createConstraint(l, length, ConstraintType.LineLength);
constraintInput.SetActive(false);
break;
case UIState.lineEqual:
Line l1 = CM.GetLine(chosen1);
Line l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineEqual);
break;
}
chosen1 = "";
chosen2 = "";
GameObject tmp = Instantiate(line);
tmp.transform.SetParent(constraintParent);
constraints.Add(tmp);
tmp.transform.localPosition = new Vector3(100 + 70 * (constraints.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n;
state = UIState.none;
constraintDropdown.GetComponent<Dropdown>().captionText.text = "None";
constraintDropdown.SetActive(false);
}
}
......@@ -10,10 +10,13 @@ public class test : MonoBehaviour
public float width = 1.0f;
Mesh mesh;
bool tryGet = false;
// Start is called before the first frame update
void Start()
{
lines = new List<Line>();
mesh = GetComponent<MeshFilter>().mesh;
}
// Update is called once per frame
......@@ -49,10 +52,18 @@ public class test : MonoBehaviour
}
mesh.SetIndices(triangles, MeshTopology.Triangles, 0);
}
if (tryGet)
{
getDig();
}
}
public void getDig()
{
if (CM.isFin)
{
lines = CM.GetLines();
tryGet = false;
}
}
}
Markdown is supported
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