Can this save this gameObject script?

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
leegod
Posts: 18
Joined: Sun Nov 20, 2016 10:42 am

Can this save this gameObject script?

Post by leegod »

gamemanager.PNG
gamemanager.PNG (37.74 KiB) Viewed 15398 times
Hi.
So I have this gamemanager object in my simulation game. Targeting PC and Android.

EasySave solution can save these each script's whole data and classes at runtime and can reconstruct when load?

Thanks.
Last edited by leegod on Mon Nov 21, 2016 3:03 am, edited 1 time in total.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can this save this gameObject script?

Post by Joel »

Hi there,

Coincidentally I've just responded to your email about this, but I'll post the response below incase it's of use to anybody else.

Unfortunately I can't comment as it depends on what fields your scripts have. However, the best idea is to check out our Supported Types guide to see what types are supported or supportable by Easy Save: http://docs.moodkie.com/easy-save-2/supported-types/

It's also worth checking out our Guides to get an idea of how Easy Save can be used: http://docs.moodkie.com/product/easy-save-2/guides/

Al the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
leegod
Posts: 18
Joined: Sun Nov 20, 2016 10:42 am

Re: Can this save this gameObject script?

Post by leegod »

For example, mainly I need to save & load this class.

------------------------------

Code: Select all

public class Publisher{ 
		public string Name;
		public bool initialSetup;
		public int level = 1;		// level of publisher
		public int Fame;			// reputation				
		[HideInInspector]
		public int calculFame;		// for calculating book require fame
		public int mania;		// how many  mania has?
		public int employee;		// how many employee?
		public int officeLevel =1;		// how office is good?
		public int officeCostLevel1 = 300000;		// level 1 office's cost
		public byte maxMakeNum = 1;		// book make line's maximum number
		public int shareRatio = 70;		// what percentage publisher give to bookstore? 60%~70%, etc
		public int bookNum;		// how many have books? sort, variety
		public int bookStock;		// how many have books? stock
		public int bookSaleUntilNow;		// how many books have been sold until now?
		public long bookSaleMoneyUntilNow;		// total received money from book sales
		public int bookSaleVolDay;			// daily
		public long bookSaleMoneyDay;		// daily
		public int bookSaleVolMonth;		// total book's monthly sales volume (how many book sold?)
		public long bookSaleMoneyMonth;			// total book's sales monthly  (how much money income by sales?)
		public int highBookSaleMonth;		// highest book sales vol monthly
		public int averageBookIndex;		// book's quality index's average value
		public int averageBookPrice;		// total average value of books's prices
		public long cash;			// present usable money
		public string cashStr;
		public int dailyProfit;		// daily profit (sales volume - all costs)
		public int monthlyProfit;
		public int weeklyProfit;
		public int profitUntilNow;
		public int officeCostMonthly;		// lease fee, operation fee, etc 
		public int officeCostTotal;			// total paid amount for office cost until now
		public long bookMakeCost;
		public long adsCostTotal;		// advertisement cost
		public int staffCost = 2500000;		// employee salary cost
		public int staffCostPerDay;		// this is 1/30 of staffCost 
		public int totalStaffWorkDay;			// employee's work day's total sum		
		public int totalStaffWorkDayUnpaid;		// unpaid day amount from workday
		public long royaltyTotal; 					// total royalty to author
		public int royaltyNotice;					// for showing at total monthly cost to user. 
		public int storageCostPerBook = 30;		// for storage books for 1 month
		public int storageCostMonthly;
		public int storageCostTotal;
		public bool useDistributeAgency;		// use delivery agency? (monthly static cost)		
		public int distributeLimit = 3000;		// up to 3000 books in a month
		public int distributeCostStatic = 300000;		// how much cost to use distribute agency? -> up to 3000 book's shipping, for over 3000 in a month, additionally need cost per book
		public int additionalDistCost = 70;		// per one book
		public int deliveryCostDaily;		
		public int deliveryCostMonthly;		
		public int deliveryCostTotal;
		public int dailyCost;		// daily cost
		public long monthlyCost;		// monthly cost
		public int weeklyCost;		// weekly cost  
		//public int monthlyStaticCost;		// monthly static cost
		public List<Book> bookList = new List<Book>(); 
		public bool hasManageStaff;		// is this company has management staff? 
		public bool hasEditorStaff;
		public int totalEditorMax;
		public int totalEditorCur;			// currently how many editor's capacity (1 man - 6 books a month)? if this is 0, all used
		public int editStaffNum;		// how many edit staff has?
		public int designStaffNum;		// how many design staff?
		public int totalDesignCur;
		public int adminStaffNum;
		public int totalAdminCur;		// currently how many books can be automatically dealed?	// one admin staff can deal automatically up to 7 books
		public int salesStaffNum;
		public int totalSalesCur;
		public int totalAdsCur;		// currently doing how many ads?
		public int planStaffNum;	 
		public int staffLimit;				// as office level increase, this also increase
		public int totalStaffNum;
		
		public int incomeMultiply;		// income increasing		, if this is 10, all income increased by 10%
		public int costReduction;		// cost reduce amount,  if this is 10, all cost reduced by 10%
		public List<StratCard> strCard = new List<StratCard>();		
		public List<Loan> loanList = new List<Loan>();
		public long monthLoanTotal;
		public bool usedBookDisposal;		// used book's disposal at low price?
		public Dictionary<int, int> MonthlySalesVol = new Dictionary<int, int>();		// monthly sales volume 
		public Dictionary<int, long> MonthlySalesVolMoney = new Dictionary<int, long>();		// monthly sales volume 
		public BookLineInfo line1Info;
		public BookLineInfo line2Info;
		public BookLineInfo line3Info;
		public BookLineInfo line4Info;
		public BookLineInfo line5Info;
	}	  
