for example:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CrateState : MonoBehaviour, IStateQuery
{
public Transform crateCap;
public SaveLoad saveLoad;
public bool hasOpened;
private bool saveOnce = true;
private State m_state = new State();
public Guid UniqueId = new Guid();//=> Guid.Parse("D9687717-CEF7-4E6C-8318-20BCC51E0110");
private class State
{
public bool open;
}
public string GetState()
{
return JsonUtility.ToJson(m_state);
}
public void SetState(string jsonString)
{
m_state = JsonUtility.FromJson<State>(jsonString);
if (m_state.open)
{
crateCap.localRotation = Quaternion.Euler(90, 0, 0);
hasOpened = true;
}
else
{
crateCap.localRotation = Quaternion.Euler(180, 0, 0);
hasOpened = false;
}
}
// Update is called once per frame
void Update()
{
if (GetComponent<UnlockCrate>().HasOpened())
{
hasOpened = true;
if (saveOnce)
{
StartCoroutine(saveLoad.SaveWithTime());
saveOnce = false;
}
}
else
{
hasOpened = false;
}
m_state.open = hasOpened;
}
}
The line :
public Guid UniqueId = new Guid();
was :
public Guid UniqueId => Guid.Parse("D9687717-CEF7-4E6C-8318-20BCC51E0110");
but it's a bit annoying to do in the menu in the visual studio: Tools > Create GUID > and then generate a new guid and copy it to the script.
I'm using this script base for every object I want to save its state. and for that i need to generate a new guid.
I tried to change the line to:
public Guid UniqueId = new Guid();
but then getting error on the top at: IStateQuery
CrateState does not implement interface member IStateQuery.UniqueId
This is the IStateQuery class:
using System;
public interface IStateQuery
{
string GetState();
void SetState(string jsonString);
Guid UniqueId { get; }
}
i'm not sure if making instance like i'm doing now is the right way and how ot fix the error. in the other hand i want to make something easier to generate each time a new guid number instead copying it manual to the state script.
I tried to make a new instance:
public Guid UniqueId = new Guid();
but this give me error on the IStateQuery so I'm not sure if this is the right approach.