/// <summary> /// Conditionally adds a middleware class to the pipeline. Must have CTOR with single parameter of type <see cref="PipelineDelagate"/> /// and method "Invoke" accepting <see cref="PipelineDelagate"/> and returning <see cref="Task"/> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition"></param> /// <returns></returns> public PipelineBuilder UseWhen <T>(Func <MiddlewareContext, bool> condition, params object[] args) { middlewares.Add(d => { return(async ctx => { if (condition(ctx)) { await WrapClass <T>(d, args)(ctx); } }); }); return(this); }
void ReloadWrap() { //sset,sget,mset,mget,new,scall,mcall,op m_wrapClasses.Clear(); if(!Directory.Exists(WrapGenFolder)){ Directory.CreateDirectory(WrapGenFolder); } else { DirectoryInfo di = new DirectoryInfo(WrapGenFolder); FileInfo[] files = di.GetFiles("*.cs", SearchOption.AllDirectories); for(int i = 0; i < files.Length; i++) { string classname = files[i].Name.Substring(0, files[i].Name.Length - 3);//去掉.cs if(files[i].Directory.ToString().Length == WrapGenFolder.Length) { WrapClass wc = GetWrapClass(""); if(wc == null) { wc = new WrapClass(""); m_wrapClasses.Add(wc); } wc.AddClass(classname); } else { string nameSpace = files[i].Directory.ToString().Substring(WrapGenFolder.Length + 1); WrapClass wc = GetWrapClass(nameSpace); if(wc == null) { wc = new WrapClass(nameSpace); m_wrapClasses.Add(wc); } wc.AddClass(classname); } } } }
void Reload() { if (string.IsNullOrEmpty(_wrapFolder)) { _wrapFolder = PlayerPrefs.GetString("WrapFolder", "CQuark/Wrap"); } m_wrapClasses.Clear(); DirectoryInfo di = new DirectoryInfo(WrapFolder); FileInfo[] files = di.GetFiles("*.cs", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { string classname = files[i].Name.Split('.')[0]; if (files[i].Directory.ToString().Length == WrapFolder.Length) { if (classname == WRAP_CORE_NAME || classname == WRAP_UTIL_NAME) { continue; } WrapClass wc = GetWrapClass(""); if (wc == null) { wc = new WrapClass(""); m_wrapClasses.Add(wc); } wc.AddClass(classname); } else { string nameSpace = files[i].Directory.ToString().Substring(WrapFolder.Length + 1); WrapClass wc = GetWrapClass(nameSpace); if (wc == null) { wc = new WrapClass(nameSpace); m_wrapClasses.Add(wc); } wc.AddClass(classname); } } PlayerPrefs.SetString("WrapFolder", _wrapFolder); }
//Wrap一个自己输入的内容,需要判断是一个类还是一个命名空间 public void WrapCustom(string text) { Type type = WrapReflectionTools.GetType(text); //输入的是一个类 if(type != null) { string assemblyName = WrapReflectionTools.GetWrapFolderName(type); string className = WrapReflectionTools.GetWrapFileName(type); WrapClass wc = GetWrapClass(assemblyName); if(wc == null) { wc = new WrapClass(assemblyName); AddClass(type); } else { if(!wc.m_classes.Contains(className)) AddClass(type); else UpdateClass(new string[]{text}); } } //输入的是一个命名空间 else{ Type[] types = WrapReflectionTools.GetTypesByNamespace(text); if(types != null) { for(int i = 0; i < types.Length; i++) { // Debug.Log(types[i].ToString()); AddClass(types[i]); } } } ReloadWrap(); UpdateWrapCore(); //Add完毕ReloadDataBase,会编译代码 AssetDatabase.Refresh(); }
// <summary> // 読み込み処理 </summary> public override IEnumerator Read() { do { using (WWW www = WWW.LoadFromCacheOrDownload(url + strExtensionAssetBundle, version)) { while (!www.isDone) { progress = www.progress; ++wwwCount; yield return(null); } string errorMessage = string.Empty; if (www.error != null) { errorMessage += www.error; } if (www.assetBundle == null) { errorMessage += "/null AssetBundle"; } if (errorMessage != string.Empty) { Debug.Log(errorMessage + "(AssetName:" + url + ")"); } else { { // オブジェクトを非同期ロード AssetBundleRequest request = www.assetBundle.LoadAsync(folder + "/" + strFileListName, typeof(TextAsset)); while (!request.isDone) { ++loadASyncCount; yield return(null); } Thread thread = new Thread(new ParameterizedThreadStart(UnpackFileList)); thread.Priority = System.Threading.ThreadPriority.Lowest; thread.Start((request.asset as TextAsset).bytes); while (thread.IsAlive) { ++msgpackCount; yield return(null); } } loadASyncCount = 0; for (int i = 0; i < fileList.obj.Count; ++i) { if (fileList.obj [i].Key == folder + "/" + strFileListName) { continue; // FileList skip. } AssetBundleRequest request = www.assetBundle.LoadAsync(fileList.obj [i].Key, WrapClass.GetType(fileList.obj [i].Value)); while (!request.isDone) { ++loadASyncCount; yield return(null); } objectList.Add(request.asset); } // threadの解放コードのお手本にはJoinが書かれているが mainthreadが止まるし目的が違うのでいらないはず www.assetBundle.Unload(false); readFlag = true; } yield return(null); } } while(readFlag == false); }
/// <summary> /// シーケンス実体 </summary> private IEnumerator Coroutine() { for (;;) { Debug.Log(currentSequence.data.sceneList[currentSequence.sceneIndex] + " index:" + currentSequence.sceneIndex); { SerializeData.Scene data = Resource.Instance.sceneList.Find(delegate(SerializeData.Scene s) { return(s.name == currentSequence.data.sceneList[currentSequence.sceneIndex]); }); currentScene = (Scene.Base)Activator.CreateInstance(WrapClass.GetType(data.functionName)); currentScene.Initialize(data); } currentScene.RequestLoad(ref GetComponent <FileAssetBundle> ().blockList); do { yield return(null); } while (GetComponent <FileAssetBundle> ().blockList.Find(delegate(Asset.Block block) { return(block.IsRead() == false); }) != null); currentScene.RequestStart(); do { if (currentScene.IsDone()) { break; } yield return(null); } while (true); currentScene.RequestUnload(); do { if (currentScene.IsUnload()) { break; } yield return(null); } while (true); switch (currentScene.endStatus) { case Scene.EndStatus.NEXT: if (currentSequence.sceneIndex < currentSequence.data.sceneList.Count - 1) { ++currentSequence.sceneIndex; } else { if (currentSequence.data.isLoop) { currentSequence.sceneIndex = 0; } else { if (currentSequence.data.next != string.Empty) { SerializeData.Sequence tmp = Resource.Instance.sequenceList.Find(delegate(SerializeData.Sequence seq) { return(seq.name == currentSequence.data.next); }); if (tmp != null) { currentSequence = new SequenceInfo(tmp); myStack.Push(currentSequence); } else { Debug.Log("no sequence"); } } else { if (myStack.Count > 1) { currentSequence = myStack.Pop(); } else { Debug.Log("root stack no back sequence"); } } } } break; case Scene.EndStatus.BACK: if (currentSequence.sceneIndex != 0) { --currentSequence.sceneIndex; } else { if (myStack.Count > 1) { currentSequence = myStack.Pop(); } else { Debug.Log("root stack no back sequence"); } } break; case Scene.EndStatus.ABORT: break; } Resources.UnloadUnusedAssets(); GC.Collect(); } }
void OnGUI() { if (_isCompiling != EditorApplication.isCompiling) { _isCompiling = EditorApplication.isCompiling; Reload(); } GUILayout.BeginHorizontal(); GUILayout.Label("WrapFolder:", GUILayout.Width(100)); _wrapFolder = GUILayout.TextField(_wrapFolder); GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.Label(" You can make Wrap with this tool simply.\n" + " Step 1 : Type Full class name in the box below(eg . UnityEngine.Vector3)\n" + " Step 2 : Click \"Add/Update\" button"); GUILayout.Space(5); GUILayout.BeginHorizontal(); GUI.backgroundColor = Color.green; GUILayout.Label("Full Classname : ", GUILayout.Width(100)); _classInput = GUILayout.TextField(_classInput, GUILayout.MinWidth(100)); GUI.enabled = !string.IsNullOrEmpty(_classInput); if (GUILayout.Button("Add/Update", GUILayout.Width(100))) { string className = ""; string assemblyName = ""; //string[] s = _classInput.Split('.'); //if(s.Length == 1) { // assemblyName = ""; // className = s[0]; //} //else if(s.Length == 2) { // assemblyName = s[0]; // className = s[1]; //} int dotIndex = _classInput.LastIndexOf('.'); if (dotIndex == -1) { assemblyName = ""; className = _classInput; } else { assemblyName = _classInput.Substring(0, dotIndex); className = _classInput.Substring(dotIndex + 1); } WrapClass wc = GetWrapClass(assemblyName); if (wc == null) { wc = new WrapClass(assemblyName); AddClass(assemblyName, className); } else { if (!wc.m_classes.Contains(className)) { AddClass(assemblyName, className); } else { UpdateClass(assemblyName, className); } } _classInput = ""; } GUI.enabled = true; GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //if(GUILayout.Button("UpdateAll")) { // // Reload(); //} //GUI.backgroundColor = Color.red; //if(GUILayout.Button("Clear", GUILayout.Width(60))) { // ClearAll(); //} //GUI.backgroundColor = Color.white; //GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.Label("Wraps : "); mScroll = GUILayout.BeginScrollView(mScroll); GUILayout.BeginVertical(); foreach (var kvp in m_wrapClasses) { GUILayout.BeginHorizontal(); if (_folderNamespace.Contains(kvp.m_nameSpace)) { if (GUILayout.Button("\u25BC", GUILayout.Width(25))) { _folderNamespace.Remove(kvp.m_nameSpace); } } else { if (GUILayout.Button("\u25BA", GUILayout.Width(25))) { _folderNamespace.Add(kvp.m_nameSpace); } } GUILayout.Label("Namespace", GUILayout.Width(80)); GUILayout.TextField(kvp.m_nameSpace, GUILayout.Width(200)); GUILayout.Label(" " + kvp.m_classes.Count + " Classes", GUILayout.Width(80)); //GUILayout.Space(90); GUILayout.EndHorizontal(); if (_folderNamespace.Contains(kvp.m_nameSpace)) { for (int i = 0; i < kvp.m_classes.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Space(60); GUILayout.Label(" Class", GUILayout.Width(54)); GUILayout.TextField(kvp.m_classes[i]); GUI.backgroundColor = Color.cyan; if (GUILayout.Button("Update", GUILayout.Width(60))) { UpdateClass(kvp.m_nameSpace, kvp.m_classes[i]); } GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.Width(25))) { RemoveClass(kvp.m_nameSpace, kvp.m_classes[i]); return; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); } } GUILayout.Space(5); } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.Space(10); GUILayout.Label("If the Serializable Field is missing, Click the button below ↓"); GUILayout.Space(5); if (GUILayout.Button("Reload")) { Reload(); } GUILayout.Space(10); }