|
@@ -0,0 +1,126 @@
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+
|
|
|
+public class TestModelMaterial : MonoBehaviour
|
|
|
+{
|
|
|
+ [Multiline]
|
|
|
+ public string info;
|
|
|
+
|
|
|
+ [Header("Highlighting Materials:")]
|
|
|
+ public Material highlightRed;
|
|
|
+ public Material highlightGreen;
|
|
|
+ public Material highlightYellow;
|
|
|
+
|
|
|
+ [Header("Highlighting Transparent Materials:")]
|
|
|
+ public Material highlightTransRed;
|
|
|
+ public Material highlightTransGreen;
|
|
|
+ public Material highlightTransYellow;
|
|
|
+
|
|
|
+ [Header("Thresholds:")]
|
|
|
+ [Tooltip("The maximum number of people (including the observed) that will be colored green.\n Threshold Green = 1 means that no further person is allowed to approach.")]
|
|
|
+ public int thresholdGreen = 1;
|
|
|
+ [Tooltip("The maximum number of people (including the observed) that will be colored yellow.\n Threshold Yellow = 2 means that only one other person may approach.")]
|
|
|
+ public int thresholdYellow = 2;
|
|
|
+
|
|
|
+ [Space]
|
|
|
+ public float radius = 1f;
|
|
|
+
|
|
|
+
|
|
|
+ private Vector3 center;
|
|
|
+ private Collider[] hitHumans;
|
|
|
+ private List<Component> allHumansTransform = new List<Component>();
|
|
|
+
|
|
|
+
|
|
|
+ private void Start()
|
|
|
+ {
|
|
|
+ Component[] allTransform = GetComponentsInChildren<Transform>();
|
|
|
+ foreach (Transform child in allTransform)
|
|
|
+ {
|
|
|
+ if (child.parent == allTransform[0])
|
|
|
+ {
|
|
|
+ allHumansTransform.Add(child);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnDrawGizmos()
|
|
|
+ {
|
|
|
+ foreach (Component lst in allHumansTransform)
|
|
|
+ {
|
|
|
+ Gizmos.color = Color.blue;
|
|
|
+ Gizmos.DrawWireSphere(lst.transform.position, radius);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void FixedUpdate()
|
|
|
+ {
|
|
|
+ foreach (Component lst in allHumansTransform)
|
|
|
+ {
|
|
|
+ center = lst.GetComponent<Transform>().position;
|
|
|
+
|
|
|
+ hitHumans = Physics.OverlapSphere(center, radius, LayerMask.GetMask("Humans"));
|
|
|
+
|
|
|
+ bool differentTag = false;
|
|
|
+ foreach (Collider hitHuman in hitHumans)
|
|
|
+ {
|
|
|
+ if (lst.CompareTag(hitHuman.tag))
|
|
|
+ differentTag = false;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ differentTag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int hitHumansLength = 0;
|
|
|
+ foreach (Collider hitHuman in hitHumans)
|
|
|
+ {
|
|
|
+ if (lst.CompareTag(hitHuman.tag))
|
|
|
+ hitHumansLength++;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (hitHumansLength <= thresholdGreen)
|
|
|
+ {
|
|
|
+ if (!differentTag)
|
|
|
+ {
|
|
|
+ Debug.Log(lst.gameObject.name + " set to Green");
|
|
|
+ lst.transform.Find("BasicMotionsDummyModel").Find("DummyMesh").gameObject.GetComponent<SkinnedMeshRenderer>().material = highlightGreen;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log(lst.gameObject.name + " set to Trans Green");
|
|
|
+ lst.transform.Find("BasicMotionsDummyModel").Find("DummyMesh").gameObject.GetComponent<SkinnedMeshRenderer>().material = highlightTransGreen;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (hitHumansLength <= thresholdYellow)
|
|
|
+ {
|
|
|
+ if (!differentTag)
|
|
|
+ {
|
|
|
+ Debug.Log(lst.gameObject.name + " set to Yellow");
|
|
|
+ lst.transform.Find("BasicMotionsDummyModel").Find("DummyMesh").gameObject.GetComponent<SkinnedMeshRenderer>().material = highlightYellow;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log(lst.gameObject.name + " set to Trans Yellow");
|
|
|
+ lst.transform.Find("BasicMotionsDummyModel").Find("DummyMesh").gameObject.GetComponent<SkinnedMeshRenderer>().material = highlightTransYellow;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!differentTag)
|
|
|
+ {
|
|
|
+ Debug.Log(lst.gameObject.name + " set to Red");
|
|
|
+ lst.transform.Find("BasicMotionsDummyModel").Find("DummyMesh").gameObject.GetComponent<SkinnedMeshRenderer>().material = highlightRed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log(lst.gameObject.name + " set to Trans Red");
|
|
|
+ lst.transform.Find("BasicMotionsDummyModel").Find("DummyMesh").gameObject.GetComponent<SkinnedMeshRenderer>().material = highlightTransRed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|