Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        //transform.localPosition += new Vector3(Random.Range (-30, 30), 0, Random.Range (-30,30));

        save = GameObject.Find ("SaveTracker").GetComponent<SaveSceneComponent>();
        index = Random.Range (0, 65000);
        //transform.localScale = new Vector3(Random.Range(1.5f, 5f), Random.Range (1.5f,5f), Random.Range (1.5f, 5f));
    }
Esempio n. 2
0
    IEnumerator kriejt2()
    {
        //float startTime = Time.realtimeSinceStartup;

        Mesh mesh = MarchingCubes.CreateMesh(m_voxels,0,0);
        if(mesh == null) yield return null;
        if(!bDodane)
        {
            saveScene = GameObject.Find("SaveTracker").GetComponent<SaveSceneComponent>();
            saveScene.save.pos.Add (new Vector3(m_pos.x, m_pos.y, m_pos.z));
        }
        int size = mesh.vertices.Length;

        if(m_normals != null)
        {
            Vector3[] normals = new Vector3[size];
            Vector3[] verts = mesh.vertices;

            //Each verts in the mesh generated is its position in the voxel array
            //and you can use this to find what the normal at this position.
            //The verts are not at whole numbers though so you need to use trilinear interpolation
            //to find the normal for that position

            for(int i = 0; i < size; i++)
                normals[i] = TriLinearInterpNormal(verts[i]);

            mesh.normals = normals;
        }
        else
        {
            mesh.RecalculateNormals();
        }

        //	Color[] control = new Color[size];
        //	Vector3[] meshNormals = mesh.normals;

        /*for(int i = 0; i < size; i++)
        {
            //This creates a control map used to texture the mesh based on the slope
            //of the vert. Its very basic and if you modify how this works yoou will
            //you will probably need to modify the shader as well.
            float dpUp = Vector3.Dot(meshNormals[i], Vector3.up);

            //Red channel is the sand on flat areas
            float R = (Mathf.Max(0.0f, dpUp) < 0.8f) ? 0.0f : 1.0f;
            //Green channel is the gravel on the sloped areas
            float G = Mathf.Pow(Mathf.Abs(dpUp), 2.0f);

            //Whats left end up being the rock face on the vertical areas

            control[i] = new Color(R,G,0,0);
        }

        //May as well store in colors
        mesh.colors = control;
        */
        m_mesh = GameObject.Instantiate (GameObject.Find ("TerrainGenerator").GetComponent<GenerateTerrain>().voxelPrefab) as GameObject;
        m_mesh.name = "Voxel Mesh " + m_pos.x.ToString() + " " + m_pos.y.ToString() + " " + m_pos.z.ToString();

        //	m_mesh.AddComponent<ChunkData>();
        m_mesh.GetComponent<ChunkData>().m_pos = m_pos;
        m_mesh.GetComponent<ChunkData>().bDodane = bDodane;
        m_mesh.transform.parent = GameObject.Find ("Terrain").transform;
        //	m_mesh.AddComponent<MeshFilter>();
        //	m_mesh.AddComponent<MeshRenderer>();
        //m_mesh.renderer.sharedMaterial = mat;
        //	m_mesh.renderer.castShadows = false;
        m_mesh.GetComponent<MeshFilter>().sharedMesh = mesh;
        m_mesh.transform.localPosition = m_pos * 32;
        m_mesh.transform.localScale = new Vector3(32,32,32);
        //	m_mesh.isStatic = true;
        MeshCollider collider = m_mesh.GetComponent<MeshCollider>();
        collider.sharedMesh = mesh;
        yield return new WaitForSeconds(0.001f);
        //Debug.Log("Create mesh time = " + (Time.realtimeSinceStartup-startTime).ToString() );
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        cam = GameObject.Find ("CameraG").GetComponent<Camera>();
        save = GameObject.Find ("SaveTracker").GetComponent<SaveSceneComponent>();
        if(!bLoaded)
        {
            tooltip.rand = Random.Range (0, 65000);

            if(!transform.parent.GetComponent<Tooltip>())
            {
                //Debug.Log ("Farm: " + tooltip.house1Availability);
                GameObject.Find ("PlayerWorld").GetComponent<PlayerData>().numberOfChatkiParent++;
                transform.name = "Chatka parent" + GameObject.Find ("PlayerWorld").GetComponent<PlayerData>().numberOfChatkiParent;
                tooltip.name = transform.name;
                tooltip.parent = GameObject.Find ("PlayerWorld").GetComponent<PlayerData>().numberOfChatkiParent;
                StartCoroutine (Test ());

            }
            StartCoroutine (CheckTooltip ());
        }
        else
        {
            transform.name = tooltip.name;
        }

        player = GameObject.Find ("PlayerWorld").GetComponent<PlayerControllerWorld>();
        playerData = GameObject.Find ("PlayerWorld").GetComponent<PlayerData>();
    }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     player = GameObject.Find ("PlayerWorld");
     save = GameObject.Find ("SaveTracker").GetComponent<SaveSceneComponent>();
 }