//Draw the property inside the given rect public override void OnGUI(Rect inRect, SerializedProperty inProperty, GUIContent inLabel) { var evt = Event.current; if (evt.type == EventType.MouseDown && evt.button == 0) { var mousePos = evt.mousePosition; if (inRect.Contains(mousePos)) { inProperty.serializedObject.Update(); CurveWindow curveEditor = CurveWindow.Init(); curveEditor.CurveSerialProp = inProperty; } } else { inLabel = EditorGUI.BeginProperty(inRect, inLabel, inProperty); EditorGUI.BeginChangeCheck(); AnimationCurve newCurve = EditorGUI.CurveField(inRect, inLabel, inProperty.animationCurveValue); if (EditorGUI.EndChangeCheck()) { inProperty.animationCurveValue = newCurve; } EditorGUI.EndProperty(); } }
private void PortOpen(object sender, RoutedEventArgs e) { string portType = (string)pmHt[sender]; DataProvider dp = PluginLoader.Instance().NewPluginInstance(portType); if (dp.Open() >= 0) { PortPannel pp = new PortPannel(); DataPump dataPump = new DataPump(); CurveWindow cw = new CurveWindow(); CodeEditor ce = new CodeEditor(); Session session = new Session(); session.dataProvider = dp; session.portPannel = pp; session.dataPump = dataPump; session.curveWindow = cw; session.codeEditor = ce; this.pannelList.Items.Add(pp); /* * double[] data = new double[2] { 23, 45 }; * for(int i = 0; i < 1600; i++) * { * cw.DeliverData(data); * } */ } }
static GlobalCurveWindow() { // instantiate textures first, before using them in window { textureBack = new Texture2D(128, 128); Color[] color = new Color[128 * 128]; for (int i = 0; i < color.Length; i++) { color[i] = Color.black; } textureBack.SetPixels(color); textureBack.Apply(); } { textureBackNarrow = new Texture2D(128, 32); Color[] color = new Color[128 * 32]; for (int i = 0; i < color.Length; i++) { color[i] = Color.black; } textureBackNarrow.SetPixels(color); textureBackNarrow.Apply(); } curve = new CurveWindow(302); gsWin = new GUIStyle("box"); gsWin.fontSize = Util.GetPix(12); gsWin.alignment = TextAnchor.UpperRight; }
void Start() { Transform crvEditor = transform.parent.Find("CurveEditor"); crvWindow = crvEditor.GetComponent <CurveWindow>(); }
public WinDataDeliver(CurveWindow c) { this.cw = c; }
private void UpdateStatus(byte[] data) { string[] types = { "数据测试中", "测试完成", "未检出", "加标测试" }; int count = _canvases.Count; for (int i = 0; i < count; i++) { int offset = i * 16; int type = (data[offset + 8] << 8) | (data[offset + 9]); int time = (data[offset + 10] << 8) | (data[offset + 11]); int v = (data[offset + 12] << 8) | (data[offset + 13]); int a = (data[offset + 14] << 24 | data[offset + 15] << 16 | data[offset + 16] << 8 | data[offset + 17]); int density = (data[offset + 18] << 24 | data[offset + 19] << 16 | data[offset + 20] << 8 | data[offset + 21]); _listTime[i].Content = "时间:" + time * 0.1 + "S"; _listMV[i].Content = "电位:" + v + "mV"; _listUA[i].Content = "电流:" + a * (0.0001) + "uA"; //取最大电流 if (maxA < a * (0.0001)) { maxA = a * (0.0001); } if (time > 0 && time < 2200 && v > 64436) { if (_cruveWindow == null) { _cruveWindow = new CurveWindow(); _cruveWindow.Show(); Global.timeValue = time * 0.1; Global.xValue = v; Global.yValue = a * (0.0001); } else { Global.timeValue = time * 0.1; Global.xValue = v; Global.yValue = a * (0.0001); } dobv[index] = v; doba[index] = a * 0.0001; index++; } else { _cruveWindow = null; } _listDensity[i].Content = "浓度:" + density * 0.0001 + "ug/l"; _Value = Convert.ToString(density * 0.0001); if (type < 4) { _listStage[i].Content = types[type]; } else { _listStage[i].Content = "检测到未知数据"; } if (type != 0) { //计算浓度 //x=(b*b-4*a(c-y)-b)/2a //a=A2,b=A1,c=A0,y为电流(取最高值) double xV = Math.Pow(((_item.a1 * _item.a1) - (4 * _item.a2) * (_item.a0 - maxA)), 1f / 2); double x = (xV - _item.a1) / (2 * _item.a2); _listJudgmentReult[i].Text = (x * _item.DilutionRatio > _item.Requirements) ? "不合格" : "合格"; _listtextNongdu[i].Text = (x * _item.DilutionRatio).ToString("F4") + "ug/l"; btn_result.IsEnabled = true; } if (type == 1) { _StandardValue = TestResultConserve.UnqualifiedOrQualified((density * 0.0001).ToString(), _item.Hole[i].SampleName, _item.Name); _UnqualifiedValue = Convert.ToString(_StandardValue[0]); _listStandardValue[i].Text = Convert.ToString(_StandardValue[2]); _listJudgmentReult[i].Text = Convert.ToString(_StandardValue[1]); _CheckValue[i, 0] = String.Format("{0:D2}", (i + 1)); _CheckValue[i, 1] = "重金属"; _CheckValue[i, 2] = _item.Name; _CheckValue[i, 3] = string.Empty;// methodToString[item.Method]; _CheckValue[i, 4] = _Value; _CheckValue[i, 5] = _item.Unit; _CheckValue[i, 6] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); _CheckValue[i, 7] = LoginWindow._userAccount.UserName; _CheckValue[i, 8] = string.IsNullOrEmpty(_item.Hole[i].SampleName) ? string.Empty : _item.Hole[i].SampleName; _CheckValue[i, 9] = Convert.ToString(_StandardValue[0]); _CheckValue[i, 10] = Convert.ToString(_StandardValue[2]); _CheckValue[i, 11] = String.Format("{0:D5}", _item.SampleNum); _CheckValue[i, 12] = Convert.ToString(_StandardValue[1]); _CheckValue[i, 13] = _item.Hole[i].TaskName ?? string.Empty; _CheckValue[i, 14] = string.IsNullOrEmpty(_item.Hole[i].CompanyName) ? string.Empty : _item.Hole[i].CompanyName; _CheckValue[i, 15] = string.IsNullOrEmpty(_item.Hole[i].SampleId) ? string.Empty : _item.Hole[i].SampleId; _CheckValue[i, 16] = _item.Hole[i].ProduceCompany; _AllNumber = TestResultConserve.ResultConserve(_CheckValue); if (LoginWindow._userAccount.UpDateNowing) { ButtonUpdate_Click(null, null); } } } }
const string lastFileLoaded = "lastFileLoaded"; //key for storing with PlayerPref /// <summary> /// Save all the fields of the AnimationCurve type together with their related gradRect,color and key's context menu options. /// </summary> static internal void SaveData(string configName, Object obj, CurveWindow crvWindow, List <CurveStruct> curveStructList, CurveStruct activeCurveStr, Dictionary <AnimationCurve, List <ContextMenuStruct> > dictCurvesContextMenus ) { string data = ""; //1st we store window's position and scale Vector3 locPos = crvWindow.transform.localPosition; Vector3 locScale = crvWindow.transform.localScale; data += ":" + locPos.x + ":" + locPos.y + ":" + locPos.z + ":" + locScale.x + ":" + locScale.y + ":" + locScale.z; data += ":" + (crvWindow.windowClosed?1:0); FieldInfo[] fields = obj.GetType().GetFields(); data += ":" + curveStructList.Count; foreach (CurveStruct crvStr in curveStructList) { data += ":" + ((crvStr.curve2 != null)?1:0); //is it a pair of curves or not? foreach (FieldInfo field in fields) { if (field.FieldType == typeof(AnimationCurve) && (field.GetValue(obj) as AnimationCurve == crvStr.curve1)) { data += ":" + field.Name; break; } } AnimationCurve curve = crvStr.curve1; data += ":" + curve.length; if (curve != null) { foreach (Keyframe key in curve.keys) { data += ":" + key.inTangent + ":" + key.outTangent + ":" + key.time + ":" + key.value; } //is this active curve or not data += ":" + ((curve == activeCurveStr.curve1)?1:0); //so this curve has been inside the curve editor data += ":" + crvStr.firstCurveSelected; data += ":" + crvStr.gradRect.x; data += ":" + crvStr.gradRect.y; data += ":" + crvStr.gradRect.width; data += ":" + crvStr.gradRect.height; } data += ":"; //empty string as the end for a curve data AnimationCurve curve2 = crvStr.curve2; if (curve2 != null) { foreach (FieldInfo field in fields) { if (field.FieldType == typeof(AnimationCurve) && (field.GetValue(obj) as AnimationCurve == curve2)) { data += ":" + field.Name; break; } } data += ":" + curve2.length; foreach (Keyframe key in curve2.keys) { data += ":" + key.inTangent + ":" + key.outTangent + ":" + key.time + ":" + key.value; } data += ":"; //empty string as the end for a curve data } if (curve != null) { foreach (ContextMenuStruct contextMenu in dictCurvesContextMenus[curve]) { data += ":" + contextMenu; } data += ":"; } if (curve2 != null) { foreach (ContextMenuStruct contextMenu in dictCurvesContextMenus[curve2]) { data += ":" + contextMenu; } data += ":"; } } foreach (FieldInfo field in fields) { if (field.FieldType == typeof(AnimationCurve)) { AnimationCurve curve = field.GetValue(obj) as AnimationCurve; CurveStruct crvStr = curveStructList.Find(x => x.curve1 == curve); if (crvStr.curve1 == null) { crvStr = curveStructList.Find(x => x.curve2 == curve); if (crvStr.curve2 == null) //this curve is not added to the curve editor,however we store it too { data += ":" + field.Name; data += ":" + curve.length; foreach (Keyframe key in curve.keys) { data += ":" + key.inTangent + ":" + key.outTangent + ":" + key.time + ":" + key.value; } data += ":"; //empty string as the end for a curve data } } } } PlayerPrefs.SetString(configName, data); string fileList = PlayerPrefs.GetString(fileListKey); if (!fileList.Contains(":" + configName)) { fileList += ":" + configName; //this is the case,a saveAs took place,or an unnamed file has been saved PlayerPrefs.SetString(fileListKey, fileList); } PlayerPrefs.SetString(lastFileLoaded, configName); PlayerPrefs.Save(); }
static internal void LoadData(string configName, Object obj, CurveWindow crvWindow, Transform collTransf, CurveLines crvLines, List <CurveStruct> curveStructList, Dictionary <AnimationCurve, List <ContextMenuStruct> > dictCurvesContextMenus) { string data = PlayerPrefs.GetString(configName); string[] elements = data.Split(':'); int i = 1;//first element should be empty string Vector3 locPos = Vector3.zero; locPos.x = float.Parse(elements[i]); i += 1; locPos.y = float.Parse(elements[i]); i += 1; locPos.z = float.Parse(elements[i]); i += 1; crvWindow.transform.localPosition = locPos; collTransf.localPosition = locPos; Vector3 locScale = Vector3.zero; locScale.x = float.Parse(elements[i]); i += 1; locScale.y = float.Parse(elements[i]); i += 1; locScale.z = float.Parse(elements[i]); i += 1; crvWindow.transform.localScale = locScale; collTransf.localScale = locScale; crvWindow.windowClosed = (int.Parse(elements[i]) == 1); i += 1; int curveStrCount = int.Parse(elements[i]); i += 1; string name; AnimationCurve activeCurve = null; for (int k = 0; k < curveStrCount; ++k) { bool isPair = (int.Parse(elements[i]) == 1); i += 1; name = elements[i]; i += 1; int length = int.Parse(elements[i]); i += 1; FieldInfo fieldInfo = obj.GetType().GetField(name); AnimationCurve curve = fieldInfo.GetValue(obj) as AnimationCurve; if (length > 0) { if (curve == null) { curve = new AnimationCurve(); //the curve is null,but after loading won't be } while (curve.length > 0) { curve.RemoveKey(0); } for (int j = 0; j < length; ++j) { //Debug.Log("curve data:"+elements[i+2]+" "+elements[i+3]+" "+elements[i]+" "+elements[i+1]); Keyframe key = new Keyframe(float.Parse(elements[i + 2]), float.Parse(elements[i + 3]), float.Parse(elements[i]), float.Parse(elements[i + 1])); curve.AddKey(key); i += 4; } bool isActiveCurveStr = (int.Parse(elements[i]) == 1); if (isActiveCurveStr) { activeCurve = curve; } i += 1; bool firstCurveSelected = bool.Parse(elements[i]); i += 1; Rect loadGradRect = new Rect(); loadGradRect.x = float.Parse(elements[i]); i += 1; loadGradRect.y = float.Parse(elements[i]); i += 1; loadGradRect.width = float.Parse(elements[i]); i += 1; loadGradRect.height = float.Parse(elements[i]); i += 1; if (elements[i] == "") { i += 1; } int length2 = 0; AnimationCurve curve2 = null; if (isPair) { name = elements[i]; i += 1; length2 = int.Parse(elements[i]); i += 1; FieldInfo fieldInfo2 = obj.GetType().GetField(name); curve2 = fieldInfo2.GetValue(obj) as AnimationCurve; if (length2 > 0) { if (curve2 == null) { curve2 = new AnimationCurve(); //the curve is null,but after loading won't be } while (curve2.length > 0) { curve2.RemoveKey(0); } for (int j = 0; j < length2; ++j) { //Debug.Log("curve data:"+elements[i+2]+" "+elements[i+3]+" "+elements[i]+" "+elements[i+1]); Keyframe key = new Keyframe(float.Parse(elements[i + 2]), float.Parse(elements[i + 3]), float.Parse(elements[i]), float.Parse(elements[i + 1])); curve2.AddKey(key); i += 4; } } else { curve2 = null; } fieldInfo2.SetValue(obj, curve2); if (elements[i] == "") { i += 1; } } crvLines.AddCurveStruct(curve, curve2); crvLines.gradRect = loadGradRect; dictCurvesContextMenus[curve].Clear(); for (int j = 0; j < length; ++j) { ContextMenuStruct contextMenu = new ContextMenuStruct(); contextMenu.UnpackData(elements[i]); dictCurvesContextMenus[curve].Add(contextMenu); i += 1; } if (elements[i] == "") { i += 1; } if (null != curve2) { dictCurvesContextMenus[curve2].Clear(); for (int j = 0; j < length2; ++j) { ContextMenuStruct contextMenu = new ContextMenuStruct(); contextMenu.UnpackData(elements[i]); dictCurvesContextMenus[curve2].Add(contextMenu); i += 1; } if (!firstCurveSelected) { CurveStruct crvStruct = curveStructList.Find(x => x.curve1 == curve); crvStruct.firstCurveSelected = false; crvLines.UpdateCurveStruct(crvStruct); } if (elements[i] == "") { i += 1; } } } //if else //the curve is not null,but after loading saved data,it will be { curve = null; } fieldInfo.SetValue(obj, curve); } //for CrvStrCount crvLines.ChangeActiveCurve(activeCurve); FieldInfo[] fields = obj.GetType().GetFields(); foreach (FieldInfo field in fields) { if (field.FieldType == typeof(AnimationCurve)) { AnimationCurve curve = field.GetValue(obj) as AnimationCurve; if (curveStructList.Find(x => x.curve1 == curve).curve1 == null && curveStructList.Find(x => x.curve2 == curve).curve2 == null) { //these is a curve not added to editor curve name = elements[i]; i += 1; int length = int.Parse(elements[i]); i += 1; if (curve == null) { curve = new AnimationCurve(); //the curve is null,but after loading won't be } while (curve.length > 0) { curve.RemoveKey(0); } for (int j = 0; j < length; ++j) { Keyframe key = new Keyframe(float.Parse(elements[i + 2]), float.Parse(elements[i + 3]), float.Parse(elements[i]), float.Parse(elements[i + 1])); curve.AddKey(key); i += 4; } if (elements[i] == "") { i += 1; } field.SetValue(obj, curve); } } } PlayerPrefs.SetString(lastFileLoaded, configName); PlayerPrefs.Save(); }