using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.IO;
//Perlin Noise Agents v1.0 - Map Behavior Class
//--Class Controls the enabling and disabling of the Behavioral Map Texture and display--Class is a component of the Map_Geometry Game Object which contains a single mesh quad
//Mode Lab - Written by Luis Quinones
public class MapBehavior : MonoBehaviour {
    public GameObject planeBehavior;
    private Renderer rend;
    public Texture2D texture;
    public Scrollbar toggleImage;
    private bool turnOn;
    private float toggleImageVal;
    public string updatePath;
    public bool runIt;

    void Start () {
        if (runIt) {
            runIt = false;
            turnOn = false;
            planeBehavior.GetComponent<MeshRenderer> ().enabled = false; //Turns off mesh rendered component to keep mesh hidden
            rend = GetComponent<Renderer> ();
            texture = new Texture2D (1024, 768); //Creates a new texture with the specified pixels        
            toggleImage.onValueChanged.AddListener (delegate {
                toggleImageVal = toggleImage.value; //Checks if we changed the scrollbar to display the mesh and texture
            if(updatePath.Length != 0){    
                var bytes = File.ReadAllBytes(updatePath);
                texture.LoadImage(bytes); //Loads image
                rend.material.mainTexture = texture; //Assigns it to instance of material
                turnOn = true; //Turns on the mesh and texture            
    void Update () {
        if (runIt) {
        //turns on and off the mesh based on the display scrollbar value which has a listener attached to it in the start function
        if (Mathf.RoundToInt(toggleImageVal) == 1) {
            planeBehavior.GetComponent<MeshRenderer> ().enabled = true;
            //plane.GetComponent<MeshCollider> ().enabled = true;
        } else {
            planeBehavior.GetComponent<MeshRenderer> ().enabled = false;
            //plane.GetComponent<MeshCollider> ().enabled = false;
  • Share