GithubHelp home page GithubHelp logo

bayatgames / savegamefree Goto Github PK

View Code? Open in Web Editor NEW
584.0 24.0 58.0 10.39 MB

Save Game Free is a free and simple but powerful solution for saving and loading game data in unity.

License: MIT License

C# 100.00%
savegame save unity unity3d serializer serialization serialization-library json-serialization binary-serialization game-data

savegamefree's Introduction

Save Game Free

Save Game Free is a free and simple but powerful solution for saving and loading game data in Unity Game Engine.

๐Ÿš€ Get Save Game Pro

Save Game Free Logo

Features

The below features made Save Game Free excellent:

  • Cross Platform (Windows, Linux, Mac OS X, Android, iOS, tvOS, SamsungTV, WebGL, ...)
  • Auto Save
  • Web Support
  • Encryption
  • Easy to Use
  • Simple but Powerful yet

Download

โœจ Download from Asset Store

๐Ÿš€ Download the latest version from the Releases section

๐Ÿ”ฅ Download the Source Code

Getting Started

Here is a simple usage of Save Game Free:

SaveGame.Save<int> ( "score", score );

and the full is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using BayatGames.SaveGameFree;

public class SimpleUsage : MonoBehaviour {

	public int score;

	void OnApplicationQuit () {

		SaveGame.Save<int> ( "score", score );

	}

}

Resources

๐Ÿ“– Documentation

๐Ÿš€ Patreon

โœจ Write Review

โญ Check out Save Game Pro

๐Ÿ”ฅ Forum Thread

๐Ÿ“ฐ Support and News

License

MIT @ Bayat Games

Made with โค๏ธ by Bayat Games

savegamefree's People

Contributors

foobraco avatar gtink911 avatar hasanbayatme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

savegamefree's Issues

Unable to clear or delete saved data

Describe the bug
Deleting a save game in a standalone build doesn't work because Player.log is currently being used by a process. I've ended all processes except the game but it doesn't work. I tried restarting my computer as well

To Reproduce
Steps to reproduce the behavior:

  1. Calling a function that calls SaveGame.Clear() or SaveGame.DeleteAll() prints this error.

Expected behavior
It should clear all saved data.

Screenshots
After clicking new game, this error appears
image

Error message:

IOException: The process cannot access the file 'C:\Users\hi\AppData\LocalLow\company\game name\Player.log' because it is being used by another process.
  at System.IO.__Error.WinIOError (System.Int32 errorCode, System.String maybeFullPath) [0x001d7] in <2b3a3162be434770b7a4fac8b896e90c>:0 
  at System.IO.FileInfo.Delete () [0x00038] in <2b3a3162be434770b7a4fac8b896e90c>:0 
  at BayatGames.SaveGameFree.SaveGame.DeleteAll (BayatGames.SaveGameFree.SaveGamePath path) [0x00037] in <81391f8c6baa4ae7b039f97e592f680c>:0 
  at BayatGames.SaveGameFree.SaveGame.Clear () [0x00005] in <81391f8c6baa4ae7b039f97e592f680c>:0 
  at QLE.NormalPanel.ClearSavedData () [0x00001] in E:\projects\game name\Assets\Scripts\UI\Main Menu\NormalPanel.cs:50 
  at UnityEngine.Events.InvokableCall.Invoke () [0x00010] in C:\buildslave\unity\build\Runtime\Export\UnityEvent\UnityEvent.cs:180 
  at UnityEngine.Events.UnityEvent.Invoke () [0x00022] in C:\buildslave\unity\build\Runtime\Export\UnityEvent\UnityEvent\UnityEvent_0.cs:58 
  at UnityEngine.UI.Button.Press () [0x00027] in E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\UI\Core\Button.cs:68 
  at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00010] in E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\UI\Core\Button.cs:110 
  at UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00001] in E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\ExecuteEvents.cs:50 
  at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00074] in E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\ExecuteEvents.cs:262 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\ExecuteEvents.cs:266)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject) (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:187)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMousePress(MouseButtonEventData) (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:641)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent(Int32) (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:547)
UnityEngine.EventSystems.StandaloneInputModule:ProcessMouseEvent() (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:527)
UnityEngine.EventSystems.StandaloneInputModule:Process() (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:282)
UnityEngine.EventSystems.EventSystem:Update() (at E:\Coding\Unity-2019\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\EventSystem.cs:385)

Desktop:

  • OS: Windows 10
  • Version 10.0.19042

the code in the button is just
image
btw, the scriptable object code does not do any calls in SaveGame

Want to get Json data

