Exemple #1
0
 /// <summary>
 /// Recache concealable game objects in the scenario element
 /// </summary>
 public void Recache()
 {
     componentsList.Clear();
     ConcealableObject.FindObjectsRecursively(componentsList, scenarioElement.gameObject);
 }
Exemple #2
0
            /// <summary>
            /// Finds recursively objects that will be shown and hidden and they are added to the scene objects list
            /// </summary>
            /// <param name="sceneObjects">List where found concealable objects are added</param>
            /// <param name="objectToCheck">Game object and its children are checked and added as concealable if needed</param>
            public static void FindObjectsRecursively(List <ConcealableObject> sceneObjects, GameObject objectToCheck)
            {
                ConcealableObject concealableObject = null;

                // Set the mesh renderer if it is enabled
                var objectRenderer = objectToCheck.GetComponent <MeshRenderer>();

                if (objectRenderer != null && objectRenderer.enabled)
                {
                    concealableObject = new ConcealableObject
                    {
                        gameObject = objectToCheck, meshRenderer = objectRenderer, bounds = objectRenderer.bounds
                    };
                }

                // Set the skinned mesh renderer if it is enabled
                var objectSkinnedRenderer = objectToCheck.GetComponent <SkinnedMeshRenderer>();

                if (objectSkinnedRenderer != null && objectSkinnedRenderer.enabled)
                {
                    if (concealableObject == null)
                    {
                        concealableObject = new ConcealableObject {
                            gameObject = objectToCheck, bounds = objectSkinnedRenderer.bounds
                        };
                    }
                    else
                    {
                        concealableObject.bounds.Encapsulate(objectSkinnedRenderer.bounds);
                    }
                    concealableObject.skinnedMeshRenderer = objectSkinnedRenderer;
                }

                // Set the collider if it is enabled
                var objectCollider = objectToCheck.GetComponent <Collider>();

                if (objectCollider != null && objectCollider.enabled)
                {
                    if (concealableObject == null)
                    {
                        concealableObject = new ConcealableObject {
                            gameObject = objectToCheck, bounds = objectCollider.bounds
                        };
                    }
                    else
                    {
                        concealableObject.bounds.Encapsulate(objectCollider.bounds);
                    }
                    concealableObject.collider = objectCollider;
                }

                // Set the line renderer if it is enabled
                var objectLineRenderer = objectToCheck.GetComponent <LineRenderer>();

                if (objectLineRenderer != null && objectLineRenderer.enabled)
                {
                    if (concealableObject == null)
                    {
                        concealableObject = new ConcealableObject {
                            gameObject = objectToCheck, bounds = objectLineRenderer.bounds
                        };
                    }
                    else
                    {
                        concealableObject.bounds.Encapsulate(objectLineRenderer.bounds);
                    }
                    concealableObject.lineRenderer = objectLineRenderer;
                }

                // Add the concealable object if it was created
                if (concealableObject != null)
                {
                    concealableObject.initialPositionY = concealableObject.gameObject.transform.position.y;
                    sceneObjects.Add(concealableObject);
                }

                // Add children recursively
                for (var i = 0; i < objectToCheck.transform.childCount; i++)
                {
                    var child = objectToCheck.transform.GetChild(i).gameObject;
                    FindObjectsRecursively(sceneObjects, child);
                }
            }