Exemple #1
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.Target = _currentTarget;
                    _currentHelper.Task   = StepHelperTask.Execute;
                    _currentHelper.OnInit();
                }
                else
                {
                    GlobalTools.LogError(string.Format("【步骤:{0}】的助手 {1} 丢失!", _currentStep + 1, _currentContent.Helper));
                }
            }

            Main.m_Controller.TheControlMode = _currentContent.InitialMode;
            Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, true);
            Main.m_Controller.SetLookAngle(_currentContent.BestView, true);

            if (_stepContentEnables.ContainsKey(_currentContent.GUID))
            {
                BeginStepEvent?.Invoke(_currentContent, _stepContentEnables[_currentContent.GUID]);
                if (!_stepContentEnables[_currentContent.GUID])
                {
                    StartCoroutine(SkipCurrentStepCoroutine());
                }
            }
            else
            {
                BeginStepEvent?.Invoke(_currentContent, false);
            }
        }
Exemple #2
0
        /// <summary>
        /// 恢复到指定步骤
        /// </summary>
        /// <param name="stepID">步骤ID</param>
        /// <returns>恢复成功/失败</returns>
        public bool RestoreStep(string stepID)
        {
            if (_running && !_executing)
            {
                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);
            }
        }
        /// <summary>
        /// 跳过到指定步骤(立即模式)
        /// </summary>
        /// <param name="index">步骤索引</param>
        private void SkipStepImmediateCoroutine(int index)
        {
            _executing       = true;
            _skipTargetIndex = index;

            CurrentTask = StepHelperTask.SkipImmediate;

            while (_currentStepIndex < _skipTargetIndex)
            {
                _currentContent = _stepContents[_currentStepIndex];
                _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                //UGUI按钮点击型步骤,自动执行按钮事件
                if (_currentContent.Trigger == StepTrigger.ButtonClick)
                {
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                        _currentButton.onClick.RemoveListener(ButtonClickCallback);
                    }
                    else
                    {
                        _currentButton = _currentContent.Target.GetComponent <Button>();
                        if (_currentButton)
                        {
                            _currentButton.onClick.Invoke();
                        }
                        else
                        {
                            Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                        }
                    }
                    _currentButton = null;
                }

                //创建步骤助手
                if (_currentHelper == null)
                {
                    _currentHelper = CreateHelper(_currentContent, StepHelperTask.SkipImmediate);
                }

                _currentContent.SkipImmediate();

                SkipStepImmediateEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                //助手执行跳过,等待生命周期结束后销毁助手
                if (_currentHelper != null)
                {
                    _currentHelper.Task = StepHelperTask.SkipImmediate;
                    _currentHelper.OnSkipImmediate();
                    _currentHelper.OnTermination();
                    _currentHelper = null;
                }

                _currentStepIndex += 1;
            }

            BeginCurrentStep();
        }
Exemple #4
0
        /// <summary>
        /// 结束整个流程
        /// </summary>
        public void End()
        {
            _currentContent = null;
            _currentTarget  = null;
            _running        = false;
            _executing      = false;

            EndEvent?.Invoke();
        }
Exemple #5
0
        private void ChangeParentSkip()
        {
            StepTarget parent = Main.m_StepMaster.GetTarget(StringValue);

            if (parent != null && parent.gameObject != Target)
            {
                Target.transform.SetParent(parent.transform);
            }
        }
        /// <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 >= _currentStepIndex)
                {
                    return(false);
                }

                CurrentTask = StepHelperTask.Restore;

                while (_currentStepIndex >= index)
                {
                    _currentContent = _stepContents[_currentStepIndex];
                    _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                    //创建步骤助手
                    if (_currentHelper == null)
                    {
                        _currentHelper = CreateHelper(_currentContent, StepHelperTask.Restore);
                    }

                    RestoreStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                    //助手执行恢复
                    if (_currentHelper != null)
                    {
                        _currentHelper.Task = StepHelperTask.Restore;
                        _currentHelper.OnRestore();
                        _currentHelper.OnTermination();
                        _currentHelper = null;
                    }

                    _currentStepIndex -= 1;
                }

                _currentStepIndex = index;
                BeginCurrentStep();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #7
