private void InitScene() { if (ROSAgentManager.Instance.currentMode == StartModeTypes.Dev) { return; } var agentListCanvas = Instantiate(UserInterfaceAgentList); var agentList = agentListCanvas.transform.FindDeepChild("Content"); // TODO needs to change !!! asap float height = 0; if (ROSAgentManager.Instance.activeAgents.Count > 1) { height = agentListCanvas.transform.FindDeepChild("AgentList").GetComponent <RectTransform>().rect.height; // TODO needs to change !!! asap } else { agentListCanvas.enabled = false; } // TODO: update spawn position from static config Vector3 defaultSpawnPosition = new Vector3(1.0f, 0.018f, 0.7f); Quaternion defaultSpawnRotation = Quaternion.identity; var spawnInfos = FindObjectsOfType <SpawnInfo>(); var spawnInfoList = spawnInfos.ToList(); spawnInfoList.Reverse(); for (int i = 0; i < ROSAgentManager.Instance.activeAgents.Count; i++) { var agentImage = Instantiate(AgentUI, agentList); agentImage.transform.FindDeepChild("Address").GetComponent <Text>().text = ROSAgentManager.Instance.activeAgents[i].PrettyAddress; var ilocal = i; var button = agentImage.GetComponent <Button>(); button.onClick.AddListener(() => { UserInterfaceSetup.ChangeFocusUI(ROSAgentManager.Instance.activeAgents[ilocal]); SteeringWheelInputController.ChangeFocusSteerWheel(ROSAgentManager.Instance.activeAgents[ilocal].Agent.GetComponentInChildren <SteeringWheelInputController>()); }); var agentSetup = ROSAgentManager.Instance.activeAgents[i].agentType; var spawnPos = defaultSpawnPosition; var spawnRot = defaultSpawnRotation; if (spawnInfoList.Count > 0) { spawnPos = spawnInfoList[spawnInfoList.Count - 1].transform.position; spawnRot = spawnInfoList[spawnInfoList.Count - 1].transform.rotation; spawnInfoList.RemoveAt(spawnInfoList.Count - 1); } GameObject bot = new GameObject(); if (FindObjectOfType <StaticConfigManager>() != null) { if (StaticConfigManager.Instance.staticConfig.initialized && ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig) { var gps = agentSetup.gameObject.transform.GetComponentInChildren <GpsDevice>(); var pos = StaticConfigManager.Instance.staticConfig.vehicles[i].position; if (pos.e != 0.0 || pos.n != 0.0) { spawnPos = gps.GetPosition(pos.e, pos.n); spawnPos.y = pos.h; var rot = StaticConfigManager.Instance.staticConfig.vehicles[i].orientation; spawnRot = Quaternion.Euler(rot.r, rot.y, rot.p); } bot = Instantiate(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject : agentSetup.gameObject, spawnPos, spawnRot); } } else { bot = Instantiate(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject : agentSetup.gameObject, spawnPos - new Vector3(0.25f * i, 0, 0), spawnRot); // TODO better system } AnalyticsManager.Instance?.EgoStartEvent(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject.name : agentSetup.gameObject.name); var bridgeConnector = ROSAgentManager.Instance.activeAgents[i]; var uiObject = Instantiate(UserInterfaceAgent); uiObject.GetComponent <RfbClient>().Address = ROSAgentManager.Instance.activeAgents[i].Address; var ui = uiObject.transform; ui.GetComponent <UserInterfaceSetup>().agent = bot; if (bot.name.Contains("duckiebot")) { HelpScreenUpdate helpScreen = uiObject.GetComponent <HelpScreenUpdate>(); helpScreen.Help = helpScreen.DuckieHelp; helpScreen.agentsText = helpScreen.duckieText; } // offset for multiple vehicle UI RectTransform rect = uiObject.GetComponent <UserInterfaceSetup>().MainPanel; if (rect != null) { rect.offsetMax = new Vector2(0, rect.offsetMax.y - height); } bridgeConnector.UiObject = uiObject; bridgeConnector.UiButton = agentImage; bridgeConnector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus; var isVehicleConfig = false; if (FindObjectOfType <StaticConfigManager>() != null) { isVehicleConfig = StaticConfigManager.Instance.staticConfig.initialized && ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig; } bot.GetComponent <AgentSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), bridgeConnector, isVehicleConfig ? StaticConfigManager.Instance.staticConfig.vehicles[i] : null); bot.GetComponent <AgentSetup>().FollowCamera.gameObject.SetActive(i == 0); button.image.sprite = bot.GetComponent <AgentSetup>().agentUISprite; uiObject.enabled = i == 0; var colors = button.colors; colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f); button.colors = colors; var name = new GameObject($"agent_{i}_name"); name.transform.parent = agentListCanvas.transform.FindDeepChild("Panel").transform; bridgeConnector.UiName = name.AddComponent <Text>(); bridgeConnector.UiName.font = Resources.GetBuiltinResource <Font>("Arial.ttf"); bridgeConnector.UiName.text = ROSAgentManager.Instance.activeAgents[i].PrettyAddress; bridgeConnector.UiName.fontSize = 16; bridgeConnector.UiName.fontStyle = FontStyle.Bold; bridgeConnector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow; bridgeConnector.UiName.verticalOverflow = VerticalWrapMode.Overflow; bridgeConnector.Agent = bot; } UserInterfaceSetup.ChangeFocusUI(ROSAgentManager.Instance.activeAgents[0]); SteeringWheelInputController.ChangeFocusSteerWheel(ROSAgentManager.Instance.activeAgents[0].Agent.GetComponentInChildren <SteeringWheelInputController>()); ROSAgentManager.Instance?.SetCurrentActiveAgent(ROSAgentManager.Instance.activeAgents[0]); //destroy spawn information after use foreach (var spawnInfo in spawnInfos) { Destroy(spawnInfo.gameObject); } InitGlobalShadowSettings(); // TODO better way for small maps }
public void SpawnVehicle(Vector3 position, Quaternion rotation, RosBridgeConnector connector, VehicleConfig staticConfig, float height = 0.0f) { var agentImage = Instantiate(AgentUI, AgentList); agentImage.transform.FindDeepChild("Address").GetComponent <Text>().text = connector.PrettyAddress; var button = agentImage.GetComponent <Button>(); button.onClick.AddListener(() => { UserInterfaceSetup.ChangeFocusUI(connector); SteeringWheelInputController.ChangeFocusSteerWheel(connector.Agent.GetComponentInChildren <SteeringWheelInputController>()); }); var agentSetup = connector.agentType; GameObject bot = Instantiate(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject : agentSetup.gameObject, position, rotation); // TODO better system AnalyticsManager.Instance?.EgoStartEvent(agentSetup == null ? ROSAgentManager.Instance.agentPrefabs[0].gameObject.name : agentSetup.gameObject.name); var uiObject = Instantiate(UserInterfaceAgent); uiObject.GetComponent <RfbClient>().Address = connector.Address; var ui = uiObject.transform; ui.GetComponent <UserInterfaceSetup>().agent = bot; if (bot.name.Contains("duckiebot")) { HelpScreenUpdate helpScreen = uiObject.GetComponent <HelpScreenUpdate>(); helpScreen.Help = helpScreen.DuckieHelp; helpScreen.agentsText = helpScreen.duckieText; } // offset for multiple vehicle UI RectTransform rect = uiObject.GetComponent <UserInterfaceSetup>().MainPanel; if (rect != null) { rect.offsetMax = new Vector2(0, rect.offsetMax.y - height); } connector.UiObject = uiObject; connector.UiButton = agentImage; connector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus; bot.GetComponent <AgentSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), connector, staticConfig); bot.GetComponent <AgentSetup>().FollowCamera.gameObject.SetActive(false); button.image.sprite = bot.GetComponent <AgentSetup>().agentUISprite; //uiObject.enabled = i == 0; var colors = button.colors; //colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f); button.colors = colors; var name = new GameObject(); name.transform.parent = AgentListCanvas.transform.FindDeepChild("Panel").transform; connector.UiName = name.AddComponent <Text>(); connector.UiName.font = Resources.GetBuiltinResource <Font>("Arial.ttf"); connector.UiName.text = connector.PrettyAddress; connector.UiName.fontSize = 16; connector.UiName.fontStyle = FontStyle.Bold; connector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow; connector.UiName.verticalOverflow = VerticalWrapMode.Overflow; connector.Agent = bot; }
void SceneLoadFinished(AsyncOperation op) { if (!Application.isEditor) { allLoadedBundles.ForEach(b => b.Unload(false)); allLoadedBundles.Clear(); } var robotListCanvas = Instantiate(UserInterfaceRobotList); var robotList = robotListCanvas.transform.FindDeepChild("Content"); float height = 0; if (Robots.Robots.Count > 1) { height = robotListCanvas.transform.FindDeepChild("RobotList").GetComponent <RectTransform>().rect.height; } else { robotListCanvas.enabled = false; } // TODO: update spawn position from static config Vector3 defaultSpawnPosition = new Vector3(1.0f, 0.018f, 0.7f); Quaternion defaultSpawnRotation = Quaternion.identity; var spawnInfos = FindObjectsOfType <SpawnInfo>(); var spawnInfoList = spawnInfos.ToList(); spawnInfoList.Reverse(); //avoid first frame collision //var sceneRobots = FindObjectsOfType<RobotSetup>(); //foreach (var robot in sceneRobots) //{ // var cols = robot.GetComponentsInChildren<Collider>(); // foreach (var col in cols) // { // col.enabled = false; // } //} for (int i = 0; i < Robots.Robots.Count; i++) { var robotImage = Instantiate(DuckiebotRobot, robotList); robotImage.transform.FindDeepChild("Address").GetComponent <Text>().text = Robots.Robots[i].PrettyAddress; var ilocal = i; var button = robotImage.GetComponent <Button>(); button.onClick.AddListener(() => { UserInterfaceSetup.ChangeFocusUI(Robots.Robots[ilocal], Robots); SteeringWheelInputController.ChangeFocusSteerWheel(Robots.Robots[ilocal].Robot.GetComponentInChildren <SteeringWheelInputController>()); }); var robotSetup = Robots.Robots[i].robotType; var spawnPos = defaultSpawnPosition; var spawnRot = defaultSpawnRotation; if (spawnInfoList.Count > 0) { spawnPos = spawnInfoList[spawnInfoList.Count - 1].transform.position; spawnRot = spawnInfoList[spawnInfoList.Count - 1].transform.rotation; spawnInfoList.RemoveAt(spawnInfoList.Count - 1); } GameObject bot = new GameObject(); if (staticConfig.initialized) { var gps = robotSetup.gameObject.transform.GetComponentInChildren <GpsDevice>(); var pos = staticConfig.vehicles[i].position; if (pos.e != 0.0 || pos.n != 0.0) { spawnPos = gps.GetPosition(pos.e, pos.n); spawnPos.y = pos.h; var rot = staticConfig.vehicles[i].orientation; spawnRot = Quaternion.Euler(rot.r, rot.y, rot.p); } bot = Instantiate(robotSetup == null ? Robots.robotCandidates[0].gameObject : robotSetup.gameObject, spawnPos, spawnRot); } else { bot = Instantiate(robotSetup == null ? Robots.robotCandidates[0].gameObject : robotSetup.gameObject, spawnPos - new Vector3(0.25f * i, 0, 0), spawnRot); // TODO better system } AnalyticsManager.Instance?.EgoStartEvent(robotSetup == null ? Robots.robotCandidates[0].gameObject.name : robotSetup.gameObject.name); var bridgeConnector = Robots.Robots[i]; var uiObject = Instantiate(UserInterface); uiObject.GetComponent <RfbClient>().Address = Robots.Robots[i].Address; var ui = uiObject.transform; if (bot.name.Contains("duckiebot")) { HelpScreenUpdate helpScreen = uiObject.GetComponent <HelpScreenUpdate>(); helpScreen.Help = helpScreen.DuckieHelp; helpScreen.RobotsText = helpScreen.DuckieRobotsText; } // offset for multiple vehicle UI RectTransform rect = uiObject.GetComponent <UserInterfaceSetup>().MainPanel; if (rect != null) { rect.offsetMax = new Vector2(0, rect.offsetMax.y - height); } bridgeConnector.UiObject = uiObject; bridgeConnector.UiButton = robotImage; bridgeConnector.BridgeStatus = uiObject.GetComponent <UserInterfaceSetup>().BridgeStatus; ui.GetComponent <HelpScreenUpdate>().Robots = Robots; bot.GetComponent <RobotSetup>().Setup(ui.GetComponent <UserInterfaceSetup>(), bridgeConnector, staticConfig.initialized ? staticConfig.vehicles[i] : null); bot.GetComponent <RobotSetup>().FollowCamera.gameObject.SetActive(i == 0); button.image.sprite = bot.GetComponent <RobotSetup>().robotUISprite; uiObject.enabled = i == 0; var colors = button.colors; colors.normalColor = i == 0 ? new Color(1, 1, 1) : new Color(0.8f, 0.8f, 0.8f); button.colors = colors; var name = new GameObject($"robot_{i}_name"); name.transform.parent = robotListCanvas.transform.FindDeepChild("Panel").transform; bridgeConnector.UiName = name.AddComponent <Text>(); bridgeConnector.UiName.font = Resources.GetBuiltinResource <Font>("Arial.ttf"); bridgeConnector.UiName.text = Robots.Robots[i].PrettyAddress; bridgeConnector.UiName.fontSize = 16; bridgeConnector.UiName.fontStyle = FontStyle.Bold; bridgeConnector.UiName.horizontalOverflow = HorizontalWrapMode.Overflow; bridgeConnector.UiName.verticalOverflow = VerticalWrapMode.Overflow; bridgeConnector.Robot = bot; SimulatorManager.Instance?.AddActiveRobot(bot); } // hack for dev SimulatorManager.Instance.SpawnDashUI(); UserInterfaceSetup.ChangeFocusUI(Robots.Robots[0], Robots); SteeringWheelInputController.ChangeFocusSteerWheel(Robots.Robots[0].Robot.GetComponentInChildren <SteeringWheelInputController>()); SimulatorManager.Instance.SetCurrentActiveRobot(Robots.Robots[0].Robot); //destroy spawn information after use foreach (var spawnInfo in spawnInfos) { Destroy(spawnInfo.gameObject); } //Configure shadow settings due to huge difference between different cars bool useRealSizeSetting = false; for (int i = 0; i < Robots.Robots.Count; i++) { var robotSetup = Robots.Robots[i].robotType; if (robotSetup.GetComponentInChildren <SimpleCarController>() == null) { useRealSizeSetting = true; break; } } if (useRealSizeSetting) { RealSizeGlobalShadowSettings(); } UserInterfaceSetup.FocusUI.Invoke("CheckStaticConfigTraffic", 0.5f); }