-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Originer packages window
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Text; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
|
||
namespace Originer.Editor | ||
{ | ||
public class EditorWebRequest | ||
{ | ||
private UnityWebRequest www; | ||
private Action<UnityWebRequest> onComplete; | ||
|
||
//POST | ||
public EditorWebRequest(string url, string postData, Action<UnityWebRequest> onComplete, bool isJson = true) | ||
{ | ||
this.onComplete = onComplete; | ||
www = UnityWebRequest.Post(url, postData); | ||
var uH = new UploadHandlerRaw(Encoding.UTF8.GetBytes(postData)); | ||
www.uploadHandler= uH; | ||
www.SetRequestHeader("Content-Type", "application/json"); | ||
www.SendWebRequest(); | ||
EditorApplication.update += EditorUpdate; | ||
|
||
Debug.Log($"Request POST start\nurl: {www.url}\ndata: {postData}"); | ||
} | ||
|
||
//GET | ||
public EditorWebRequest(string url, Action<UnityWebRequest> onComplete) | ||
{ | ||
this.onComplete = onComplete; | ||
www = UnityWebRequest.Get(url); | ||
www.SendWebRequest(); | ||
EditorApplication.update += EditorUpdate; | ||
} | ||
|
||
void EditorUpdate() | ||
{ | ||
if (!www.isDone) | ||
{ | ||
return; | ||
} | ||
|
||
if(www.isNetworkError | www.isHttpError) | ||
{ | ||
Debug.LogError($"Request error\nurl: {www.url}\nerror: {www.error}"); | ||
} | ||
|
||
Debug.Log($"Request completed\nurl: {www.url}\nresponse: {www.downloadHandler.text}"); | ||
|
||
onComplete?.Invoke(www); | ||
|
||
EditorApplication.update -= EditorUpdate; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "Originer.Editor", | ||
"references": [ | ||
"GUID:a7072912caac232a684608bc94fedf21" | ||
], | ||
"optionalUnityReferences": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
.container { | ||
-unity-position: absolute; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
} | ||
|
||
.mainLayout { | ||
flex-direction: row; | ||
flex-grow: 1; | ||
} | ||
|
||
.flex-row { | ||
flex-direction: row; | ||
} | ||
|
||
.toolbar { | ||
justify-content: flex-end; | ||
} | ||
|
||
#packageList { | ||
} | ||
|
||
#packageInfo { | ||
flex-grow: 1; | ||
padding-right: 10px; | ||
} | ||
|
||
.item { | ||
height: 29px; | ||
width: 300px; | ||
border-bottom-width: 1px; | ||
border-color: #555; | ||
flex-direction: row; | ||
align-items: center; | ||
padding-left: 5px; | ||
} | ||
|
||
.item:hover { | ||
background-color: #aaa; | ||
} | ||
|
||
.item:focus { | ||
background-color: #999; | ||
} | ||
|
||
.item > Label { | ||
font-size: 13; | ||
} | ||
|
||
.border-left { | ||
border-left-width: 1px; | ||
border-color: #555; | ||
} | ||
|
||
.border-right { | ||
border-right-width: 1px; | ||
border-color: #555; | ||
} | ||
|
||
.flatButton { | ||
width: 20; | ||
height: 20; | ||
} | ||
|
||
.flatButton:hover { | ||
background-color: #aaa; | ||
} | ||
|
||
.pager { | ||
justify-content: space-between; | ||
flex-direction: row; | ||
border-bottom-width: 1px; | ||
border-color: #555; | ||
} | ||
|
||
.align-center { | ||
align-items: center; | ||
} | ||
|
||
.bold { | ||
font-style: bold; | ||
} | ||
|
||
.header { | ||
font-size: 15; | ||
} | ||
|
||
.packageInfoContainer { | ||
padding-left: 15px; | ||
padding-top: 10px; | ||
} | ||
|
||
.m-t-5 { | ||
margin-top: 5px; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<UXML xmlns="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements"> | ||
<uie:Template path="Packages/Originer/Editor/Pager.uxml" name="Pager"/> | ||
|
||
<VisualElement class="container"> | ||
|
||
<uie:Toolbar class="toolbar"> | ||
<uie:ToolbarSpacer /> | ||
<uie:ToolbarButton name="searchButton" text="Search" /> | ||
<uie:ToolbarPopupSearchField /> | ||
</uie:Toolbar> | ||
|
||
<VisualElement class="mainLayout"> | ||
<ScrollView class="border-right"> | ||
<Instance template="Pager" name="pagerTop"/> | ||
|
||
<VisualElement name="packageList"> | ||
<Label text="Loading"/> | ||
</VisualElement> | ||
</ScrollView> | ||
|
||
<VisualElement name="packageInfo"> | ||
<Label text="Select package" /> | ||
</VisualElement> | ||
</VisualElement> | ||
</VisualElement> | ||
</UXML> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Linq; | ||
using System; | ||
using System.Runtime.Serialization; | ||
using UnityEngine.Networking; | ||
using UnityEngine; | ||
|
||
namespace Originer.Editor | ||
{ | ||
public class OriginerModel | ||
{ | ||
public OriginerPackageSearchModelDto searchResult = new OriginerPackageSearchModelDto(); | ||
public OriginerPackageSearchRequrstDto searchRequest = new OriginerPackageSearchRequrstDto(); | ||
|
||
public void Search(Action<bool> onComplete) | ||
{ | ||
new EditorWebRequest("https://api.originer.parabox.tech/api/search", | ||
searchRequest.JsonDeserialize(), req => | ||
{ | ||
OnSearchComplete(req); | ||
onComplete?.Invoke(req.isHttpError | req.isNetworkError); | ||
}); | ||
} | ||
|
||
private void OnSearchComplete(UnityWebRequest request) | ||
{ | ||
try | ||
{ | ||
searchResult = request | ||
.downloadHandler | ||
.text | ||
.JsonSerialize<OriginerPackageSearchModelDto>(); | ||
} | ||
catch(Exception e) | ||
{ | ||
Debug.LogError("Search response serialization error"); | ||
Debug.LogException(e); | ||
} | ||
|
||
var isError = request.isHttpError | request.isNetworkError; | ||
|
||
if(isError) | ||
{ | ||
Debug.LogError($"Search request error\nerror: {request.error}"); | ||
} | ||
} | ||
} | ||
|
||
[DataContract] | ||
[Serializable] | ||
public class OriginerPackageSearchRequrstDto | ||
{ | ||
[DataMember] | ||
public int page; | ||
|
||
[DataMember] | ||
public int count = 20; | ||
|
||
[DataMember] | ||
public string name = ""; | ||
} | ||
|
||
[DataContract] | ||
[Serializable] | ||
[KnownType(typeof(PackageInfoDto))] | ||
[KnownType(typeof(PackageInfoDto[]))] | ||
public class OriginerPackageSearchModelDto | ||
{ | ||
[DataMember] | ||
public int count; | ||
|
||
[DataMember] | ||
public int itemsPerPage; | ||
|
||
[DataMember] | ||
public int page; | ||
|
||
[DataMember] | ||
public PackageInfoDto[] items; | ||
|
||
public OriginerPackageSearchModelDto() | ||
{ | ||
count = 450; | ||
itemsPerPage = 15; | ||
page = 2; | ||
items = Enumerable.Range(0, 15).Select(i => new PackageInfoDto | ||
{ | ||
displayName = i + Guid.NewGuid().ToString(), | ||
name = i + Guid.NewGuid().ToString().Substring(5) | ||
}).ToArray(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.