Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        currentHealthPoints = maxHealthPoints;
        terrainControl      = FindObjectOfType <TerrainControl>();
        EnviromentTile[] Tiles = FindObjectsOfType <EnviromentTile>();
        foreach (EnviromentTile tile in Tiles)
        {
            if (tile.ObjectHeld == this.gameObject)
            {
                TileOn = tile;
            }
        }


        loseScreen = FindObjectOfType <LoseScreen>();
        winScreen  = FindObjectOfType <WinScreen>();
        if (loseScreen != null)
        {
            loseScreen.gameObject.SetActive(false);
        }
        if (winScreen != null)
        {
            winScreen.gameObject.SetActive(false);
        }
    }
Esempio n. 2
0
 // awake needs to be used in order to be called as soon as instantiated
 void Awake()
 {
     aiCharacterControl  = GetComponent <AICharacterControl>();
     terrainControl      = FindObjectOfType <TerrainControl>();
     currentHealthPoints = maxHealthPoints;
     m_Rigidbody         = GetComponent <Rigidbody>();
     MaxMoveDistance     = initialMaxMoveDistance;
     MaxAttackDistance   = initialMaxAttackDistance;
     AttackDamageMin     = initAttackDamageMin;
     AttackDamageMax     = initAttackDamageMax;
     CurrentCommbatState = CombatType.OutOfCombat;
 }
Esempio n. 3
0
 private void OnEnable()
 {
     TerrainControl.activeTerrainControl = this;
     this.quitting = false;
     if (!this.running)
     {
         this.running = true;
         this.BindTerrainSettings();
     }
     if (this.reassignTerrainDataInterval > 0f)
     {
         base.Invoke("ReassignTerrainData", this.reassignTerrainDataInterval);
     }
 }
Esempio n. 4
0
    private void Start()
    {
        terrainControl = FindObjectOfType <TerrainControl>();
        int        layerMask = 1 << (int)Layer.LevelTerrain;
        RaycastHit hit;
        bool       hasHit = Physics.Raycast(transform.position + Vector3.up, Vector3.down, out hit, 3f, layerMask);

        if (hasHit)
        {
            TileOn = hit.transform.GetComponent <EnviromentTile>();
        }
        else
        {
            Debug.LogWarning("Spawner not over an enviroment tile");
        }
    }
    // Use this for initialization
    void Start()
    {
        //currentHealthPoints = maxHealthPoints;
        cardObject     = GetComponent <CardObject>();
        terrainControl = FindObjectOfType <TerrainControl>();


        loseScreen = FindObjectOfType <LoseScreen>();
        winScreen  = FindObjectOfType <WinScreen>();
        if (loseScreen != null)
        {
            loseScreen.gameObject.SetActive(false);
        }
        if (winScreen != null)
        {
            winScreen.gameObject.SetActive(false);
        }
    }
    public static MeshInfo CreateMesh(TerrainControl terrainControl)
    {
        //width and height are the same size since we use an assigned mapSize
        int size = terrainControl.mapData.GetLength(0);

        MeshInfo meshInfo = new MeshInfo(size);

        int numVertices  = 0;
        int numTriangles = 0;

        for (int y = 0; y < size; y++)
        {
            for (int x = 0; x < size; x++)
            {
                meshInfo.vertices[numVertices] = new Vector3(x, terrainControl.meshHeightCurve.Evaluate(terrainControl.mapData[x, y]) * terrainControl.meshHeightMultiplier, -y);
                meshInfo.uvs[numVertices]      = new Vector2(x / size, y / size);

                if (x < size - 1 && y < size - 1)
                {
                    meshInfo.triangles[numTriangles] = numVertices;
                    numTriangles++;
                    meshInfo.triangles[numTriangles] = numVertices + size + 1;
                    numTriangles++;
                    meshInfo.triangles[numTriangles] = numVertices + size;
                    numTriangles++;
                    meshInfo.triangles[numTriangles] = numVertices + size + 1;
                    numTriangles++;
                    meshInfo.triangles[numTriangles] = numVertices;
                    numTriangles++;
                    meshInfo.triangles[numTriangles] = numVertices + 1;
                    numTriangles++;
                }
                numVertices++;
            }
        }

        return(meshInfo);
    }
