Battlehub0x / RTE_Docs

This is a repository for Runtime Editor documentation, discussion and tracking features and issues.
https://assetstore.unity.com/packages/tools/modeling/runtime-editor-64806
9 stars 0 forks source link

How to set the path for project data #100

Closed Battlehub0x closed 7 months ago

Battlehub0x commented 7 months ago

Hi, Feature request: Rather than use Application.persistentDataPath for project data, could you have a setting for this? I need to store my data elsewhere so it is include in git. I implemented this in the last version I had, but it of course got stomped when I updated.

Battlehub0x commented 7 months ago

Using code:

using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.RTSL.Interface;
using UnityEngine;

[DefaultExecutionOrder(-95)]
public class SetRootPath : EditorExtension
{
    protected override void OnInit()
    {
        var projectAsync =  IOC.Resolve<IProjectAsync>();
        projectAsync.Safe.SetRootPathAsync("C:/Dev/Data/");
    }
}

Using settings:

image

Here's how to load the scene after opening the project at the specified path:

using Battlehub.RTCommon;
using Battlehub.RTEditor;
using Battlehub.RTSL.Interface;
using UnityEngine.SceneManagement;

public class LoadScene : EditorExtension
{
    private IProjectAsync m_projectAsync;

    protected override void OnInit()
    {
        base.OnInit();
        m_projectAsync = IOC.Resolve<IProjectAsync>();
        m_projectAsync.Events.OpenProjectCompleted += OnOpenProjectCompleted;
    }

    protected override void OnCleanup()
    {
        base.OnCleanup();
        m_projectAsync.Events.OpenProjectCompleted -= OnOpenProjectCompleted;
        m_projectAsync = null;
    }

    private async void OnOpenProjectCompleted(object sender, ProjectEventArgs<ProjectInfo> e)
    {
        await m_projectAsync.LoadAsync("scene123", typeof(Scene));
    }
}