Can it save this class?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can this save this gameObject script?

Post by Joel »

Hi there,

Assuming that the classes being stored in your class (for example, the Book class) also only have primitive fields, you should have no problem saving the class.

You will just need to add support in Manage Types for the classes inside your Manager class (for example, the Book class, etc), and then add support for the Manager in Manage Types.

Then you can just use ES2.Save and ES2.Load to save the Manager component.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
leegod
Posts: 18
Joined: Sun Nov 20, 2016 10:42 am

Re: Can this save this gameObject script?

Post by leegod »

Joel wrote:Hi there,

Assuming that the classes being stored in your class (for example, the Book class) also only have primitive fields, you should have no problem saving the class.

You will just need to add support in Manage Types for the classes inside your Manager class (for example, the Book class, etc), and then add support for the Manager in Manage Types.

Then you can just use ES2.Save and ES2.Load to save the Manager component.

All the best,
Joel
Thanks for reply.

And more question.

When I want to save, should I save each variables in that class (above Publisher class that has over 100 variables)?
And when I want to restore, load each variables and reconstruct code needed?

Or just can it be done by few line codes?
leegod
Posts: 18
Joined: Sun Nov 20, 2016 10:42 am

Re: Can this save this gameObject script?

Post by leegod »

And what is better thing of EasySave compared to Json or XML serialization solution?
Last edited by Joel on Mon Nov 21, 2016 7:35 am, edited 1 time in total.
Reason: Removed link
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can this save this gameObject script?

Post by Joel »

Hi there,

You can select the fields of your Publisher class you want to save in the Manage Types window, and then you can Save and Load it with a single line of code. i.e.
ES2.Save(publisher, "publisher");
ES2.Load<Publisher>("publisher", publisher);
// Or if you want to create a new instance.
publisher = ES2.Load<Publisher>("publisher");
Also note that in Easy Save 3 (which will be a free update to existing users, and be entering beta in December) will be able to automatically save classes without needing to add support for them in Manage Types.

I removed your link as we're not allowed to link to other assets for legal reasons. The main advantage of Easy Save's format over JSON or XML is significantly improved performance and much more compact file sizes. It's also much more flexible with regards to API, and allows you to easily save multiple different classes to a single file using random access.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
leegod
Posts: 18
Joined: Sun Nov 20, 2016 10:42 am

Re: Can this save this gameObject script?

Post by leegod »

Thanks for reply.

So eventually what I want is, I want to save whole public variables from scripts like [Game Manager], [Time Manager], [Publisher Manager] pictured at origin post I wrote here.

So EasySave can save and load these monobehaviour scripts?

I just write combined class for above purpose, but maybe I am wrong, I don't know how.

SaveScript.cs
--------------------

Code: Select all

using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;

public class SaveClass
{
    public GameManager gm { get; set; }
    public TimeManager tm { get; set; }
    public PublisherManager pm { get; set; }

    public SaveClass()
    {
        Init();
    }
    void Init()
    {
        gm = GameManager.Instance();
    }

    public void Load()
    {
        GameManager = gm;   // ?
    }
}  
public class SaveScript : MonoBehaviour
{
    public static SaveScript Instance; 

    private string savedString;
    void Awake()
    {
        Instance = this;
    }
	void Start ()
	{
	    SaveClass();
	}
	 
    public void SaveClass ()
    { 
        var settings = new JsonSerializerSettings();
        settings.TypeNameHandling = TypeNameHandling.Auto; 
        var json = JsonConvert.SerializeObject(Instance, Formatting.None, settings);
        savedString = json;
        PlayerPrefs.SetString("Save Script", savedString);
        Debug.Log("Save user called and string is " + savedString);
    }
    void LoadClass ()
    {
        savedString = PlayerPrefs.GetString("Save Script");
        var settings = new JsonSerializerSettings();
        settings.TypeNameHandling = TypeNameHandling.Auto;
        
        if (String.IsNullOrEmpty(savedString) == false)
            Instance = JsonConvert.DeserializeObject<SaveScript>(savedString, settings);
             
    }

    void Update()
    {
        if (Input.GetKeyDown("a"))
        {
            LoadClass();
        }
    }
}
and GameManager.cs

Code: Select all

public class GameManager : MonoBehaviour { 
       private static GameManager instance;

	public bool nowDevelop;
    public bool setLangBySystem;
	public bool noTitle; 
    public bool steamVersion;       // is this for steam build? (PC build?)
	public bool freeVersion;		// is this free version? or paid version? 
    public Sprite engTitleImg;
    public Sprite korTitleImg;
    public Language lang; 
	public static GameState State; 
	public int initialCash;	 
	 
	void Awake(){
		if(instance != null && instance != this){
			Destroy(gameObject);
			return;
		}else{
			instance = this;	
		} 
	} 
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can this save this gameObject script?

Post by Joel »

Hi there,

You would need to add support for the MonoBehaviours in the Manage Types window (see http://docs.moodkie.com/easy-save-2/gui ... her-types/).

Then you will be able to save each one using:
ES2.Save(GetComponent<StoryScript>(), "storyScript");
ES2.Save(GetComponent<BookMarket>(), "bookMarket");
// etc ..
And then load them as follows:
ES2.Load<StoryScript>("storyScript", GetComponent<StoryScript>());
ES2.Load<BookMarket>("bookMarket", GetComponent<BookMarket>());
// etc ..
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked