Skip to content

Commit

Permalink
updated home window with versions + script updates
Browse files Browse the repository at this point in the history
  • Loading branch information
saszer committed May 18, 2022
1 parent da295fa commit aa2f9e0
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 27 deletions.
27 changes: 25 additions & 2 deletions Editor/NFTPortSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.IO;
using UnityEngine;
using UnityEditor;
using Newtonsoft.Json;
Expand All @@ -16,6 +17,7 @@ public class NFTPortSettings : EditorWindow

protected static Type WindowType = typeof(NFTPortSettings);
private static bool windowopen = false;
PkgJson releasedPkgJson = null;
[MenuItem("NFTPort/Home")]
public static void ShowWindow()
{
Expand Down Expand Up @@ -82,6 +84,27 @@ void OnGUI()
{
EditorGUILayout.LabelField(" Welcome " + userModel.profile.name);
}

EditorGUILayout.LabelField("");

GuiLine();
GUILayout.BeginHorizontal("box");
EditorGUILayout.LabelField("installed version: " + PkgInfo.GetPackageVer());

var ls = LatestRel.Initialize();
if (ls != null)
{
ls.OnComplete(pkg => releasedPkgJson = pkg);
ls.Run();
}

if (releasedPkgJson != null)
{
EditorGUILayout.LabelField("Latest release version: " + releasedPkgJson.version);
}

GUILayout.EndHorizontal();

}

void OnEnable()
Expand Down Expand Up @@ -118,8 +141,8 @@ static void ShowHomeWindow()
}
static void SetSize(NFTPortSettings win)
{
win.minSize = new Vector2(530, 530);
win.maxSize = new Vector2(530, 530);
win.minSize = new Vector2(530, 590);
win.maxSize = new Vector2(530, 590);
}

static void GuiLine( int i_height = 1 )
Expand Down
27 changes: 27 additions & 0 deletions Editor/PkgInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;

namespace NFTPort.Editor
{
////≧◠‿◠≦✌ _sz_ Ω //≧◠‿◠≦✌ _sz_ Ω
public static class PkgInfo
{
public static string GetPackageVer()
{
string path = "Packages/com.nftport.nftport/package.json";
if (File.Exists(path))
{
var targetFile = File.ReadAllText(path);

if (targetFile != null)
{
PkgJson pkgJson = JsonConvert.DeserializeObject<PkgJson>(targetFile);
return pkgJson.version;
}
}
return null;
}
}
}
11 changes: 11 additions & 0 deletions Editor/PkgInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Editor/Storage_UploadMetadata_Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void OnInspectorGUI()
myScript.Stop(false);

if(GUILayout.Button("Save File Locally", GUILayout.Height(25)))
myScript.SaveFileasJson(myScript.metadata, myScript.saveToPath, myScript.fileName);
myScript.SaveFile(myScript.saveToPath, myScript.fileName);

if(GUILayout.Button("View Documentation", GUILayout.Height(25)))
Application.OpenURL(PortConstants.Docs_GettingStarted);
Expand Down
73 changes: 73 additions & 0 deletions Runtime/Internal/LatestRel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Newtonsoft.Json;
using NFTPort.Internal;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;

namespace NFTPort.Editor
{
#if UNITY_EDITOR
public class LatestRel : MonoBehaviour
{
public static bool running = false;
private UnityAction<PkgJson> OnCompleteAction;
////≧◠‿◠≦✌ _sz_ Ω //≧◠‿◠≦✌ _sz_ Ω
public static LatestRel Initialize()
{
if (!running)
{
running = true;
var _this = new GameObject("NFTPort initialise delete this gameobject").AddComponent<LatestRel>();
return _this;
}
return null;
}
public LatestRel OnComplete(UnityAction<PkgJson> action)
{
this.OnCompleteAction = action;
return this;
}

public void Run()
{
StopAllCoroutines();
StartCoroutine(LatestReleaseversion());
StartCoroutine(ForceEnd());
}
IEnumerator ForceEnd()
{
yield return new WaitForSeconds(3f);
End();
}

private UnityWebRequest www;
IEnumerator LatestReleaseversion()
{
string WEB_URL = "https://raw.githubusercontent.com/nftport/nftport-unity/com.nftport.nftport/package.json";
www = UnityWebRequest.Get(WEB_URL);
yield return www.SendWebRequest();

if (www.result != UnityWebRequest.Result.Success) {

}
else
{
PkgJson pkgJson = JsonConvert.DeserializeObject<PkgJson>(www.downloadHandler.text);
if(OnCompleteAction!=null)
OnCompleteAction.Invoke(pkgJson);
}
End();
}

void End()
{
www.Dispose();
running = false;
DestroyImmediate(gameObject);
}
}
#endif
}
11 changes: 11 additions & 0 deletions Runtime/Internal/LatestRel.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Runtime/Internal/PkgJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace NFTPort.Editor
{
[Serializable]
public class PkgJson
{
[Serializable]
public class Author
{
public string name;
public string email;
public string url;
}

public string name;
public string displayName;
public string version;
public string description;
public string type;
public string documentationUrl;
public List<string> keywords;
public Author author;
public List<Sample> samples;

[Serializable]
public class Sample
{
public string displayName;
public string description;
public string path;
}
}
}

