コード例 #1
0
        public bool RemoveFunctionChain(string key, JobTodo Todo = null, JobToDoCondition toDoCheck = null,
                                        JobAutoDropCondition autoDropCondition = null, bool isExecuteImmediately = true)
        {
            JobRepeatBase Job = JobList.Find(job => job.key.Equals(key));

            if (Job == null)
            {
                return(false);
            }

            StopCoroutine(Job.worker);

            Job.jobTodo          -= Todo;
            Job.jobToDoCheck     -= toDoCheck;
            Job.jobAutoDropCheck -= autoDropCondition;

            if (Job.jobTodo == null)
            {
                Job.state = JOB_STATE.JOB_EMPTY;
                return(true);
            }

            if (isExecuteImmediately)
            {
                Job.state = JOB_STATE.JOB_STANDBY;
                StartCoroutine(Job.worker);
            }
            return(true);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();
            JobRepeatBase job = (JobRepeatBase)target;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Execute Immediately"))
            {
                if (job.jobTodo != null)
                {
                    job.jobTodo();
                    job.excuteCount++;
                }
            }

            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Drop"))
            {
                job.state = JobRepeatBase.JOB_STATE.JOB_DROP;
            }

            if (GUILayout.Button("Drop Immediately"))
            {
                JobRepeatManager.Instance.RemoveJob(job.key);
                DestroyImmediate(job.gameObject);
            }

            EditorGUILayout.EndHorizontal();
        }
コード例 #3
0
        public bool RemoveJob(string key)
        {
            JobRepeatBase findJob = JobList.Find(job => job.key.Equals(key));

            if (findJob == null)
            {
                return(false);
            }

            DestroyImmediate(findJob.gameObject);
            return(JobList.Remove(findJob));
        }
コード例 #4
0
        public bool JobStart(string key)
        {
            JobRepeatBase findJob = JobList.Find(job => job.key.Equals(key));

            if (findJob == null)
            {
                return(false);
            }

            StopCoroutine(findJob.worker);

            findJob.state = JOB_STATE.JOB_STANDBY;
            StartCoroutine(findJob.worker);
            return(true);
        }
コード例 #5
0
        public bool ChangeJobDelay(string key, float newDelay)
        {
            JobRepeatBase findJob = JobList.Find(job => job.key.Equals(key));

            if (findJob == null)
            {
                return(false);
            }

            findJob.repeatDelay = newDelay;
            StopCoroutine(findJob.worker);

            findJob.state = JOB_STATE.JOB_STANDBY;
            StartCoroutine(findJob.worker);
            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Job RepeatManager > Adding Job
        /// <para>key = JobKeyName,
        /// todo = ExecuteFunctionPointer,
        /// delay = Update Sequence Delay(Seconds),
        /// repeatCount = Total Execute Count,
        /// parameter = params object[] : Your Parameter
        /// todoCondition = Execute Condition(true = Available Execute, false = Block Execute),
        /// autoDropCondition = Job Drop Condition(Flag : true = Drop, false = MoveNext)</para>
        /// </summary>
        public bool AddDelegateJob(string key, JobTodo toDo, float delay = 1.0f, int repeatCount = 0, object[] parameter = null,
                                   JobEndAction endActionWhenDrop        = null,
                                   JobToDoCondition toDoCondition        = null, JobAutoDropCondition autoDropCondition = null, bool isImmediately = true)
        {
            // Already Registered Job Check
            if (JobList.Find(job => job.key.Equals(key)) != null)
            {
                return(false);
            }

            GameObject JobObject = new GameObject(key);

            JobObject.transform.parent = this.transform;
            JobRepeatBase newJob = JobObject.AddComponent <JobRepeatBase>();

            newJob.key              = key;
            newJob.jobCoroutine     = null;
            newJob.jobTodo          = toDo;
            newJob.repeatDelay      = delay;
            newJob.repeatCount      = repeatCount;
            newJob.excuteCount      = 0;
            newJob.jobToDoCheck     = toDoCondition;
            newJob.jobAutoDropCheck = autoDropCondition;
            newJob.jobEndAction     = endActionWhenDrop;
            newJob.state            = JOB_STATE.JOB_STANDBY;
            newJob.worker           = CoJobHandle(key);
            newJob.parameter        = parameter;

            if (toDo == null)
            {
                Debug.LogWarningFormat("Are You Sure Adding Empty Job? Todo Parameter is null (key:{0})", key);
                newJob.state = JOB_STATE.JOB_EMPTY;
            }

            newJob.repeatDelay = newJob.repeatDelay < m_MinDelayTime ? m_MinDelayTime : newJob.repeatDelay;
            JobList.Add(newJob);

            if (isImmediately)
            {
                StartCoroutine(newJob.worker);
            }

            return(true);
        }
コード例 #7
0
        private IEnumerator CoJobHandle(string key)
        {
            yield return(null);

            JobRepeatBase findJob = JobList.Find(x => x.key == key);

            if (findJob == null)
            {
                yield break;
            }

            switch (findJob.state)
            {
            case JOB_STATE.JOB_EMPTY:
                yield break;

            case JOB_STATE.JOB_STANDBY:
                if (findJob.jobToDoCheck != null)
                {
                    if (findJob.jobToDoCheck(findJob.parameter))
                    {
                        findJob.state = JOB_STATE.JOB_WORKING;

                        findJob.jobTodo?.Invoke(findJob.parameter);
                        if (findJob.jobCoroutine != null)
                        {
                            yield return(StartCoroutine(findJob.jobCoroutine));
                        }

                        findJob.excuteCount++;
                        if (findJob.excuteCount >= findJob.repeatCount && findJob.repeatCount != 0)
                        {
                            findJob.state = JOB_STATE.JOB_DROP;
                        }
                        else
                        {
                            findJob.state = JOB_STATE.JOB_WAITING;
                        }
                    }
                }
                else
                {
                    findJob.state = JOB_STATE.JOB_WORKING;
                    findJob.jobTodo?.Invoke(findJob.parameter);
                    if (findJob.jobCoroutine != null)
                    {
                        yield return(StartCoroutine(findJob.jobCoroutine));
                    }

                    findJob.excuteCount++;
                    if (findJob.excuteCount >= findJob.repeatCount && findJob.repeatCount != 0)
                    {
                        findJob.state = JOB_STATE.JOB_DROP;
                    }
                    else
                    {
                        findJob.state = JOB_STATE.JOB_WAITING;
                    }
                }

                if (findJob.jobAutoDropCheck != null)
                {
                    if (findJob.jobAutoDropCheck(findJob.parameter))
                    {
                        findJob.state = JOB_STATE.JOB_DROP;
                        break;
                    }
                }
                break;

            case JOB_STATE.JOB_WAITING:
                WaitForSeconds WaitForDelay = new WaitForSeconds(findJob.repeatDelay);
                yield return(WaitForDelay);

                findJob.state = JOB_STATE.JOB_STANDBY;
                break;

            case JOB_STATE.JOB_DROP:
                yield break;
            }

            yield return(StartCoroutine(CoJobHandle(findJob.key)));
        }