Esempio n. 7
0
 public static void reassign_nocopy(ref ConsoleSystem.Arg arg)
 {
     TerrainControl.ter_reassign_nocopy();
 }
Esempio n. 8
0
 public static void mat(ref ConsoleSystem.Arg arg)
 {
     TerrainControl.ter_mat();
 }
Esempio n. 9
0
 public static void flushtrees(ref ConsoleSystem.Arg arg)
 {
     TerrainControl.ter_flushtrees();
 }
    public static float[,] NoiseMap(int mapSize, TerrainControl terrainControl)
    {
        float[,] noiseMap = new float[mapSize, mapSize];

        float amplitude, frequency, height, targetX, targetY, noiseValue;

        //give values one that will be changed in if statement
        float maxHeight = 0f;
        float minHeight = 1f;

        //for every position
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                //reset variables to default values
                amplitude = 1f;
                frequency = 1;
                height    = 0;

                //do for every octave
                for (int i = 0; i < terrainControl.octaves; i++)
                {
                    targetX = x / terrainControl.noiseScale * frequency;
                    targetY = y / terrainControl.noiseScale * frequency;

                    noiseValue = Mathf.PerlinNoise(targetX + terrainControl.seed, targetY + terrainControl.seed);
                    height    += noiseValue * amplitude;

                    amplitude *= terrainControl.GetPersistance();
                    frequency *= terrainControl.GetLacunarity();
                }

                if (height > maxHeight)
                {
                    maxHeight = height;
                }
                else if (height < minHeight)
                {
                    minHeight = height;
                }

                //assign this value so we can use it in our lerp function
                //noiseMap[x, y] = Mathf.InverseLerp(minHeight, maxHeight, height);
                noiseMap[x, y] = height;
            }
        }

        //this has to be done seperately since the min and max height can change
        //doing noiseMap[x, y] = Mathf.InverseLerp(minHeight, maxHeight, height);
        //in main loop causes aborations around edges
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                noiseMap[x, y] = Mathf.InverseLerp(minHeight, maxHeight, noiseMap[x, y]);
            }
        }

        return(noiseMap);
    }
