Beispiel #1
0
    /// <summary>
    /// Checks biome at terrain uv position and spawns different terrain if needed
    /// </summary>
    public void CheckBiome()
    {
        // determine which mask cam to check based on masterDecalTag
        if (!Physics.Raycast(tp.maskPainterCams[(int)MaskNames.Master].transform.position + uvPos, Vector3.forward, out var hitMaster))
        {
            return;
        }

        Vector3 checkMaskCamPos;

        if (hitMaster.collider.CompareTag(MaskNames.Red.ToString()))
        {
            checkMaskCamPos = tp.maskPainterCams[(int)MaskNames.Red].transform.position;
        }
        else if (hitMaster.collider.CompareTag(MaskNames.Green.ToString()))
        {
            checkMaskCamPos = tp.maskPainterCams[(int)MaskNames.Green].transform.position;
        }
        else
        {
            checkMaskCamPos = tp.maskPainterCams[(int)MaskNames.Blue].transform.position;
        }

        // check mask cam for mask cam decal tag and send to terrain select
        if (!Physics.Raycast(checkMaskCamPos + uvPos, Vector3.forward, out var hitMask))
        {
            return;
        }

        // selects new terrain and adds terrain behaviour data
        GameObject selectedTerrain = ts.SelectedTerrain(hitMaster.collider.tag, hitMask.collider.tag, isUp);

        // check if same terrain
        if (hitMaster.collider.CompareTag(masterDecalTag) && hitMask.collider.CompareTag(maskDecalTag))
        {
            return;
        }
        //Debug.Log("<b>Old Master:</b> " + masterDecalTag + "<b> New Master:</b> " + hitMaster.collider.tag + " <b>Old Mask:</b> " + maskDecalTag + " <b>New Mask:</b> " + hitMask.collider.tag + " <b>Old Terrain:</b> " + transform.parent.name + " <b>New Terrain:</b> " + selectedTerrain.name);

        // spawn new terrain
        var        pos            = transform;
        GameObject spawnedTerrain = Instantiate(selectedTerrain, pos.position, pos.rotation, planet);

        spawnedTerrain.GetComponentInChildren <TerrainBehaviour>().SetTerrainValues(hitMaster.collider.tag, hitMask.collider.tag, uvPos);

        //print("<b>GameObject: </b>" + gameObject.name + " <b>Parent: </b>" + spawnedTerrain.transform.parent.name);
        //Debug.Log("<b>Old Master:</b> " + masterDecalTag + "<b> New Master:</b> " + hitMaster.collider.tag + " <b>Old Mask:</b> " + maskDecalTag + " <b>New Mask:</b> " + hitMask.collider.tag + " <b>Old Terrain:</b> " + gameObject.name + " <b>New Terrain:</b> " + selectedTerrain.name);

        // destroy old (parent)
        Destroy(gameObject.transform.parent.gameObject);
    }
Beispiel #2
0
    /// <summary>
    /// Determine the terrain to spawn based on terrain tool selected and biome hit
    /// </summary>
    /// <param name="cursorRay">The position of the hit</param>
    private void DetermineTerrain(Ray cursorRay)
    {
        if (terrainToolSelected == TerrainTools.Erase)
        {
            selectedTerrain = terrainEraser;
            SpawnTerrainEraser(cursorRay);
        }
        else
        {
            // Get UV pos
            Vector3 uvWorldPosition = Vector3.zero;
            if (!HitTestUVPosition(cursorRay, ref uvWorldPosition, maskPainterCams[(int)MaskNames.Master]))
            {
                return;
            }

            // determine which mask cam to check based on masterDecalTag
            if (!Physics.Raycast(maskPainterCams[(int)MaskNames.Master].transform.position + uvWorldPosition, Vector3.forward, out var hitMaster))
            {
                return;
            }

            Vector3 checkMaskCamPos;
            if (hitMaster.collider.CompareTag(MaskNames.Red.ToString()))
            {
                checkMaskCamPos = maskPainterCams[(int)MaskNames.Red].transform.position;
            }
            else if (hitMaster.collider.CompareTag(MaskNames.Green.ToString()))
            {
                checkMaskCamPos = maskPainterCams[(int)MaskNames.Green].transform.position;
            }
            else
            {
                checkMaskCamPos = maskPainterCams[(int)MaskNames.Blue].transform.position;
            }

            // check mask cam for mask cam decal tag and send to terrain select
            if (!Physics.Raycast(checkMaskCamPos + uvWorldPosition, Vector3.forward, out var hitMask))
            {
                return;
            }

            switch (terrainToolSelected)
            {
            case TerrainTools.Plants:
                selectedTerrain = ts.SelectedTerrain(hitMaster.collider.tag, hitMask.collider.tag, false);
                break;

            case TerrainTools.Up:
                selectedTerrain = ts.SelectedTerrain(hitMaster.collider.tag, hitMask.collider.tag, true);
                break;
            }

            //Debug.Log("<b>Master:</b> " + hitMaster.collider.tag + " <b>Mask:</b> " + hitMask.collider.tag + " <b>Terrain:</b> " + selectedTerrain.name);

            SpawnTerrainOnPlanet(cursorRay, hitMaster.collider.tag, hitMask.collider.tag, uvWorldPosition);
        }

        // choose terrain audio
        placementAudio.ChooseTerrainAudio(selectedTerrain);
    }