Пример #1
0
 // Use this for initialization
 void AssetRequestPublisher.PublishAssetRequest(AssetRequest assetReq, SimpleProcessListener listener)
 {
     RequiredFuncs.ProcessHTTP(
         "https://api.taiga.io/api/v1/auth",
         (response) => {
         var auth           = RequiredFuncs.FromJson <TaigaIOUserInfo>(response);
         var headerWithAuth = new KeyValuePair <string, string>[] {
             new KeyValuePair <string, string>("Content-Type", "application/json"),
             new KeyValuePair <string, string>("Authorization", "Bearer " + auth.auth_token)
         };
         RequiredFuncs.ProcessHTTP(
             "https://api.taiga.io/api/v1/userstories?project=" + projectID,
             (storiesJson) => {
             var stories = RequiredFuncs.FromJsonToArray <TaigaIOUserStory>(storiesJson);
             foreach (var reqUnit in assetReq.units)
             {
                 if (reqUnit.attributes.Count == 0)
                 {
                     continue;
                 }
                 var storySubjForReq        = "Asset Wanted: " + reqUnit.attributes[0] + " " + reqUnit.assettype;
                 bool shouldPublishAssetReq = true;
                 foreach (var story in stories)
                 {
                     if (story.subject == storySubjForReq)
                     {
                         shouldPublishAssetReq = false;
                         break;
                     }
                 }
                 if (shouldPublishAssetReq)
                 {
                     RequiredFuncs.ProcessHTTP(
                         "https://api.taiga.io/api/v1/userstories",
                         (addStoryResponseText) => {
                         RequiredFuncs.Log(RequiredFuncs.ToJsonString(new TaigaIOUserStoryAdd {
                             subject = storySubjForReq, project = projectID
                         }));
                     },
                         headerWithAuth,
                         RequiredFuncs.ToJson(new TaigaIOUserStoryAdd {
                         subject = storySubjForReq, project = projectID
                     })
                         );
                 }
             }
             listener.OnFinish(true);
         },
             headerWithAuth
             );
     },
         new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("Content-Type", "application/json") },
         RequiredFuncs.ToJson(new TaigaIOAuth {
         username = username, password = password, type = "normal"
     })
         );
 }
Пример #2
0
        void AssetSupplier.SupplyAsset(AssetRequest assetRequest, AssetSupplyListener listener)
        {
            Debug.Log("Begin fetching assets.");
            inteceptHelper.OnBeginSession(listener);
            var assetRequestJson = JsonUtility.ToJson(assetRequest);

            Debug.Log("Forward requst to Web.... " + assetRequestJson);
            WWWForm wwwForm = new WWWForm();

            wwwForm.AddField("assetRequestInJson", assetRequestJson);
            UnityWebRequest www = UnityWebRequest.Post(serverURL, wwwForm);

            NetworkUtil.ProcessWebRequest(www, (givenWebReq) => {
                bool didSuccess = false;
                if (givenWebReq.isNetworkError || givenWebReq.isHttpError)
                {
                    Debug.Log(givenWebReq.error);
                }
                else
                {
                    Debug.Log(Encoding.UTF8.GetString(givenWebReq.downloadHandler.data));
                    var assetPick = RequiredFuncs.FromJson <AssetPick>(givenWebReq.downloadHandler.data);
                    if (assetPick != null)
                    {
                        if (assetPick.units.Count > 0)
                        {
                            didSuccess = true;
                            listener.supplyTaker.Take(assetPick);
                        }
                    }
                }
                if (!didSuccess)
                {
                    listener.supplyTaker.None();
                }
                inteceptHelper.OnEndSession(listener);
            }
                                          );
        }
Пример #3
0
 void BasicAssetOut.PickAssetAtPath <ElementType>(string path, Taker <ElementType> collector)
 {
     try {
         var contentFullPath = Path.GetDirectoryName(assetUnitInfo.localref) + "/" + path;
         if (typeof(ElementType) == (typeof(ModelImporter)))
         {
             var importer = (ElementType)(object)ModelImporter.GetAtPath(contentFullPath);
             collector.Take(importer);
         }
         else if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(ElementType)))
         {
             try {
                 foreach (var asset in AssetDatabase.LoadAllAssetsAtPath(contentFullPath))
                 {
                     try {
                         var concreteAsset = (ElementType)(object)asset;
                         if (concreteAsset != null)
                         {
                             collector.Take(concreteAsset);
                             break;
                         }
                     } catch { }
                 }
             } catch {
                 collector.OnFail("StdEditTimeUnityAssetIO.PickAssetAtPath: ");
             }
         }
         else
         {
             if (File.Exists(contentFullPath))
             {
                 collector.Take(RequiredFuncs.FromJsonAtPath <ElementType>(contentFullPath));
             }
         }
     } catch (Exception e) {
         Debug.LogError(e);
     }
     collector.OnFinish();
 }
