Пример #1
0
    private void UpdateCollider(bool enableColliders)
    {
        if (enableColliders == true)
        {
            if (Mesh == null)
            {
                SgtPatchBuilder.GenerateMesh(this);
            }

            if (meshCollider == null)
            {
                meshCollider = SgtHelper.GetOrAddComponent <MeshCollider>(gameObject);
            }

            if (meshCollider.sharedMesh != Mesh)
            {
                SgtHelper.BeginStealthSet(meshCollider);
                {
                    meshCollider.sharedMesh = Mesh;
                }
                SgtHelper.EndStealthSet();
            }

            SgtHelper.SetEnabled(meshCollider, true);
        }
        else
        {
            SgtHelper.SetEnabled(meshCollider, false);
        }
    }
Пример #2
0
    public void UpdateState()
    {
        if (Material != null)
        {
            FinalMaterial = Material;
        }
        else
        {
            if (Parent != null)
            {
                FinalMaterial = Parent.FinalMaterial;
            }
            else
            {
                FinalMaterial = Terrain.Material;
            }
        }

        if (ChildrenExist == true)
        {
            if (meshRenderer != null)
            {
                SgtHelper.SetEnabled(meshRenderer, false);
            }

            // Has colliders if it's the last depth
            UpdateCollider(Depth + 1 == Terrain.MaxColliderDepth);
        }
        else
        {
            if (Mesh == null)
            {
                SgtPatchBuilder.GenerateMesh(this);
            }

            if (meshRenderer == null)
            {
                meshRenderer = SgtHelper.GetOrAddComponent <MeshRenderer>(gameObject);
            }

            if (meshFilter == null)
            {
                meshFilter = SgtHelper.GetOrAddComponent <MeshFilter>(gameObject);
            }

            SgtHelper.SetEnabled(meshRenderer, true);

            if (meshFilter.sharedMesh != Mesh)
            {
                SgtHelper.BeginStealthSet(meshFilter);
                {
                    meshFilter.sharedMesh = Mesh;
                }
                SgtHelper.EndStealthSet();
            }

            UpdateMaterials();

            // Has colliders if it's under max depth
            UpdateCollider(Depth < Terrain.MaxColliderDepth);
        }
    }