I want to get the information like (Position, Rotation, Scaling and other custom information) of Multiple game objects and save that information as a JSON File. But, the issue I am facing right now that I am only getting information as a string.
Can any one please guide me about this how can I get all information in a single file using this asset.

Problem with Saver.Load

Hi,

Thank you for this great resource. I have used the awake function as shown in the Demo to initialize save and load, but when I try calling Saver.Load in other places in my code, I get:

NullReferenceException: Object reference not set to an instance of an object
SaveGameFree.Saver.Save (System.Object obj, System.String fileName, ISerializer serializer, PathType savePath, System.String extension) (at Assets/SaveGameFree/Saver.cs:527)
SaveGameFree.Saver.Load[StripesData] (System.String fileName, ISerializer serializer, PathType savePath, System.String extension) (at Assets/SaveGameFree/Saver.cs:625)
SaveGameFree.Saver.Load[StripesData] (System.String fileName) (at Assets/SaveGameFree/Saver.cs:539)
GameManager.Start () (at Assets/scripts/GameManager.cs:38)

Any idea what the problem could be here? I cannot understand why calling 'Saver.Load' in the awake function works but calling the same function elsewhere doesn't. Thanks in advance.

Loading with encoded bool

I can save a bool with a password, but i cant load it from file with same password. There is no documentation on loading the data, can you help me?

Duplicate Saver.OnSaved and Saver.OnLoaded

After each load of a level void Saver_OnLoaded and void Saver_OnSaved start to duplicate, and when I save or load something, it happens 2 times, or three times if I load 2 levels and so on.
123

Identifiers not working en WebGL

Hello. Not sure if anyone else has experienced this problem, but the identifiers stop working for some reason after importing another unrelated asset (might be coincidental, can't confirm, and those imported assets has nothing to do with saving, so it shouldn't be incompatibility issues), unabling me to load or save anything (i also tested the examples scenes and the problem appeared too). I tried re importing the asset, but it didn't solve anything. Delenting the other imported assets didn't help, either.

Update: I found out the problem. After scratching my head for days, i decided to just switch Platform to the default WIndows and the identifiers worked again and it could save once move. So i doesn't have to do with any asset compatibility.... It just doesn't work with WebGL, so, there is still a problem (at least inside the editor, haven't tested it published). I tested it with other platforms, like Android and iOS, and they work too, being WebGL the only one which doesn't work. If anyone know the solution for this, let me know.

SaveGameFree tries to delete output_log.txt

Hello,

I'm using this repo to handle my saves. So far so good when using the editor and with my Android build.
When I build on Windows however, and I try to execute the .exe there's an issue.
I am calling the DeleteAll method. The method tries to remove everything in the folder, including the output_log.txt which is by default put in that folder by Unity.
This makes the whole game crash, since it tries to delete a file that the game needs to access at every moment ( basically I have an IOException Cannot access file output_log.txt because it is being used by another process).
It also removes the Analytics folder that gets created, this doesn't let the game crash but I guess is not exactly intended.

I think we should either avoid having the saves in the same folder as the output_log.txt or explicitly ignore that file (and probably the Analytics folder)

Loading Failure Callback & Backup Saving

  1. Hi! Are there any callbacks in cases where the loading process fails, like if there's a corrupted file which could not be decrypted or serialized correctly? (SaveGame.Exists() wont suit my needs this time).

  2. It would be realy nice if there were an option for backup/versioning saving, where it could for example add a cycling index at the end of the ID. Then, if it failed to load using the last saved index, it would try loading a previous one.

This backup system is what I'm trying to implement and the reason I need the failure callback btw, please let me know if there is another way to do so.

Thanks in advance!

UnityWebRequest.Send() is obsolete (which generates a warning)

Describe the bug
UnityWebRequest.Send() is obsolete and is used in SaveGameFree/Scripts/SaveGameWeb.cs(578,17). I received the following warning when importing SaveGameFree into Unity 2019.4.20f1

Assets/_PluginsMIT/SaveGameFree/Scripts/SaveGameWeb.cs(578,17): warning CS0618: 'UnityWebRequest.Send()' is obsolete: 'Use SendWebRequest. It returns a UnityWebRequestAsyncOperation which contains a reference to the WebRequest object.'

When did it become obsolete?
Looking at different versions of the documentation it looks like this became obsolete in 2017.2.

  1. This 2019.4 documentation says its obsolete
  2. This 2017.2 documentation says its obsolete
  3. This 2017.1 documentation says its ok (doesnt say its obsolete)

What should it be replaced with?
The Unity 2019.4 Documentation shows how to do it the new way for a get and the same approach for post using that exact approach I have no errors or warnings in 2019.4.20f1 (and will submit a pull request momentarily) so it seems to work.

To Reproduce
To get the warning just import the latest version of SaveGameFree into Unity 2019.4.20f1 and look at the warning in the console.

Additional context
I'll submit a pull request with a proposal, and will make clear in the pull request that while my fix (which I took directly from the documentation and theres no ingenuity involved at all) solves the warning with no errors but I don't have a way to actually test the UnityWebRequest functionality.

Serialization Exception: invalid binary format when saving DateTime with a password

Hello! I've using SaveGameFree for some time without problems but when I changed my code to use encoding and encryption it fails to load serialized data.
I'm using the current asset store version and received the error in both Unity 2017.3.1f1 and Unity 2018.1.1f1. I'm using Windows 7 64-bits and my project is targeting Android (IL2CPP).

The error is:

SerializationException: Invalid binary format
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadRefTypeObjectInstance (System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:281)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:179)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (BinaryElement element, System.IO.BinaryReader reader) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:130)
System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:104)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:179)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:136)
BayatGames.SaveGameFree.Serializers.SaveGameBinarySerializer.Deserialize[StorageSG] (System.IO.Stream stream, System.Text.Encoding encoding) (at Assets/BayatGames/SaveGameFree/Scripts/Serializers/SaveGameBinarySerializer.cs:57)
UnityEngine.Debug:LogException(Exception)
BayatGames.SaveGameFree.Serializers.SaveGameBinarySerializer:Deserialize(Stream, Encoding) (at Assets/BayatGames/SaveGameFree/Scripts/Serializers/SaveGameBinarySerializer.cs:61)
BayatGames.SaveGameFree.SaveGame:Load(String, StorageSG, Boolean, String, ISaveGameSerializer, ISaveGameEncoder, Encoding, SaveGamePath) (at Assets/BayatGames/SaveGameFree/Scripts/SaveGame.cs:675)
BayatGames.SaveGameFree.SaveGame:Load(String, Boolean, String) (at Assets/BayatGames/SaveGameFree/Scripts/SaveGame.cs:450)
Assets.Scripts.TestSaveGameFreeEncoder:Start() (at Assets/Scripts/TestSaveGameFreeEncoder.cs:35)