0
        /// <summary>
        /// 恢复到指定步骤
        /// </summary>
        public bool RestoreStep(int stepIndex)
        {
            if (_ongoing && !_running)
            {
                if (stepIndex < 0 || stepIndex >= _currentStep)
                {
                    return(false);
                }

                while (_currentStep >= stepIndex)
                {
                    _currentContent = _stepContents[_currentStep];
                    _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                    if (RestoreStepEvent != null)
                    {
                        RestoreStepEvent(_currentContent);
                    }

                    //创建步骤助手
                    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("【步骤:" + (_currentStep + 1) + "】的助手 " + _currentContent.Helper + " 丢失!");
                        }
                    }
                    //助手执行恢复
                    if (_currentHelper != null)
                    {
                        _currentHelper.Task = StepHelperTask.Restore;
                        _currentHelper.OnRestore();
                        _currentHelper.OnTermination();
                        _currentHelper = null;
                    }

                    _currentStep -= 1;
                }

                _currentStep = stepIndex;
                BeginCurrentStep();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #8
0
        /// <summary>
        /// 结束整个流程
        /// </summary>
        public void End()
        {
            _currentContent = null;
            _currentTarget  = null;
            _ongoing        = false;
            _running        = false;

            if (EndEvent != null)
            {
                EndEvent();
            }
        }
        /// <summary>
        /// 结束任务流程
        /// </summary>
        public void End()
        {
            _currentStepIndex = 0;
            _currentContent   = null;
            _currentTarget    = null;
            _currentHelper    = null;
            _running          = false;
            _pause            = false;
            _executing        = false;

            EndEvent?.Invoke();
        }
Exemple #10
0
        private void BeginCurrentStep()
        {
            _running        = 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("【步骤:" + (_currentStep + 1) + "】的目标丢失Button组件!");
                }
            }
            //状态改变触发类型的步骤,自动重置状态
            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.Target = _currentTarget;
                    _currentHelper.Task   = StepHelperTask.Execute;
                    _currentHelper.OnInit();
                }
                else
                {
                    GlobalTools.LogError("【步骤:" + (_currentStep + 1) + "】的助手 " + _currentContent.Helper + " 丢失!");
                }
            }

            Main.m_Controller.TheControlMode = _currentContent.InitialMode;
            Main.m_Controller.SetLookPoint(_currentTarget.transform.position + _currentContent.ViewOffset, true);
            Main.m_Controller.SetLookAngle(_currentContent.BestView, true);

            if (BeginStepEvent != null)
            {
                BeginStepEvent(_currentContent);
            }
        }
Exemple #11
0
        /// <summary>
        /// 开始整个流程
        /// </summary>
        public void Begin()
        {
            if (!ContentAsset)
            {
                return;
            }

            _currentStep    = 0;
            _currentContent = null;
            _currentTarget  = null;
            _running        = true;
            _executing      = false;

            BeginEvent?.Invoke();

            BeginCurrentStep();
        }
        /// <summary>
        /// 步骤开始
        /// </summary>
        private void BeginCurrentStep()
        {
            _executing      = false;
            _currentContent = _stepContents[_currentStepIndex];
            _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

            CurrentTask = StepHelperTask.Execute;

            //UGUI按钮点击型步骤,注册监听
            if (_currentContent.Trigger == StepTrigger.ButtonClick)
            {
                _isButtonClick = false;
                _currentButton = _currentTarget.GetComponent <Button>();
                if (_currentButton)
                {
                    _currentButton.onClick.AddListener(ButtonClickCallback);
                }
                else
                {
                    Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                }
            }
            //状态改变触发类型的步骤,自动重置状态
            else if (_currentContent.Trigger == StepTrigger.StateChange)
            {
                _currentTarget.State = StepTargetState.Normal;
            }

            //激活的步骤正常启动,未激活的步骤自动跳过
            if (_stepContentEnables.ContainsKey(_currentContent.GUID) && _stepContentEnables[_currentContent.GUID])
            {
                //创建步骤助手
                _currentHelper = CreateHelper(_currentContent, StepHelperTask.Execute);

                BeginStepEvent?.Invoke(_currentContent, true);
            }
            else
            {
                //创建步骤助手
                _currentHelper = CreateHelper(_currentContent, StepHelperTask.SkipImmediate);

                BeginStepEvent?.Invoke(_currentContent, false);

                SkipCurrentStepImmediateCoroutine();
            }
        }
