private void SaveDatum(ES3File saveFile, BaseVariable variable) { string saveKey = variable.Name; if (variable is IntVariable intVar) { saveFile.Save <int>(saveKey, intVar.Value); } else if (variable is FloatVariable floatVar) { saveFile.Save <float>(saveKey, floatVar.Value); } else if (variable is StringVariable stringVar) { saveFile.Save <string>(saveKey, stringVar.Value); } else if (variable is BoolVariable boolVar) { saveFile.Save <bool>(saveKey, boolVar.Value); } else { Debug.LogWarning("[ScriptableObjectSaveSystem]" + " Save Type not implemented. " + "Rich is just being lazy."); } }
private static void ShowVariable(BaseVariable variable) { if (variable == null) { return; } Variables[variable].FoldOut = EditorGUILayout.Foldout(Variables[variable].FoldOut, variable.name); if (Variables[variable].FoldOut) { var serializedObject = new SerializedObject(variable); serializedObject.Update(); EditorGUI.indentLevel++; var property = serializedObject.GetIterator(); property.NextVisible(true); do { if (!SkipFields.Contains(property.name)) { EditorGUILayout.PropertyField(property); } } while (property.NextVisible(false)); EditorGUI.indentLevel--; serializedObject.ApplyModifiedProperties(); } }
static void Main() { try { BaseVariable.InitXmlVar();//初始化基础变量 if (!File.Exists(BaseVariable.XmlFilePath)) { throw new Exception("Config.xml配置文件不存在,请检查"); } XmlHelper xml = new XmlHelper(); BaseVariable.RequestURL = xml.SelectValue("/Root/Server/APIURL"); string modelVaild = xml.SelectValue("/Root/Sys/ModelVaild"); if (modelVaild.Trim().Equals("1")) { string c = BaseVariable.APPRootPath + "config.dat"; if (!File.Exists(BaseVariable.XmlFilePath)) { throw new Exception("config.dat系统文件不存在,请检查"); } SystemIdentity info = SystemIdentity.GetFromFile(c); if (info.GetDeviceModel() != "CK3X") { throw new Exception("设备版本不兼容!!!"); } } string appName = Assembly.GetExecutingAssembly().GetName().Name; if (!MutexHelper.IsApplicationOnRun(appName)) { #region 创建快捷方式 Shortcut sc = new Shortcut(Assembly.GetExecutingAssembly(), "鸿泰集成防错系统"); if (!sc.IsExist()) { sc.Create(); } #endregion TaskBarHelper.ShowTaskBar(false); Application.Run(new FrmLogin()); Application.Exit(); } else { MessageBox.Show("系统正在运行!");//如果该程序已经运行则返回,避免程序重复运行 Application.Exit(); return; } } catch (Exception e) { MessageBox.Show(e.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } finally { TaskBarHelper.ShowTaskBar(true); } }
public BaseVariable[] CopyVariables(BaseVariable[] vars) { if (vars == null) { throw new ArgumentNullException("vars"); } return vars.Select(a => a.Clone()).ToArray(); }
public override BaseVariable[] CreateVariables() { var variables = new BaseVariable[Problema.NumberOfVariables]; for (var var = 0; var < Problema.NumberOfVariables; var++) { variables[var] = new Real(Problema.LowerLimit[var], Problema.UpperLimit[var]); } return variables; }
private static void AddVariable(BaseVariable variable, VariableData variableData) { if (Variables.ContainsKey(variable)) { Variables[variable] = variableData; } else { Variables.Add(variable, variableData); } }
public override BaseVariable[] CreateVariables() { var variables = new BaseVariable[Problema.NumberOfVariables]; for (var var = 0; var < Problema.NumberOfVariables; var++) { variables[var] = new Binary(Problema.GetLength(var)); } return variables; }
public override BaseVariable[] CreateVariables() { var variables = new BaseVariable[Problema.NumberOfVariables]; for (var var = 0; var < Problema.NumberOfVariables; var++) { variables[var] = new ArrayReal(Problema.NumberOfVariables, Problema); } return variables; }
public override BaseVariable[] CreateVariables() { BaseVariable[] variables = new BaseVariable[Problema.NumberOfVariables]; for (int var = 0; var < Problema.NumberOfVariables; var++) { variables[var] = new Permutation(Problema.GetLength(var)); } return variables; }
public override BaseVariable[] CreateVariables() { BaseVariable[] variables = new BaseVariable[Problema.NumberOfVariables]; for (int var = 0; var < Problema.NumberOfVariables; var++) { variables[var] = new Int((int) Problema.LowerLimit[var], (int) Problema.UpperLimit[var]); } return variables; }
private void LoadVarible(BaseVariable variable) { BinaryFormatter bf = new BinaryFormatter(); var fileName = Path.Combine(Application.persistentDataPath, $"{variable.name}.bin"); FileStream dataFile; if (File.Exists(fileName)) { dataFile = File.OpenRead(fileName); variable.BaseValue = bf.Deserialize(dataFile); dataFile.Dispose(); } }
// This method works only in Editor private static BaseVariable[] GetAllVariables() { string[] guids = AssetDatabase.FindAssets("t:BaseVariable"); BaseVariable[] vars = new BaseVariable[guids.Length]; for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); vars[i] = AssetDatabase.LoadAssetAtPath <BaseVariable>(path); if (string.IsNullOrEmpty(vars[i].Guid)) { vars[i].Guid = guids[i]; } } return(vars); }
public void InitVariable(BaseVariable variable) { if (IsVaribleSaved(variable)) { LoadVarible(variable); } else { if (SaveData) { SaveVarible(variable); } } variable.AddListener(this); }
public void SaveVarible(BaseVariable variable) { BinaryFormatter bf = new BinaryFormatter(); var fileName = Path.Combine(Application.persistentDataPath, $"{variable.name}.bin"); FileStream dataFile; if (File.Exists(fileName)) { dataFile = File.OpenWrite(fileName); } else { dataFile = File.Create(fileName); } bf.Serialize(dataFile, variable.BaseValue); dataFile.Dispose(); }
protected void ShouldNotCallOnChangedWhenSameValueIsSet(ValueType value1, ValueType value2) { var variable = ScriptableObject.CreateInstance <VariableType>(); bool onChangeWasCalled = false; BaseVariable <ValueType> .Change onChange = (x, y) => { onChangeWasCalled = true; }; variable.OnChange += onChange; variable.Set(value1); variable.Set(value1); Assert.IsFalse(onChangeWasCalled); variable.Set(value2); Assert.IsTrue(onChangeWasCalled); variable.OnChange -= onChange; }
public override BaseVariable[] CreateVariables() { BaseVariable[] variables = new BaseVariable[Problema.NumberOfVariables]; for (int localVariable = 0; localVariable < Problema.NumberOfVariables; localVariable++) { if (Problema.Precision == null) { int[] precision = new int[Problema.NumberOfVariables]; for (int i = 0; i < Problema.NumberOfVariables; i++) { precision[i] = BinaryReal.DefaultPrecision; } Problema.Precision = new int[precision.Length]; Array.Copy(precision, Problema.Precision, precision.Length); } // if variables[localVariable] = new BinaryReal(Problema.Precision[localVariable], Problema.LowerLimit[localVariable], Problema.UpperLimit[localVariable]); } // for return variables; }
public static void Reset() { string[] variableGuids = AssetDatabase.FindAssets("t:BaseVariable", new string[] { "Assets/Objects" }); string[] collectionGuids = AssetDatabase.FindAssets("t:BaseCollection", new string[] { "Assets/Objects" }); if (variableGuids.Length == 0 && collectionGuids.Length == 0) { return; } int count = 0; foreach (string guid in variableGuids) { string path = AssetDatabase.GUIDToAssetPath(guid); BaseVariable variable = (BaseVariable)AssetDatabase.LoadAssetAtPath(path, typeof(BaseVariable)); if (!variable.ReadOnly) { variable.ResetValue(); count++; } } foreach (string guid in collectionGuids) { string path = AssetDatabase.GUIDToAssetPath(guid); BaseCollection collection = (BaseCollection)AssetDatabase.LoadAssetAtPath(path, typeof(BaseCollection)); if (!collection.ReadOnly) { collection.Reset(); count++; } } if (count > 0) { Debug.LogFormat("Reset {0} writable variable{1}", count, count == 1 ? "" : "s"); } }
public override short SetValue(BaseVariable <short> value) { return(ClampValue(value.Value)); }
public bool IsVaribleSaved(BaseVariable variable) { var fileName = Path.Combine(Application.persistentDataPath, $"{variable.name}.bin"); return(File.Exists(fileName)); }
public override BaseVariable[] CreateVariables() { BaseVariable[] variables = new BaseVariable[1]; variables[0] = new ArrayReal(Problema.NumberOfVariables, Problema); return variables; }
/// <summary> /// Initializes a TypeGo for a runtime type /// the typeGo makes use of everything faster with easy access /// </summary> /// <param name="options"></param> /// <returns></returns> public static TypeGoInfo <T> Generate <T>(ITypeOptions options) { lock (_lockobj) { Type type = typeof(T); if (options.TryGetValueOfTypeGo(type, out object find)) { return((TypeGoInfo <T>)find); } var baseType = Nullable.GetUnderlyingType(type); bool isNullable = false; //when type is not nullable if (baseType == null) { baseType = type; } else { isNullable = true; } TypeGoInfo <T> typeGoInfo = new TypeGoInfo <T> { Properties = new Dictionary <string, BasePropertyGoInfo <T> >(), Type = type, }; options.AddTypes(type, typeGoInfo); if (isNullable) { if (baseType == typeof(bool)) { InitializeVariable <BoolNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(DateTime)) { InitializeVariable <DateTimeNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(uint)) { InitializeVariable <UIntNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(long)) { InitializeVariable <LongNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(short)) { InitializeVariable <ShortNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(byte)) { InitializeVariable <ByteNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(double)) { InitializeVariable <DoubleNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(float)) { InitializeVariable <FloatNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(decimal)) { InitializeVariable <DecimalNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(sbyte)) { InitializeVariable <SByteNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(ulong)) { InitializeVariable <ULongNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(ushort)) { InitializeVariable <UShortNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(int)) { InitializeVariable <IntNullableVariable>(typeGoInfo, options); } else if (baseType == typeof(Guid)) { InitializeVariable <GuidNullableVariable>(typeGoInfo, options); } //else if (baseType == typeof(byte[])) // InitializeVariable<ByteArrayNullableVariable>(typeGoInfo, options); else if (baseType.IsEnum) { BaseVariable variable = (BaseVariable)typeof(EnumNullableVariable <>).MakeGenericType(baseType) .GetMethod("Initialize", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) .Invoke(null, new object[] { }); variable.InitializeBase(typeGoInfo, options); } } else { if (baseType == typeof(bool)) { InitializeVariable <BoolVariable>(typeGoInfo, options); } else if (baseType == typeof(DateTime)) { InitializeVariable <DateTimeVariable>(typeGoInfo, options); } else if (baseType == typeof(uint)) { InitializeVariable <UIntVariable>(typeGoInfo, options); } else if (baseType == typeof(long)) { InitializeVariable <LongVariable>(typeGoInfo, options); } else if (baseType == typeof(short)) { InitializeVariable <ShortVariable>(typeGoInfo, options); } else if (baseType == typeof(byte)) { InitializeVariable <ByteVariable>(typeGoInfo, options); } else if (baseType == typeof(double)) { InitializeVariable <DoubleVariable>(typeGoInfo, options); } else if (baseType == typeof(float)) { InitializeVariable <FloatVariable>(typeGoInfo, options); } else if (baseType == typeof(decimal)) { InitializeVariable <DecimalVariable>(typeGoInfo, options); } else if (baseType == typeof(sbyte)) { InitializeVariable <SByteVariable>(typeGoInfo, options); } else if (baseType == typeof(ulong)) { InitializeVariable <ULongVariable>(typeGoInfo, options); } else if (baseType == typeof(ushort)) { InitializeVariable <UShortVariable>(typeGoInfo, options); } else if (baseType == typeof(int)) { InitializeVariable <IntVariable>(typeGoInfo, options); } else if (baseType == typeof(byte[])) { InitializeVariable <ByteArrayVariable>(typeGoInfo, options); } else if (baseType == typeof(string)) { InitializeVariable <StringVariable>(typeGoInfo, options); } else if (baseType == typeof(Guid)) { InitializeVariable <GuidVariable>(typeGoInfo, options); } else if (baseType.IsEnum) { BaseVariable variable = (BaseVariable)typeof(EnumVariable <>).MakeGenericType(typeof(T)) .GetMethod("Initialize", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) .Invoke(null, new object[] { }); variable.InitializeBase(typeGoInfo, options); } //array data else if (baseType.IsArray) { var elementType = baseType.GetElementType(); var method = typeof(BaseTypeGoInfo) .GetMethod("InitializeVariable", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) .MakeGenericMethod(typeof(ArrayVariable <>).MakeGenericType(elementType)); method.Invoke(null, new object[] { typeGoInfo, options }); } //enumrable list data else if (baseType.GetGenericArguments().Length > 0 && baseType.GetGenericTypeDefinition() == typeof(List <>)) { var elementType = baseType.GetGenericArguments()[0]; var method = typeof(BaseTypeGoInfo) .GetMethod("InitializeVariable", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) .MakeGenericMethod(typeof(GenericListVariable <>).MakeGenericType(elementType)); method.Invoke(null, new object[] { typeGoInfo, options }); } //object daat else { InitializeVariable <ObjectVariable <T> >(typeGoInfo, options); } } return(typeGoInfo); } }
public override int SetValue(BaseVariable <int> value) { return(ClampValue(value.Value)); }
public override byte SetValue(BaseVariable <byte> value) { return(ClampValue(value.Value)); }
private static void AddFieldDisposeBlock(ElementBuilder elementBuilder, If parentIfDisposingBlock, BaseVariable field) { If ifFieldIsAssignedBlock = new If(); ifFieldIsAssignedBlock.Expression = CodeRush.Language.GetNullCheck(field.Name).Invert(); elementBuilder.AddMethodCall(ifFieldIsAssignedBlock, field.Name + CodeRush.Language.MemberAccessOperator + STR_Dispose); if (!field.IsReadOnly) elementBuilder.AddAssignment(ifFieldIsAssignedBlock, field.Name, CodeRush.Language.GetNullReferenceExpression()); parentIfDisposingBlock.AddNode(ifFieldIsAssignedBlock); }
public override long SetValue(BaseVariable <long> value) { return(ClampValue(value.Value)); }
public override int GetHashCode() { return(BaseVariable.GetHashCode()); }
public void SetValue(BaseVariable <TDatatype> value) { Value = value.Value; }
public BaseVariable[] CopyeVariables(BaseVariable[] variables) { var copy = new BaseVariable[1]; copy[0] = variables[0].Clone(); return variables; }
private static VariableData GetVariableData(BaseVariable variable) { return(Variables[variable]); }
public override double SetValue(BaseVariable <double> value) { return(ClampValue(value.Value)); }
public override float SetValue(BaseVariable <float> value) { return(ClampValue(value.Value)); }
public VariableValuePair(BaseVariable variable, object value) { // Set our properties Variable = variable; Value = value; }