Exemple #1
0
    public void Update(int layer, string tag)
    {
        var surfaceCount = Count;

        if (multiMeshes == null || multiMeshes.Length != surfaceCount)
        {
            multiMeshes = new SGT_MultiMesh[surfaceCount];
        }
        if (multiMeshGameObjects == null || multiMeshGameObjects.Length != surfaceCount)
        {
            multiMeshGameObjects = new GameObject[surfaceCount];
        }

        // Update multi meshes
        for (var i = 0; i < multiMeshes.Length; i++)
        {
            var multiMesh           = multiMeshes[i];
            var multiMeshGameObject = multiMeshGameObjects[i];

            if (multiMesh == null)
            {
                multiMesh      = new SGT_MultiMesh();
                multiMeshes[i] = multiMesh;
            }

            if (multiMeshGameObject == null)
            {
                multiMeshGameObject     = SGT_Helper.CreateGameObject("Multi Mesh " + (i + 1), gameObject);
                multiMeshGameObjects[i] = multiMeshGameObject;
            }

            if (gameObject != null)
            {
                SGT_Helper.SetParent(multiMeshGameObject, gameObject);
                SGT_Helper.SetLayer(multiMeshGameObject, gameObject.layer);
                SGT_Helper.SetTag(multiMeshGameObject, gameObject.tag);
            }

            multiMesh.GameObject            = multiMeshGameObject;
            multiMesh.HasMeshRenderers      = hasMeshRenderers;
            multiMesh.MeshRenderersEnabled  = meshRenderersEnabled;
            multiMesh.HasMeshColliders      = hasMeshColliders;
            multiMesh.MeshCollidersEnabled  = meshCollidersEnabled;
            multiMesh.SharedPhysicsMaterial = sharedPhysicsMaterial;
            multiMesh.Update();
        }

        // Check integrity
        if (gameObject != null && gameObject.transform.childCount != surfaceCount)
        {
            SGT_Helper.DestroyGameObjects(multiMeshGameObjects);
            SGT_Helper.DestroyChildren(gameObject);
        }
    }
Exemple #2
0
    public void Update()
    {
        if (meshes == null)
        {
            meshes = new MeshList();
        }
        if (meshGameObjects == null)
        {
            meshGameObjects = new GameObjectList();
        }

        if (meshGameObjects.Count != meshes.Count)
        {
            SGT_ArrayHelper.Resize(ref meshGameObjects, meshes.Count, true);
        }

        // Update meshes
        for (var i = meshes.Count - 1; i >= 0; i--)
        {
            var mesh           = meshes[i];
            var meshGameObject = meshGameObjects[i];

            if (mesh == null)
            {
                mesh      = new SGT_Mesh();
                meshes[i] = mesh;
            }

            if (meshGameObject == null)
            {
                meshGameObject     = SGT_Helper.CreateGameObject("Mesh " + (i + 1), gameObject);
                meshGameObjects[i] = meshGameObject;
            }

            if (gameObject != null)
            {
                SGT_Helper.SetParent(meshGameObject, gameObject);
                SGT_Helper.SetLayer(meshGameObject, gameObject.layer);
                SGT_Helper.SetTag(meshGameObject, gameObject.tag);
            }

            if (sharedMesh != null)
            {
                mesh.SharedMesh = sharedMesh;
            }
            if (sharedMaterial != null)
            {
                mesh.SharedMaterial = sharedMaterial;
            }
            if (sharedPhysicsMaterial != null)
            {
                mesh.SharedPhysicsMaterial = sharedPhysicsMaterial;
            }

            mesh.GameObject          = meshGameObject;
            mesh.HasMeshRenderer     = hasMeshRenderers;
            mesh.MeshRendererEnabled = meshRenderersEnabled;
            mesh.HasMeshCollider     = hasMeshColliders;
            mesh.MeshColliderEnabled = meshCollidersEnabled;
            mesh.Update();
        }

        // Check integrity
        if (gameObject != null && meshGameObjects.Count != gameObject.transform.childCount)
        {
            SGT_Helper.DestroyChildren(gameObject);
            SGT_Helper.DestroyGameObjects(meshGameObjects);
        }
    }