using System;

namespace Cryville.Crtr.Components {
	public abstract class MeshBase : SkinComponent {
		public MeshBase() {
			SubmitProperty("zindex", new PropOp.Integer(v => ZIndex = (short)v));
		}

		protected MeshWrapper mesh = new MeshWrapper();

		short _zindex;
		public short ZIndex {
			get {
				return _zindex;
			}
			set {
				if (value < 0 || value > 5000)
					throw new ArgumentOutOfRangeException("value", "Z-index must be in [0..5000]");
				_zindex = value;
				UpdateZIndex();
			}
		}
		protected void UpdateZIndex() {
			if (!mesh.Initialized) return;
			foreach (var mat in mesh.Renderer.materials) {
				mat.renderQueue = _zindex;
			}
		}
	}
}
