Here are the examples of the csharp api UnityEngine.GUI.Button(UnityEngine.Rect, UnityEngine.Texture, UnityEngine.GUIStyle) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
View Source File : CoSimulationDebugger.cs
License : MIT License
Project Creator : Daimler
License : MIT License
Project Creator : Daimler
private void ShowInstructionWindows()
{
GUIStyle guiStyle = new GUIStyle
{
padding = new RectOffset(0, 0, 0, 0)
};
int totalWidth = Screen.width - (int)(sliderOffsetX * 2);
int hierachyLevel = 1;
//To do Check how many are simulatanously active
foreach(InstructionWindow w in instructionWindows)
{
//-----------------Start events--------------------------------------------------------------------
GUI.color = Color.black;
GUI.backgroundColor = Color.black;
//Total height in pixels
int height = 20;
//Total width in pixel
float width = 1f / (float)(this.record.Frames.Count) * (float)totalWidth;
int index = 0;
foreach (int eventIndex in w.Events)
{
//Adjust color depending on event type
MSimulationEvent simEvent = w.RawEvents[index];
GUI.color = Color.black;
GUI.backgroundColor = Color.black;
if (simEvent.Type == mmiConstants.MSimulationEvent_Start)
GUI.color = Color.blue;
if (simEvent.Type == mmiConstants.MSimulationEvent_End)
GUI.color = Color.green;
//To do
Texture2D texture = new Texture2D((int)width, height);
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
texture.SetPixel(x, y, Color.black);
}
float relCoord = (float)eventIndex / (float)this.record.Frames.Count;
if (GUI.Button(new Rect(sliderOffsetX + relCoord * totalWidth - width /2f, Screen.height - 60 - hierachyLevel * 20, width, height), texture, guiStyle))
{
//Display the name of the event
this.sliderValue = eventIndex;
}
index++;
}
//-----------------End events--------------------------------------------------------------------
GUI.color = Color.green;
GUI.backgroundColor = Color.black;
if (currentInstruction != null && currentInstruction.ID == w.Instruction.ID)
{
GUI.backgroundColor = Color.green;
}
float start = (float)w.StartIndex / (float)this.record.Frames.Count;
float end = (float)w.EndIndex / (float)this.record.Frames.Count;
float relativeWidth = end - start;
if(GUI.Button(new Rect(sliderOffsetX + start * totalWidth, Screen.height - 60 - hierachyLevel * 20, relativeWidth * totalWidth, 20 ), w.Instruction.Name))
{
this.sliderValue = w.StartIndex;
}
hierachyLevel++;
}
}
19
View Source File : Button.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
public override void OnGUI()
{
mRect.width = mTexture2D.width;
mRect.height = mTexture2D.height;
if (UnityEngine.GUI.Button(mRect, mTexture2D, GUIStyle.none))
{
QFramework.Log.I("click");
mClickEvent.Invoke();
}
}
19
View Source File : UPADrawer.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
public static void DrawLayerPanel (Rect window) {
style.imagePosition = ImagePosition.ImageAbove;
int from = 0;
int to = 0;
if (CurrentImg == null)
return;
for (int i = 0; i < CurrentImg.layers.Count; i++) {
GUI.backgroundColor = Color.white;
if (i == CurrentImg.selectedLayer) {
GUI.backgroundColor = new Color (0.7f, 0.7f, 0.7f);
}
UPALayer tempLayer = CurrentImg.layers[i];
if (GUI.Button (new Rect (12, window.height - 60 - i * 36, 65, 33), "")) {
CurrentImg.selectedLayer = i;
}
GUI.backgroundColor = Color.white;
GUI.Label (new Rect (15, window.height - 52 - i * 36, 90, 30), tempLayer.name);
bool layerEnabled = tempLayer.enabled;
tempLayer.enabled = GUI.Toggle (new Rect (80, window.height - 61 - i * 36, 15, 15), tempLayer.enabled, "");
if (tempLayer.enabled != layerEnabled)
tempLayer.parentImg.dirty = true;
if (removeLayerIcon == null)
removeLayerIcon = (Texture2D)Resources.Load ("UI/CrossWhite");
if (tempLayer.locked) {
if (GUI.Button (new Rect (80, window.height - 43 - i * 36, 15, 15), Resources.Load("UI/locked") as Texture2D,style)) {
tempLayer.locked = false;
}
} else {
if (GUI.Button (new Rect (80, window.height - 43 - i * 36, 15, 15), Resources.Load("UI/unlocked") as Texture2D,style)) {
tempLayer.locked = true;
}
}
if (i + 1 < CurrentImg.layers.Count) {
if (GUI.Button (new Rect (97, window.height - 60 - i * 36, 22, 16), "+")) {
from = i;
to = i + 1;
}
}
if (i > 0) {
if (GUI.Button (new Rect (97, window.height - 44 - i * 36, 22, 16), "-")) {
from = i;
to = i - 1;
}
}
CurrentImg.layers[i] = tempLayer;
}
if (from != 0 || to != 0) {
CurrentImg.ChangeLayerPosition (from, to);
}
GUIStyle smallButon = new GUIStyle();
smallButon.fontSize = 8;
smallButon.alignment = TextAnchor.MiddleCenter;
smallButon.normal.background = Resources.Load ("Background") as Texture2D;
if (GUI.Button (new Rect (12, window.height - 20, 18, 18), new GUIContent(Resources.Load("UI/add") as Texture, "Add Layer"), smallButon)) {
CurrentImg.AddLayer ();
}
if (CurrentImg.layerCount == 1)
{
GUI.contentColor = new Color(0.7f, 0.7f, 0.7f);
}
if (GUI.Button(new Rect(12 + 20, window.height - 20, 18, 18), new GUIContent(Resources.Load("UI/delete") as Texture, "Delete Layer"), smallButon))
{
if (CurrentImg.layers.Count > 1) {
bool delete = EditorUtility.DisplayDialog(
"Delete Layer",
"Do you want to remove " + CurrentImg.layers[CurrentImg.selectedLayer].name + "?",
"Delete",
"Cancel");
if (delete) {
CurrentImg.RemoveLayerAt(CurrentImg.selectedLayer);
}
}
}
GUI.contentColor = Color.white;
if (GUI.Button(new Rect(12 + 20 * 2, window.height - 20, 18, 18), new GUIContent(Resources.Load("UI/import") as Texture, "Import Image"), smallButon))
{
string path = EditorUtility.OpenFilePanel(
"Find an Image (.jpg | .png)",
"/",
"Image Files;*.jpg;*.png");
if (path.Length != 0) {
// Load Texture from file
Texture2D tex = null;
byte[] fileData;
if (File.Exists(path)) {
fileData = File.ReadAllBytes(path);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
}
// Create a new Image with textures dimensions
CurrentImg.AddLayer();
// Set pixel colors
UPALayer layer = CurrentImg.layers[CurrentImg.layers.Count - 1];
for (int x = 0; x < CurrentImg.width; x++) {
for (int y = 0; y < CurrentImg.height; y++) {
layer.map[x + y * CurrentImg.width] = tex.GetPixel(x, CurrentImg.height - 1 - y);
}
}
layer.LoadTexFromMap();
}
}
if (GUI.Button(new Rect(12 + 20 * 3, window.height - 20, 18, 18), new GUIContent(Resources.Load("UI/duplicate") as Texture, "Duplicate Layer"), smallButon))
{
CurrentImg.layers.Add(new UPALayer(CurrentImg.layers[CurrentImg.selectedLayer]));
}
if (CurrentImg.selectedLayer == 0)
{
GUI.contentColor = new Color(0.7f, 0.7f, 0.7f);
}
if (GUI.Button(new Rect(12 + 20 * 4, window.height - 20, 18, 18), new GUIContent(Resources.Load("UI/merge") as Texture, "Merge Layer Down"), smallButon))
{
if (CurrentImg.selectedLayer > 0)
{
UPALayer upper = CurrentImg.layers[CurrentImg.selectedLayer];
UPALayer lower = CurrentImg.layers[CurrentImg.selectedLayer - 1];
lower.tex = UPABlendModes.Blend(lower.tex, lower.opacity, upper.tex, upper.opacity, upper.mode);
for (int x = 0; x < lower.tex.width; x++)
{
for (int y = 0; y < lower.tex.height; y++)
{
lower.map[x + y * lower.tex.width] = lower.tex.GetPixel(x, lower.tex.height - 1 - y);
}
}
CurrentImg.RemoveLayerAt(CurrentImg.selectedLayer);
}
}
GUI.contentColor = Color.white;
//if (GUI.Button (new Rect (12 + 18 * 4, window.height - 18, 16, 16), Resources.Load("UI/up") as Texture2D, style)) {
// CurrentImg.AddLayer ();
//}
//if (GUI.Button (new Rect (12 + 18 * 5, window.height - 18, 16, 16), Resources.Load("UI/down") as Texture2D, style)) {
// CurrentImg.AddLayer ();
//}
if (GUI.Button(new Rect(12 + 20 * 5, window.height - 20, 18, 18), new GUIContent(Resources.Load("UI/edit") as Texture, "Layer Options"), smallButon))
{
UPALayerSettings.Init(CurrentImg.layers[CurrentImg.selectedLayer]);
}
// Draw layer button tooltips
if (GUI.tooltip != "")
GUI.Box(new Rect(12, window.height - 43, 120, 20), GUI.tooltip);
//CurrentImg.selectedLayer = GUI.Toolbar (new Rect (4, window.height - 200, 90, 30), CurrentImg.selectedLayer, layerNames);
}