Синтаксис:
Используется csharp
using System;
using System.Collections.Generic;
public class DelegateList<T> {
private List<T> list = new List<T>();
//Индексатор
public T this[int i]
{
get {return (T)list[i];}
set {list[i] = value;}
}
//Добавить сциль
public T Add
{
set {
T type;
list.Add(type);
list[list.Count - 1] = value;
}
}
//Удалить сциль
public T Remove
{
set { list.Remove(value);}
}
//Количество сцилей в списке.
public int Count
{
get { return list.Count;}
}
}
using System.Collections.Generic;
public class DelegateList<T> {
private List<T> list = new List<T>();
//Индексатор
public T this[int i]
{
get {return (T)list[i];}
set {list[i] = value;}
}
//Добавить сциль
public T Add
{
set {
T type;
list.Add(type);
list[list.Count - 1] = value;
}
}
//Удалить сциль
public T Remove
{
set { list.Remove(value);}
}
//Количество сцилей в списке.
public int Count
{
get { return list.Count;}
}
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class UserInterface : ScriptableObject
{
//Обявление делегата
private delegate void Connector();
//Список для хранения делегатов с определенной подписью
DelegateList<Connector> test = null;
//Базовое окно
GUI.WindowFunction myWindow = null;
private Rect myWindowRect;
private int iterator;
private string[] mass = null;
private int selector;
//Конструктор
public UserInterface(Vector2 windowPosition)
{
iterator = 0;
selector = 0;
test = new DelegateList<Connector>();
myWindow = MyWindow;
myWindowRect = new Rect(windowPosition.x, windowPosition.y, 0, 0);
mass = new string[3] { "qwer", "asdf", "zxcv" };
//Добавляем методы с контентом окна
test.Add = ContentA;
test.Add = ContentB;
test.Add = ContentC;
}
//Просчет нажатия пробела
public void MyUpdate()
{
if(Input.GetKeyUp(KeyCode.Space))
iterator++;
if(iterator > test.Count-1)
iterator = 0;
}
//Рисуем Базовое окно
public void MyGUI()
{
myWindowRect = GUI.Window(0, myWindowRect, myWindow,"Unity3D.ru");
}
//Собсно базовое окно
private void MyWindow(int windowID)
{
GUI.Label(new Rect(5, 15, myWindowRect.width, 30), "press space bar to continue");
test[iterator](); //Делегируем контент
GUI.DragWindow(new Rect(0, 0, 10000, 20));
}
//Контент окна А
private void ContentA()
{
myWindowRect.width = 200;
myWindowRect.height = 100;
GUI.Button(new Rect(5, 50, 100, 30), "Destroy");
}
//Контент окна B
private void ContentB()
{
myWindowRect.width = 200;
myWindowRect.height = 200;
GUI.Label(new Rect(5, 50, 100, 30), "Clones the object ");
GUI.Button(new Rect(5, 70, 130, 120),"MyName");
}
//Контент окна C
private void ContentC()
{
selector = GUI.Toolbar(new Rect(5, 50, 190, 240), selector, mass);
myWindowRect.width = 200;
myWindowRect.height = 300;
}
}
using System.Collections;
public class UserInterface : ScriptableObject
{
//Обявление делегата
private delegate void Connector();
//Список для хранения делегатов с определенной подписью
DelegateList<Connector> test = null;
//Базовое окно
GUI.WindowFunction myWindow = null;
private Rect myWindowRect;
private int iterator;
private string[] mass = null;
private int selector;
//Конструктор
public UserInterface(Vector2 windowPosition)
{
iterator = 0;
selector = 0;
test = new DelegateList<Connector>();
myWindow = MyWindow;
myWindowRect = new Rect(windowPosition.x, windowPosition.y, 0, 0);
mass = new string[3] { "qwer", "asdf", "zxcv" };
//Добавляем методы с контентом окна
test.Add = ContentA;
test.Add = ContentB;
test.Add = ContentC;
}
//Просчет нажатия пробела
public void MyUpdate()
{
if(Input.GetKeyUp(KeyCode.Space))
iterator++;
if(iterator > test.Count-1)
iterator = 0;
}
//Рисуем Базовое окно
public void MyGUI()
{
myWindowRect = GUI.Window(0, myWindowRect, myWindow,"Unity3D.ru");
}
//Собсно базовое окно
private void MyWindow(int windowID)
{
GUI.Label(new Rect(5, 15, myWindowRect.width, 30), "press space bar to continue");
test[iterator](); //Делегируем контент
GUI.DragWindow(new Rect(0, 0, 10000, 20));
}
//Контент окна А
private void ContentA()
{
myWindowRect.width = 200;
myWindowRect.height = 100;
GUI.Button(new Rect(5, 50, 100, 30), "Destroy");
}
//Контент окна B
private void ContentB()
{
myWindowRect.width = 200;
myWindowRect.height = 200;
GUI.Label(new Rect(5, 50, 100, 30), "Clones the object ");
GUI.Button(new Rect(5, 70, 130, 120),"MyName");
}
//Контент окна C
private void ContentC()
{
selector = GUI.Toolbar(new Rect(5, 50, 190, 240), selector, mass);
myWindowRect.width = 200;
myWindowRect.height = 300;
}
}
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class MainTest : MonoBehaviour
{
UserInterface userInterface = null;
// Use this for initialization
void Start()
{
userInterface = new UserInterface(new Vector2(50f,50f));
}
void Update()
{
userInterface.MyUpdate();
}
void OnGUI()
{
userInterface.MyGUI();
}
}
using System.Collections;
public class MainTest : MonoBehaviour
{
UserInterface userInterface = null;
// Use this for initialization
void Start()
{
userInterface = new UserInterface(new Vector2(50f,50f));
}
void Update()
{
userInterface.MyUpdate();
}
void OnGUI()
{
userInterface.MyGUI();
}
}
А вот и сама сцена (ИСХОДНИК). Качаем, жмем на плей и лупим по пробелу
http://www.4shared.com/file/emkKYU9O/constTest.html
Надеюсь кому нить это будет полезным.
HTML код для вашего блога :