add fire render
This commit is contained in:
Generated
+49
@@ -138487,6 +138487,54 @@ Transform:
|
|||||||
m_CorrespondingSourceObject: {fileID: 7990292180534428959, guid: 3581c78ebfd056b47ae08282ffd0efa2, type: 3}
|
m_CorrespondingSourceObject: {fileID: 7990292180534428959, guid: 3581c78ebfd056b47ae08282ffd0efa2, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1329484390}
|
m_PrefabInstance: {fileID: 1329484390}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!1 &1329767849
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1329767851}
|
||||||
|
- component: {fileID: 1329767850}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Campfires
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!114 &1329767850
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1329767849}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 34f796181d1c16e72ba23d3e1ada060e, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
objectCollector: {fileID: 1329767849}
|
||||||
|
objectToSpawn: {fileID: 1781949194303238870, guid: e92a0207ed6f749459a3646c2aaf3cd9, type: 3}
|
||||||
|
topic_name: /locations
|
||||||
|
useNamespace: 0
|
||||||
|
--- !u!4 &1329767851
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1329767849}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &1330179475
|
--- !u!1001 &1330179475
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -222195,3 +222243,4 @@ SceneRoots:
|
|||||||
- {fileID: 332740253}
|
- {fileID: 332740253}
|
||||||
- {fileID: 1278719290}
|
- {fileID: 1278719290}
|
||||||
- {fileID: 178756651}
|
- {fileID: 178756651}
|
||||||
|
- {fileID: 1329767851}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Unity.Robotics.Core;
|
||||||
|
using RosMessageTypes.Geometry;
|
||||||
|
using Unity.Robotics.ROSTCPConnector;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using RosMessageTypes.GenLocationsOnMesh;
|
||||||
|
|
||||||
|
public class CampfireRenderer : MonoBehaviour
|
||||||
|
{
|
||||||
|
public GameObject objectCollector, objectToSpawn;
|
||||||
|
public string topic_name = "/campfire_status";
|
||||||
|
|
||||||
|
protected string _namespace;
|
||||||
|
public bool useNamespace = true;
|
||||||
|
|
||||||
|
ROSConnection ros;
|
||||||
|
|
||||||
|
private Dictionary<int, GameObject> campfire;
|
||||||
|
private GameObject newSpawnedObject;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (useNamespace)
|
||||||
|
{
|
||||||
|
_namespace = "/" + gameObject.name;
|
||||||
|
topic_name = topic_name[0] == '/' ? _namespace + topic_name : _namespace + "/" + topic_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
ros = ROSConnection.GetOrCreateInstance();
|
||||||
|
ros.Subscribe<LocationsOnMeshMsg>(topic_name, CampfireHandler);
|
||||||
|
|
||||||
|
campfire = new Dictionary<int, GameObject>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CampfireHandler(LocationsOnMeshMsg capmfireInfo)
|
||||||
|
{
|
||||||
|
for (int id = 0; id < capmfireInfo.location_id.Length; id++)
|
||||||
|
{
|
||||||
|
Vector3 pose = new Vector3(
|
||||||
|
(float)capmfireInfo.x[id],
|
||||||
|
(float)capmfireInfo.y[id],
|
||||||
|
(float)capmfireInfo.z[id]);
|
||||||
|
if(campfire.TryGetValue(id, out GameObject go))
|
||||||
|
{
|
||||||
|
go.transform.position = pose;
|
||||||
|
go.SetActive(true);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
SpawnCampfire(id, pose);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int id = capmfireInfo.location_id.Length; id < campfire.Count; id++)
|
||||||
|
{
|
||||||
|
campfire[id].SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpawnCampfire(int id, Vector3 pos)
|
||||||
|
{
|
||||||
|
newSpawnedObject = Instantiate(objectToSpawn, pos, transform.rotation);
|
||||||
|
newSpawnedObject.name = "Campfire_" + id;
|
||||||
|
newSpawnedObject.transform.SetParent(objectCollector.transform);
|
||||||
|
campfire.Add(id, newSpawnedObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+2
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 34f796181d1c16e72ba23d3e1ada060e
|
||||||
Reference in New Issue
Block a user