Here is a test code that gives the same error I received in my actual project.

namespace Assets.Scripts
{
	[System.Serializable]
	public class StorageSG
	{
		public DateTime myDateTime;

		public StorageSG()
		{
			myDateTime = DateTime.UtcNow;
		}
	}
	
	public class TestSaveGameFreeEncoder : MonoBehaviour
	{
		private string _encodePassword;
		
		private void Start()
		{
			_encodePassword = "12345678910abcdef12345678910abcdef";

			SaveGame.DefaultEncoding = Encoding.UTF8;
			SaveGame.Encode = true;

			ISaveGameSerializer sgBinarySerializer = new SaveGameBinarySerializer();

			SaveGame.Serializer = sgBinarySerializer;

			StorageSG ssg = new StorageSG();
			
			SaveGame.Save<StorageSG>("pizza2", ssg, _encodePassword);

			StorageSG ssgLoaded = SaveGame.Load<StorageSG>("pizza2", true, _encodePassword);

			Debug.Log(ssgLoaded.myDateTime.ToLocalTime().ToString());
		}
	}
}```

Thanks in advance.

Fast encryption?

Is there anyway to do fast encryption (I dont need a zero go to a 100 char long code... 4 or something like this would be enough,,, becaues I need to save more than 200 files and this takes around 10 secounds (annoying) and loading also takes long...

would be nice if you can help me.

By the way this tool is awesome!

SamsungTVPlayer Obsolete in Unity 2017 and newer

Describe the bug
This warning appears in Unity 2019.4.20f1 (LTS) and based on the warning text it probably also appears in 2017.3+
warning CS0618: 'RuntimePlatform.SamsungTVPlayer' is obsolete: 'SamsungTVPlayer export is no longer supported in Unity 2017.3+.'

To Reproduce
Steps to reproduce the behavior:

  1. Import the repo
  2. See the warning in the console

Expected behavior
This warning should not appear and doesn't need to appear with the right Platform Dependent Preprocessor settings.

missing documentation

Hello

the included 'documentation' files (pdf, rtf, doc, html) are not really a documentation, just an introduction that link to documents on the web. That would have been fine but sadly all the web links return 404.

e.g. http://docs.bayat.io/scripting-api/savegame/save etc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.