HELP NEEDED: Creating a super basic calendar timeline

Hoping for some direction.

Summary I am creating a simple calendar timeline that will have an event with Title and Time. This “event” will appear on a simple timeline organized by time.
Timeline Example

ISSUE : I currently do not know the best way to do this. With Dictionaries, with Lists, with custom classes.

I’ve tried all the above methods but my beginner mind isn’t grasping it and I have been unable to Load (See Controller Load() step 3) a debug log of all all the eventParams with a foreach containing mixed variables.

CURRENT SAVE SYSTEM
Save.cs

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

[System.Serializable]
public class Save
{
    public List<string> customEvents = new List<string>();

    //For Saving example
    public string eventParams = "Title";
    
    // Something to save Custom Event Parameters Title & Time
    // Able to have mixed Variables
    // Add to customEvents list to be pulled from for Timeline
}

CURRENT EVENT CONTROLLER SYSTEM
EventController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection;

public class EventController : MonoBehaviour
{

    private Save CreateSaveEvent()
    {
        Save save = new Save();

        save.customEvents.Add(save.eventParams);

        return save;
    }

    public void SaveEvent() // Calls CreateSaveEvent()
    {
        //1 
        Save save = CreateSaveEvent();

        //2

        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create(Application.persistentDataPath + "/gamesave.save");
        bf.Serialize(file, save);
        file.Close();

        //3
        Debug.Log("Event Has Been Save");
    }

    public void LoadEvent()
    {
        //1 
        if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
        {
            //CLEAR SCREEN??

            //2 
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file = File.Open(Application.persistentDataPath +
        "/gamesave.save", FileMode.Open);
            Save save = (Save)bf.Deserialize(file);
            file.Close();

//3 **** Load events ******
            Debug.Log(save.customEvents[0]);


            //4 Load Any set variables
            
            Debug.Log("Events Loaded");
        }

        else
            {
                Debug.Log("No Events saved!");
            }



    }

}

Hi,

Before wondering what “the best way” might be, maybe it would be a good idea to think about the goal and the structure of your concept. In most cases, if you have a logical concept, “the best way” reveals itself.

The first picture visualises the idea, which is a good start. However, unlike humans, the computer does not know “time”, “event” and not even an order. You have to define these things first before thinking about how to make them work in your program.

It is also important to focus on one specific problem at a time to find a solution. The first part of your thread sounds as if you didn’t know how to translate the first image to code, the second part suddenly mentions some save system which itself does not have anything to do with the concept of “time + event”.

Before trying to save things, generate the relevant data during runtime. Once your calendar timeline works during runtime, saving the generated data willl not be that difficult anymore. Without knowing what you want to save, creating a solution for the saving system is impossible.

The best would be to define “time”, a proper data structure for your “events” and the relationship between “time and event”. Once you have that, you can decide how to process the data.

I do not know what exactly your goal is but if your time values are unique, you could use them as keys in a dictionary, and an Event object for the value. Does it make sense to use a dictionary? That depends on your goal and concept.

Good luck! :slight_smile:

1 Like

Hey Nina. The issue with my question may be in part because I broke my existing Event structure down to virtually nothing for the question. I had another suggestion on a forum of keeping the Event in a class of it’s own which I tried previously I was just missing some steps.

My problem came down too… I tried about 5 different ways of doing it and about 8-10 hours on this one problem trying to do it myself that I overwhelmed myself which eventually led me to search for assistance.

I’ll be trying some suggestions and come back to this forum with either my solution or more specific question :slight_smile:

Thanks!

Privacy & Terms