Skip to content

Commit

Permalink
Merge pull request #2 from k0dep/originer_window
Browse files Browse the repository at this point in the history
Originer packages window
  • Loading branch information
k0dep authored Jun 17, 2019
2 parents 7faac4a + c2fdaef commit f9730ee
Show file tree
Hide file tree
Showing 31 changed files with 611 additions and 12 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

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

57 changes: 57 additions & 0 deletions Editor/EditorWebRequest.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Editor/EditorWebRequest.cs.meta

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

17 changes: 17 additions & 0 deletions Editor/Originer.Editor.asmdef
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": []
}
7 changes: 7 additions & 0 deletions Editor/Originer.Editor.asmdef.meta

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

98 changes: 98 additions & 0 deletions Editor/Originer.uss
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;
}
10 changes: 10 additions & 0 deletions Editor/Originer.uss.meta

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

26 changes: 26 additions & 0 deletions Editor/Originer.uxml
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>
10 changes: 10 additions & 0 deletions Editor/Originer.uxml.meta

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

92 changes: 92 additions & 0 deletions Editor/OriginerPackageInfoDto.cs
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();
}
}
}
11 changes: 11 additions & 0 deletions Editor/OriginerPackageInfoDto.cs.meta

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

Loading

0 comments on commit f9730ee

Please sign in to comment.