Exemple #13
0
        /// <summary>
        /// 开始整个流程
        /// </summary>
        public void Begin()
        {
            if (!ContentAsset || ContentAsset.Content.Count <= 0)
            {
                return;
            }

            _currentStep    = 0;
            _currentContent = null;
            _currentTarget  = null;
            _currentHelper  = null;
            _running        = true;
            _pause          = false;
            _executing      = false;

            BeginEvent?.Invoke();

            BeginCurrentStep();
        }
Exemple #14
0
        /// <summary>
        /// 开始步骤流程
        /// </summary>
        public void Begin()
        {
            if (!ContentAsset || ContentAsset.Content.Count <= 0 || _stepContents.Count <= 0)
            {
                throw new HTFrameworkException(HTFrameworkModule.StepEditor, "步骤控制者:当前无法开始步骤流程,请重新编译步骤内容 RecompileStepContent!");
            }

            _currentStepIndex = 0;
            _currentContent   = null;
            _currentTarget    = null;
            _currentHelper    = null;
            _running          = true;
            _pause            = false;
            _executing        = false;

            BeginEvent?.Invoke();

            BeginCurrentStep();
        }
Exemple #15
0
        /// <summary>
        /// 开始整个流程
        /// </summary>
        public void Begin(int beginIndex = 0)
        {
            if (!ContentAsset)
            {
                return;
            }

            _currentStep    = ((beginIndex <0 || beginIndex> _stepContents.Count - 1) ? 0 : beginIndex);
            _currentContent = null;
            _currentTarget  = null;
            _ongoing        = true;
            _running        = false;

            if (BeginEvent != null)
            {
                BeginEvent();
            }

            BeginCurrentStep();
        }
Exemple #16
0
        /// <summary>
        /// 结束任务流程
        /// </summary>
        public void End()
        {
            _currentStepIndex = 0;
            _currentContent   = null;
            _currentTarget    = null;
            _currentHelper    = null;
            _running          = false;
            _pause            = false;
            _executing        = false;

            StopSkip();

            if (_waitCoroutine != null)
            {
                Main.Current.StopCoroutine(_waitCoroutine);
                _waitCoroutine = null;
            }

            EndEvent?.Invoke();
        }
Exemple #17
0
        private IEnumerator SkipStepCoroutine(int index)
        {
            _executing = true;
            _skipIndex = index;

            while (_currentStep < _skipIndex)
            {
                _currentContent = _stepContents[_currentStep];
                _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();
                _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));

                _currentStep += 1;
            }

            SkipStepDoneEvent?.Invoke();

            BeginCurrentStep();
        }
Exemple #18
0
 protected override void OnEnable()
 {
     _target = target as StepTarget;
 }
