Skip to content

Commit

Permalink
feat: Updated home window with hide API option
Browse files Browse the repository at this point in the history
  • Loading branch information
saszer committed Jun 28, 2022
1 parent add3604 commit 9020054
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 54 deletions.
44 changes: 37 additions & 7 deletions Editor/NFTPortSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ static void LatestReleaseCallback(PkgJson pkg)
}
}
}



private bool apiIsPass = true;
void OnGUI()
{
Texture banner = Resources.Load<Texture>("banner");
Expand All @@ -117,19 +118,48 @@ void OnGUI()

GUILayout.BeginHorizontal("box");
var defaultColor = GUI.backgroundColor;
if(APIkeyOk())
GUI.color = UnityEngine.Color.green;

if (myAPIString == PortConstants.DefaultAPIKey)
{
apiIsPass = false;
GUI.color = UnityEngine.Color.cyan;
}
else
{
GUI.color = UnityEngine.Color.red;
if(APIkeyOk())
GUI.color = UnityEngine.Color.green;
else
{
GUI.color = UnityEngine.Color.red;
}
}

if (!apiIsPass)
{
if (GUILayout.Button("hide", GUILayout.Width(42)))
apiIsPass = true;

myAPIString = EditorGUILayout.TextField("APIKEY", myAPIString);
}
myAPIString = EditorGUILayout.TextField("APIKEY", myAPIString);
else
{
if (GUILayout.Button("show", GUILayout.Width(42)))
apiIsPass = false;

myAPIString = EditorGUILayout.PasswordField("APIKEY", myAPIString);
}


GUI.color = defaultColor;
GUILayout.EndHorizontal();


if (GUILayout.Button("Save API Key", GUILayout.Height(25)))
{
SaveChanges();
apiIsPass = true;
}


GuiLine();

Expand Down
52 changes: 6 additions & 46 deletions Editor/ReadmeEditor.cs → Editor/ReadmeEditor_NFTPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,24 @@

namespace NFTPort.Editor
{
[CustomEditor(typeof(Readme))]
[CustomEditor(typeof(Readme_NFTPort))]
[InitializeOnLoad]
public class ReadmeEditor : UnityEditor.Editor {
public class ReadmeEditor_NFTPort : UnityEditor.Editor {

static string kShowedReadmeSessionStateName = "ReadmeEditor.showedReadme";

static float kSpace = 16f;

static ReadmeEditor()
{
EditorApplication.delayCall += SelectReadmeAutomatically;
}

static void SelectReadmeAutomatically()
{
if (!SessionState.GetBool(kShowedReadmeSessionStateName, false ))
{
var readme = SelectReadme();
SessionState.SetBool(kShowedReadmeSessionStateName, true);

if (readme && !readme.loadedLayout)
{
LoadLayout();
readme.loadedLayout = true;
}
}
}


static void LoadLayout()
{
var assembly = typeof(EditorApplication).Assembly;
var windowLayoutType = assembly.GetType("UnityEditor.WindowLayout", true);
var method = windowLayoutType.GetMethod("LoadWindowLayout", BindingFlags.Public | BindingFlags.Static);
method.Invoke(null, new object[]{Path.Combine(Application.dataPath, "TutorialInfo/Layout.wlt"), false});
}

[MenuItem("Tutorial/Show Tutorial Instructions")]
static Readme SelectReadme()
{
var ids = AssetDatabase.FindAssets("Readme t:Readme");
if (ids.Length == 1)
{
var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0]));

Selection.objects = new UnityEngine.Object[]{readmeObject};

return (Readme)readmeObject;
}
else
{
Debug.Log("Couldn't find a readme");
return null;
}
}


protected override void OnHeaderGUI()
{
var readme = (Readme)target;
var readme = (Readme_NFTPort)target;
Init();

var iconWidth = Mathf.Min(EditorGUIUtility.currentViewWidth/3f - 20f, 128f);
Expand All @@ -80,7 +40,7 @@ protected override void OnHeaderGUI()

public override void OnInspectorGUI()
{
var readme = (Readme)target;
var readme = (Readme_NFTPort)target;
Init();

foreach (var section in readme.sections)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Editor/Readme.cs → Editor/Readme_NFTPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace NFTPort.Editor
{
public class Readme : ScriptableObject {
public class Readme_NFTPort : ScriptableObject {
public Texture2D icon;
public string title;
public Section[] sections;
Expand Down
File renamed without changes.

0 comments on commit 9020054

Please sign in to comment.