public override void OnGui (bool aisClicabled)
{
GUI.Box (new Rect (rect.x - 4, rect.y - 4, rect.width + 10, rect.height + 8), "");
//int scrl_index = (int)(invScroller.y / lineHeight);
//int on_scr = (int)(rect.height / lineHeight);
//GUI.Label (new Rect (10, 10, 800, 20), "selectIndex=" + selectIndex + " scrl_index=" + scrl_index + " on_scr=" + on_scr);
GUIStyle style = new GUIStyle
{
fontSize = fontSize,
font = GuiProcessor.getI.rusfont,
normal = {textColor = Color.white},
richText = true,
alignment = TextAnchor.MiddleLeft
};
invScroller = GUI.BeginScrollView (rect, invScroller, new Rect (rect.x, rect.y, rect.width - 18, items.Count * lineHeight + 20f), false, false);
for (int i=0; i<items.Count; i++) {
ItemBase obj = items [i];
float px = rect.x + 5;
float py = rect.y + 5 + i * lineHeight;
GUI.DrawTextureWithTexCoords(new Rect(px, py, rect.width - 18, lineHeight), GuiProcessor.getI.WLBLine,
selectIndex == i ? new Rect(0, 0, 1f, .5f) : new Rect(0, .5f, 1f, .5f), true);
float textDt = 0;
if (obj.ToImage () != null) {
Texture tex = obj.ToImage ().texture;
float scaleKf = lineHeight / tex.height;
float idx = tex.width * scaleKf;
float idy = tex.height * scaleKf;
GUI.DrawTexture (new Rect (px + 8, py, idx, idy), tex, ScaleMode.StretchToFill);
textDt = textDt + idx + 5;
}
GUI.Label (new Rect (px + 8 + textDt, py, rect.width - 15, lineHeight), obj.ToString (), style);
if (GUI.RepeatButton (new Rect (px, py, rect.width - 10, lineHeight), "", GUIStyle.none)) {
if (selectIndex != i) {
//New item click
selectIndex = i;
//SoundMgr.getI.PlaySample2D ("human_move_2.wav");
}
}
}
GUI.EndScrollView ();
//Обработка нажатий клавишь и прочее управление
if (Environment.TickCount - keyWaitMs > waitTime) {
if (Input.GetKey (KeyCode.DownArrow)) {
if (selectIndex < items.Count - 1) {
selectIndex++;
keyWaitMs = Environment.TickCount;
updateScroller ();
}
}
if (Input.GetKey (KeyCode.UpArrow)) {
if (selectIndex > 0) {
selectIndex--;
keyWaitMs = Environment.TickCount;
updateScroller ();
}
}
}
base.OnGui (aisClicabled);
}
..........................................
public void updateScroller ()
{
int scrl_index = (int)(invScroller.y / lineHeight);
int on_scr = (int)(rect.height / lineHeight);
if (selectIndex >= items.Count) {
selectIndex = items.Count - 1;
}
if (selectIndex > scrl_index + on_scr) {
invScroller.y = selectIndex * lineHeight - on_scr * lineHeight;
invScroller.y += 20f;
} else {
if (selectIndex <= scrl_index) {
invScroller.y = selectIndex * lineHeight;
if (invScroller.y < 0)
invScroller.y = 0;
}
}
}
public int selectIndex {
get {
return FselectIndex;
}
set {
int oldsi = FselectIndex;
FselectIndex = value;
if (FselectIndex != oldsi) {
itemChange();
}
}
}
public void itemChange ()
{
if (onItemChange == null) return;
if (items.Count > 0) {
onItemChange (this, items [FselectIndex]);
}
}