Exemple #19
0
        private void ChangeParentGUI()
        {
            #region 父级目标物体丢失,根据目标GUID重新搜寻
            if (!GameObjectValue)
            {
                if (StringValue != "<None>")
                {
                    GameObjectValue = GameObject.Find(StringValue2);
                    if (!GameObjectValue)
                    {
                        StepTarget[] targets = UnityEngine.Object.FindObjectsOfType <StepTarget>();
                        foreach (StepTarget target in targets)
                        {
                            if (target.GUID == StringValue && !target.GetComponent <StepPreview>())
                            {
                                GameObjectValue = target.gameObject;
                                StringValue2    = target.transform.FullName();
                                break;
                            }
                        }
                    }
                    else
                    {
                        StepTarget target = GameObjectValue.GetComponent <StepTarget>();
                        if (!target)
                        {
                            target      = GameObjectValue.AddComponent <StepTarget>();
                            target.GUID = StringValue;
                        }
                    }
                }
            }
            #endregion

            GUILayout.BeginHorizontal();
            GUILayout.Label("Parent:", GUILayout.Width(50));
            GUI.color = GameObjectValue ? Color.white : Color.gray;
            GameObject parent = EditorGUILayout.ObjectField(GameObjectValue, typeof(GameObject), true, GUILayout.Width(130)) as GameObject;
            GUI.color = Color.white;
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("GUID: " + StringValue, GUILayout.Width(140));
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Clear", EditorStyles.miniButton, GUILayout.Width(40)))
            {
                parent       = GameObjectValue = null;
                StringValue  = "<None>";
                StringValue2 = "<None>";
                GUI.FocusControl(null);
            }
            GUILayout.EndHorizontal();

            #region 父级目标改变
            if (parent != GameObjectValue)
            {
                if (parent)
                {
                    StepTarget target = parent.GetComponent <StepTarget>();
                    if (!target)
                    {
                        target = parent.AddComponent <StepTarget>();
                    }
                    if (target.GUID == "<None>")
                    {
                        target.GUID = Guid.NewGuid().ToString();
                    }
                    GameObjectValue = parent;
                    StringValue     = target.GUID;
                    StringValue2    = parent.transform.FullName();
                }
            }
            #endregion
        }
