void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { string[] assetRef = assetUnitInfo.reference.Split(':'); if (System.Collections.CaseInsensitiveComparer.Equals(assetRef[0], "github")) { listener.OnBeginRefering(); //whole repository if (assetRef.Length == 2) { listener.OnBasicIOObtained(new GitHubAssetBasicIO { parent = this, repositoryAddress = assetRef[1], auInfo = assetUnitInfo }); listener.OnFinish(); } if (assetRef.Length == 3) { var www = new UnityWebRequest(addressBase + assetRef[1] + assetRef[2]); NetworkUtil.ProcessWebRequest(www, (givenWWW) => { if (string.IsNullOrEmpty(givenWWW.error)) { listener.OnRawAssetContentObtained(givenWWW.downloadHandler.data, assetRef[2]); } listener.OnFinish(); }); } } }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { if (assetUnitInfo.reference.StartsWith("file:///")) { listener.OnBeginRefering(); if (!assetUnitInfo.reference.EndsWith("/")) { ; UnityWebRequest www = new UnityWebRequest(assetUnitInfo.reference); NetworkUtil.ProcessWebRequest(www, (givenWWW) => { if (string.IsNullOrEmpty(givenWWW.error)) { listener.OnRawAssetContentObtained(givenWWW.downloadHandler.data, ""); } listener.OnFinish(); }); } else { //whole repository listener.OnBasicIOObtained(new FileProtocolBasicIO { auInfo = assetUnitInfo }); listener.OnFinish(); } } string[] assetRef = assetUnitInfo.reference.Split(':'); if (System.Collections.CaseInsensitiveComparer.Equals(assetRef[0], "folder://")) { } }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { if (assetUnitInfo.reference.StartsWith("unityab:")) { listener.OnBeginRefering(); var json = assetUnitInfo.reference.Substring(8); var abRef = RequiredFuncs.FromJson <AssetBundleRef>(json); NetworkUtil.ProcessWebRequest( UnityWebRequestAssetBundle.GetAssetBundle(abRef.uri, 0), (www) => { var bundle = DownloadHandlerAssetBundle.GetContent(www); if (string.IsNullOrEmpty(abRef.assetPath)) { //stub } else { var bundleAsset = bundle.LoadAsset(abRef.assetPath); if (bundleAsset != null) { listener.OnObjectObtained(bundleAsset, abRef.assetPath); } } listener.OnFinish(); } ); } }
public static AssetInfo EntityToAssetInfo(IDataReader reader) { AssetUnitInfo assetUnitInfo = EditTimeAssetUtils.EntityToAssetUnitInfo(reader); AssetInfo newAssetInfo = new AssetInfo(); newAssetInfo.units = new List <AssetUnitInfo>(); newAssetInfo.units.Add(assetUnitInfo); return(newAssetInfo); }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { if (assetUnitInfo.reference.StartsWith("http")) { listener.OnBeginRefering(); UnityAssetUtil.PickFromDownloadLink(assetUnitInfo.reference, new PrvtColl { listener = listener }); } }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { if (assetUnitInfo.reference.StartsWith("platform:")) { var json = assetUnitInfo.reference.Substring(9); var pRef = RequiredFuncs.FromJson <PlatformRef>(json); var auInfoClone = AssetUtils.CloneAssetRef(assetUnitInfo); auInfoClone.reference = pRef.defaultBuild; baseReferer.assetReferer.ReferAsset(auInfoClone, listener); } }
public static AssetUnitInfo CloneAssetRef(AssetUnitInfo sourceAsset) { return(new AssetUnitInfo { assettype = sourceAsset.assettype, attributes = sourceAsset.attributes, distributor = sourceAsset.distributor, shortname = sourceAsset.shortname, id = sourceAsset.id, lastupdate = sourceAsset.lastupdate, reference = sourceAsset.reference }); }
public static AssetUnitInfo LocalizeAssetRef(AssetUnitInfo sourceAsset, string newAssetLocalRef) { return(new AssetUnitInfo { assettype = sourceAsset.assettype, attributes = sourceAsset.attributes, distributor = sourceAsset.distributor, shortname = sourceAsset.shortname, id = sourceAsset.id, lastupdate = sourceAsset.lastupdate, reference = newAssetLocalRef }); }
public static AssetUnitInfo EntityToAssetUnitInfo(IDataReader reader) { AssetUnitInfo assetUnitInfo = new AssetUnitInfo(); assetUnitInfo.id = reader.GetInt32(0); assetUnitInfo.reference = reader.GetString(1); assetUnitInfo.distributor = reader.GetString(2); assetUnitInfo.shortname = reader.GetString(3); assetUnitInfo.lastupdate = reader.GetString(4); assetUnitInfo.assettype = reader.GetString(7); assetUnitInfo.attributes = reader.GetString(8); return(assetUnitInfo); }
public static AssetUnitInfo AUInfoRemoteToLocal(AssetUnitInfo remoteAssetUnitInfo) { var localizedInfo = new AssetUnitInfo { id = remoteAssetUnitInfo.id, reference = GetAssetDirectoryPath(remoteAssetUnitInfo) + "/agas.json", distributor = remoteAssetUnitInfo.distributor, shortname = remoteAssetUnitInfo.shortname, lastupdate = remoteAssetUnitInfo.lastupdate, assettype = remoteAssetUnitInfo.assettype, attributes = remoteAssetUnitInfo.attributes }; return(localizedInfo); }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { foreach (var referer in referers) { var listenerWrapper = new PrvtAssetReferenceListener { clientListener = listener }; referer.ReferAsset(assetUnitInfo, listenerWrapper); if (listenerWrapper.didBegin) { return; } } }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { if (string.IsNullOrEmpty(clientID) || string.IsNullOrEmpty(clientSecret)) { return; } //asume like "deviantart:{GUID}" string[] assetRef = assetUnitInfo.reference.Split(':'); if (System.Collections.CaseInsensitiveComparer.Equals(assetRef[0], "deviantart")) { listener.OnBeginRefering(); var webReq = new UnityWebRequest("https://www.deviantart.com/oauth2/token?grant_type=client_credentials&client_id=" + clientID + "&client_secret=" + clientSecret); webReq.downloadHandler = new DownloadHandlerBuffer(); NetworkUtil.ProcessWebRequest( webReq, (www) => { if (www.error != null) { listener.OnFinish(); return; } var token = JsonUtility.FromJson <DeviantArtToken>(www.downloadHandler.text); var webReq2 = new UnityWebRequest("https://www.deviantart.com/api/v1/oauth2/deviation/download/" + assetRef[1] + "?token=" + token.access_token); webReq2.downloadHandler = new DownloadHandlerBuffer(); NetworkUtil.ProcessWebRequest( webReq2, (www2) => { if (www2.error != null) { listener.OnFinish(); return; } var dl = JsonUtility.FromJson <DeviantArtDownload>(www2.downloadHandler.text); NetworkUtil.ProcessWebRequest(UnityWebRequestTexture.GetTexture(dl.src), (www3) => { if (www3.error != null) { listener.OnFinish(); return; } Debug.Log("Deviant art texture obtained."); var texture = DownloadHandlerTexture.GetContent(www3); listener.OnAssetContentObtained(texture, ""); listener.OnFinish(); }); }); } ); } }
public static AssetUnitInfo CombineAssetUnitInfo(AssetUnitInfo left, AssetUnitInfo right) { /*var combined = new AssetUnitInfo { * assettype = left.assettype, * attributes = left.attributes + ";" + right.attributes, * creatorref = left.creatorref + ";" * }; * if(left.assettype != right.assettype) * combined.assettype = left.assettype + ";" + right.assettype; * if (left.attributes != right.attributes) * combined.attributes = left.attributes + ";" + right.attributes; * left.assettype*/ //todo return(left); }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { if (assetUnitInfo.reference.Contains("agas.zip")) { listener.OnBeginRefering(); var www = new UnityWebRequest(assetUnitInfo.reference); NetworkUtil.ProcessWebRequest(www, (doneWWW) => { listener.OnStdArchiveObtained(doneWWW.downloadHandler.data); listener.OnFinish(); }); } else { listener.OnFinish(); } }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { var refElements = assetUnitInfo.reference.Split(':'); if (string.Compare(refElements[0], "GSearch", true) != 0) { return; } listener.OnBeginRefering(); var chache = caches.Find((cache) => string.Compare(cache.auInfo.reference, assetUnitInfo.reference, true) == 0); if (chache != null) { listener.OnAssetContentObtained(chache.sprite, ""); listener.OnFinish(); return; } NetworkUtil.ProcessWebRequest( new UnityWebRequest("https://www.googleapis.com/customsearch/v1?key=" + "&searchType=image&q=" + refElements[1]), (doneWWW1) => { if (doneWWW1.error == null) { var result = JsonUtility.FromJson <GoogleImageSearchResult>(doneWWW1.downloadHandler.text); NetworkUtil.ProcessWebRequest( new UnityWebRequest(result.items[0].image.thumbnailLink), (doneWWW2) => { if (doneWWW2.error == null) { var texture = DownloadHandlerTexture.GetContent(doneWWW2); var sprite = Sprite.Create(texture, new Rect(Vector2.zero, new Vector2(texture.width, texture.height)), new Vector2(0.5f, 0.5f), System.Math.Max(texture.width, texture.height)); caches.Add(new SearchCache { auInfo = assetUnitInfo, sprite = sprite }); listener.OnAssetContentObtained(sprite, ""); } listener.OnFinish(); } ); } else { listener.OnFinish(); } } ); }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { var strings = assetUnitInfo.reference.Split(' '); if (strings[0].EndsWith(".git")) { var vcsRef = new VersionControlSystemRef { repository = strings[0], systemName = "git" }; if (strings.Length > 1) { vcsRef.targetPath = strings[1]; } listener.OnBeginRefering(); listener.OnVCSReferenceObtained(vcsRef); listener.OnFinish(); } }
void EnsureLocalAssetDirectory() { #region create asset directory localAUInfo = EditTimeAssetUtils.AUInfoRemoteToLocal(baseAssetUnitInfo); assetRootPath = Path.GetDirectoryName(localAUInfo.localref); if (!Directory.Exists(assetRootPath)) { Directory.CreateDirectory(assetRootPath); } if (localAssetInterface == null) { var customItfc = parent.customAssetInterfaceGiver[AssetUtils.GetPrimalType(localAUInfo)]; localAssetInterface = customItfc.PickBestElement(new StdEditTimeUnityAssetIO { assetUnitInfo = localAUInfo }); } #endregion }
void AssetUnitSupplier.SupplyAssetUnit(AssetRequestUnit assetRequest, AssetUnitSupplyListener listener) { if (assetRequest.assettype != "Picture") { listener.supplyTaker.None(); return; } //check cache var temporaryAUInfo = new AssetUnitInfo { assettype = assetRequest.assettype, attributes = assetRequest.attributes[0], distributor = "GSearch", reference = "GSearch:" + assetRequest.attributes[0], shortname = "GSearch-" + assetRequest.attributes[0] }; listener.supplyTaker.Take(temporaryAUInfo); }
void AssetReferer.ReferAsset(AssetUnitInfo assetUnitInfo, AssetReferenceListener listener) { string[] assetRefParts = assetUnitInfo.reference.Split(':'); if (System.Collections.CaseInsensitiveComparer.Equals(assetRefParts[0], "soundcloud")) { listener.OnBeginRefering(); NetworkUtil.ProcessWebRequest( new UnityWebRequest("https://api.soundcloud.com/tracks/" + assetRefParts[1] + "/download?client_id=" + clientID), (www) => { if (www.error == null) { listener.OnAssetContentObtained(DownloadHandlerAudioClip.GetContent(www), ""); } listener.OnFinish(); } ); } }
public void AddAssetToDatabase(AssetUnitInfo localizedAssetUnitInfo) { try { var equivelent = (this as ImmediateGiver <AssetUnitInfo, AssetUnitInfo>).PickBestElement(localizedAssetUnitInfo); if (equivelent != null) { return; } var sqlInsertBuilder = new System.Text.StringBuilder(); var sqlInsertVarBuilder = new System.Text.StringBuilder(); var sqlInsertValueBuilder = new System.Text.StringBuilder(); sqlInsertVarBuilder.Append("localref, creatorref, sname, lastupdate"); sqlInsertValueBuilder.Append("\'" + localizedAssetUnitInfo.reference + "\'"); sqlInsertValueBuilder.Append(",\'" + localizedAssetUnitInfo.distributor + "\'"); sqlInsertValueBuilder.Append(",\'" + localizedAssetUnitInfo.shortname + "\'"); sqlInsertValueBuilder.Append(",\'" + localizedAssetUnitInfo.lastupdate + "\'"); if (localizedAssetUnitInfo.assettype != null) { sqlInsertVarBuilder.Append(", assettype"); sqlInsertValueBuilder.Append(",\'" + localizedAssetUnitInfo.assettype + "\'"); } if (localizedAssetUnitInfo.attributes != null) { sqlInsertVarBuilder.Append(", attributes"); sqlInsertValueBuilder.Append(",\'" + localizedAssetUnitInfo.attributes + "\'"); } sqlInsertBuilder.Append( "INSERT INTO assets(" + sqlInsertVarBuilder.ToString() + ") VALUES (" + sqlInsertValueBuilder.ToString() + ")" ); string insertString = sqlInsertBuilder.ToString(); Debug.Log(insertString); IDbCommand dbcmd = dbconn.CreateCommand(); dbcmd.CommandText = insertString; dbcmd.ExecuteNonQuery(); dbcmd.Dispose(); dbcmd = null; } catch (Exception e) { error = e.ToString(); } }
AssetUnitInfo ImmediateGiver <AssetUnitInfo, AssetUnitInfo> .PickBestElement(AssetUnitInfo key) { var sqlQueryBuilder = new System.Text.StringBuilder(); sqlQueryBuilder.Append("SELECT * FROM assets WHERE sname = \'" + key.shortname + "\' And creatorref = \'" + key.distributor + "\'"); bool hasCondition = false; IDbCommand dbcmd = dbconn.CreateCommand(); dbcmd.CommandText = sqlQueryBuilder.ToString(); IDataReader reader = dbcmd.ExecuteReader(); AssetUnitInfo newAssetInfo = null; if (reader.Read()) { newAssetInfo = EditTimeAssetUtils.EntityToAssetInfo(reader).units[0]; } reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; return(newAssetInfo); }
public static bool DoesContainType(AssetUnitInfo assetUnitInfo, string type) { return(Array.Find(assetUnitInfo.assettype.Split(';'), (str) => CaseInsensitiveComparer.Equals(assetUnitInfo, type)) != null); }
void AssetReferenceListener.OnAssetInfoObtained(AssetUnitInfo obtained, AssetReferer referer) { //todo : proper info combination //var newAssetUnitInfo = AssetUtils.CombineAssetUnitInfo(baseAssetUnitInfo, obtained); referer.ReferAsset(obtained, this); }
public static string GetAssetDirectoryPath(AssetUnitInfo remoteAssetUnitInfo) { return(assetFetcheDir + GetAssetDirectoryName(remoteAssetUnitInfo)); }
public static string GetAssetDirectoryName(AssetUnitInfo remoteAssetUnitInfo) { return(remoteAssetUnitInfo.distributor + "_" + remoteAssetUnitInfo.shortname); }
public static string LocalAssetRefForGenerated(AssetUnitInfo generatedAssetUnitInfo) { return(assetGenDir + GetAssetDirectoryName(generatedAssetUnitInfo) + "/agas.json"); }
public abstract ImplType IntegrateImplementType <ParamAssetType>(ParamAssetType asset, AssetUnitInfo auInfo, AssetRequestUnit assetReqUnit);
public override NamedPicture IntegrateImplementType <ParamAssetType>(ParamAssetType asset, AssetUnitInfo auInfo, AssetRequestUnit assetReqUnit) { if (typeof(ParamAssetType) == typeof(Sprite)) { return(new NamedPicture { asset = (Sprite)(object)asset, name = AssetUtils.ExtractPackedAssetAttribute(auInfo.attributes)[0] }); } return(null); }
public static string GetPrimalType(AssetUnitInfo assetUnitInfo) { return(assetUnitInfo.assettype.Split(';')[0]); }
public static string StdAssetIDName(AssetUnitInfo sourceAsset) { return(sourceAsset.distributor + "_" + sourceAsset.shortname); }