public void Save(string path) { RegisterResolver.Register(); var entries = AllEntries.ToArray(); File.WriteAllBytes(Path.Combine(path, "AetherDB.msgpack"), MessagePackSerializer.Serialize(entries)); }
public void OnGUI() { //var obj = new ShieldData() {ID = Guid.NewGuid(), Name = "Bar" , HeatPerformanceCurve = new []{float4(0,0,0,0), float4(1,1,1,1)}} as DatabaseEntry; //var obj = new GalaxyRequestMessage() as Message; var obj = new Gradient(); var times = Enumerable.Range(0, 5).Select(i => (float)i / 4).ToArray(); obj.alphaKeys = times.Select(f => new GradientAlphaKey(1, f)).ToArray(); obj.colorKeys = times.Select(f => new GradientColorKey(UnityEngine.Random.ColorHSV(), f)).ToArray(); // JsonSerializer serializer = new JsonSerializer(); // serializer.Converters.Add(new MathJsonConverter()); // serializer.Converters.Add(Converter.DateTimeConverter); // serializer.Converters.Add(Converter.BinaryConverter); // serializer.Converters.Add(Converter.GroupingConverter); // serializer.Converters.Add(Converter.PocoExprConverter); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List <JsonConverter> { new MathJsonConverter(), Converter.DateTimeConverter, Converter.BinaryConverter, Converter.GroupingConverter, Converter.PocoExprConverter } }; Converter.Serializer.Converters.Add(new MathJsonConverter()); RegisterResolver.Register(); if (GUILayout.Button("Print MsgPack JSON")) { Debug.Log(MessagePackSerializer.SerializeToJson(obj)); } //var writer = new StringWriter(); if (GUILayout.Button("Print Newtonsoft JSON")) { //serializer.Serialize(writer, obj); Debug.Log(JsonConvert.SerializeObject(obj)); } if (GUILayout.Button("Create Database")) { R.DbCreate("Aetheria").Run(_connection); } if (GUILayout.Button("Create Table")) { R.Db("Aetheria").TableCreate("Items").Run(_connection); } if (GUILayout.Button("Send to RethinkDB")) { R.Db("Aetheria").Table("Items").Insert(obj).Run(_connection); } }
public void Load(string path) { RegisterResolver.Register(); var bytes = File.ReadAllBytes(Path.Combine(path, "AetherDB.msgpack")); var entries = MessagePackSerializer.Deserialize <DatabaseEntry[]>(bytes); AddAll(entries); }
void UpdateSettings() { RegisterResolver.Register(); var hash = MessagePackSerializer.Serialize(SlimeSettings).GetHashSHA1(); if (hash != _settingsHash) { _settingsHash = hash; _parameterBuffer.SetData(new[] { SlimeSettings }); } }
void OnGUI() { ScriptableObject target = this; SerializedObject so = new SerializedObject(target); SerializedProperty stringsProperty = so.FindProperty("NameFiles"); EditorGUILayout.PropertyField(stringsProperty, true); // True means show children so.ApplyModifiedProperties(); // Remember to apply modified properties if (GUILayout.Button("Save Name Files")) { RegisterResolver.Register(); var nameFilesDirectory = ActionGameManager.GameDataDirectory.CreateSubdirectory("NameFile"); foreach (var nameFile in NameFiles) { var entry = new NameFile { Name = nameFile.name, Names = nameFile.text.Split('\n') }; File.WriteAllBytes(Path.Combine(nameFilesDirectory.FullName, $"{entry.ID.ToString()}.msgpack"), MessagePackSerializer.Serialize((DatabaseEntry)entry)); } } nameFile = (TextAsset)EditorGUILayout.ObjectField("Name File", nameFile, typeof(TextAsset), false); minWordLength = EditorGUILayout.IntField("Minimum File Word Length", minWordLength); NameGeneratorMinLength = EditorGUILayout.IntField("Generated Minimum Word Length", NameGeneratorMinLength); NameGeneratorMaxLength = EditorGUILayout.IntField("Generated Maximum Word Length", NameGeneratorMaxLength); NameGeneratorOrder = EditorGUILayout.IntField("Generator Order", NameGeneratorOrder); _stripNumberTokens = GUILayout.Toggle(_stripNumberTokens, "Strip Number Tokens"); if (GUILayout.Button("Clean Name File")) { var lines = nameFile.text.Split('\n'); using StreamWriter outputFile = new StreamWriter(Path.Combine(Application.dataPath, nameFile.name + ".csv")); var names = new HashSet <string>(); foreach (var line in lines) { var tokens = line.Split(',', ' '); foreach (var t in tokens) { if (!HasNonASCIIChars(t)) { var s = new string(t.Where(c => char.IsLetter(c) || c == '-' || c == '`' || c == '\'').ToArray()).Trim().Trim('`', '-'); if (s.Length >= minWordLength && !names.Contains(s)) { names.Add(s); outputFile.WriteLine(s); } } } } } if (GUILayout.Button("Process Name File") && nameFile != null) { var names = new HashSet <string>(); var lines = nameFile.text.Split('\n'); foreach (var line in lines) { foreach (var word in line.ToUpperInvariant().Split(' ', ',', '.', '"')) { if (word.Length >= minWordLength && !names.Contains(word)) { names.Add(word); } } } Debug.Log($"Found {lines.Length} lines, with {names.Count} unique names!"); var random = new Random(1337); _nameGenerator = new MarkovNameGenerator(ref random, names, NameGeneratorOrder, NameGeneratorMinLength, NameGeneratorMaxLength); } if (_nameGenerator != null) { if (GUILayout.Button("Generate Name")) { Debug.Log(_nameGenerator.NextName); } } }
void Start() { _canvas = transform.root.GetComponent <Canvas>(); var path = Path.Combine(ActionGameManager.GameDataDirectory.CreateSubdirectory("KeyboardLayouts").FullName, $"{LayoutFile.name}.msgpack"); // _inputLayout = ParseJson(LayoutFile.text); RegisterResolver.Register(); _inputLayout = MessagePackSerializer.Deserialize <InputLayout>(File.ReadAllBytes(path)); // _inputLayout = JsonConvert.DeserializeObject<InputLayout>(File.ReadAllText(path)); // SaveLayout(); DisplayLayout(_inputLayout); _buttonMappings.Add(MapMouseButton(MouseLeft, "<Mouse>/leftButton")); _buttonMappings.Add(MapMouseButton(MouseRight, "<Mouse>/rightButton")); _buttonMappings.Add(MapMouseButton(MouseMiddle, "<Mouse>/middleButton")); _buttonMappings.Add(MapMouseButton(MouseForward, "<Mouse>/forwardButton")); _buttonMappings.Add(MapMouseButton(MouseBack, "<Mouse>/backButton")); Canvas.ForceUpdateCanvases(); foreach (var buttonMapping in _buttonMappings) { _bindButtons[buttonMapping.Button.InputSystemPath] = buttonMapping; buttonMapping.TestAction = new InputAction(binding: buttonMapping.Button.InputSystemPath); buttonMapping.TestAction.started += context => { buttonMapping.DisplayButton.Outline.color = HighlightColor; buttonMapping.DisplayButton.Outline.gameObject.SetActive(true); var fillColor = HighlightColor; fillColor *= FillBrightness; fillColor.a = FillAlpha; buttonMapping.DisplayButton.Fill.color = fillColor; }; buttonMapping.TestAction.canceled += context => AssignColor(buttonMapping); buttonMapping.TestAction.Enable(); } foreach (var actionBarInput in ActionGameManager.PlayerSettings.InputSettings.ActionBarInputs) { if (!_bindButtons.ContainsKey(actionBarInput)) { Debug.LogError($"Unable to find input button for \"{actionBarInput}\""); } else { _bindButtons[actionBarInput].IsActionBarButton = true; AssignColor(_bindButtons[actionBarInput]); } } if (Input == null) { var input = new AetheriaInput(); Input = input.asset; } ProcessActions(Input); // input.Enable(); // input.Global.Interact.performed += context => Debug.Log($"Interact Performed! Time = {((int) (Time.time * 1000)).ToString()}ms"); Observable.NextFrame().Subscribe(_ => { foreach (var actionMapping in _actionMappings) { actionMapping.Label = CreateLabel(actionMapping); PlaceLabel(actionMapping); } RegisterMouseCallbacks(); }); //StartCoroutine(AssociateInputKeys(_inputLayout)); }