示例#1
0
        public static Dictionary <string, string> SerializeAll()
        {
            var filesToWrite = new Dictionary <string, string>();

            foreach (var kvp in _dirtyChunks)
            {
                var fileName = kvp.Key.ToString();
                var data     = new SerializableChunk(kvp.Value).Serialize();
                filesToWrite.Add(fileName, data);
            }

            foreach (var kvp in _dirtyBuilders)
            {
                var fileName = kvp.Key.ToString() + "B";
                var data     = new SerializableChunkBuilder(kvp.Value).Serialize();
                filesToWrite.Add(fileName, data);
            }

            foreach (var kvp in _dirtySpaces)
            {
                var fileName = kvp.Key;
                var data     = SerializableSpaceHelper.ToSerializableSpace(kvp.Value).Serialize();
                filesToWrite.Add(fileName, data);
            }

            var characterFile = new SerializableCharacter(CurrentCharacter);

            filesToWrite.Add(Paths.CHARACTERFILE, characterFile.Serialize());

            return(filesToWrite);
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            _asset = EditorGUILayout.ObjectField("Asset", _asset, typeof(CustomSpace), false) as CustomSpace;

            _target = target as SpaceCrafter;

            GUILayout.BeginVertical();
            {
                GUILayout.Space(20);
                GUILayout.Label("Add Crafters");

                if (GUILayout.Button("Add Enemy Spawn Crafter"))
                {
                    _target.AddEnemySpawnCrafter();
                }

                if (GUILayout.Button("Add Block Override"))
                {
                    _target.AddBlockOverride();
                }
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            {
                GUILayout.Space(20);
                if (GUILayout.Button("Save"))
                {
                    if (_asset == null)
                    {
                        _asset = CreateInstance <CustomSpace>();
                        AssetDatabase.CreateAsset(_asset, ASSET_PATH + System.IO.Path.GetRandomFileName() + ".asset");
                    }

                    Undo.RecordObject(_asset, "Set SerializableSpace JSON");
                    _asset.Set(SerializableSpaceHelper.ToSerializableSpace(_target.Build()));
                    EditorUtility.SetDirty(_asset);

                    AssetDatabase.SaveAssets();
                }

                if (GUILayout.Button("Load"))
                {
                    if (_asset != null)
                    {
                        _target.InitializeFromSpace(_asset.Build());
                    }
                    else
                    {
                        _log.Warning($"No asset loaded!  Drag a custom space into the asset field to load.");
                    }
                }
            }
            GUILayout.EndVertical();
        }