Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.L) && islocked == false)
        {
            islocked         = true;
            Cursor.lockState = CursorLockMode.Locked;
        }
        else if (Input.GetKey(KeyCode.L) && islocked)
        {
            islocked         = false;
            Cursor.lockState = CursorLockMode.None;
        }


        RaycastHit hit;

        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

        if (VoxelTerrainEngine.RaycastVoxels(ray, out hit, 100, mask))
        {
            block.transform.position = hit.point;
            if (Input.GetButton("Fire1"))
            {
            }
            if (Input.GetButton("Fire2"))
            {
            }
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        cam    = Camera.main;
        player = Camera.main.transform;
        if (m_Terrain == null)
        {
            m_Terrain = GameObject.FindObjectOfType <VoxelTerrainEngine>();
        }
        thispos = new Vector3(transform.position.x + (m_Terrain.m_voxelWidth / 2)
                              , transform.position.y + (m_Terrain.m_voxelHeight / 2), transform.position.z
                              + (m_Terrain.m_voxelWidth / 2));

        UnityEngine.Random.seed = m_Terrain.m_surfaceSeed;
        //Fill arrays with grass and trees from terrain engine
        if (maxTrees == 0)
        {
            maxTrees = m_Terrain.MaxTrees;

            maxGrass = m_Terrain.MaxGrass;

            Grass = m_Terrain.Grass;

            Trees = m_Terrain.Trees;

            GrassWeights = m_Terrain.GrassWeights;

            TreesWeights = m_Terrain.TreesWeights;
        }
        int g = Grass.Length;

        for (int t = 0; t < GrassWeights.Length; t++)
        {
            totalweights += GrassWeights[t];
        }

        if (mesh == null)
        {
            mesh = new Mesh[g];

            material = new Material[g];

            for (int i = 0; i < g; i++)
            {
                mesh[i] = Grass[i].GetComponent <MeshFilter>().mesh;

                material[i] = Grass[i].GetComponent <MeshRenderer>().material;
            }
        }
        StartCoroutine(spawnstuff());
    }
 public void OnDrawGizmos()
 {
     if (UnityEditor.EditorApplication.isPlaying == false)
     {
         Engine.playMode = EditorPlay.isEditor;
     }
     if (Engine != null && Engine.playMode == EditorPlay.isEditor)
     {
         Engine.UpdateTerrain();
     }
     if (Engine == null)
     {
         Engine = GetComponent <VoxelTerrainEngine>();
     }
 }
Example #4
0
    // Use this for initialization
    void Start()
    {
        cam = Camera.main;
        if (m_Terrain == null)
        {
            m_Terrain = GameObject.FindObjectOfType <VoxelTerrainEngine>();
        }


        //Fill arrays with grass and trees from terrain engine
        if (maxTrees == 0)
        {
            maxTrees = m_Terrain.MaxTrees;

            maxGrass = m_Terrain.MaxGrass;

            Grass = m_Terrain.Grass;

            Trees = m_Terrain.Trees;

            GrassWeights = m_Terrain.GrassWeights;

            //TreesWeights= m_Terrain.TreesWeights;
        }
        int g = Grass.Length;

        for (int t = 0; t < GrassWeights.Length; t++)
        {
            totalweights += GrassWeights[t];
        }

        if (mesh == null)
        {
            mesh = new Mesh[g];

            material = new Material[g];

            for (int i = 0; i < g; i++)
            {
                mesh[i] = Grass[i].GetComponent <MeshFilter>().mesh;

                material[i] = Grass[i].GetComponent <MeshRenderer>().material;
            }
        }
        StartCoroutine(spawnstuff());
    }
    // Update is called once per frame
    void Start()
    {
        if (engine == null)
        {
            engine = GetComponent <VoxelTerrainEngine>();
        }

        Transform[] gamos = GetComponentsInChildren <Transform>();
        for (int i = 0; i < gamos.Length; i++)
        {
            if (gamos[i] != transform)
            {
                DestroyImmediate(gamos[i].gameObject);
            }
        }
        engine.Initialize();

        Debug.Log("Entered Playmode");
    }