Esempio n. 11
0
 private void OnEnable()
 {
     TerrainControl.activeTerrainControl = this;
     this.quitting = false;
     if (!this.running)
     {
         this.running = true;
         this.BindTerrainSettings();
     }
     if (this.reassignTerrainDataInterval > 0f)
     {
         base.Invoke("ReassignTerrainData", this.reassignTerrainDataInterval);
     }
 }
    public void AddObjects(bool redo, TerrainControl terrainControl)
    {
        //we want to delete the previously placed trees when generating new ones
        if (redo == true)
        {
            for (int i = 0; i < objectList.Count; i++)
            {
                DestroyImmediate(objectList[i]);
                //DestroyObject(objectList[i]);
            }
            objectList.Clear();
            redo           = false;
            currentObjects = 0;
        }

        //make sure beginheight is always less than end height so it doesnt crash
        if (beginheight >= endheight)
        {
            beginheight = endheight - 0.1f;
        }

        while (currentObjects < numberOfObjects)
        {
            // generate random x position
            int posx = Random.Range(0, 0 + terrainControl.mapSize);
            // generate random z position
            int posz = Random.Range(0, 0 + terrainControl.mapSize);

            float height = terrainControl.mapData[posx, posz];

            // get the terrain height at the random position
            float posy = terrainControl.meshHeightCurve.Evaluate(height) * terrainControl.meshHeightMultiplier;

            posx *= 5; posy *= 5; posz *= 5;

            Collider[] intersecting = Physics.OverlapSphere(new Vector3(posx, posy, -posz), 1.5f);

            //want to check whether or not there is already a game object placed at that location
            if (intersecting.Length == 0)
            {
                if (posy / 5 >= beginheight && posy / 5 <= endheight && currentObjects < numberOfObjects)
                {
                    // create new gameObject on random position
                    GameObject newObject = (GameObject)Instantiate(Obj, new Vector3(posx, posy + 1, -posz), Quaternion.Euler(new Vector3(0, Random.Range(0, 360), 0)));
                    newObject.transform.localScale = new Vector3(2.0f, 2.0f, 2.0f);
                    objectList.Add(newObject);
                    currentObjects += 1;
                }
            }
        }

        //add a mesh collider to each object, since these prefabs are several parts we need to assign the mesh collider to the Box001 mesh
        foreach (var gameObj in FindObjectsOfType(typeof(GameObject)) as GameObject[])
        {
            if (gameObj.name == "Box001")
            {
                gameObj.AddComponent(typeof(MeshCollider));
            }
        }

        //set all objects parent to mesh "easier for looking at at moving all at the same time"
        for (int i = 0; i < objectList.Count; i++)
        {
            //GameObject.Find("Box001").AddComponent(typeof(MeshCollider));
            objectList[i].transform.SetParent(GameObject.FindWithTag("TerrainMesh").transform);
        }
    }
    public void AddObjects(bool redo, TerrainControl terrainControl)
    {
        //we want to delete the previously placed trees when generating new ones
        if (redo == true)
        {
            for (int i = 0; i < objectList.Count; i++)
            {
                DestroyImmediate(objectList[i]);
                //DestroyObject(objectList[i]);
            }
            objectList.Clear();
            redo           = false;
            currentObjects = 0;
        }

        //make sure beginheight is always less than end height so it doesnt crash
        if (beginheight >= endheight)
        {
            beginheight = endheight - 0.1f;
        }

        //loops through every vertice on the map

        /*for (int y = 0; y < mapSize; y++)
         * {
         *  for (int x = 0; x < mapSize; x++)
         *  {
         *      rand = Random.Range(0, 1000);
         *      float height = heightmap[x, y];
         *
         *      if (rand > 980)
         *      {
         *          if (height >= darkGrass && height <= stone)
         *          {
         *              ObjTrans.SetPositionAndRotation(new Vector3(x, heightCurve.Evaluate(height) * heightMultiplier, -y), new Quaternion(0, 0, 0, 0));
         *              objectList.Add(Instantiate(Obj, ObjTrans.transform.position, ObjTrans.transform.rotation));
         *          }
         *      }
         *      if (rand > 995)
         *      {
         *          if (height >= grass && height <= darkGrass)
         *          {
         *              ObjTrans.SetPositionAndRotation(new Vector3(x, heightCurve.Evaluate(height) * heightMultiplier, -y), new Quaternion(0, 0, 0, 0));
         *              objectList.Add(Instantiate(Obj, ObjTrans.transform.position, ObjTrans.transform.rotation));
         *          }
         *      }
         *  }
         * }*/

        while (currentObjects < numberOfObjects)
        {
            // generate random x position
            int posx = Random.Range(0, 0 + terrainControl.mapSize);
            // generate random z position
            int posz = Random.Range(0, 0 + terrainControl.mapSize);

            int objType = Random.Range(0, Obj.Count());

            float height = terrainControl.mapData[posx, posz];

            // get the terrain height at the random position
            float posy = terrainControl.meshHeightCurve.Evaluate(height) * terrainControl.meshHeightMultiplier;

            randScale = Random.Range(3, 5);

            posx *= 5; posy *= 5; posz *= 5;

            Collider[] intersecting = Physics.OverlapSphere(new Vector3(posx, posy, -posz), 0.5f);


            //want to check whether or not there is already a game object placed at that location
            if (intersecting.Length == 0)
            {
                if (posy / 5 >= beginheight && posy / 5 <= endheight && currentObjects < numberOfObjects)
                {
                    // create new gameObject on random position
                    GameObject newObject = (GameObject)Instantiate(Obj[objType], new Vector3(posx, posy, -posz), Quaternion.identity);
                    newObject.AddComponent(typeof(MeshCollider));
                    newObject.transform.localScale = new Vector3(randScale / 2, randScale / 2, randScale / 2);
                    objectList.Add(newObject);
                    currentObjects += 1;
                }
            }
        }

        //set all objects parent to mesh "easier for looking at at moving all at the same time"
        for (int i = 0; i < objectList.Count; i++)
        {
            objectList[i].transform.SetParent(GameObject.FindWithTag("TerrainMesh").transform);
        }
    }