11 changes: 11 additions & 0 deletions Runtime/Internal/PkgJson.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Runtime/Internal/User_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,18 @@ public User_Settings Run()
WEB_URL = BuildUrl();
StopAllCoroutines();
StartCoroutine(CallAPIProcess());
StartCoroutine(ForceEnd());
}

return this;
}

IEnumerator ForceEnd()
{
yield return new WaitForSeconds(5f);
End();
}

private void OnDestroy()
{
running = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace NFTPort
{
[System.Serializable]
public class MetadataToUpload
public class MetadataToUpload_model
{
[Tooltip("Main NFT File URL, use 'Storage File Upload' to get url")]
public string file_url = "Required Field";
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Runtime/Storage_UploadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Storage_UploadFile : MonoBehaviour
public Storage_model.Storage storageModel;

private UnityAction<string> OnStartedAction;
private UnityAction<float> OnProgressAction;
private UnityAction<int> OnProgressAction;
private UnityAction<string> OnErrorAction;
private UnityAction<Storage_model.Storage> OnCompleteAction;
private bool destroyAtEnd = false;
Expand Down Expand Up @@ -95,7 +95,7 @@ public Storage_UploadFile OnStarted(UnityAction<string> action)
/// Action on File Upload Progress returining Progress percentage
/// </summary>
/// <returns> float uploadProgress .</returns>
public Storage_UploadFile OnProgress(UnityAction<float> action)
public Storage_UploadFile OnProgress(UnityAction<int> action)
{
this.OnProgressAction = action;
return this;
Expand Down
49 changes: 29 additions & 20 deletions Runtime/Storage_UploadMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class Storage_UploadMetadata : MonoBehaviour
{
#region Parameter Defines

public MetadataToUpload metadata;
public MetadataToUpload_model metadata;

[Space(20)]
[ReadOnly]public float uploadProgress = 0;
[ReadOnly]public float uplodedBytes = 0;

[Space(20)] [Header("Use Save file as Json function to save it to defined path")]
public string saveToPath = "Assets/NFTPort/";
public string fileName = "netadata.json";
public string fileName = "metadata.json";

[Space(20)]
//[Header("Called When API call starts")]
Expand All @@ -47,7 +47,7 @@ public class Storage_UploadMetadata : MonoBehaviour
public Storage_model.Storage storageModel;

private UnityAction<string> OnStartedAction;
private UnityAction<float> OnProgressAction;
private UnityAction<int> OnProgressAction;
private UnityAction<string> OnErrorAction;
private UnityAction<Storage_model.Storage> OnCompleteAction;
private bool destroyAtEnd = false;
Expand Down Expand Up @@ -87,7 +87,7 @@ public static Storage_UploadMetadata Initialize(bool destroyAtEnd = true)
/// Set MetaData properties, This will override any values set in metadata in the editor ≧◔◡◔≦ .
/// </summary>
/// <param name="MetadataToUpload"> metadata.</param>
public Storage_UploadMetadata SetMetaData(MetadataToUpload _metadata)
public Storage_UploadMetadata SetMetadata(MetadataToUpload_model _metadata)
{
metadata = _metadata;
return this;
Expand All @@ -105,10 +105,10 @@ public Storage_UploadMetadata OnStarted(UnityAction<string> action)
}

/// <summary>
/// Action on File Upload Progress returining Progress percentage
/// Action on File Upload Progress returning Progress percentage
/// </summary>
/// <returns> float uploadProgress .</returns>
public Storage_UploadMetadata OnProgress(UnityAction<float> action)
public Storage_UploadMetadata OnProgress(UnityAction<int> action)
{
this.OnProgressAction = action;
return this;
Expand Down Expand Up @@ -146,6 +146,9 @@ public void Run()
StartCoroutine(CallAPIProcess());
}

/// <summary>
/// Stop Any In progress calls
/// </summary>
public void Stop(bool destroy)
{
StopAllCoroutines();
Expand All @@ -164,23 +167,29 @@ public void Stop(bool destroy)
/// <summary>
/// Save File as Json locally.
/// </summary>
/// <param name="MetadataToUpload"> of type MetadataToUpload.</param>
/// <param name="saveToPath"> Path to save to as string.</param>
/// <param name="fileName"> FileName as string, include extension, eg: metadata.json.</param>
public void SaveFileasJson(MetadataToUpload metadata, string saveToPath, string fileName)
/// <param name="fileName"> FileName as string</param>
public void SaveFile(string saveToPath, string fileName)
{
string json = JsonConvert.SerializeObject(
metadata,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
});
System.IO.File.WriteAllText(saveToPath + fileName, json);
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
Debug.Log($"File Saved to: " + saveToPath + fileName);
metadata,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
});
System.IO.File.WriteAllText(saveToPath + fileName, json);
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
if(File.Exists(saveToPath+fileName)){
Debug.Log($"File Saved to: " + saveToPath + fileName);
}
else
{
Debug.Log($"Path Not Found: " + saveToPath);
}

}

string BuildUrl()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.nftport.nftport",
"displayName": "NFTPort",
"version": "0.1.1-preview",
"version": "0.2.0-preview",
"description": "NFTPort.xyz unity extension provides tools and features to integrate NFT's crosschain at lightning speed in Unity.\n\n https://github.com/nftport/nftport-unity.git",
"type": "tool",
"documentationUrl": "https://docs.nftport.xyz/docs/nftport",
Expand Down

0 comments on commit aa2f9e0

Please sign in to comment.