/// <summary> /// 恢复到指定步骤 /// </summary> /// <param name="stepID">步骤ID</param> /// <returns>恢复成功/失败</returns> public bool RestoreStep(string stepID) { if (_running && !_executing) { if (_pause) { return(false); } if (!_stepContentIndexs.ContainsKey(stepID)) { return(false); } int index = _stepContentIndexs[stepID]; if (index < 0 || index >= _currentStep) { return(false); } while (_currentStep >= index) { _currentContent = _stepContents[_currentStep]; _currentTarget = _currentContent.Target.GetComponent <StepTarget>(); RestoreStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false); //创建步骤助手 if (_currentHelper == null && _currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Restore; _currentHelper.OnInit(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper)); } } //助手执行恢复 if (_currentHelper != null) { _currentHelper.Task = StepHelperTask.Restore; _currentHelper.OnRestore(); _currentHelper.OnTermination(); _currentHelper = null; } _currentStep -= 1; } _currentStep = index; BeginCurrentStep(); return(true); } else { return(false); } }
private void Awake() { if (IsAutoRegister) { Main.m_FSM.RegisterFSM(this); } //加载数据类 if (Data != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(Data); if (type != null) { if (type.IsSubclassOf(typeof(FSMData))) { _data = Activator.CreateInstance(type) as FSMData; _data.StateMachine = this; _data.OnInit(); } else { GlobalTools.LogError(string.Format("创建数据类失败:数据类 {0} 必须继承至有限状态机数据基类:FSMData!", Data)); } } else { GlobalTools.LogError(string.Format("创建数据类失败:丢失数据类 {0}!", Data)); } } //加载所有状态 for (int i = 0; i < States.Count; i++) { Type type = GlobalTools.GetTypeInRunTimeAssemblies(States[i]); if (type != null) { if (type.IsSubclassOf(typeof(FiniteState))) { if (!_stateInstances.ContainsKey(type)) { FiniteState state = Activator.CreateInstance(type) as FiniteState; state.StateMachine = this; state.OnInit(); _stateInstances.Add(type, state); } } else { GlobalTools.LogError(string.Format("加载有限状态失败:有限状态 {0} 必须继承至有限状态基类:FiniteState!", States[i])); } } else { GlobalTools.LogError(string.Format("加载有限状态失败:丢失有限状态 {0}!", States[i])); } } //进入默认状态 if (DefaultState == "" || _stateInstances.Count <= 0) { GlobalTools.LogError(string.Format("有限状态机 {0} 的状态为空!或未指定默认状态!", Name)); return; } Type dtype = GlobalTools.GetTypeInRunTimeAssemblies(DefaultState); if (dtype != null) { if (_stateInstances.ContainsKey(dtype)) { _currentState = _stateInstances[dtype]; _currentState.OnEnter(); } else { GlobalTools.LogError(string.Format("切换状态失败:有限状态机 {0} 不存在状态 {1}!", Name, dtype.Name)); } } else { GlobalTools.LogError(string.Format("切换状态失败:丢失有限状态 {0}!", DefaultState)); } }
/// <summary> /// 重新编译步骤内容 /// </summary> /// <param name="prohibitStepID">禁用的步骤ID列表(当为null时启用所有步骤,禁用的步骤会自动跳过)</param> public void RecompileStepContent(HashSet <string> prohibitStepID = null) { if (ContentAsset) { //搜寻框架下所有目标 _targets.Clear(); List <StepTarget> targets = new List <StepTarget>(); Main.Current.transform.GetComponentsInChildren(true, targets); for (int i = 0; i < targets.Count; i++) { if (!_targets.ContainsKey(targets[i].GUID)) { _targets.Add(targets[i].GUID, targets[i]); } else { GlobalTools.LogWarning(string.Format("发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", targets[i].GUID, _targets[targets[i].GUID].transform.FullName(), targets[i].transform.FullName())); } } //搜寻场景所有目标 GameObject[] rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject rootObj in rootObjs) { targets.Clear(); rootObj.transform.GetComponentsInChildren(true, targets); for (int i = 0; i < targets.Count; i++) { if (!_targets.ContainsKey(targets[i].GUID)) { _targets.Add(targets[i].GUID, targets[i]); } else { GlobalTools.LogWarning(string.Format("发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", targets[i].GUID, _targets[targets[i].GUID].transform.FullName(), targets[i].transform.FullName())); } } } //判断步骤ID是否重复 _stepContentIDs.Clear(); for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_stepContentIDs.ContainsKey(content.GUID)) { GlobalTools.LogError(string.Format("发现相同GUID的步骤!GUID:{0}\r\n步骤:{1} 和 {2}", content.GUID, _stepContentIDs[content.GUID].Name, content.Name)); return; } else { _stepContentIDs.Add(content.GUID, content); } } _stepContents.Clear(); _stepContentEnables.Clear(); _stepContentIndexs.Clear(); //启用所有步骤 if (prohibitStepID == null) { for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_targets.ContainsKey(content.TargetGUID)) { content.Target = _targets[content.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("【步骤:{0}】【{1}】目标没有找到,目标路径:{2}", i, content.Name, content.TargetPath)); } for (int j = 0; j < content.Operations.Count; j++) { StepOperation operation = content.Operations[j]; if (_targets.ContainsKey(operation.TargetGUID)) { operation.Target = _targets[operation.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("【步骤:{0}】【操作:{1}】目标没有找到,目标路径:{2}", i, operation.Name, operation.TargetPath)); } } _stepContents.Add(content); if (!_stepContentEnables.ContainsKey(content.GUID)) { _stepContentEnables.Add(content.GUID, true); _stepContentIndexs.Add(content.GUID, _stepContents.Count - 1); } } } //禁用 prohibitStepID 指定的步骤 else { for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_targets.ContainsKey(content.TargetGUID)) { content.Target = _targets[content.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("【步骤:{0}】【{1}】目标没有找到,目标路径:{2}", i, content.Name, content.TargetPath)); } for (int j = 0; j < content.Operations.Count; j++) { StepOperation operation = content.Operations[j]; if (_targets.ContainsKey(operation.TargetGUID)) { operation.Target = _targets[operation.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("【步骤:{0}】【操作:{1}】目标没有找到,目标路径:{2}", i, operation.Name, operation.TargetPath)); } } _stepContents.Add(content); if (!_stepContentEnables.ContainsKey(content.GUID)) { _stepContentEnables.Add(content.GUID, !prohibitStepID.Contains(ContentAsset.Content[i].GUID)); _stepContentIndexs.Add(content.GUID, _stepContents.Count - 1); } } } _currentStep = 0; _currentContent = null; _currentTarget = null; _running = false; _pause = false; _executing = false; ClearCustomOrder(); } else { GlobalTools.LogError("步骤控制器丢失了步骤资源 Step Content Asset!"); } }
private void ScriptingDefineGUI() { GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUILayout.Space(10); _showScriptingDefine = EditorGUILayout.Foldout(_showScriptingDefine, "Scripting Define", true); GUILayout.EndHorizontal(); if (_showScriptingDefine) { GUILayout.BeginHorizontal(); GUILayout.Label("Defined"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.TextField(_currentScriptingDefine.Defined); GUI.enabled = _currentScriptingDefine.IsAnyDefined; if (GUILayout.Button("Clear", "Minibutton", GUILayout.Width(40))) { _currentScriptingDefine.ClearDefines(); } GUI.enabled = true; if (GUILayout.Button("New", "Minibutton", GUILayout.Width(40))) { _isNewDefine = !_isNewDefine; _newDefine = ""; } if (GUILayout.Button("Apply", "Minibutton", GUILayout.Width(45))) { _currentScriptingDefine.Apply(); } GUILayout.EndHorizontal(); if (_isNewDefine) { GUILayout.BeginHorizontal(); _newDefine = EditorGUILayout.TextField(_newDefine); if (GUILayout.Button("OK", "Minibutton", GUILayout.Width(30))) { if (_newDefine != "") { _currentScriptingDefine.AddDefine(_newDefine); _isNewDefine = false; _newDefine = ""; } else { GlobalTools.LogError("输入的宏定义不能为空!"); } } if (GUILayout.Button("NO", "Minibutton", GUILayout.Width(30))) { _isNewDefine = false; _newDefine = ""; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Historical record"); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear record", "Minibutton", GUILayout.Width(80))) { _currentScriptingDefine.ClearDefinesRecord(); } GUILayout.EndHorizontal(); for (int i = 0; i < _currentScriptingDefine.DefinedsRecord.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Label(_currentScriptingDefine.DefinedsRecord[i], "PR PrefabLabel"); GUILayout.FlexibleSpace(); if (GUILayout.Button("Use", "Minibutton", GUILayout.Width(30))) { _newDefine += _currentScriptingDefine.DefinedsRecord[i] + ";"; } GUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); }
/// <summary> /// 重新编译任务内容,在更改任务资源 ContentAsset 后,必须重新编译一次才可以开始任务流程 /// </summary> /// <param name="disableTaskIDs">禁用的任务点ID集合(当为null时启用所有任务,禁用的任务不会触发)</param> public void RecompileTaskContent(HashSet <string> disableTaskIDs = null) { if (ContentAsset) { #region 搜寻任务目标 _targets.Clear(); //搜寻框架下所有任务目标 List <TaskTarget> targetCaches = new List <TaskTarget>(); Main.Current.transform.GetComponentsInChildren(true, targetCaches); for (int i = 0; i < targetCaches.Count; i++) { if (!_targets.ContainsKey(targetCaches[i].GUID)) { _targets.Add(targetCaches[i].GUID, targetCaches[i]); } else { GlobalTools.LogWarning(string.Format("任务控制者:发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", targetCaches[i].GUID, _targets[targetCaches[i].GUID].transform.FullName(), targetCaches[i].transform.FullName())); } } //搜寻场景中所有任务目标 GameObject[] rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject rootObj in rootObjs) { targetCaches.Clear(); rootObj.transform.GetComponentsInChildren(true, targetCaches); for (int i = 0; i < targetCaches.Count; i++) { if (!_targets.ContainsKey(targetCaches[i].GUID)) { _targets.Add(targetCaches[i].GUID, targetCaches[i]); } else { GlobalTools.LogWarning(string.Format("任务控制者:发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", targetCaches[i].GUID, _targets[targetCaches[i].GUID].transform.FullName(), targetCaches[i].transform.FullName())); } } } #endregion #region 判断任务ID是否重复 _taskContents.Clear(); _taskPoints.Clear(); for (int i = 0; i < ContentAsset.Content.Count; i++) { TaskContentBase content = ContentAsset.Content[i]; if (_taskContents.ContainsKey(content.GUID)) { GlobalTools.LogError(string.Format("任务控制者:发现相同GUID的任务内容!GUID:{0}\r\n任务内容:{1} 和 {2}", content.GUID, _taskContents[content.GUID].Name, content.Name)); } else { _taskContents.Add(content.GUID, content); } for (int j = 0; j < content.Points.Count; j++) { TaskPointBase point = content.Points[j]; if (_taskPoints.ContainsKey(point.GUID)) { GlobalTools.LogError(string.Format("任务控制者:发现相同GUID的任务点!GUID:{0}\r\n任务点:{1} 和 {2}", point.GUID, _taskPoints[point.GUID].Name, point.Name)); } else { _taskPoints.Add(point.GUID, point); } if (_taskContents.ContainsKey(point.GUID)) { GlobalTools.LogError(string.Format("任务控制者:发现相同GUID的任务内容和任务点!GUID:{0}\r\n任务内容:{1} 任务点:{2}", point.GUID, _taskContents[point.GUID].Name, point.Name)); } } } #endregion #region 刷新任务状态 foreach (var item in _taskContents) { item.Value.ReSet(); } foreach (var item in _taskPoints) { item.Value.ReSet(); } if (disableTaskIDs != null && disableTaskIDs.Count > 0) { foreach (var item in disableTaskIDs) { if (_taskPoints.ContainsKey(item)) { _taskPoints[item].IsEnable = false; } } } _currentContentIndex = 0; _currentContent = null; _running = false; #endregion } else { throw new HTFrameworkException(HTFrameworkModule.TaskEditor, "任务控制者:重新编译任务失败,任务控制者丢失了任务资源 TaskContentAsset!"); } }
private IEnumerator SkipStepCoroutine(int index) { _running = true; _skipIndex = index; while (_currentStep < _skipIndex) { _currentContent = _stepContents[_currentStep]; _currentTarget = _currentContent.Target.GetComponent <StepTarget>(); Main.m_Controller.TheControlMode = _currentContent.InitialMode; Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, false); Main.m_Controller.SetLookAngle(_currentContent.BestView, true); if (SkipStepEvent != null) { SkipStepEvent(_currentContent); } //UGUI按钮点击型步骤,自动执行按钮事件 if (_currentContent.Trigger == StepTrigger.ButtonClick) { if (_currentButton) { _currentButton.onClick.Invoke(); } else { _currentButton = _currentContent.Target.GetComponent <Button>(); if (_currentButton) { _currentButton.onClick.Invoke(); } else { GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的目标丢失Button组件!"); } } _currentButton = null; } //创建步骤助手 if (_currentHelper == null && _currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Skip; _currentHelper.OnInit(); } else { GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的助手 " + _currentContent.Helper + " 丢失!"); } } //助手执行跳过,等待生命周期结束后销毁助手 if (_currentHelper != null) { _currentHelper.Task = StepHelperTask.Skip; _currentHelper.OnSkip(); if (_currentHelper.SkipLifeTime > 0) { yield return(new WaitForSeconds(_currentHelper.SkipLifeTime / SkipMultiple)); } _currentHelper.OnTermination(); _currentHelper = null; } _currentContent.Skip(this); yield return(new WaitForSeconds(_currentContent.ElapseTime / SkipMultiple)); _currentStep += 1; } if (SkipStepDoneEvent != null) { SkipStepDoneEvent(); } BeginCurrentStep(); }
public override void OnInspectorGUI() { GUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Activated Procedure Count:" + _target.ActivatedProcedures.Count, MessageType.Info); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.enabled = _target.DefaultProcedure != ""; GUILayout.Label("Default: " + _target.DefaultProcedure); GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.enabled = _target.ActivatedProcedures.Count > 0; if (GUILayout.Button("Set Default", "MiniPopup")) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < _target.ActivatedProcedures.Count; i++) { int j = i; gm.AddItem(new GUIContent(_target.ActivatedProcedures[j]), _target.DefaultProcedure == _target.ActivatedProcedures[j], () => { Undo.RecordObject(target, "Set Default Procedure"); _target.DefaultProcedure = _target.ActivatedProcedures[j]; this.HasChanged(); }); } gm.ShowAsContext(); } GUI.enabled = true; GUILayout.EndHorizontal(); for (int i = 0; i < _target.ActivatedProcedures.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label((i + 1) + "." + _target.ActivatedProcedures[i]); GUILayout.FlexibleSpace(); if (GUILayout.Button("Edit", "MiniButton")) { if (_procedureTypes.ContainsKey(_target.ActivatedProcedures[i])) { UnityEngine.Object classFile = AssetDatabase.LoadAssetAtPath(_procedureTypes[_target.ActivatedProcedures[i]], typeof(TextAsset)); if (classFile) { AssetDatabase.OpenAsset(classFile); } else { GlobalTools.LogError("没有找到 " + _target.ActivatedProcedures[i] + " 脚本文件!"); } } else { GlobalTools.LogError("没有找到 " + _target.ActivatedProcedures[i] + " 脚本文件!"); } } if (GUILayout.Button("Delete", "MiniButton")) { Undo.RecordObject(target, "Delete Procedure"); if (_target.DefaultProcedure == _target.ActivatedProcedures[i]) { _target.DefaultProcedure = ""; } _target.ActivatedProcedures.RemoveAt(i); if (_target.DefaultProcedure == "" && _target.ActivatedProcedures.Count > 0) { _target.DefaultProcedure = _target.ActivatedProcedures[0]; } this.HasChanged(); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Procedure", "MiniPopup")) { GenericMenu gm = new GenericMenu(); List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); for (int i = 0; i < types.Count; i++) { if (types[i].BaseType == typeof(Procedure)) { int j = i; if (_target.ActivatedProcedures.Contains(types[j].FullName)) { gm.AddDisabledItem(new GUIContent(types[j].FullName)); } else { gm.AddItem(new GUIContent(types[j].FullName), false, () => { Undo.RecordObject(target, "Add Procedure"); _target.ActivatedProcedures.Add(types[j].FullName); if (_target.DefaultProcedure == "") { _target.DefaultProcedure = _target.ActivatedProcedures[0]; } this.HasChanged(); }); } } } gm.ShowAsContext(); } GUILayout.EndHorizontal(); }
/// <summary> /// 重新编译步骤内容,在更改步骤资源 ContentAsset 后,必须重新编译一次才可以开始任务流程 /// </summary> /// <param name="disableStepIDs">禁用的步骤ID集合(当为null时启用所有步骤,禁用的步骤会自动跳过)</param> public void RecompileStepContent(HashSet <string> disableStepIDs = null) { if (ContentAsset) { #region 搜寻步骤目标 _targets.Clear(); //搜寻框架下所有步骤目标 List <StepTarget> targetCaches = new List <StepTarget>(); Main.Current.transform.GetComponentsInChildren(true, targetCaches); for (int i = 0; i < targetCaches.Count; i++) { if (!_targets.ContainsKey(targetCaches[i].GUID)) { _targets.Add(targetCaches[i].GUID, targetCaches[i]); } else { GlobalTools.LogWarning(string.Format("步骤控制者:发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", targetCaches[i].GUID, _targets[targetCaches[i].GUID].transform.FullName(), targetCaches[i].transform.FullName())); } } //搜寻场景中所有步骤目标 GameObject[] rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject rootObj in rootObjs) { targetCaches.Clear(); rootObj.transform.GetComponentsInChildren(true, targetCaches); for (int i = 0; i < targetCaches.Count; i++) { if (!_targets.ContainsKey(targetCaches[i].GUID)) { _targets.Add(targetCaches[i].GUID, targetCaches[i]); } else { GlobalTools.LogWarning(string.Format("步骤控制者:发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", targetCaches[i].GUID, _targets[targetCaches[i].GUID].transform.FullName(), targetCaches[i].transform.FullName())); } } } #endregion #region 判断步骤ID是否重复 _stepContentIDs.Clear(); for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_stepContentIDs.ContainsKey(content.GUID)) { GlobalTools.LogError(string.Format("步骤控制者:发现相同GUID的步骤!GUID:{0}\r\n步骤:{1} 和 {2}", content.GUID, _stepContentIDs[content.GUID].Name, content.Name)); } else { _stepContentIDs.Add(content.GUID, content); } } #endregion #region 生成所有步骤信息 _stepContents.Clear(); _stepContentEnables.Clear(); _stepContentIndexs.Clear(); //启用所有步骤 if (disableStepIDs == null || disableStepIDs.Count == 0) { for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_targets.ContainsKey(content.TargetGUID)) { content.Target = _targets[content.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("步骤控制者:【步骤:{0}】【{1}】目标没有找到,目标路径:{2}", i, content.Name, content.TargetPath)); } for (int j = 0; j < content.Operations.Count; j++) { StepOperation operation = content.Operations[j]; if (_targets.ContainsKey(operation.TargetGUID)) { operation.Target = _targets[operation.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("步骤控制者:【步骤:{0}】【操作:{1}】目标没有找到,目标路径:{2}", i, operation.Name, operation.TargetPath)); } } _stepContents.Add(content); if (!_stepContentEnables.ContainsKey(content.GUID)) { _stepContentEnables.Add(content.GUID, true); _stepContentIndexs.Add(content.GUID, _stepContents.Count - 1); } } } //禁用 disableStepIDs 指定的步骤 else { for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_targets.ContainsKey(content.TargetGUID)) { content.Target = _targets[content.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("步骤控制者:【步骤:{0}】【{1}】目标没有找到,目标路径:{2}", i, content.Name, content.TargetPath)); } for (int j = 0; j < content.Operations.Count; j++) { StepOperation operation = content.Operations[j]; if (_targets.ContainsKey(operation.TargetGUID)) { operation.Target = _targets[operation.TargetGUID].gameObject; } else { GlobalTools.LogError(string.Format("步骤控制者:【步骤:{0}】【操作:{1}】目标没有找到,目标路径:{2}", i, operation.Name, operation.TargetPath)); } } _stepContents.Add(content); if (!_stepContentEnables.ContainsKey(content.GUID)) { _stepContentEnables.Add(content.GUID, !disableStepIDs.Contains(content.GUID)); _stepContentIndexs.Add(content.GUID, _stepContents.Count - 1); } } } _currentStepIndex = 0; _currentContent = null; _currentTarget = null; _currentHelper = null; _running = false; _pause = false; _executing = false; ClearCustomOrder(); #endregion } else { throw new HTFrameworkException(HTFrameworkModule.StepEditor, "步骤控制者:重新编译步骤失败,步骤控制者丢失了步骤资源 StepContentAsset!"); } }
private IEnumerator LoadCoroutine <T>(ResourceInfoBase info, HTFAction <float> loadingAction, HTFAction <T> loadDoneAction, bool isPrefab = false, Transform parent = null, bool isUI = false) where T : UnityEngine.Object { if (_isLoading) { yield return(_loadWait); } _isLoading = true; UnityEngine.Object asset = null; if (Mode == ResourceMode.Resource) { ResourceRequest request = Resources.LoadAsync <T>(info.ResourcePath); while (!request.isDone) { loadingAction?.Invoke(request.progress); yield return(null); } asset = request.asset; if (!asset) { GlobalTools.LogError("加载资源失败:Resources文件夹中不存在 " + typeof(T) + " 资源 " + info.ResourcePath); } else { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } } else { #if UNITY_EDITOR loadingAction?.Invoke(1); yield return(null); asset = AssetDatabase.LoadAssetAtPath <T>(info.AssetPath); if (!asset) { GlobalTools.LogError("加载资源失败:路径中不存在资源 " + info.AssetPath); } else { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } #else if (_assetBundles.ContainsKey(info.AssetBundleName)) { loadingAction?.Invoke(1); yield return(null); asset = _assetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (!asset) { GlobalTools.LogError("加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath); } else { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } } else { UnityWebRequest request = UnityWebRequest.Get(_assetBundlePath + info.AssetBundleName); DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(request.url, 0); request.downloadHandler = handler; request.SendWebRequest(); while (!request.isDone) { loadingAction?.Invoke(request.downloadProgress); yield return(null); } if (!request.isNetworkError && !request.isHttpError) { if (handler.assetBundle) { asset = handler.assetBundle.LoadAsset <T>(info.AssetPath); if (!asset) { GlobalTools.LogError("加载资源失败:AB包 " + info.AssetBundleName + " 中不存在资源 " + info.AssetPath); } else { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } if (IsCacheAssetBundle) { if (!_assetBundles.ContainsKey(info.AssetBundleName)) { _assetBundles.Add(info.AssetBundleName, handler.assetBundle); } } else { handler.assetBundle.Unload(false); } } else { GlobalTools.LogError("请求:" + request.url + " 未下载到AB包!"); } } else { GlobalTools.LogError("请求:" + request.url + " 遇到网络错误:" + request.error); } request.Dispose(); handler.Dispose(); } #endif } if (asset) { DataSetInfo dataSet = info as DataSetInfo; if (dataSet != null && dataSet.Data != null) { (asset as DataSet).Fill(dataSet.Data); } loadDoneAction?.Invoke(asset as T); } asset = null; _isLoading = false; }
/// <summary> /// 获取已经打开的UI /// </summary> /// <param name="type">UI逻辑类</param> /// <returns>UI逻辑对象</returns> public UILogicBase GetOpenedUI(Type type) { UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>(); if (attribute != null) { switch (attribute.EntityType) { case UIType.Overlay: if (_overlayUIs.ContainsKey(type)) { UILogicBase ui = _overlayUIs[type]; if (ui.IsOpened) { return(ui); } else { return(null); } } else { GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 并未存在,或并未打开!", type.Name)); return(null); } case UIType.Camera: if (_cameraUIs.ContainsKey(type)) { UILogicBase ui = _cameraUIs[type]; if (ui.IsOpened) { return(ui); } else { return(null); } } else { GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 并未存在,或并未打开!", type.Name)); return(null); } case UIType.World: if (_worldUIs.ContainsKey(attribute.WorldUIDomainName)) { return(_worldUIs[attribute.WorldUIDomainName].GetOpenedUI(type)); } else { GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName)); return(null); } } } return(null); }
/// <summary> /// 销毁UI /// </summary> /// <param name="type">UI逻辑类</param> public void DestroyUI(Type type) { UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>(); if (attribute != null) { switch (attribute.EntityType) { case UIType.Overlay: if (_overlayUIs.ContainsKey(type)) { UILogicBase ui = _overlayUIs[type]; if (!ui.IsCreated) { return; } if (ui.IsOpened) { return; } ui.OnDestroy(); Destroy(ui.UIEntity); ui.UIEntity = null; } else { GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.Camera: if (_cameraUIs.ContainsKey(type)) { UILogicBase ui = _cameraUIs[type]; if (!ui.IsCreated) { return; } if (ui.IsOpened) { return; } ui.OnDestroy(); Destroy(ui.UIEntity); ui.UIEntity = null; } else { GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.World: if (_worldUIs.ContainsKey(attribute.WorldUIDomainName)) { _worldUIs[attribute.WorldUIDomainName].DestroyUI(type); } else { GlobalTools.LogError(string.Format("销毁UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName)); } break; } } }
/// <summary> /// 打开非常驻UI /// </summary> /// <param name="type">非常驻UI逻辑类</param> /// <param name="args">可选参数</param> /// <returns>加载协程</returns> public Coroutine OpenTemporaryUI(Type type, params object[] args) { UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>(); if (attribute != null) { switch (attribute.EntityType) { case UIType.Overlay: if (_overlayUIs.ContainsKey(type)) { UILogicTemporary ui = _overlayUIs[type] as UILogicTemporary; if (ui.IsOpened) { return(null); } if (_currentOverlayTemporaryUI != null && _currentOverlayTemporaryUI.IsOpened) { _currentOverlayTemporaryUI.UIEntity.SetActive(false); _currentOverlayTemporaryUI.OnClose(); _currentOverlayTemporaryUI = null; } if (!ui.IsCreated) { return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _overlayTemporaryPanel, null, (obj) => { ui.UIEntity = obj; ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnInit(); ui.OnOpen(args); _currentOverlayTemporaryUI = ui; }, true)); } else { ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnOpen(args); _currentOverlayTemporaryUI = ui; } } else { GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.Camera: if (_cameraUIs.ContainsKey(type)) { UILogicTemporary ui = _cameraUIs[type] as UILogicTemporary; if (ui.IsOpened) { return(null); } if (_currentCameraTemporaryUI != null && _currentCameraTemporaryUI.IsOpened) { _currentCameraTemporaryUI.UIEntity.SetActive(false); _currentCameraTemporaryUI.OnClose(); _currentCameraTemporaryUI = null; } if (!ui.IsCreated) { return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _cameraTemporaryPanel, null, (obj) => { ui.UIEntity = obj; ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnInit(); ui.OnOpen(args); _currentCameraTemporaryUI = ui; }, true)); } else { ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnOpen(args); _currentCameraTemporaryUI = ui; } } else { GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.World: if (_worldUIs.ContainsKey(attribute.WorldUIDomainName)) { return(_worldUIs[attribute.WorldUIDomainName].OpenTemporaryUI(type, args)); } else { GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName)); } break; } } return(null); }
public override void OnInitialization() { base.OnInitialization(); _UIEntity = transform.FindChildren("UIEntity"); _overlayUIRoot = _UIEntity.transform.Find("OverlayUIRoot"); _overlayUIRootRect = _overlayUIRoot.rectTransform(); _overlayResidentPanel = _overlayUIRoot.Find("ResidentPanel"); _overlayTemporaryPanel = _overlayUIRoot.Find("TemporaryPanel"); _cameraUIRoot = _UIEntity.transform.Find("CameraUIRoot"); _cameraUIRootRect = _cameraUIRoot.rectTransform(); _cameraResidentPanel = _cameraUIRoot.Find("ResidentPanel"); _cameraTemporaryPanel = _cameraUIRoot.Find("TemporaryPanel"); _worldUIRoot = _UIEntity.transform.Find("WorldUIRoot"); UICamera = _UIEntity.GetComponentByChild <Camera>("UICamera"); _overlayUIRoot.gameObject.SetActive(IsEnableOverlayUI); _cameraUIRoot.gameObject.SetActive(IsEnableCameraUI); UICamera.gameObject.SetActive(IsEnableCameraUI); _worldUIRoot.gameObject.SetActive(IsEnableWorldUI); //创建所有UI的逻辑对象 List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); for (int i = 0; i < types.Count; i++) { if (types[i].IsSubclassOf(typeof(UILogicResident)) || types[i].IsSubclassOf(typeof(UILogicTemporary))) { UIResourceAttribute attribute = types[i].GetCustomAttribute <UIResourceAttribute>(); if (attribute != null) { switch (attribute.EntityType) { case UIType.Overlay: if (IsEnableOverlayUI) { _overlayUIs.Add(types[i], Activator.CreateInstance(types[i]) as UILogicBase); } break; case UIType.Camera: if (IsEnableCameraUI) { _cameraUIs.Add(types[i], Activator.CreateInstance(types[i]) as UILogicBase); } break; case UIType.World: if (IsEnableWorldUI) { if (!_worldUIs.ContainsKey(attribute.WorldUIDomainName)) { _worldUIs.Add(attribute.WorldUIDomainName, new WorldUIDomain(attribute.WorldUIDomainName, _worldUIRoot.FindChildren("CanvasTem"))); } _worldUIs[attribute.WorldUIDomainName].Injection(types[i]); } break; } } else { GlobalTools.LogError(string.Format("创建UI逻辑对象失败:UI逻辑类 {0} 丢失 UIResourceAttribute 标记!", types[i].Name)); } } } }
/// <summary> /// 预加载非常驻UI /// </summary> /// <param name="type">非常驻UI逻辑类</param> /// <returns>加载协程</returns> public Coroutine PreloadingTemporaryUI(Type type) { UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>(); if (attribute != null) { switch (attribute.EntityType) { case UIType.Overlay: if (_overlayUIs.ContainsKey(type)) { UILogicBase ui = _overlayUIs[type]; if (!ui.IsCreated) { return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _overlayTemporaryPanel, null, (obj) => { ui.UIEntity = obj; ui.OnInit(); }, true)); } } else { GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.Camera: if (_cameraUIs.ContainsKey(type)) { UILogicBase ui = _cameraUIs[type]; if (!ui.IsCreated) { return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _cameraTemporaryPanel, null, (obj) => { ui.UIEntity = obj; ui.OnInit(); }, true)); } } else { GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.World: if (_worldUIs.ContainsKey(attribute.WorldUIDomainName)) { return(_worldUIs[attribute.WorldUIDomainName].PreloadingTemporaryUI(type)); } else { GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName)); } break; } } return(null); }
private IEnumerator SkipCurrentStepCoroutine() { _executing = true; _currentContent.Skip(this); Main.m_Controller.TheControlMode = _currentContent.InitialMode; Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, false); Main.m_Controller.SetLookAngle(_currentContent.BestView, true); SkipStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false); //UGUI按钮点击型步骤,自动执行按钮事件 if (_currentContent.Trigger == StepTrigger.ButtonClick) { if (_currentButton) { _currentButton.onClick.Invoke(); } else { _currentButton = _currentContent.Target.GetComponent <Button>(); if (_currentButton) { _currentButton.onClick.Invoke(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的目标丢失Button组件!", _currentStep + 1)); } } _currentButton = null; } //创建步骤助手 if (_currentHelper == null && _currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Skip; _currentHelper.OnInit(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper)); } } //助手执行跳过,等待生命周期结束后销毁助手 if (_currentHelper != null) { _currentHelper.Task = StepHelperTask.Skip; _currentHelper.OnSkip(); if (_currentHelper.SkipLifeTime > 0) { yield return(YieldInstructioner.GetWaitForSeconds(_currentHelper.SkipLifeTime / SkipMultiple)); } _currentHelper.OnTermination(); _currentHelper = null; } yield return(YieldInstructioner.GetWaitForSeconds(_currentContent.ElapseTime / SkipMultiple)); yield return(WaitCoroutine(ChangeNextStep, 0)); }
private void BeginCurrentStep() { _executing = false; _currentContent = _stepContents[_currentStep]; _currentTarget = _currentContent.Target.GetComponent <StepTarget>(); //UGUI按钮点击型步骤,注册监听 if (_currentContent.Trigger == StepTrigger.ButtonClick) { _isButtonClick = false; _currentButton = _currentContent.Target.GetComponent <Button>(); if (_currentButton) { _currentButton.onClick.AddListener(ButtonClickCallback); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的目标丢失Button组件!", _currentStep + 1)); } } //状态改变触发类型的步骤,自动重置状态 else if (_currentContent.Trigger == StepTrigger.StateChange) { _currentTarget.State = StepTargetState.Normal; } //创建步骤助手 if (_currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Parameters = _currentContent.Parameters; for (int i = 0; i < _currentHelper.Parameters.Count; i++) { if (_currentHelper.Parameters[i].Type == StepParameter.ParameterType.GameObject) { if (_targets.ContainsKey(_currentHelper.Parameters[i].GameObjectGUID)) { _currentHelper.Parameters[i].GameObjectValue = _targets[_currentHelper.Parameters[i].GameObjectGUID].gameObject; } } } _currentHelper.Content = _currentContent; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Execute; _currentHelper.OnInit(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper)); } } if (_stepContentEnables.ContainsKey(_currentContent.GUID)) { BeginStepEvent?.Invoke(_currentContent, _stepContentEnables[_currentContent.GUID]); if (!_stepContentEnables[_currentContent.GUID]) { StartCoroutine(SkipCurrentStepCoroutine()); } } else { BeginStepEvent?.Invoke(_currentContent, false); } }
/// <summary> /// 重新编译步骤内容 /// </summary> /// <param name="prohibitStepIndex">禁用的步骤索引列表(当为null时启用所有步骤)</param> public void RecompileStepContent(List <int> prohibitStepIndex = null) { if (ContentAsset) { _targets.Clear(); GameObject[] rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject rootObj in rootObjs) { StepTarget[] targets = rootObj.transform.GetComponentsInChildren <StepTarget>(true); foreach (StepTarget target in targets) { if (!_targets.ContainsKey(target.GUID)) { _targets.Add(target.GUID, target); } else { GlobalTools.LogWarning("发现相同GUID的目标!GUID:" + target.GUID + "!\r\n目标物体:" + _targets[target.GUID].transform.FullName() + " 和 " + target.transform.FullName()); } } } _stepContents.Clear(); //启用所有步骤 if (prohibitStepIndex == null) { for (int i = 0; i < ContentAsset.Content.Count; i++) { StepContent content = ContentAsset.Content[i]; if (_targets.ContainsKey(content.TargetGUID)) { content.Target = _targets[content.TargetGUID].gameObject; } else { GlobalTools.LogError("【步骤:" + (i + 1) + "】【" + content.Name + "】目标没有找到,目标路径:" + content.TargetPath); } for (int j = 0; j < content.Operations.Count; j++) { StepOperation operation = content.Operations[j]; if (_targets.ContainsKey(operation.TargetGUID)) { operation.Target = _targets[operation.TargetGUID].gameObject; } else { GlobalTools.LogError("【步骤:" + (i + 1) + "】【操作:" + operation.Name + "】目标没有找到,目标路径:" + operation.TargetPath); } } _stepContents.Add(content); } } //禁用 prohibitStepIndex 指定的步骤 else { for (int i = 0; i < ContentAsset.Content.Count; i++) { if (prohibitStepIndex.Contains(i)) { continue; } StepContent content = ContentAsset.Content[i]; if (_targets.ContainsKey(content.TargetGUID)) { content.Target = _targets[content.TargetGUID].gameObject; } else { GlobalTools.LogError("【步骤:" + (i + 1) + "】【" + content.Name + "】目标没有找到,目标路径:" + content.TargetPath); } for (int j = 0; j < content.Operations.Count; j++) { StepOperation operation = content.Operations[j]; if (_targets.ContainsKey(operation.TargetGUID)) { operation.Target = _targets[operation.TargetGUID].gameObject; } else { GlobalTools.LogError("【步骤:" + (i + 1) + "】【操作:" + operation.Name + "】目标没有找到,目标路径:" + operation.TargetPath); } } _stepContents.Add(content); } } _currentStep = 0; _currentContent = null; _currentTarget = null; _ongoing = false; _running = false; ClearCustomOrder(); } else { GlobalTools.LogWarning("步骤控制器丢失了步骤资源 Step Content Asset!"); } }
private IEnumerator SkipStepCoroutine(int index) { _executing = true; _skipIndex = index; while (_currentStep < _skipIndex) { _currentContent = _stepContents[_currentStep]; _currentTarget = _currentContent.Target.GetComponent <StepTarget>(); _currentContent.Skip(this); SkipStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false); //UGUI按钮点击型步骤,自动执行按钮事件 if (_currentContent.Trigger == StepTrigger.ButtonClick) { if (_currentButton) { _currentButton.onClick.Invoke(); } else { _currentButton = _currentContent.Target.GetComponent <Button>(); if (_currentButton) { _currentButton.onClick.Invoke(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的目标丢失Button组件!", _currentStep + 1)); } } _currentButton = null; } //创建步骤助手 if (_currentHelper == null && _currentContent.Helper != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(_currentContent.Helper); if (type != null) { _currentHelper = Activator.CreateInstance(type) as StepHelper; _currentHelper.Parameters = _currentContent.Parameters; for (int i = 0; i < _currentHelper.Parameters.Count; i++) { if (_currentHelper.Parameters[i].Type == StepParameter.ParameterType.GameObject) { if (_targets.ContainsKey(_currentHelper.Parameters[i].GameObjectGUID)) { _currentHelper.Parameters[i].GameObjectValue = _targets[_currentHelper.Parameters[i].GameObjectGUID].gameObject; } } } _currentHelper.Content = _currentContent; _currentHelper.Target = _currentTarget; _currentHelper.Task = StepHelperTask.Skip; _currentHelper.OnInit(); } else { GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper)); } } //助手执行跳过,等待生命周期结束后销毁助手 if (_currentHelper != null) { _currentHelper.Task = StepHelperTask.Skip; _currentHelper.OnSkip(); if (_currentHelper.SkipLifeTime > 0) { yield return(YieldInstructioner.GetWaitForSeconds(_currentHelper.SkipLifeTime / SkipMultiple)); } _currentHelper.OnTermination(); _currentHelper = null; } yield return(YieldInstructioner.GetWaitForSeconds(_currentContent.ElapseTime / SkipMultiple)); _currentStep += 1; } SkipStepDoneEvent?.Invoke(); yield return(WaitCoroutine(BeginCurrentStep, 0)); }
private void Check() { for (int i = 0; i < CheckBuildPreconditions.Count; i++) { if (!CheckBuildPreconditions[i]()) { _isCanBuild = false; GlobalTools.LogError("当前无法构建项目:未满足允许项目构建的前置条件!"); return; } } Main main = FindObjectOfType <Main>(); if (main == null) { _isCanBuild = false; GlobalTools.LogError("当前无法构建项目:请先打开包含框架主体的场景!"); return; } ProcedureManager procedure = main.GetComponentByChild <ProcedureManager>("Procedure"); if (procedure != null && procedure.ActivatedProcedures.Count <= 0) { _isCanBuild = false; GlobalTools.LogError("当前无法构建项目:请添加至少一个流程!"); return; } EntityManager entity = main.GetComponentByChild <EntityManager>("Entity"); if (entity != null) { for (int i = 0; i < entity.DefineEntityTargets.Count; i++) { if (entity.DefineEntityTargets[i] == null) { _isCanBuild = false; GlobalTools.LogError("当前无法构建项目:实体管理器丢失了至少一个预定义对象!"); return; } } } UIManager ui = main.GetComponentByChild <UIManager>("UI"); if (ui != null) { for (int i = 0; i < ui.DefineUIEntitys.Count; i++) { if (ui.DefineUIEntitys[i] == null) { _isCanBuild = false; GlobalTools.LogError("当前无法构建项目:UI管理器丢失了至少一个预定义对象!"); return; } } } _isCanBuild = true; }
public override void OnInspectorGUI() { GUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("State Count:" + _target.StateNames.Count, MessageType.Info); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); Toggle(_target.IsAutoRegister, out _target.IsAutoRegister, "Auto Register"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Name: "); TextField(_target.Name, out _target.Name); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Data: "); if (GUILayout.Button(_target.Data, "MiniPopup")) { GenericMenu gm = new GenericMenu(); List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); gm.AddItem(new GUIContent("<None>"), _target.Data == "<None>", () => { Undo.RecordObject(target, "Set FSM Data Class"); _target.Data = "<None>"; HasChanged(); }); for (int i = 0; i < types.Count; i++) { if (types[i].BaseType == typeof(FSMData)) { int j = i; gm.AddItem(new GUIContent(types[j].FullName), _target.Data == types[j].FullName, () => { Undo.RecordObject(target, "Set FSM Data Class"); _target.Data = types[j].FullName; HasChanged(); }); } } gm.ShowAsContext(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.enabled = _target.DefaultStateName != ""; GUILayout.Label("Default: " + _target.DefaultStateName); GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.enabled = _target.StateNames.Count > 0; if (GUILayout.Button("Set Default", "MiniPopup")) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < _target.StateNames.Count; i++) { int j = i; gm.AddItem(new GUIContent(_target.StateNames[j]), _target.DefaultStateName == _target.StateNames[j], () => { Undo.RecordObject(target, "Set FSM Default State"); _target.DefaultState = _target.States[j]; _target.DefaultStateName = _target.StateNames[j]; HasChanged(); }); } gm.ShowAsContext(); } GUI.enabled = true; GUILayout.EndHorizontal(); for (int i = 0; i < _target.StateNames.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label(string.Format("{0}.{1}", i + 1, _target.StateNames[i])); GUILayout.FlexibleSpace(); if (GUILayout.Button("Edit", "minibuttonleft")) { if (_stateTypes.ContainsKey(_target.States[i])) { UnityEngine.Object classFile = AssetDatabase.LoadAssetAtPath(_stateTypes[_target.States[i]], typeof(TextAsset)); if (classFile) { AssetDatabase.OpenAsset(classFile); } else { GlobalTools.LogError("没有找到 " + _target.States[i] + " 脚本文件!"); } } else { GlobalTools.LogError("没有找到 " + _target.States[i] + " 脚本文件!"); } } if (GUILayout.Button("Delete", "minibuttonright")) { Undo.RecordObject(target, "Delete FSM State"); if (_target.DefaultStateName == _target.StateNames[i]) { _target.DefaultState = ""; _target.DefaultStateName = ""; } _target.States.RemoveAt(i); _target.StateNames.RemoveAt(i); if (_target.DefaultStateName == "" && _target.StateNames.Count > 0) { _target.DefaultState = _target.States[0]; _target.DefaultStateName = _target.StateNames[0]; } HasChanged(); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Add State", "MiniPopup")) { GenericMenu gm = new GenericMenu(); List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); for (int i = 0; i < types.Count; i++) { if (types[i].BaseType == typeof(FiniteState)) { int j = i; string stateName = types[j].FullName; FiniteStateNameAttribute fsmAtt = types[j].GetCustomAttribute <FiniteStateNameAttribute>(); if (fsmAtt != null) { stateName = fsmAtt.Name; } if (_target.States.Contains(types[j].FullName)) { gm.AddDisabledItem(new GUIContent(stateName)); } else { gm.AddItem(new GUIContent(stateName), false, () => { Undo.RecordObject(target, "Add FSM State"); _target.States.Add(types[j].FullName); _target.StateNames.Add(stateName); if (_target.DefaultStateName == "") { _target.DefaultState = _target.States[0]; _target.DefaultStateName = _target.StateNames[0]; } HasChanged(); }); } } } gm.ShowAsContext(); } GUILayout.EndHorizontal(); base.OnInspectorGUI(); }
//异步加载资源 private IEnumerator LoadAssetAsync <T>(ResourceInfoBase info, HTFAction <float> loadingAction, HTFAction <T> loadDoneAction, bool isPrefab = false, Transform parent = null, bool isUI = false) where T : UnityEngine.Object { DateTime beginTime = DateTime.Now; if (_isLoading) { yield return(_loadWait); } _isLoading = true; yield return(Main.Current.StartCoroutine(LoadDependenciesAssetBundleAsync(info.AssetBundleName))); DateTime waitTime = DateTime.Now; UnityEngine.Object asset = null; if (Mode == ResourceLoadMode.Resource) { ResourceRequest request = Resources.LoadAsync <T>(info.ResourcePath); while (!request.isDone) { loadingAction?.Invoke(request.progress); yield return(null); } asset = request.asset; if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { GlobalTools.LogError(string.Format("加载资源失败:Resources文件夹中不存在资源 {0}!", info.ResourcePath)); } } else { #if UNITY_EDITOR if (IsEditorMode) { loadingAction?.Invoke(1); yield return(null); asset = AssetDatabase.LoadAssetAtPath <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { GlobalTools.LogError(string.Format("加载资源失败:路径中不存在资源 {0}!", info.AssetPath)); } } else { if (_assetBundles.ContainsKey(info.AssetBundleName)) { loadingAction?.Invoke(1); yield return(null); asset = _assetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { GlobalTools.LogError(string.Format("加载资源失败:AB包 {0} 中不存在资源 {1}!", info.AssetBundleName, info.AssetPath)); } } else { using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(_assetBundleRootPath + info.AssetBundleName, GetAssetBundleHash(info.AssetBundleName))) { request.SendWebRequest(); while (!request.isDone) { loadingAction?.Invoke(request.downloadProgress); yield return(null); } if (!request.isNetworkError && !request.isHttpError) { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); if (bundle) { asset = bundle.LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { GlobalTools.LogError(string.Format("加载资源失败:AB包 {0} 中不存在资源 {1}!", info.AssetBundleName, info.AssetPath)); } if (IsCacheAssetBundle) { if (!_assetBundles.ContainsKey(info.AssetBundleName)) { _assetBundles.Add(info.AssetBundleName, bundle); } } else { bundle.Unload(false); } } else { GlobalTools.LogError(string.Format("请求:{0} 未下载到AB包!", request.url)); } } else { GlobalTools.LogError(string.Format("请求:{0} 遇到网络错误:{1}!", request.url, request.error)); } } } } #else if (_assetBundles.ContainsKey(info.AssetBundleName)) { loadingAction?.Invoke(1); yield return(null); asset = _assetBundles[info.AssetBundleName].LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { GlobalTools.LogError(string.Format("加载资源失败:AB包 {0} 中不存在资源 {1}!", info.AssetBundleName, info.AssetPath)); } } else { using (UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(_assetBundleRootPath + info.AssetBundleName, GetAssetBundleHash(info.AssetBundleName))) { request.SendWebRequest(); while (!request.isDone) { loadingAction?.Invoke(request.downloadProgress); yield return(null); } if (!request.isNetworkError && !request.isHttpError) { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); if (bundle) { asset = bundle.LoadAsset <T>(info.AssetPath); if (asset) { if (isPrefab) { asset = ClonePrefab(asset as GameObject, parent, isUI); } } else { GlobalTools.LogError(string.Format("加载资源失败:AB包 {0} 中不存在资源 {1}!", info.AssetBundleName, info.AssetPath)); } if (IsCacheAssetBundle) { if (!_assetBundles.ContainsKey(info.AssetBundleName)) { _assetBundles.Add(info.AssetBundleName, bundle); } } else { bundle.Unload(false); } } else { GlobalTools.LogError(string.Format("请求:{0} 未下载到AB包!", request.url)); } } else { GlobalTools.LogError(string.Format("请求:{0} 遇到网络错误:{1}!", request.url, request.error)); } } } #endif } DateTime endTime = DateTime.Now; GlobalTools.LogInfo(string.Format("异步加载资源{0}[{1}模式]:\r\n{2}\r\n等待耗时:{3}秒 加载耗时:{4}秒", asset ? "成功" : "失败", Mode , Mode == ResourceLoadMode.Resource ? info.GetResourceFullPath() : info.GetAssetBundleFullPath(_assetBundleRootPath) , (waitTime - beginTime).TotalSeconds, (endTime - waitTime).TotalSeconds)); if (asset) { DataSetInfo dataSet = info as DataSetInfo; if (dataSet != null && dataSet.Data != null) { asset.Cast <DataSet>().Fill(dataSet.Data); } loadDoneAction?.Invoke(asset as T); } asset = null; _isLoading = false; }
protected override void OnInspectorDefaultGUI() { base.OnInspectorDefaultGUI(); GUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Procedure Manager, this is the beginning and the end of everything!", MessageType.Info); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.enabled = Target.DefaultProcedure != ""; GUILayout.Label("Default: " + Target.DefaultProcedure); GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.enabled = Target.ActivatedProcedures.Count > 0; if (GUILayout.Button("Set Default", EditorGlobalTools.Styles.MiniPopup)) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < Target.ActivatedProcedures.Count; i++) { int j = i; gm.AddItem(new GUIContent(Target.ActivatedProcedures[j]), Target.DefaultProcedure == Target.ActivatedProcedures[j], () => { Undo.RecordObject(target, "Set Default Procedure"); Target.DefaultProcedure = Target.ActivatedProcedures[j]; HasChanged(); }); } gm.ShowAsContext(); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginVertical(EditorGlobalTools.Styles.Box); GUILayout.BeginHorizontal(); GUILayout.Label("Enabled Procedures:"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); for (int i = 0; i < Target.ActivatedProcedures.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label((i + 1) + "." + Target.ActivatedProcedures[i]); GUILayout.FlexibleSpace(); if (GUILayout.Button("▲", EditorStyles.miniButtonLeft)) { if (i > 0) { Undo.RecordObject(target, "Set Procedure Order"); string procedure = Target.ActivatedProcedures[i]; Target.ActivatedProcedures.RemoveAt(i); Target.ActivatedProcedures.Insert(i - 1, procedure); HasChanged(); continue; } } if (GUILayout.Button("▼", EditorStyles.miniButtonMid)) { if (i < Target.ActivatedProcedures.Count - 1) { Undo.RecordObject(target, "Set Procedure Order"); string procedure = Target.ActivatedProcedures[i]; Target.ActivatedProcedures.RemoveAt(i); Target.ActivatedProcedures.Insert(i + 1, procedure); HasChanged(); continue; } } if (GUILayout.Button("Edit", EditorStyles.miniButtonMid)) { string[] names = Target.ActivatedProcedures[i].Split('.'); if (_procedureTypes.ContainsKey(names[names.Length - 1])) { UnityEngine.Object classFile = AssetDatabase.LoadAssetAtPath(_procedureTypes[names[names.Length - 1]], typeof(TextAsset)); if (classFile) { AssetDatabase.OpenAsset(classFile); } else { GlobalTools.LogError("没有找到 " + Target.ActivatedProcedures[i] + " 脚本文件!"); } } else { GlobalTools.LogError("没有找到 " + Target.ActivatedProcedures[i] + " 脚本文件!"); } } if (GUILayout.Button("Delete", EditorStyles.miniButtonRight)) { Undo.RecordObject(target, "Delete Procedure"); if (Target.DefaultProcedure == Target.ActivatedProcedures[i]) { Target.DefaultProcedure = ""; } Target.ActivatedProcedures.RemoveAt(i); if (Target.DefaultProcedure == "" && Target.ActivatedProcedures.Count > 0) { Target.DefaultProcedure = Target.ActivatedProcedures[0]; } HasChanged(); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Procedure", EditorGlobalTools.Styles.MiniPopup)) { GenericMenu gm = new GenericMenu(); List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); for (int i = 0; i < types.Count; i++) { if (types[i].IsSubclassOf(typeof(ProcedureBase))) { int j = i; if (Target.ActivatedProcedures.Contains(types[j].FullName)) { gm.AddDisabledItem(new GUIContent(types[j].FullName)); } else { gm.AddItem(new GUIContent(types[j].FullName), false, () => { Undo.RecordObject(target, "Add Procedure"); Target.ActivatedProcedures.Add(types[j].FullName); if (Target.DefaultProcedure == "") { Target.DefaultProcedure = Target.ActivatedProcedures[0]; } HasChanged(); }); } } } gm.ShowAsContext(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
private void Awake() { Main.m_FSM.RegisterFSM(this); //加载数据类 if (Data != "<None>") { Type type = GlobalTools.GetTypeInRunTimeAssemblies(Data); if (type != null) { if (type.BaseType == typeof(FSMData)) { _data = Activator.CreateInstance(type) as FSMData; _data.StateMachine = this; _data.OnInit(); } else { GlobalTools.LogError("创建数据类失败:数据类 " + Data + " 必须继承至有限状态机数据基类:FSMData!"); } } else { GlobalTools.LogError("创建数据类失败:丢失数据类 " + Data + "!"); } } //加载所有状态 for (int i = 0; i < States.Count; i++) { Type type = GlobalTools.GetTypeInRunTimeAssemblies(States[i]); if (type != null) { if (type.BaseType == typeof(FiniteState)) { if (!_stateInstances.ContainsKey(type)) { FiniteState state = Activator.CreateInstance(type) as FiniteState; state.StateMachine = this; state.OnInit(); _stateInstances.Add(type, state); } } else { GlobalTools.LogError("加载有限状态失败:有限状态 " + States[i] + " 必须继承至有限状态基类:FiniteState!"); } } else { GlobalTools.LogError("加载有限状态失败:丢失有限状态 " + States[i] + "!"); } } //进入默认状态 if (DefaultState == "" || _stateInstances.Count <= 0) { GlobalTools.LogError("有限状态机 " + Name + " 的状态为空!或未指定默认状态!"); return; } Type dtype = GlobalTools.GetTypeInRunTimeAssemblies(DefaultState); if (dtype != null) { if (_stateInstances.ContainsKey(dtype)) { _currentState = _stateInstances[dtype]; _currentState.OnEnter(); } else { GlobalTools.LogError("切换状态失败:有限状态机 " + Name + " 不存在状态 " + dtype.Name + "!"); } } else { GlobalTools.LogError("切换状态失败:丢失有限状态 " + DefaultState + "!"); } }
private static void ConsoleDebugLogError() { GlobalTools.LogError("Debug.LogError!"); }
protected override void OnInspectorDefaultGUI() { base.OnInspectorDefaultGUI(); GUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Finite state machine!", MessageType.Info); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); Toggle(Target.IsAutoRegister, out Target.IsAutoRegister, "Auto Register"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); TextField(Target.Name, out Target.Name, "Name"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.color = Target.Data == "<None>" ? Color.gray : Color.white; GUILayout.Label("Data", GUILayout.Width(60)); if (GUILayout.Button(Target.Data, EditorGlobalTools.Styles.MiniPopup)) { GenericMenu gm = new GenericMenu(); gm.AddItem(new GUIContent("<None>"), Target.Data == "<None>", () => { Undo.RecordObject(target, "Set FSM Data Class"); Target.Data = "<None>"; HasChanged(); }); List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); for (int i = 0; i < types.Count; i++) { if (types[i].IsSubclassOf(typeof(FSMDataBase))) { int j = i; gm.AddItem(new GUIContent(types[j].FullName), Target.Data == types[j].FullName, () => { Undo.RecordObject(target, "Set FSM Data Class"); Target.Data = types[j].FullName; HasChanged(); }); } } gm.ShowAsContext(); } GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.enabled = Target.DefaultStateName != ""; GUILayout.Label("Default: " + Target.DefaultStateName); GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.enabled = Target.StateNames.Count > 0; if (GUILayout.Button("Set Default", EditorGlobalTools.Styles.MiniPopup)) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < Target.StateNames.Count; i++) { int j = i; gm.AddItem(new GUIContent(Target.StateNames[j]), Target.DefaultStateName == Target.StateNames[j], () => { Undo.RecordObject(target, "Set FSM Default State"); Target.DefaultState = Target.States[j]; Target.DefaultStateName = Target.StateNames[j]; HasChanged(); }); } gm.ShowAsContext(); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.enabled = Target.FinalStateName != ""; GUILayout.Label("Final: " + Target.FinalStateName); GUI.enabled = true; GUILayout.FlexibleSpace(); GUI.enabled = Target.StateNames.Count > 0; if (GUILayout.Button("Set Final", EditorGlobalTools.Styles.MiniPopup)) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < Target.StateNames.Count; i++) { int j = i; gm.AddItem(new GUIContent(Target.StateNames[j]), Target.FinalStateName == Target.StateNames[j], () => { Undo.RecordObject(target, "Set FSM Final State"); Target.FinalState = Target.States[j]; Target.FinalStateName = Target.StateNames[j]; HasChanged(); }); } gm.ShowAsContext(); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.BeginVertical(EditorGlobalTools.Styles.Box); GUILayout.BeginHorizontal(); GUILayout.Label("Enabled State:"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); for (int i = 0; i < Target.StateNames.Count; i++) { GUILayout.BeginHorizontal(); GUILayout.Label(string.Format("{0}.{1}", i + 1, Target.StateNames[i])); GUILayout.FlexibleSpace(); if (GUILayout.Button("Edit", EditorStyles.miniButtonLeft)) { string[] names = Target.States[i].Split('.'); if (_stateTypes.ContainsKey(names[names.Length - 1])) { UnityEngine.Object classFile = AssetDatabase.LoadAssetAtPath(_stateTypes[names[names.Length - 1]], typeof(TextAsset)); if (classFile) { AssetDatabase.OpenAsset(classFile); } else { GlobalTools.LogError("没有找到 " + Target.States[i] + " 脚本文件!"); } } else { GlobalTools.LogError("没有找到 " + Target.States[i] + " 脚本文件!"); } } if (GUILayout.Button("Delete", EditorStyles.miniButtonRight)) { Undo.RecordObject(target, "Delete FSM State"); if (Target.DefaultStateName == Target.StateNames[i]) { Target.DefaultState = ""; Target.DefaultStateName = ""; } if (Target.FinalStateName == Target.StateNames[i]) { Target.FinalState = ""; Target.FinalStateName = ""; } Target.States.RemoveAt(i); Target.StateNames.RemoveAt(i); if (Target.DefaultStateName == "" && Target.StateNames.Count > 0) { Target.DefaultState = Target.States[0]; Target.DefaultStateName = Target.StateNames[0]; } if (Target.FinalStateName == "" && Target.StateNames.Count > 0) { Target.FinalState = Target.States[0]; Target.FinalStateName = Target.StateNames[0]; } HasChanged(); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Add State", EditorGlobalTools.Styles.MiniPopup)) { GenericMenu gm = new GenericMenu(); List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies(); for (int i = 0; i < types.Count; i++) { if (types[i].IsSubclassOf(typeof(FiniteStateBase))) { int j = i; string stateName = types[j].FullName; FiniteStateNameAttribute fsmAtt = types[j].GetCustomAttribute <FiniteStateNameAttribute>(); if (fsmAtt != null) { stateName = fsmAtt.Name; } if (Target.States.Contains(types[j].FullName)) { gm.AddDisabledItem(new GUIContent(stateName)); } else { gm.AddItem(new GUIContent(stateName), false, () => { Undo.RecordObject(target, "Add FSM State"); Target.States.Add(types[j].FullName); Target.StateNames.Add(stateName); if (Target.DefaultStateName == "") { Target.DefaultState = Target.States[0]; Target.DefaultStateName = Target.StateNames[0]; } if (Target.FinalStateName == "") { Target.FinalState = Target.States[0]; Target.FinalStateName = Target.StateNames[0]; } HasChanged(); }); } } } gm.ShowAsContext(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
/// <summary> /// 打开常驻UI /// </summary> /// <param name="type">常驻UI逻辑类</param> /// <param name="args">可选参数</param> public void OpenResidentUI(Type type, params object[] args) { UIResourceAttribute attribute = type.GetCustomAttribute <UIResourceAttribute>(); if (attribute != null) { switch (attribute.EntityType) { case UIType.Overlay: if (_overlayUIs.ContainsKey(type)) { UILogicResident ui = _overlayUIs[type] as UILogicResident; if (ui.IsOpened) { return; } if (!ui.IsCreated) { Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _overlayResidentPanel, null, (obj) => { ui.UIEntity = obj; ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnInit(); ui.OnOpen(args); ui.OnPlaceTop(); }, true); } else { ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnOpen(args); ui.OnPlaceTop(); } } else { GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.Camera: if (_cameraUIs.ContainsKey(type)) { UILogicResident ui = _cameraUIs[type] as UILogicResident; if (ui.IsOpened) { return; } if (!ui.IsCreated) { Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _cameraResidentPanel, null, (obj) => { ui.UIEntity = obj; ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnInit(); ui.OnOpen(args); ui.OnPlaceTop(); }, true); } else { ui.UIEntity.transform.SetAsLastSibling(); ui.UIEntity.SetActive(true); ui.OnOpen(args); ui.OnPlaceTop(); } } else { GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name)); } break; case UIType.World: if (_worldUIs.ContainsKey(attribute.WorldUIDomainName)) { _worldUIs[attribute.WorldUIDomainName].OpenResidentUI(type); } else { GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 的域 {1} 并未存在!", type.Name, attribute.WorldUIDomainName)); } break; } } }