Exemple #20
0
        protected override void OnBodyGUI()
        {
            base.OnBodyGUI();

            GUILayout.BeginVertical(EditorGlobalTools.Styles.Box);
            _scroll = GUILayout.BeginScrollView(_scroll);

            for (int i = 0; i < _content.Parameters.Count; i++)
            {
                StepParameter stepParameter = _content.Parameters[i];

                GUILayout.BeginVertical(EditorStyles.helpBox);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Type:", GUILayout.Width(40));
                stepParameter.Type = (StepParameter.ParameterType)EditorGUILayout.EnumPopup(stepParameter.Type, GUILayout.Width(100));
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("▲", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
                {
                    if (i > 0)
                    {
                        _content.Parameters.Remove(stepParameter);
                        _content.Parameters.Insert(i - 1, stepParameter);
                        continue;
                    }
                }
                if (GUILayout.Button("▼", EditorStyles.miniButtonMid, GUILayout.Width(20)))
                {
                    if (i < _content.Parameters.Count - 1)
                    {
                        _content.Parameters.Remove(stepParameter);
                        _content.Parameters.Insert(i + 1, stepParameter);
                        continue;
                    }
                }
                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("Delete", EditorStyles.miniButtonRight))
                {
                    _content.Parameters.RemoveAt(i);
                    continue;
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Name:", GUILayout.Width(40));
                stepParameter.Name = EditorGUILayout.TextField(stepParameter.Name);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Value:", GUILayout.Width(40));
                switch (_content.Parameters[i].Type)
                {
                case StepParameter.ParameterType.String:
                    stepParameter.StringValue = EditorGUILayout.TextField(stepParameter.StringValue);
                    break;

                case StepParameter.ParameterType.Integer:
                    stepParameter.IntegerValue = EditorGUILayout.IntField(stepParameter.IntegerValue);
                    break;

                case StepParameter.ParameterType.Float:
                    stepParameter.FloatValue = EditorGUILayout.FloatField(stepParameter.FloatValue);
                    break;

                case StepParameter.ParameterType.Boolean:
                    stepParameter.BooleanValue = EditorGUILayout.Toggle(stepParameter.BooleanValue);
                    break;

                case StepParameter.ParameterType.Vector2:
                    stepParameter.Vector2Value = EditorGUILayout.Vector2Field("", stepParameter.Vector2Value);
                    break;

                case StepParameter.ParameterType.Vector3:
                    stepParameter.Vector3Value = EditorGUILayout.Vector3Field("", stepParameter.Vector3Value);
                    break;

                case StepParameter.ParameterType.Color:
                    stepParameter.ColorValue = EditorGUILayout.ColorField(stepParameter.ColorValue);
                    break;

                case StepParameter.ParameterType.GameObject:
                    #region 步骤目标物体丢失,根据目标GUID重新搜寻
                    if (!stepParameter.GameObjectValue)
                    {
                        if (stepParameter.GameObjectGUID != "<None>")
                        {
                            stepParameter.GameObjectValue = GameObject.Find(stepParameter.GameObjectPath);
                            if (!stepParameter.GameObjectValue)
                            {
                                StepTarget[] targets = FindObjectsOfType <StepTarget>();
                                foreach (StepTarget target in targets)
                                {
                                    if (target.GUID == stepParameter.GameObjectGUID)
                                    {
                                        stepParameter.GameObjectValue = target.gameObject;
                                        stepParameter.GameObjectPath  = target.transform.FullName();
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                StepTarget target = stepParameter.GameObjectValue.GetComponent <StepTarget>();
                                if (!target)
                                {
                                    target      = stepParameter.GameObjectValue.AddComponent <StepTarget>();
                                    target.GUID = stepParameter.GameObjectGUID;
                                }
                            }
                        }
                    }
                    #endregion

                    GUI.color = stepParameter.GameObjectValue ? Color.white : Color.gray;
                    GameObject objValue = EditorGUILayout.ObjectField(stepParameter.GameObjectValue, typeof(GameObject), true) as GameObject;
                    GUI.color = Color.white;

                    #region 步骤目标改变
                    if (objValue != stepParameter.GameObjectValue)
                    {
                        if (objValue)
                        {
                            StepTarget target = objValue.GetComponent <StepTarget>();
                            if (!target)
                            {
                                target = objValue.AddComponent <StepTarget>();
                            }
                            if (target.GUID == "<None>")
                            {
                                target.GUID = Guid.NewGuid().ToString();
                            }
                            stepParameter.GameObjectValue = objValue;
                            stepParameter.GameObjectGUID  = target.GUID;
                            stepParameter.GameObjectPath  = objValue.transform.FullName();
                        }
                    }
                    #endregion
                    break;

                case StepParameter.ParameterType.Texture:
                    GUI.color = stepParameter.TextureValue ? Color.white : Color.gray;
                    stepParameter.TextureValue = EditorGUILayout.ObjectField(stepParameter.TextureValue, typeof(Texture), false) as Texture;
                    GUI.color = Color.white;
                    break;

                case StepParameter.ParameterType.AudioClip:
                    GUI.color = stepParameter.AudioClipValue ? Color.white : Color.gray;
                    stepParameter.AudioClipValue = EditorGUILayout.ObjectField(stepParameter.AudioClipValue, typeof(AudioClip), false) as AudioClip;
                    GUI.color = Color.white;
                    break;

                case StepParameter.ParameterType.Material:
                    GUI.color = stepParameter.MaterialValue ? Color.white : Color.gray;
                    stepParameter.MaterialValue = EditorGUILayout.ObjectField(stepParameter.MaterialValue, typeof(Material), false) as Material;
                    GUI.color = Color.white;
                    break;
                }
                GUILayout.EndHorizontal();

                if (_content.Parameters[i].Type == StepParameter.ParameterType.GameObject)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("GUID:", GUILayout.Width(40));
                    EditorGUILayout.TextField(_content.Parameters[i].GameObjectGUID);
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Clear", EditorStyles.miniButton, GUILayout.Width(40)))
                    {
                        _content.Parameters[i].GameObjectValue = null;
                        _content.Parameters[i].GameObjectGUID  = "<None>";
                        _content.Parameters[i].GameObjectPath  = "<None>";
                        GUI.FocusControl(null);
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add", EditorGlobalTools.Styles.ButtonLeft))
            {
                _content.Parameters.Add(new StepParameter());
            }
            if (GUILayout.Button("Clear", EditorGlobalTools.Styles.ButtonRight))
            {
                if (EditorUtility.DisplayDialog("Prompt", "Are you sure delete all parameter?", "Yes", "No"))
                {
                    _content.Parameters.Clear();
                }
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Apply"))
            {
                GUI.FocusControl(null);
                EditorUtility.SetDirty(_contentAsset);
            }
            GUILayout.EndHorizontal();
        }
Exemple #21
0
        /// <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!");
            }
        }
Exemple #22
0
        /// <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!");
            }
        }
 private void OnEnable()
 {
     _target = target as StepTarget;
 }
Exemple #24
0
        //跳过到指定步骤
        private IEnumerator SkipStepCoroutine(int index)
        {
            _executing       = true;
            _skipTargetIndex = index;

            while (_currentStepIndex < _skipTargetIndex)
            {
                _currentContent = _stepContents[_currentStepIndex];
                _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();
                _currentContent.Skip();

                SkipStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                //UGUI按钮点击型步骤,自动执行按钮事件
                if (_currentContent.Trigger == StepTrigger.ButtonClick)
                {
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                        _currentButton.onClick.RemoveListener(ButtonClickCallback);
                    }
                    else
                    {
                        _currentButton = _currentContent.Target.GetComponent <Button>();
                        if (_currentButton)
                        {
                            _currentButton.onClick.Invoke();
                        }
                        else
                        {
                            Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                        }
                    }
                    _currentButton = null;
                }

                //创建步骤助手
                if (_currentHelper == null && _currentContent.Helper != "<None>")
                {
                    Type type = ReflectionToolkit.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
                    {
                        Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的助手 {2} 丢失!", _currentStepIndex + 1, _currentContent.Name, _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));

                _currentStepIndex += 1;
            }

            SkipStepDoneEvent?.Invoke();

            _waitCoroutine = Main.Current.StartCoroutine(WaitCoroutine(BeginCurrentStep, 0));
        }
Exemple #25
0
        //步骤开始
        private void BeginCurrentStep()
        {
            _executing      = false;
            _currentContent = _stepContents[_currentStepIndex];
            _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

            //UGUI按钮点击型步骤,注册监听
            if (_currentContent.Trigger == StepTrigger.ButtonClick)
            {
                _isButtonClick = false;
                _currentButton = _currentTarget.GetComponent <Button>();
                if (_currentButton)
                {
                    _currentButton.onClick.AddListener(ButtonClickCallback);
                }
                else
                {
                    Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                }
            }
            //状态改变触发类型的步骤,自动重置状态
            else if (_currentContent.Trigger == StepTrigger.StateChange)
            {
                _currentTarget.State = StepTargetState.Normal;
            }

            //创建步骤助手
            if (_currentContent.Helper != "<None>")
            {
                Type type = ReflectionToolkit.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
                {
                    Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的助手 {2} 丢失!", _currentStepIndex + 1, _currentContent.Name, _currentContent.Helper));
                }
            }

            //未激活的步骤自动跳过
            if (_stepContentEnables.ContainsKey(_currentContent.GUID))
            {
                BeginStepEvent?.Invoke(_currentContent, _stepContentEnables[_currentContent.GUID]);
                if (!_stepContentEnables[_currentContent.GUID])
                {
                    Main.Current.StartCoroutine(SkipCurrentStepCoroutine());
                }
            }
            else
            {
                BeginStepEvent?.Invoke(_currentContent, false);
            }
        }
Exemple #26
0
        /// <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 >= _currentStepIndex)
                {
                    return(false);
                }

                while (_currentStepIndex >= index)
                {
                    _currentContent = _stepContents[_currentStepIndex];
                    _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                    RestoreStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                    //创建步骤助手
                    if (_currentHelper == null && _currentContent.Helper != "<None>")
                    {
                        Type type = ReflectionToolkit.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.Restore;
                            _currentHelper.OnInit();
                        }
                        else
                        {
                            Log.Error(string.Format("步骤控制者:【步骤:{0}】的助手 {1} 丢失!", _currentStepIndex + 1, _currentContent.Helper));
                        }
                    }
                    //助手执行恢复
                    if (_currentHelper != null)
                    {
                        _currentHelper.Task = StepHelperTask.Restore;
                        _currentHelper.OnRestore();
                        _currentHelper.OnTermination();
                        _currentHelper = null;
                    }

                    _currentStepIndex -= 1;
                }

                _currentStepIndex = index;
                BeginCurrentStep();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #27
0
        /// <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!");
            }
        }