Пример #4
0
 void AssetModifyInterface.SetContent <ContentType>(AssetContentSettingParam <ContentType> setParam, AssetInResultListener <ContentType> listener)
 {
     if (string.IsNullOrEmpty(setParam.contentPath))
     {
         if ((typeof(MainContentBaseType) == typeof(ContentType)))
         {
             basicAssetIO.assetIn.SetContent(new BasicAssetInParam <ContentType> {
                 content     = setParam.content,
                 contentPath = "Main.json",
                 doOverwrite = setParam.doOverwrite
             }, listener);
         }
         else if (typeof(MainContentType) == typeof(ContentType))
         {
             basicAssetIO.assetIn.SetContent(new BasicAssetInParam <ContentType> {
                 content     = setParam.content,
                 contentPath = "Main.json",
                 doOverwrite = setParam.doOverwrite
             }, listener);
         }
         else if (typeof(byte[]) == typeof(ContentType))
         {
             basicAssetIO.assetIn.SetContent(new BasicAssetInParam <MainContentType> {
                 content     = RequiredFuncs.FromJson <MainContentType>(Encoding.UTF8.GetString((byte[])(object)setParam.content)),
                 contentPath = "Main.json",
                 doOverwrite = setParam.doOverwrite
             }, new StubAssetInResultListener <MainContentType>());
         }
     }
     else
     {
         basicAssetIO.assetIn.SetContent(new BasicAssetInParam <ContentType> {
             content     = setParam.content,
             contentPath = setParam.contentPath,
             doOverwrite = setParam.doOverwrite
         }, listener);
     }
 }
Пример #5
0
 AssetAddResult <AssetContentType> BasicAssetIn.SetContent <AssetContentType>(BasicAssetInParam <AssetContentType> settingParam)
 {
     try {
         var assetRootPath = Path.GetDirectoryName(assetUnitInfo.localref);
         if (!Directory.Exists(assetRootPath))
         {
             Directory.CreateDirectory(assetRootPath);
         }
         var assetPath = assetRootPath + "/" + settingParam.assetPath;
         if (typeof(AssetContentType) == typeof(GameObject))
         {
             var        gObj       = (GameObject)Convert.ChangeType(settingParam.content, typeof(GameObject));
             GameObject oldPrefab  = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
             GameObject newContent = null;
             if (oldPrefab != null && settingParam.doOverwrite)
             {
                 newContent = PrefabUtility.ReplacePrefab(gObj, oldPrefab);
             }
             else
             {
                 newContent = PrefabUtility.CreatePrefab(assetPath, gObj);
             }
             EditorUtility.SetDirty(newContent);
             AssetDatabase.SaveAssets();
             return(new AssetAddResult <AssetContentType> {
                 permanentContent = (AssetContentType)Convert.ChangeType(newContent, typeof(AssetContentType)), didSuccess = true
             });
         }
         else if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(AssetContentType)))
         {
             UnityEngine.Object obj = (UnityEngine.Object)(object) settingParam.content;
             var oldAssetPath       = AssetDatabase.GetAssetPath(obj);
             if (Utilities.IsStringEmpty(oldAssetPath))
             {
                 AssetDatabase.CreateAsset(obj, assetPath);
             }
             else
             {
                 if (oldAssetPath.StartsWith("Assets/"))
                 {
                     AssetDatabase.MoveAsset(oldAssetPath, assetPath);
                 }
                 else
                 {
                     if (typeof(AssetContentType) == typeof(Material))
                     {
                         AssetDatabase.CreateAsset(new Material((Material)(object)obj), assetPath);
                     }
                 }
             }
             EditorUtility.SetDirty(obj);
             AssetDatabase.SaveAssets();
             return(new AssetAddResult <AssetContentType> {
                 permanentContent = settingParam.content, didSuccess = true
             });
         }
         else if (typeof(CommonAssetRef).IsAssignableFrom(typeof(AssetContentType)))
         {
             if (File.Exists(assetPath) && settingParam.doOverwrite)
             {
                 try {
                     return(new AssetAddResult <AssetContentType> {
                         didSuccess = false, permanentContent = RequiredFuncs.FromJsonAtPath <AssetContentType>(assetPath)
                     });
                 } catch { return(new AssetAddResult <AssetContentType> {
                         didSuccess = false
                     }); }
             }
             File.WriteAllText(assetPath, RequiredFuncs.ToJson(settingParam.content));
             //AssetDatabase.Refresh();
             //AssetDatabase.SaveAssets();
             return(new AssetAddResult <AssetContentType> {
                 permanentContent = settingParam.content, didSuccess = true
             });
         }
     } catch (Exception e) { Debug.LogError(e); }
     return(new AssetAddResult <AssetContentType> {
         didSuccess = false
     });
 }