/// <summary> /// 克隆 /// </summary> /// <returns>新的对象</returns> internal StepOperation Clone() { StepOperation operation = new StepOperation(); operation.GUID = Guid.NewGuid().ToString(); operation.Anchor = Anchor; operation.ElapseTime = ElapseTime; operation.Instant = Instant; operation.Target = Target; operation.TargetGUID = TargetGUID; operation.TargetPath = TargetPath; operation.Name = Name; operation.OperationType = OperationType; operation.Vector3Value = Vector3Value; operation.Vector2Value = Vector2Value; operation.ColorValue = ColorValue; operation.IntValue = IntValue; operation.FloatValue = FloatValue; operation.StringValue = StringValue; operation.BoolValue = BoolValue; operation.AnimationEase = AnimationEase; operation.Vector3Value2 = Vector3Value2; operation.StringValue2 = StringValue2; operation.BoolValue2 = BoolValue2; return(operation); }
/// <summary> /// 重新编译步骤内容 /// </summary> /// <param name="prohibitStepID">禁用的步骤ID列表(当为null时启用所有步骤,禁用的步骤会自动跳过)</param> public void RecompileStepContent(HashSet <string> prohibitStepID = 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(string.Format("发现相同GUID的目标!GUID:{0}\r\n目标物体:{1} 和 {2}", target.GUID, _targets[target.GUID].transform.FullName(), target.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; _executing = false; ClearCustomOrder(); } else { GlobalTools.LogError("步骤控制器丢失了步骤资源 Step Content Asset!"); } }
/// <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!"); } }
/// <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 { Log.Warning(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 { Log.Warning(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)) { Log.Error(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 { Log.Error(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 { Log.Error(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 { Log.Error(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 { Log.Error(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!"); } }
/// <summary> /// 设置预览目标的初始变换 /// </summary> /// <param name="stepContent">步骤内容</param> /// <param name="operationIndex">步骤操作的索引</param> internal void SetPreviewTransform(StepContent stepContent, int operationIndex) { //已读取的节点 HashSet <int> alreadyReads = new HashSet <int>(); //是否已设置预览目标位置 bool isSetPosition = false; //是否已设置预览目标旋转 bool isSetRotation = false; //是否已设置预览目标缩放 bool isSetScale = false; //当前的连线右端节点 int index = operationIndex; while (true) { //已经完成预览目标的变换设置,结束遍历 if (isSetPosition && isSetRotation && isSetScale) { break; } //标记节点已读取 alreadyReads.Add(index); //读取连线左侧节点 int leftIndex = stepContent.GetLeftIndex(index); //左侧存在节点 if (leftIndex >= 0) { //如果重复读取到相同节点,则存在循环连线,结束遍历 if (alreadyReads.Contains(leftIndex)) { break; } //获取左侧节点,并设置位置、旋转、缩放 StepOperation operation = stepContent.Operations[leftIndex]; if (operation.Target == Target) { if (!isSetPosition) { if (operation.OperationType == StepOperationType.Move) { PreviewTarget.transform.localPosition = operation.Vector3Value; isSetPosition = true; } else if (operation.OperationType == StepOperationType.Transform) { PreviewTarget.transform.localPosition = operation.Vector3Value; isSetPosition = true; } } if (!isSetRotation) { if (operation.OperationType == StepOperationType.Rotate) { PreviewTarget.transform.localRotation = operation.Vector3Value.ToQuaternion(); isSetRotation = true; } else if (operation.OperationType == StepOperationType.Transform) { PreviewTarget.transform.localRotation = operation.Vector3Value2.ToQuaternion(); isSetRotation = true; } } if (!isSetScale) { if (operation.OperationType == StepOperationType.Scale) { PreviewTarget.transform.localScale = operation.Vector3Value; isSetScale = true; } else if (operation.OperationType == StepOperationType.Transform) { PreviewTarget.transform.localScale = operation.Vector3Value3; isSetScale = true; } } } index = leftIndex; } //左侧已不存在节点,结束遍历 else { break; } } //未找到连线中的移动相关节点,设置位置为初始值 if (!isSetPosition) { PreviewTarget.transform.localPosition = Target.transform.localPosition; } //未找到连线中的旋转相关节点,设置旋转为初始值 if (!isSetRotation) { PreviewTarget.transform.localRotation = Target.transform.localRotation; } //未找到连线中的缩放相关节点,设置缩放为初始值 if (!isSetScale) { PreviewTarget.transform.localScale = Target.transform.localScale; } alreadyReads = null; }