using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cyber.Util;
namespace Cyber.Util {
///
/// Applies a texture to a specificed material containing specified text.
///
public class TextTextureApplier : MonoBehaviour {
///
/// The text and related properties that defines the texture that
/// will be applied.
///
public TextTextureProperties TextProperties = new TextTextureProperties("");
///
/// The mesh that has the material that should use this texture.
///
public MeshRenderer Mesh;
///
/// The index of the material that should use this texture.
///
public int MaterialIndex = 0;
///
/// Whether the Emissive or Albedo map is set.
///
public bool Emissive = true;
///
/// The brightness of the texture if this is .
///
public float Brightness = 1f;
private Material Material;
private bool Dirty = true;
///
/// Sets the text properties.
///
/// Properties.
public void SetTextProperties(TextTextureProperties Props) {
TextProperties = Props;
Dirty = true;
}
private void Start() {
Material = Mesh.materials[MaterialIndex];
}
private void Update() {
Texture2D Tex;
if (Dirty && (Tex = TextTextureRenderer.GetText(TextProperties)) != null) {
if (Emissive) {
Material.SetTexture("_EmissionMap", Tex);
Material.SetColor("_EmissionColor",
new Color(Brightness, Brightness, Brightness));
} else {
Material.SetTexture("_MainTex", Tex);
}
Dirty = false;
}
}
}
}