Create Custom Class Types and using it on Generic List<T>

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
minshou
Posts: 2
Joined: Tue Jan 22, 2019 8:42 am

Create Custom Class Types and using it on Generic List<T>

Post by minshou »

Greetings Moodkie team,

I'm quite new to Unity.
I have a few questions to ask:

----------------------------------------------------------------- Question 1 -----------------------------------------------------------------------------------
1. How do I add a custom Class type, for example, let's say a "Ball" class with these variables?

Code: Select all

public class Ball : MonoBehaviour
{
     public Vector2 ballLocation;
     public bool ballBounce;
}
2. I tried following the steps provided in the Moodkie Documentation site, by heading to the Easy Save 2 > Manage Types... > ClassType > Add Type. But I just have no clue on how to edit these areas.
3. Should I replace all the error keywords with my class Name?
Image
--------------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------- Question 2 ---------------------------------------------------------------------------------
1. If I manage to add the customer class "Ball" type, will it work if I add it to a List<T> then saving the list directly as such:

Code: Select all

public class GameManager : MonoBehaviour
{
     List<Ball> ballList = new List<Ball>();
     Piece ballObj = new Piece();
     ballObj = GetComponent<Ball>();
     ballObj.position.x = 2.0f;
     ballObj.position.y = 2.0f;
     ballObj.ballBounce = true;
     ballList.Add(ballObj);

     ES2.Save(ballList, "Match1.txt?tag=runnerUp");
}
2. If it's not possible, are there any other way to work around this issue?
--------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance.
Regards,
Chan
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Create Custom Class Types and using it on Generic List<T

Post by Joel »

Hi there,

Are you sure you selected the Ball class in the Types pane? It looks like the ES2Type generated is for a different type entirely.

Once it is correctly added in the Types pane, you will also be able to save List<Ball>.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
minshou
Posts: 2
Joined: Tue Jan 22, 2019 8:42 am

Re: Create Custom Class Types and using it on Generic List<T

Post by minshou »

HI Joe,

Ah, I get it, Easy Save automatically detects the Ball class when it's created. I originally thought I have to manually add the Ball class type. So, I guess I have to head to the Easy Save 2 > Manage Types... > Ball > tick on the variables that I wish to save and load > Add type.

I apologize if my thread is a bit dumb.

Thanks.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Create Custom Class Types and using it on Generic List<T

Post by Joel »

Hi there,

This is indeed the case, and you can find more info here: https://docs.moodkie.com/easy-save-2/gu ... her-types/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked