Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity world loading #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
583 changes: 583 additions & 0 deletions Assets/Scenes/InitScene.unity

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Assets/Scenes/InitScene.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions Assets/Scripts/SceneLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
public CommandLineParser commandLineParser;
void Start()
{
commandLineParser = CommandLineParser.Instance;

if (commandLineParser.unityMap == null)
{
Debug.Log("No unity map specified loading default empty scene");
SceneManager.LoadScene("empty");
}
else
{
Debug.Log($"Loading scene {commandLineParser.unityMap}");
int index = SceneUtility.GetBuildIndexByScenePath(commandLineParser.unityMap);
if (index != -1)
{
SceneManager.LoadScene(index);
}
else
{
Debug.Log("Scene not found loading default empty scene");
SceneManager.LoadScene("empty");
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/SceneLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Assets/Scripts/ServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public class ServiceController : MonoBehaviour
public GameObject Cube;

void Start()
{
{
// Init variables
activeModels = new Dictionary<string, GameObject>();
commandLineArgs = gameObject.AddComponent<CommandLineParser>();

commandLineArgs = CommandLineParser.Instance;

// register the services with ROS
ROSConnection ros_con = ROSConnection.GetOrCreateInstance();
Expand Down Expand Up @@ -130,8 +131,8 @@ private RobotConfig LoadRobotModelYaml(string robotName)
// Take command line arg if executable build is running
string arenaSimSetupPath = commandLineArgs.arena_sim_setup_path;
// Use relative path if running in Editor
arenaSimSetupPath ??= Path.Combine(Application.dataPath, "../../arena-simulation-setup");
string yamlPath = Path.Combine(arenaSimSetupPath, "robot", robotName, robotName + ".model.yaml");
arenaSimSetupPath ??= Path.Combine(Application.dataPath, "../../simulation-setup");
string yamlPath = Path.Combine(arenaSimSetupPath, "entities", "robots", robotName, robotName + ".model.yaml");

// Check if the file exists
if (!File.Exists(yamlPath))
Expand Down
49 changes: 40 additions & 9 deletions Assets/Scripts/Utils/CommandLineParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.SceneManagement;

public class CommandLineParser : MonoBehaviour
public class CommandLineParser
{
public string arena_sim_setup_path;
public string unityMap;

private static CommandLineParser instance;

public static CommandLineParser Instance
{
get
{
if (instance == null)
{
instance = new CommandLineParser();
instance.Initialize();
}
return instance;
}
}

private CommandLineParser()
{
// Private constructor to prevent instantiation
}

private void Initialize()
{
string[] args = Environment.GetCommandLineArgs();
Debug.Log($"Args: {string.Join(", ", args)}");

arena_sim_setup_path = GetValue("arena_sim_setup_path");
string unityMapFile = GetValue("map");
if (unityMapFile != null && unityMapFile != "")
{
var i = unityMapFile.IndexOf("_unity");
if (i != -1)
{
unityMap = unityMapFile.Substring(0, i);
}
}
}

private string GetValue(string argName)
{
Expand All @@ -20,10 +57,4 @@ private string GetValue(string argName)

return null;
}

// Assigns all properties the matching command line argument value
void Start()
{
arena_sim_setup_path = GetValue("arena_sim_setup_path");
}
}
5 changes: 4 additions & 1 deletion ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
path: Assets/Scenes/InitScene.unity
guid: e0ffd24a5fa79d7918c5d398b43db3b6
- enabled: 1
path: Assets/Scenes/Empty.unity
guid: 3db1837cc97a95e4c98610966fac2b0b
m_configObjects:
com.unity.input.settings: {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2}
3 changes: 2 additions & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ PlayerSettings:
vulkanEnableCommandBufferRecycling: 1
loadStoreDebugModeEnabled: 0
bundleVersion: 0.1
preloadedAssets: []
preloadedAssets:
- {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
Expand Down