Пример #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);
        }
    }
    private SgtPatch CreatePatch(string name, Quaternion rotation)
    {
        var pointBL = rotation * new Vector3(-1.0f, -1.0f, 1.0f);
        var pointBR = rotation * new Vector3(1.0f, -1.0f, 1.0f);
        var pointTL = rotation * new Vector3(-1.0f, 1.0f, 1.0f);
        var pointTR = rotation * new Vector3(1.0f, 1.0f, 1.0f);
        var coordBL = new Vector2(1.0f, 0.0f);
        var coordBR = new Vector2(0.0f, 0.0f);
        var coordTL = new Vector2(1.0f, 1.0f);
        var coordTR = new Vector2(0.0f, 1.0f);

        return(SgtPatchBuilder.CreatePatch(name, this, null, pointBL, pointBR, pointTL, pointTR, coordBL, coordBR, coordTL, coordTR, 0));
    }
Пример #3
0
    private void Split()
    {
        if (ChildrenExist == false)
        {
            var PointCC = (PointBL + PointTR) * 0.5f;
            var PointBC = (PointBL + PointBR) * 0.5f;
            var PointTC = (PointTL + PointTR) * 0.5f;
            var PointCL = (PointTL + PointBL) * 0.5f;
            var PointCR = (PointTR + PointBR) * 0.5f;

            var CoordCC = (CoordBL + CoordTR) * 0.5f;
            var CoordBC = (CoordBL + CoordBR) * 0.5f;
            var CoordTC = (CoordTL + CoordTR) * 0.5f;
            var CoordCL = (CoordTL + CoordBL) * 0.5f;
            var CoordCR = (CoordTR + CoordBR) * 0.5f;

            if (ChildBL == null)
            {
                ChildBL = SgtPatchBuilder.CreatePatch("Bottom Left", Terrain, this, PointBL, PointBC, PointCL, PointCC, CoordBL, CoordBC, CoordCL, CoordCC, Depth + 1);
            }
            if (ChildBR == null)
            {
                ChildBR = SgtPatchBuilder.CreatePatch("Bottom Right", Terrain, this, PointBC, PointBR, PointCC, PointCR, CoordBC, CoordBR, CoordCC, CoordCR, Depth + 1);
            }
            if (ChildTL == null)
            {
                ChildTL = SgtPatchBuilder.CreatePatch("Top Left", Terrain, this, PointCL, PointCC, PointTL, PointTC, CoordCL, CoordCC, CoordTL, CoordTC, Depth + 1);
            }
            if (ChildTR == null)
            {
                ChildTR = SgtPatchBuilder.CreatePatch("Top Right", Terrain, this, PointCC, PointCR, PointTC, PointTR, CoordCC, CoordCR, CoordTC, CoordTR, Depth + 1);
            }

            UpdateState();
        }
    }
Пример #4
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);
        }
    }