Skip to content

Commit 43effdf

Browse files
committed
fixes an issue wuth color change and ray interaction with prefab
1 parent f634a43 commit 43effdf

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

Unity Template VR/Assets/Scripts/Gama Provider/Simulation/SimulationManager.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ private void instantiateGO(GameObject obj, String name, PropertiesGAMA prop)
869869
}
870870
if (interaction.colliders.Count == 0)
871871
{
872-
Collider[] cs = obj.GetComponentsInChildren<Collider>(true);
872+
Collider[] cs = obj.GetComponentsInChildren<Collider>();
873873
if (cs != null)
874874
{
875875
foreach (Collider c in cs)
@@ -908,6 +908,9 @@ private GameObject instantiatePrefab(String name, PropertiesGAMA prop, bool init
908908
{
909909
GameObject b = l.renderers[0].gameObject;
910910
Collider c = b.GetComponent<Collider>();
911+
if (c != null && c.bounds.extents.x == 0)
912+
c = null;
913+
911914
if (c == null)
912915
{
913916
BoxCollider bc = b.AddComponent<BoxCollider>();
@@ -921,6 +924,8 @@ private GameObject instantiatePrefab(String name, PropertiesGAMA prop, bool init
921924
else
922925
{
923926
Collider c = obj.GetComponent<Collider>();
927+
if (c != null && c.bounds.extents.x == 0)
928+
c = null;
924929
if (c == null)
925930
{
926931
BoxCollider bc = obj.AddComponent<BoxCollider>();
@@ -1013,12 +1018,24 @@ protected virtual void SelectInteraction(SelectEnterEventArgs ev)
10131018

10141019
}
10151020

1021+
1022+
private static readonly string[] colorNames = { "_BaseColor", "_Color", "_MainColor", "Color", "BaseColor" };
10161023
static public void ChangeColor(GameObject obj, Color color)
10171024
{
10181025
Renderer[] renderers = obj.gameObject.GetComponentsInChildren<Renderer>();
10191026
for (int i = 0; i < renderers.Length; i++)
10201027
{
1021-
renderers[i].material.color = color;
1028+
Material mat = renderers[i].material;
1029+
1030+
foreach (string prop in colorNames)
1031+
{
1032+
if (mat.HasProperty(prop))
1033+
{
1034+
mat.SetColor(prop, color);
1035+
break;
1036+
}
1037+
}
1038+
10221039
}
10231040
}
10241041
protected virtual void AdditionalInitAfterGeomLoading()

0 commit comments

Comments
 (0)