using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using UnityEditor;
using UnityEngine;
using System.IO;
public class Manager : EditorWindow
{
private static bool red;
[MenuItem("Tools/Manager")]
static void Managers()
{
EditorWindow.GetWindow<Manager>();
Init();
}
private static void Init()
{
red = true;
}
private void OnGUI()
{
GUIContent c = new GUIContent();
var style = new GUIStyle(GUI.skin.button);
if (red)
{
style.normal.textColor = Color.red;
}
else
{
style.normal.textColor = Color.green;
}
style.fontSize = 18;
string[] Paths = new string[2];
string[0] = "testing1";
string[1] = "testing2";
for (int i = 0; i < Paths.Length; i++)
{
if (Paths[i].Contains("test")) // or .js if you want
{
var x = assetPaths[i].LastIndexOf("/");
var t = assetPaths[i].Substring(x + 1);
GUILayout.Button(t, style, GUILayout.Width(1000), GUILayout.Height(50));
if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
{
OnMouseOver(i);
}
}
}
}
private void OnMouseOver(int buttinIndex)
{
UnityEngine.Debug.LogFormat("OnMouseOver {0}", buttinIndex);
red = !red;
}
}
问题是,当我将鼠标光标移到其中一个按钮上时,它会将所有按钮涂成绿色,然后又变回红色。
我希望当我单击特定按钮或将鼠标光标移至特定按钮颜色上方时,仅此按钮为绿色,而将按钮保留为绿色。
答案 0 :(得分:0)
您应该记录每个按钮使用列表或其他样式的样式。
当前,您的代码导致所有按钮使用相同的样式,因此它们会一起更改。
我提供小费。希望对您有所帮助。
private void OnMouseOver(int buttinIndex)
{
UnityEngine.Debug.LogFormat("OnMouseOver {0}", buttinIndex);
//red = !red;
//try to record style or color flag for each button use index.
}
以及绘制按钮时
GUILayout.Button(t, GetStyleFromList(i), GUILayout.Width(1000), GUILayout.Height(50));