Exemple #28
0
        private void OnGUI()
        {
            GUILayout.BeginHorizontal("Toolbar");
            if (GUILayout.Button(_content.Name, "Toolbarpopup"))
            {
                GenericMenu gm = new GenericMenu();
                for (int i = 0; i < _contentAsset.Content.Count; i++)
                {
                    StepContent stepContent = _contentAsset.Content[i];
                    gm.AddItem(new GUIContent(i + "." + stepContent.Name), stepContent == _content, () =>
                    {
                        _content = stepContent;
                    });
                }
                gm.ShowAsContext();
            }
            if (GUILayout.Button(_content.Helper, "Toolbarbutton"))
            {
                if (_content.Helper != "<None>")
                {
                    _stepEditorWindow.OpenHelperScript(_content.Helper);
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical("Box");
            _scroll = GUILayout.BeginScrollView(_scroll);

            for (int i = 0; i < _content.Parameters.Count; i++)
            {
                StepParameter stepParameter = _content.Parameters[i];

                GUILayout.BeginVertical("Helpbox");

                GUILayout.BeginHorizontal();
                GUILayout.Label("Type:", GUILayout.Width(40));
                stepParameter.Type = (StepParameter.ParameterType)EditorGUILayout.EnumPopup(stepParameter.Type, GUILayout.Width(100));
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("▲", "MiniButtonleft", GUILayout.Width(20)))
                {
                    if (i > 0)
                    {
                        _content.Parameters.Remove(stepParameter);
                        _content.Parameters.Insert(i - 1, stepParameter);
                        continue;
                    }
                }
                if (GUILayout.Button("▼", "MiniButtonmid", GUILayout.Width(20)))
                {
                    if (i < _content.Parameters.Count - 1)
                    {
                        _content.Parameters.Remove(stepParameter);
                        _content.Parameters.Insert(i + 1, stepParameter);
                        continue;
                    }
                }
                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("Delete", "Minibuttonright"))
                {
                    _content.Parameters.RemoveAt(i);
                    continue;
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Name:", GUILayout.Width(40));
                stepParameter.Name = EditorGUILayout.TextField(stepParameter.Name);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Value:", GUILayout.Width(40));
                switch (_content.Parameters[i].Type)
                {
                case StepParameter.ParameterType.String:
                    stepParameter.StringValue = EditorGUILayout.TextField(stepParameter.StringValue);
                    break;

                case StepParameter.ParameterType.Integer:
                    stepParameter.IntegerValue = EditorGUILayout.IntField(stepParameter.IntegerValue);
                    break;

                case StepParameter.ParameterType.Float:
                    stepParameter.FloatValue = EditorGUILayout.FloatField(stepParameter.FloatValue);
                    break;

                case StepParameter.ParameterType.Boolean:
                    stepParameter.BooleanValue = EditorGUILayout.Toggle(stepParameter.BooleanValue);
                    break;

                case StepParameter.ParameterType.Vector2:
                    stepParameter.Vector2Value = EditorGUILayout.Vector2Field("", stepParameter.Vector2Value);
                    break;

                case StepParameter.ParameterType.Vector3:
                    stepParameter.Vector3Value = EditorGUILayout.Vector3Field("", stepParameter.Vector3Value);
                    break;

                case StepParameter.ParameterType.Color:
                    stepParameter.ColorValue = EditorGUILayout.ColorField(stepParameter.ColorValue);
                    break;

                case StepParameter.ParameterType.GameObject:
                    #region 步骤目标物体丢失,根据目标GUID重新搜寻
                    if (!stepParameter.GameObjectValue)
                    {
                        if (stepParameter.GameObjectGUID != "<None>")
                        {
                            stepParameter.GameObjectValue = GameObject.Find(stepParameter.GameObjectPath);
                            if (!stepParameter.GameObjectValue)
                            {
                                StepTarget[] targets = FindObjectsOfType <StepTarget>();
                                foreach (StepTarget target in targets)
                                {
                                    if (target.GUID == stepParameter.GameObjectGUID)
                                    {
                                        stepParameter.GameObjectValue = target.gameObject;
                                        stepParameter.GameObjectPath  = target.transform.FullName();
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                StepTarget target = stepParameter.GameObjectValue.GetComponent <StepTarget>();
                                if (!target)
                                {
                                    target      = stepParameter.GameObjectValue.AddComponent <StepTarget>();
                                    target.GUID = stepParameter.GameObjectGUID;
                                }
                            }
                        }
                    }
                    #endregion

                    GUI.color = stepParameter.GameObjectValue ? Color.white : Color.gray;
                    GameObject objValue = EditorGUILayout.ObjectField(stepParameter.GameObjectValue, typeof(GameObject), true) as GameObject;
                    GUI.color = Color.white;

                    #region 步骤目标改变
                    if (objValue != stepParameter.GameObjectValue)
                    {
                        if (objValue)
                        {
                            StepTarget target = objValue.GetComponent <StepTarget>();
                            if (!target)
                            {
                                target = objValue.AddComponent <StepTarget>();
                            }
                            if (target.GUID == "<None>")
                            {
                                target.GUID = Guid.NewGuid().ToString();
                            }
                            stepParameter.GameObjectValue = objValue;
                            stepParameter.GameObjectGUID  = target.GUID;
                            stepParameter.GameObjectPath  = objValue.transform.FullName();
                        }
                    }
                    #endregion
                    break;
                }
                GUILayout.EndHorizontal();

                if (_content.Parameters[i].Type == StepParameter.ParameterType.GameObject)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("GUID:", GUILayout.Width(40));
                    EditorGUILayout.TextField(_content.Parameters[i].GameObjectGUID);
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Clear", "Minibutton", GUILayout.Width(40)))
                    {
                        _content.Parameters[i].GameObjectValue = null;
                        _content.Parameters[i].GameObjectGUID  = "<None>";
                        _content.Parameters[i].GameObjectPath  = "<None>";
                        GUI.FocusControl(null);
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add", "ButtonLeft"))
            {
                _content.Parameters.Add(new StepParameter());
            }
            if (GUILayout.Button("Clear", "ButtonRight"))
            {
                if (EditorUtility.DisplayDialog("Prompt", "Are you sure delete all parameter?", "Yes", "No"))
                {
                    _content.Parameters.Clear();
                }
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Apply"))
            {
                GUI.FocusControl(null);
                EditorUtility.SetDirty(_contentAsset);
            }
            GUILayout.EndHorizontal();
        }
        /// <summary>
        /// 跳过到指定步骤
        /// </summary>
        /// <param name="index">步骤索引</param>
        private IEnumerator SkipStepCoroutine(int index)
        {
            _executing       = true;
            _skipTargetIndex = index;

            CurrentTask = StepHelperTask.Skip;

            while (_currentStepIndex < _skipTargetIndex)
            {
                _currentContent = _stepContents[_currentStepIndex];
                _currentTarget  = _currentContent.Target.GetComponent <StepTarget>();

                //UGUI按钮点击型步骤,自动执行按钮事件
                if (_currentContent.Trigger == StepTrigger.ButtonClick)
                {
                    if (_currentButton)
                    {
                        _currentButton.onClick.Invoke();
                        _currentButton.onClick.RemoveListener(ButtonClickCallback);
                    }
                    else
                    {
                        _currentButton = _currentContent.Target.GetComponent <Button>();
                        if (_currentButton)
                        {
                            _currentButton.onClick.Invoke();
                        }
                        else
                        {
                            Log.Error(string.Format("步骤控制器:【步骤:{0}】【{1}】的目标丢失Button组件!", _currentStepIndex + 1, _currentContent.Name));
                        }
                    }
                    _currentButton = null;
                }

                //创建步骤助手
                if (_currentHelper == null)
                {
                    _currentHelper = CreateHelper(_currentContent, StepHelperTask.Skip);
                }

                _currentContent.Skip();

                SkipStepEvent?.Invoke(_currentContent, _stepContentEnables.ContainsKey(_currentContent.GUID) ? _stepContentEnables[_currentContent.GUID] : false);

                //助手执行跳过,等待生命周期结束后销毁助手
                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));

                _currentStepIndex += 1;
            }

            SkipStepDoneEvent?.Invoke();

            _waitCoroutine = Main.Current.StartCoroutine(WaitCoroutine(BeginCurrentStep, 0));
        }