Commit 1bdb6cb7 authored by BlackAngle233's avatar BlackAngle233
Browse files

2021_6_1_14_45

parent 07399915
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
This diff is collapsed.
This diff is collapsed.
fileFormatVersion: 2
guid: 39bc7e7b244b82542b17c6ebeadb8ecd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6658da0b86525fc4499692f44c3370fa
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 13021387cf451a640bc3ed5891b6af8d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 5b86e571ea2b50447866c8f9d0733c5b
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
public class CanvasManager3D : MonoBehaviour public class CanvasManager3D : MonoBehaviour
{ {
Dictionary<string, Point> points; Dictionary<string, Point> points;
Dictionary<string, Line> lines; Dictionary<string, Line> lines;
Dictionary<string, Plane> planes; Dictionary<string, Plane> planes;
List<Vector> vectors; List<Vector> vectors;
List<Angle> angles; List<Angle> angles;
List<Constraint> constraints; List<Constraint> constraints;
public bool isFin = false; public bool isFin = false;
public CanvasManager3D() public CanvasManager3D()
{ {
points = new Dictionary<string, Point>(); points = new Dictionary<string, Point>();
lines = new Dictionary<string, Line>(); lines = new Dictionary<string, Line>();
planes = new Dictionary<string, Plane>(); planes = new Dictionary<string, Plane>();
vectors = new List<Vector>(); vectors = new List<Vector>();
angles = new List<Angle>(); angles = new List<Angle>();
constraints = new List<Constraint>(); constraints = new List<Constraint>();
} }
public void calculateDig() public void calculateDig()
{ {
float startTime = Time.realtimeSinceStartup; float startTime = Time.realtimeSinceStartup;
Point first = null; Point first = null;
if(points.Count != 0) if(points.Count != 0)
{ {
first = points.First().Value; first = points.First().Value;
} }
else else
{ {
return ; return ;
} }
first.setPoint(1000, 0, 0); first.setPoint(1000, 0, 0);
first.setState(State.confirm); first.setState(State.confirm);
HashSet<Point> usedPoint = new HashSet<Point>(); HashSet<Point> usedPoint = new HashSet<Point>();
Queue<Point> restPoint = new Queue<Point>(); Queue<Point> restPoint = new Queue<Point>();
restPoint.Enqueue(first); restPoint.Enqueue(first);
bool flag = true; bool flag = true;
while(restPoint.Count != 0 && flag) while(restPoint.Count != 0 && flag)
{ {
Point tmp = restPoint.Peek(); Point tmp = restPoint.Peek();
foreach(Line l in tmp.lines) foreach(Line l in tmp.lines)
{ {
Point p = l.getAnotherPoint(tmp); Point p = l.getAnotherPoint(tmp);
if(!restPoint.Contains(p) && !usedPoint.Contains(p)) if(!restPoint.Contains(p) && !usedPoint.Contains(p))
restPoint.Enqueue(p); restPoint.Enqueue(p);
} }
if (tmp.getState() == State.confirm) if (tmp.getState() == State.confirm)
{ {
restPoint.Dequeue(); restPoint.Dequeue();
usedPoint.Add(tmp); usedPoint.Add(tmp);
} }
else else
{ {
int check = tmp.checkConstraint(); int check = tmp.checkConstraint();
if (check == 0) if (check == 0)
{ {
tmp.setState(State.confirm); tmp.setState(State.confirm);
restPoint.Dequeue(); restPoint.Dequeue();
usedPoint.Add(tmp); usedPoint.Add(tmp);
} }
else if (check == 1) else if (check == 1)
{ {
//calculate constaint //calculate constaint
List<Constraint> calculates = new List<Constraint>(); List<Constraint> calculates = new List<Constraint>();
foreach (Constraint c in tmp.constraints) foreach (Constraint c in tmp.constraints)
{ {
if (c.getState() == State.halfconfirm) if (c.getState() == State.halfconfirm)
{ {
calculates.Add(c); calculates.Add(c);
} }
} }
if (calculates.Count == 1) if (calculates.Count == 1)
{ {
calculates[0].calculateConstraint(tmp); calculates[0].calculateConstraint(tmp);
} }
else else
{ {
int count = 0; int count = 0;
bool isFinish = false; bool isFinish = false;
while (count < 10000) while (count < 10000)
{ {
foreach (Constraint c in calculates) foreach (Constraint c in calculates)
{ {
c.tryCalculateConstraint(tmp); c.tryCalculateConstraint(tmp);
} }
if (checkConstraints(calculates)) if (checkConstraints(calculates))
{ {
isFinish = true; isFinish = true;
foreach (Constraint c in calculates) foreach (Constraint c in calculates)
{ {
c.setState(State.confirm); c.setState(State.confirm);
} }
break; break;
} }
count++; count++;
} }
if (!isFinish) if (!isFinish)
{ {
foreach (Constraint c in calculates) foreach (Constraint c in calculates)
{ {
c.setState(State.halfconfirm); c.setState(State.halfconfirm);
} }
restPoint.Dequeue(); restPoint.Dequeue();
restPoint.Enqueue(tmp); restPoint.Enqueue(tmp);
} }
else else
{ {
tmp.setState(State.confirm); tmp.setState(State.confirm);
restPoint.Dequeue(); restPoint.Dequeue();
usedPoint.Add(tmp); usedPoint.Add(tmp);
} }
} }
} }
else if (check == 2) else if (check == 2)
{ {
//random //random
restPoint.Dequeue(); restPoint.Dequeue();
restPoint.Enqueue(tmp); restPoint.Enqueue(tmp);
} }
else else
{ {
restPoint.Dequeue(); restPoint.Dequeue();
restPoint.Enqueue(tmp); restPoint.Enqueue(tmp);
} }
} }
if(restPoint.Count == 0 && usedPoint.Count != points.Count) if(restPoint.Count == 0 && usedPoint.Count != points.Count)
{ {
foreach(var p in points) foreach(var p in points)
{ {
if (!usedPoint.Contains(p.Value)) if (!usedPoint.Contains(p.Value))
{ {
restPoint.Enqueue(p.Value); restPoint.Enqueue(p.Value);
break; break;
} }
} }
} }
} }
foreach(Point p in usedPoint) foreach(Point p in usedPoint)
{ {
p.x -= 1000; p.x -= 1000;
} }
PrintPoints(); PrintPoints();
isFin = true; isFin = true;
float endTime = Time.realtimeSinceStartup; float endTime = Time.realtimeSinceStartup;
Debug.Log(endTime - startTime); Debug.Log(endTime - startTime);
} }
public string createPoint(string name = "") public string createPoint(string name = "")
{ {
if (name.Equals("")) if (name.Equals(""))
{ {
char n = 'A'; char n = 'A';
while (points.ContainsKey(n.ToString())) while (points.ContainsKey(n.ToString()))
{ {
n++; n++;
} }
name = n.ToString(); name = n.ToString();
} }
if (!points.ContainsKey(name)) if (!points.ContainsKey(name))
{ {
Point p = new Point(0, 0, 0, name); Point p = new Point(0, 0, 0, name);
points.Add(name, p); points.Add(name, p);
} }
return name; return name;
} }
public void setPoint(string name, float x, float y, float z) public void setPoint(string name, float x, float y, float z)
{ {
if (points.ContainsKey(name)) if (points.ContainsKey(name))
{ {
Point p = points[name]; Point p = points[name];
p.setPoint(x, y, z); p.setPoint(x, y, z);
p.update(); p.update();
} }
} }
public Point GetPoint(string name) public Point GetPoint(string name)
{ {
if (points.ContainsKey(name)) if (points.ContainsKey(name))
{ {
Point p = points[name]; Point p = points[name];
return p; return p;
} }
else else
return null; return null;
} }
public Vector3[] GetPoints() public Vector3[] GetPoints()
{ {
Vector3[] tmp = new Vector3[points.Count]; Vector3[] tmp = new Vector3[points.Count];
int i = 0; int i = 0;
foreach (var p in points) foreach (var p in points)
{ {
tmp[i] = new Vector3(p.Value.x, p.Value.y, p.Value.z); tmp[i] = new Vector3(p.Value.x, p.Value.y, p.Value.z);
i++; i++;
} }
return tmp; return tmp;
} }
public string createLine(string n1, string n2, float length = 0) public string createLine(string n1, string n2, float length = 0)
{ {
Point p1 = null, p2 = null; Point p1 = null, p2 = null;
points.TryGetValue(n1, out p1); points.TryGetValue(n1, out p1);
points.TryGetValue(n2, out p2); points.TryGetValue(n2, out p2);
if (p1 != null && p2 != null) if (p1 != null && p2 != null)
{ {
Line line = new Line(p1, p2); Line line = new Line(p1, p2);
if(length != 0) if(length != 0)
{ {
createConstraint(line, length, ConstraintType.LineLength); createConstraint(line, length, ConstraintType.LineLength);
} }
string lineName = p1.name + p2.name; string lineName = p1.name + p2.name;
lines[lineName] = line; lines[lineName] = line;
p1.addLine(line); p1.addLine(line);
p2.addLine(line); p2.addLine(line);
return lineName; return lineName;
} }
return ""; return "";
} }
public string createPlane(string n1, string n2) public string createPlane(string n1, string n2)
{ {
List<Point> ps = new List<Point>(); List<Point> ps = new List<Point>();
...@@ -255,7 +255,7 @@ public class CanvasManager3D : MonoBehaviour ...@@ -255,7 +255,7 @@ public class CanvasManager3D : MonoBehaviour
ps.Add(line.point2); ps.Add(line.point2);
} }
else else
return ""; return "";
lines.TryGetValue(n2, out line); lines.TryGetValue(n2, out line);
if (line != null) if (line != null)
...@@ -266,42 +266,42 @@ public class CanvasManager3D : MonoBehaviour ...@@ -266,42 +266,42 @@ public class CanvasManager3D : MonoBehaviour
ps.Add(line.point2); ; ps.Add(line.point2); ;
} }
else else
return ""; return "";
Plane plane = new Plane(ps); Plane plane = new Plane(ps);
string planeName = ""; string planeName = "";
foreach (Point p in ps) foreach (Point p in ps)
{ {
planeName += p.name; planeName += p.name;
} }
planes.Add(planeName, plane); planes.Add(planeName, plane);
return planeName; return planeName;
} }
public void setLine(string n, float length) public void setLine(string n, float length)
{ {
Line l1 = null; Line l1 = null;
lines.TryGetValue(n, out l1); lines.TryGetValue(n, out l1);
if(l1 != null) if(l1 != null)
{ {
createConstraint(l1, length, ConstraintType.LineLength); createConstraint(l1, length, ConstraintType.LineLength);
} }
} }
public Line GetLine(string n) public Line GetLine(string n)
{ {
Line l1 = null; Line l1 = null;
lines.TryGetValue(n, out l1); lines.TryGetValue(n, out l1);
return l1; return l1;
} }
public Plane GetPlane(string n) public Plane GetPlane(string n)
{ {
Plane p = null; Plane p = null;
...@@ -309,85 +309,85 @@ public class CanvasManager3D : MonoBehaviour ...@@ -309,85 +309,85 @@ public class CanvasManager3D : MonoBehaviour
planes.TryGetValue(n, out p); planes.TryGetValue(n, out p);
return p; return p;
} }
public List<Line> GetLines() public List<Line> GetLines()
{ {
List<Line> tmp = new List<Line>(); List<Line> tmp = new List<Line>();
foreach (var l in lines) foreach (var l in lines)
{ {
tmp.Add(l.Value); tmp.Add(l.Value);
} }
return tmp; return tmp;
} }
public string createConstraint(object obj1, object obj2, ConstraintType type) public string createConstraint(object obj1, object obj2, ConstraintType type)
{ {
Constraint constraint = new Constraint(type, obj1, obj2); Constraint constraint = new Constraint(type, obj1, obj2);
constraints.Add(constraint); constraints.Add(constraint);
return constraint.name; return constraint.name;
} }
void PrintPoints() void PrintPoints()
{ {
foreach(var p in points) foreach(var p in points)
{ {
Point tmp = p.Value; Point tmp = p.Value;
Debug.Log(tmp.name + ":(" + tmp.x.ToString() + ", " + tmp.y.ToString() + ", " + tmp.z.ToString() + ")"); Debug.Log(tmp.name + ":(" + tmp.x.ToString() + ", " + tmp.y.ToString() + ", " + tmp.z.ToString() + ")");
} }
foreach(var l in lines) foreach(var l in lines)
{ {
Line tmp = l.Value; Line tmp = l.Value;
Debug.Log(l.Key + ":" + tmp.getLength()); Debug.Log(l.Key + ":" + tmp.getLength());
} }
} }
bool checkConstraints(List<Constraint> constraint) bool checkConstraints(List<Constraint> constraint)
{ {
bool flag = true; bool flag = true;
foreach(Constraint c in constraint) foreach(Constraint c in constraint)
{ {
if(Mathf.Abs(c.getConstraintValue()) > 0.001f) if(Mathf.Abs(c.getConstraintValue()) > 0.001f)
{ {
flag = false; flag = false;
break; break;
} }
} }
return flag; return flag;
} }
public void test1(){ public void test1(){
points.Clear(); points.Clear();
lines.Clear(); lines.Clear();
Point a = new Point(0, 1, 0); Point a = new Point(0, 1, 0);
Point b = new Point(0, 0, 0); Point b = new Point(0, 0, 0);
Point c = new Point(1, 0, 0); Point c = new Point(1, 0, 0);
//Point d = new Point(1, 1, 0); Point d = new Point(1, 1, 0);
//Point e = new Point(0.5f, 1, 0.5f); Point e = new Point(0.5f, 1, 0.5f);
//Point f = new Point(0.5f, 0, 0); Point f = new Point(0.5f, 0, 0);
//Point g = new Point(0.25f, 1, 0.25f); Point g = new Point(0.25f, 1, 0.25f);
points.Add("A", a); points.Add("A", a);
points.Add("B", b); points.Add("B", b);
points.Add("C", c); points.Add("C", c);
//points.Add("D", d); points.Add("D", d);
//points.Add("E", e); points.Add("E", e);
//points.Add("F", f); points.Add("F", f);
//points.Add("G", g); points.Add("G", g);
lines.Add("AB", new Line(a, b)); lines.Add("AB", new Line(a, b));
lines.Add("BC", new Line(b, c)); lines.Add("BC", new Line(b, c));
//lines.Add("CD", new Line(c, d)); lines.Add("CD", new Line(c, d));
//lines.Add("AD", new Line(a, d)); lines.Add("AD", new Line(a, d));
//lines.Add("AE", new Line(a, e)); lines.Add("AE", new Line(a, e));
//lines.Add("DE", new Line(d, e)); lines.Add("DE", new Line(d, e));
//lines.Add("CE", new Line(c, e)); lines.Add("CE", new Line(c, e));
//lines.Add("FG", new Line(f, g)); lines.Add("FG", new Line(f, g));
isFin = true; isFin = true;
} }
} }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour
{
private Touch _OldTouch1;
private Touch _OldTouch2;
Vector2 _M_Screenpos = new Vector2();
bool _bMoveOrRotation;
Vector3 _OldPosition;
void Start()
{
_OldPosition = Camera.main.transform.position;
}
void Update()
{
if (Input.touchCount <= 0)
{
return;
}
if (1 == Input.touchCount)
{
if (_bMoveOrRotation)
{
Touch _Touch = Input.GetTouch(0);
Vector2 _DeltaPos = _Touch.deltaPosition;
transform.Rotate(Vector3.down * _DeltaPos.x, Space.World);
transform.Rotate(Vector3.right * _DeltaPos.y, Space.World);
}
else
{
if (Input.touches[0].phase == TouchPhase.Began)
{
_M_Screenpos = Input.touches[0].position;
}
else if (Input.touches[0].phase == TouchPhase.Moved)
{
Camera.main.transform.Translate(new Vector3(-Input.touches[0].deltaPosition.x * Time.deltaTime * 0.1f, -Input.touches[0].deltaPosition.y * Time.deltaTime * 0.1f, 0));
}
}
}
Touch _NewTouch1 = Input.GetTouch(0);
Touch _NewTouch2 = Input.GetTouch(1);
if (_NewTouch2.phase == TouchPhase.Began)
{
_OldTouch2 = _NewTouch2;
_OldTouch1 = _NewTouch1;
return;
}
float _OldDistance = Vector2.Distance(_OldTouch1.position, _OldTouch2.position);
float _NewDistance = Vector2.Distance(_NewTouch1.position, _NewTouch2.position);
float _Offset = _NewDistance - _OldDistance;
float _ScaleFactor = _Offset / 100f;
Vector3 _LocalScale = transform.localScale;
Vector3 _Scale = new Vector3(_LocalScale.x + _ScaleFactor,
_LocalScale.y + _ScaleFactor,
_LocalScale.z + _ScaleFactor);
if (_Scale.x > 0.3f && _Scale.y > 0.3f && _Scale.z > 0.3f)
{
transform.localScale = _Scale;
}
_OldTouch1 = _NewTouch1;
_OldTouch2 = _NewTouch2;
}
public void BackPosition()
{
Camera.main.transform.position = _OldPosition;
Camera.main.transform.eulerAngles = Vector3.zero;
}
public void RotationOrMove()
{
_bMoveOrRotation = !_bMoveOrRotation;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 19d4823d2f70fba4bb0b9121dc196d89
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using ZXing;//引入库  
using ZXing.QrCode; 
public class QRcode : MonoBehaviour
{
    public Texture2D encoded;
    public string Lastresult;
    void Start()  
    {
        encoded = new Texture2D(256, 256);  
        Lastresult = "http://www.qq.com";  
    }
  
    private static Color32[] Encode(string textForEncoding, int width, int height)  
    {  
        var writer = new BarcodeWriter  
        {  
            Format = BarcodeFormat.QR_CODE,  
            Options = new QrCodeEncodingOptions  
            {  
                Height = height,  
                Width = width  
            }  
        };  
        return writer.Write(textForEncoding);  
    }  
  
  
    public void Save()  
    {  
        var textForEncoding = Lastresult;  
        if (textForEncoding != null)  
        {   
            var color32 = Encode(textForEncoding, encoded.width, encoded.height);  
            encoded.SetPixels32(color32);  
            encoded.Apply();
byte[] bytes = encoded.EncodeToPNG();
string path = Application.persistentDataPath;
Debug.Log(path);
#if UNITY_ANDROID
path = "/storage/emulated/0/DCIM/MathTec";
#endif
if (Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string savePath = string.Format("{0}/{1}.png", path, "pic");
File.WriteAllBytes(savePath, bytes);
        }  
    }  
  
}
\ No newline at end of file
fileFormatVersion: 2
guid: 341a32be5dc6c0e4f99bd2d98ea5a5c1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class UIManager : MonoBehaviour public class UIManager : MonoBehaviour
{ {
List<GameObject> points; List<GameObject> points;
List<GameObject> lines; List<GameObject> lines;
List<GameObject> planes; List<GameObject> planes;
List<GameObject> constraints; List<GameObject> constraints;
public GameObject constraintDropdown; public List<GameObject> UIControl;
public GameObject constraintInput;
public GameObject constraintDropdown;
public Transform pointsParent; public GameObject constraintInput;
public Transform linesParent;
public Transform planesParent; public Transform pointsParent;
public Transform constraintParent; public Transform linesParent;
public Transform planesParent;
public GameObject button; public Transform constraintParent;
public GameObject line;
public GameObject constraint; public GameObject button;
public GameObject line;
string chosen1 = ""; public GameObject constraint;
string chosen2 = "";
string chosen1 = "";
public CanvasManager3D CM; string chosen2 = "";
enum UIState public CanvasManager3D CM;
{
none, enum UIState
createLine, {
createPlane, none,
linelength, createLine,
lineEqual, createPlane,
lineNormal, linelength,
lineEqual,
lineNormal,
lineParallel, lineParallel,
lineParallelPlane, lineParallelPlane,
lineCross, lineCross,
...@@ -44,49 +46,49 @@ public class UIManager : MonoBehaviour ...@@ -44,49 +46,49 @@ public class UIManager : MonoBehaviour
angleEqual, angleEqual,
planeParallelPlane, planeParallelPlane,
planeNormalPlane, planeNormalPlane,
planeArea planeArea
} }
UIState state = UIState.none; UIState state = UIState.none;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
points = new List<GameObject>(); points = new List<GameObject>();
lines = new List<GameObject>(); lines = new List<GameObject>();
planes = new List<GameObject>(); planes = new List<GameObject>();
constraints = new List<GameObject>(); constraints = new List<GameObject>();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
switch (state) switch (state)
{ {
case UIState.none: case UIState.none:
break; break;
case UIState.createLine: case UIState.createLine:
if(!chosen1.Equals("") && !chosen2.Equals("")) if(!chosen1.Equals("") && !chosen2.Equals(""))
{ {
createLine(); createLine();
} }
break; break;
case UIState.createPlane: case UIState.createPlane:
if (!chosen1.Equals("") && !chosen2.Equals("")) if (!chosen1.Equals("") && !chosen2.Equals(""))
{ {
createPlane(); createPlane();
} }
break; break;
case UIState.linelength: case UIState.linelength:
case UIState.angleEqual: case UIState.angleEqual:
case UIState.planeArea: case UIState.planeArea:
if (!chosen1.Equals("") && !constraintInput.GetComponent<InputField>().text.Equals("")) if (!chosen1.Equals("") && !constraintInput.GetComponent<InputField>().text.Equals(""))
{ {
createConstraint(); createConstraint();
} }
break; break;
case UIState.lineEqual: case UIState.lineEqual:
case UIState.lineNormal: case UIState.lineNormal:
case UIState.lineParallel: case UIState.lineParallel:
case UIState.lineParallelPlane: case UIState.lineParallelPlane:
case UIState.lineCross: case UIState.lineCross:
...@@ -94,191 +96,191 @@ public class UIManager : MonoBehaviour ...@@ -94,191 +96,191 @@ public class UIManager : MonoBehaviour
case UIState.pointOnLine: case UIState.pointOnLine:
case UIState.pointInPlane: case UIState.pointInPlane:
case UIState.planeParallelPlane: case UIState.planeParallelPlane:
case UIState.planeNormalPlane: case UIState.planeNormalPlane:
if (!chosen1.Equals("") && !chosen2.Equals("")) if (!chosen1.Equals("") && !chosen2.Equals(""))
{ {
createConstraint(); createConstraint();
} }
break; break;
} }
} }
public void createPoint() public void createPoint()
{ {
string n = CM.createPoint(); string n = CM.createPoint();
GameObject tmp = Instantiate(button); GameObject tmp = Instantiate(button);
tmp.transform.SetParent(pointsParent); tmp.transform.SetParent(pointsParent);
points.Add(tmp); points.Add(tmp);
tmp.transform.localPosition = new Vector3(100 + 70 * (points.Count - 1), 0, 0); tmp.transform.localPosition = new Vector3(100 + 70 * (points.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n; tmp.GetComponentInChildren<Text>().text = n;
tmp.GetComponent<Button>().onClick.AddListener(delegate(){ chooseObject(n); }); tmp.GetComponent<Button>().onClick.AddListener(delegate(){ chooseObject(n); });
} }
public void createLineButton() public void createLineButton()
{ {
state = UIState.createLine; state = UIState.createLine;
} }
void createLine() void createLine()
{ {
string n = CM.createLine(chosen1, chosen2); string n = CM.createLine(chosen1, chosen2);
chosen1 = ""; chosen1 = "";
chosen2 = ""; chosen2 = "";
GameObject tmp = Instantiate(line); GameObject tmp = Instantiate(line);
tmp.transform.SetParent(linesParent); tmp.transform.SetParent(linesParent);
lines.Add(tmp); lines.Add(tmp);
tmp.transform.localPosition = new Vector3(100 + 70 * (lines.Count - 1), 0, 0); tmp.transform.localPosition = new Vector3(100 + 70 * (lines.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n; tmp.GetComponentInChildren<Text>().text = n;
tmp.GetComponent<Button>().onClick.AddListener(delegate () { chooseObject(n); }); tmp.GetComponent<Button>().onClick.AddListener(delegate () { chooseObject(n); });
state = UIState.none; state = UIState.none;
} }
public void createPlaneButton() public void createPlaneButton()
{ {
state = UIState.createPlane; state = UIState.createPlane;
} }
void createPlane() void createPlane()
{ {
string n = CM.createPlane(chosen1, chosen2); string n = CM.createPlane(chosen1, chosen2);
chosen1 = ""; chosen1 = "";
chosen2 = ""; chosen2 = "";
GameObject tmp = Instantiate(line); GameObject tmp = Instantiate(line);
tmp.transform.SetParent(planesParent); tmp.transform.SetParent(planesParent);
planes.Add(tmp); planes.Add(tmp);
tmp.transform.localPosition = new Vector3(100 + 70 * (planes.Count - 1), 0, 0); tmp.transform.localPosition = new Vector3(100 + 70 * (planes.Count - 1), 0, 0);
tmp.GetComponentInChildren<Text>().text = n; tmp.GetComponentInChildren<Text>().text = n;
tmp.GetComponent<Button>().onClick.AddListener(delegate () { chooseObject(n); }); tmp.GetComponent<Button>().onClick.AddListener(delegate () { chooseObject(n); });
state = UIState.none; state = UIState.none;
} }
public void chooseObject(string obj) public void chooseObject(string obj)
{ {
if(state != UIState.none) if(state != UIState.none)
{ {
if (chosen1.Equals("")) if (chosen1.Equals(""))
chosen1 = obj; chosen1 = obj;
if (!chosen1.Equals("") && !chosen1.Equals(obj) && chosen2.Equals("")) if (!chosen1.Equals("") && !chosen1.Equals(obj) && chosen2.Equals(""))
chosen2 = obj; chosen2 = obj;
Debug.Log(obj); Debug.Log(obj);
} }
} }
public void LineButton() public void LineButton()
{ {
if(state == UIState.none) if(state == UIState.none)
{ {
} }
} }
public void createConstraintButton() public void createConstraintButton()
{ {
constraintDropdown.SetActive(true); constraintDropdown.SetActive(true);
} }
public void constraintDropdownChange() public void constraintDropdownChange()
{ {
string text = constraintDropdown.GetComponent<Dropdown>().captionText.text; string text = constraintDropdown.GetComponent<Dropdown>().captionText.text;
if (text.Equals("None")) return; if (text.Equals("None")) return;
ConstraintType type = (ConstraintType)System.Enum.Parse(typeof(ConstraintType), text); ConstraintType type = (ConstraintType)System.Enum.Parse(typeof(ConstraintType), text);
switch (type) switch (type)
{ {
case ConstraintType.LineLength: case ConstraintType.LineLength:
state = UIState.linelength; state = UIState.linelength;
constraintInput.SetActive(true); constraintInput.SetActive(true);
break; break;
case ConstraintType.LineEqual: case ConstraintType.LineEqual:
state = UIState.lineEqual; state = UIState.lineEqual;
break; break;
case ConstraintType.LineNormal: case ConstraintType.LineNormal:
state = UIState.lineNormal; state = UIState.lineNormal;
break; break;
case ConstraintType.LineParallel: case ConstraintType.LineParallel:
state = UIState.lineParallel; state = UIState.lineParallel;
break; break;
case ConstraintType.LineParallelPlane: case ConstraintType.LineParallelPlane:
state = UIState.lineParallelPlane; state = UIState.lineParallelPlane;
break; break;
case ConstraintType.LineCross: case ConstraintType.LineCross:
state = UIState.lineCross; state = UIState.lineCross;
break; break;
case ConstraintType.MidPoint: case ConstraintType.MidPoint:
state = UIState.midPoint; state = UIState.midPoint;
break; break;
case ConstraintType.PointOnLine: case ConstraintType.PointOnLine:
state = UIState.pointOnLine; state = UIState.pointOnLine;
break; break;
case ConstraintType.PointInPlane: case ConstraintType.PointInPlane:
state = UIState.pointInPlane; state = UIState.pointInPlane;
break; break;
case ConstraintType.AngleEqual: case ConstraintType.AngleEqual:
state = UIState.angleEqual; state = UIState.angleEqual;
break; break;
case ConstraintType.PlaneParallelPlane: case ConstraintType.PlaneParallelPlane:
state = UIState.planeParallelPlane; state = UIState.planeParallelPlane;
break; break;
case ConstraintType.PlaneNormalPlane: case ConstraintType.PlaneNormalPlane:
state = UIState.planeNormalPlane; state = UIState.planeNormalPlane;
break;
case ConstraintType.PlaneArea:
state = UIState.planeArea;
constraintInput.SetActive(true);
break;
}
}
void createConstraint()
{
Point p = null;
Line l1 = null;
Line l2 = null;
Plane p1 = null;
Plane p2 = null;
float length;
string n = "";
switch (state)
{
case UIState.linelength:
l1 = CM.GetLine(chosen1);
length = float.Parse(constraintInput.GetComponent<InputField>().text);
n = CM.createConstraint(l1, length, ConstraintType.LineLength);
constraintInput.SetActive(false);
break;
case UIState.lineEqual:
l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineEqual);
break; break;
case ConstraintType.PlaneArea: case UIState.lineNormal:
state = UIState.planeArea; l1 = CM.GetLine(chosen1);
constraintInput.SetActive(true); l2 = CM.GetLine(chosen2);
break; n = CM.createConstraint(l1, l2, ConstraintType.LineNormal);
}
}
void createConstraint()
{
Point p = null;
Line l1 = null;
Line l2 = null;
Plane p1 = null;
Plane p2 = null;
float length;
string n = "";
switch (state)
{
case UIState.linelength:
l1 = CM.GetLine(chosen1);
length = float.Parse(constraintInput.GetComponent<InputField>().text);
n = CM.createConstraint(l1, length, ConstraintType.LineLength);
constraintInput.SetActive(false);
break;
case UIState.lineEqual:
l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineEqual);
break;
case UIState.lineNormal:
l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineNormal);
break; break;
case UIState.lineParallel: case UIState.lineParallel:
l1 = CM.GetLine(chosen1); l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2); l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineParallel); n = CM.createConstraint(l1, l2, ConstraintType.LineParallel);
break; break;
case UIState.lineParallelPlane: case UIState.lineParallelPlane:
l1 = CM.GetLine(chosen1); l1 = CM.GetLine(chosen1);
p1 = CM.GetPlane(chosen2); p1 = CM.GetPlane(chosen2);
n = CM.createConstraint(l1, p1, ConstraintType.LineParallelPlane); n = CM.createConstraint(l1, p1, ConstraintType.LineParallelPlane);
break; break;
case UIState.lineCross: case UIState.lineCross:
l1 = CM.GetLine(chosen1); l1 = CM.GetLine(chosen1);
l2 = CM.GetLine(chosen2); l2 = CM.GetLine(chosen2);
n = CM.createConstraint(l1, l2, ConstraintType.LineCross); n = CM.createConstraint(l1, l2, ConstraintType.LineCross);
break; break;
case UIState.midPoint: case UIState.midPoint:
l1 = CM.GetLine(chosen1); l1 = CM.GetLine(chosen1);
p = CM.GetPoint(chosen2); p = CM.GetPoint(chosen2);
n = CM.createConstraint(l1, p, ConstraintType.MidPoint); n = CM.createConstraint(l1, p, ConstraintType.MidPoint);
break; break;
case UIState.planeParallelPlane: case UIState.planeParallelPlane:
...@@ -286,7 +288,7 @@ public class UIManager : MonoBehaviour ...@@ -286,7 +288,7 @@ public class UIManager : MonoBehaviour
p2 = CM.GetPlane(chosen2); p2 = CM.GetPlane(chosen2);
n = CM.createConstraint(p1, p2, ConstraintType.PlaneParallelPlane); n = CM.createConstraint(p1, p2, ConstraintType.PlaneParallelPlane);
break; break;
case UIState.planeNormalPlane: case UIState.planeNormalPlane:
p1 = CM.GetPlane(chosen1); p1 = CM.GetPlane(chosen1);
p2 = CM.GetPlane(chosen2); p2 = CM.GetPlane(chosen2);
n = CM.createConstraint(p1, p2, ConstraintType.PlaneNormalPlane); n = CM.createConstraint(p1, p2, ConstraintType.PlaneNormalPlane);
...@@ -294,19 +296,30 @@ public class UIManager : MonoBehaviour ...@@ -294,19 +296,30 @@ public class UIManager : MonoBehaviour
case UIState.angleEqual: case UIState.angleEqual:
case UIState.planeArea: case UIState.planeArea:
case UIState.pointOnLine: case UIState.pointOnLine:
case UIState.pointInPlane: case UIState.pointInPlane:
break; break;
} }
chosen1 = ""; chosen1 = "";
chosen2 = ""; chosen2 = "";
GameObject tmp = Instantiate(constraint); GameObject tmp = Instantiate(constraint);
tmp.transform.SetParent(constraintParent); tmp.transform.SetParent(constraintParent);
constraints.Add(tmp); constraints.Add(tmp);
tmp.transform.localPosition = new Vector3(150 + 165 * (constraints.Count - 1), 0, 0); if(constraints.Count < 11)
tmp.GetComponentInChildren<Text>().text = n; tmp.transform.localPosition = new Vector3(150 + 165 * (constraints.Count - 1), 0, 0);
state = UIState.none; else
constraintDropdown.GetComponent<Dropdown>().captionText.text = "None"; tmp.transform.localPosition = new Vector3(150 + 165 * (constraints.Count - 11), -80, 0);
constraintDropdown.GetComponent<Dropdown>().value = 0; tmp.GetComponentInChildren<Text>().text = n;
constraintDropdown.SetActive(false); state = UIState.none;
} constraintDropdown.GetComponent<Dropdown>().captionText.text = "None";
} constraintDropdown.GetComponent<Dropdown>().value = 0;
constraintDropdown.SetActive(false);
}
public void UIShow()
{
foreach(var ui in UIControl)
{
ui.SetActive(!ui.activeSelf);
}
}
}
fileFormatVersion: 2
guid: be3555aa3d1aa6a40879bdbd184ac036
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
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