| 105 | #if USE_EDITOR |
| 106 | |
| 107 | bool GameplayGlobals::Save(const StringView& path) |
| 108 | { |
| 109 | if (OnCheckSave(path)) |
| 110 | return true; |
| 111 | ScopeLock lock(Locker); |
| 112 | |
| 113 | // Save to bytes |
| 114 | MemoryWriteStream stream(1024); |
| 115 | stream.Write(Variables.Count()); |
| 116 | for (auto& e : Variables) |
| 117 | { |
| 118 | stream.Write(e.Key, 71); |
| 119 | stream.Write(e.Value.DefaultValue); |
| 120 | } |
| 121 | |
| 122 | // Set chunk data |
| 123 | FlaxChunk* chunk; |
| 124 | if (IsVirtual()) |
| 125 | { |
| 126 | _header.Chunks[0] = chunk = New<FlaxChunk>(); |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | chunk = GetOrCreateChunk(0); |
| 131 | } |
| 132 | chunk->Data.Copy(ToSpan(stream)); |
| 133 | |
| 134 | // Save |
| 135 | AssetInitData data; |
| 136 | data.SerializedVersion = SerializedVersion; |
| 137 | const bool saveResult = path.HasChars() ? SaveAsset(path, data) : SaveAsset(data, true); |
| 138 | if (IsVirtual()) |
| 139 | { |
| 140 | _header.Chunks[0] = nullptr; |
| 141 | Delete(chunk); |
| 142 | } |
| 143 | if (saveResult) |
| 144 | { |
| 145 | LOG(Error, "Cannot save \'{0}\'", ToString()); |
| 146 | return true; |
| 147 | } |
| 148 | |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | #endif |
| 153 | |