示例#1
0
		public void translation(string name)
		{

			
			if (!this.states_.ContainsKey(name))//if no target return!
			{
				return;
			}

			State target = this.states_[name];//target state
			while (!string.IsNullOrEmpty (target.defSubState) && this.states_.ContainsKey(target.defSubState)) {
				target = this.states_[target.defSubState];
			}
			
			//if current, reset
			if(target == this.currState_[this.currState_.Count-1])
			{
				target.over();
				target.start();
				return;
			}
			
			
			
			State publicState = null;
			
			List<State> stateList = new List<State>();
			
			State tempState = target;
			string fatherName = tempState.fatherName;
			
			//do loop 
			while(tempState != null)
			{
				//reiterator current list
				for(var i = this.currState_.Count -1; i >= 0; i--){
					State state = this.currState_[i] as State;
					//if has public 
					if(state == tempState){
						publicState = state;	
						break;
					}
				}
				
				//end
				if(publicState != null){
					break;
				}
				
				//else push state_list
				stateList.Insert(0, tempState);
				//state_list.unshift(temp_state);
				
				if(fatherName != ""){
					tempState = this.states_[fatherName] as State;
					fatherName = tempState.fatherName;
				}else{
					tempState = null;
				}
				
			}
			//if no public return
			if (publicState == null){
				return;
			}
			
			List<State> newCurrState = new List<State>();
			bool under = true;
			//-- 析构状态
			for(int i2 = this.currState_.Count -1; i2>=0; --i2)
			{
				State state2 = this.currState_[i2] as State;
				if(state2 == publicState)
				{
					under = false;
				}
				if(under){
					state2.over();
				}
				else{
					newCurrState.Insert(0, state2);
				}
				
			}
			
			
			//-- 构建状态
			for(int i3 = 0; i3 < stateList.Count; ++i3){
				State state3 = stateList[i3] as State;
				state3.start();

				newCurrState.Add(state3);
			}

			this.currState_ = newCurrState;
			string outs = "";
			for(int i = 0; i < currState_.Count; ++i){
				outs+= ":" + currState_[i].name;
			}
			
//			Debug.LogWarning (outs);

		}
示例#2
0
        /// <summary>
        /// 根据名称转换为对应的状态,然后将该状态放到当前可执行状态前端
        /// </summary>
        /// <param name="name"></param>
        public void translation(string name)
        {
            State target = this.states_[name] as State; //target state

            if (target == null)                         //if no target return!
            {
                return;
            }

            //如果该状态为状态列表中的最后一个状态,则初始化该状态,即先结束该状态,然后在开始该状态
            //if current, reset
            if (target == this.currState_[this.currState_.Count - 1])
            {
                target.over();
                target.start();
                return;
            }



            State publicState = null;

            ArrayList stateList = new ArrayList();

            State  tempState  = target;
            string fatherName = tempState.fatherName;

            //do loop
            while (tempState != null)
            {
                //reiterator current list
                for (var i = this.currState_.Count - 1; i >= 0; i--)
                {
                    State state = this.currState_[i] as State;
                    //if has public
                    if (state == tempState)
                    {
                        publicState = state;
                        break;
                    }
                }

                //end
                if (publicState != null)
                {
                    break;
                }

                //else push state_list
                stateList.Insert(0, tempState);
                //state_list.unshift(temp_state);

                if (fatherName != "")
                {
                    tempState  = this.states_[fatherName] as State;
                    fatherName = tempState.fatherName;
                }
                else
                {
                    tempState = null;
                }
            }
            //if no public return
            if (publicState == null)
            {
                return;
            }

            ArrayList newCurrState = new ArrayList();
            bool      under        = true;

            //-- 析构状态
            for (int i2 = this.currState_.Count - 1; i2 >= 0; --i2)
            {
                State state2 = this.currState_[i2] as State;
                if (state2 == publicState)
                {
                    under = false;
                }
                if (under)
                {
                    state2.over();
                }
                else
                {
                    newCurrState.Insert(0, state2);
                }
            }


            //-- 构建状态
            for (int i3 = 0; i3 < stateList.Count; ++i3)
            {
                State state3 = stateList[i3] as State;
                state3.start();
                newCurrState.Add(state3);
            }
            this.currState_ = newCurrState;
        }