public void OnCacheTab() { //如果是tab控件,确保有且只有一个处于选中状态 StateHandle sNeedSet = null;//需要设置到提起状态的控件 bool needSet = true; foreach (var s in m_stateHandles) { if (s == null) { continue; } s.EnableCtrlState = false; //让状态控件,自己不能控制状态 if (s.m_curState == 0 && needSet == true) //找到需要设置为提起状态的控件 { sNeedSet = s; } if (s.m_curState == 1 && needSet == false)//只有一个控件能为提起状态,其他控件要设置为0 { s.SetState(0, false); } if (s.m_curState == 1 && needSet == true)//找到一个已经设置为提起状态的控件的话,记录下 { needSet = false; sNeedSet = s; } } if (needSet && sNeedSet != null)//设置为选中状态 { sNeedSet.SetState(1, false); } m_curStateHandle = sNeedSet;//当前选中的状态控件 }
public State(string stateName, StateHandle onEnter = null, StateHandle onExcute = null, StateHandle onExit = null) { this.stateName = stateName; this.onEnter = onEnter; this.onExcute = onExcute; this.onExit = onExit; }
public void OnSel(StateHandle selStateHandle, bool isDuration, bool byStateHandle) { if (m_cached == false)//初始化中的话不用处理 { return; } //类型状态机 bool selSuccess = true; switch (m_ctrlType) { case CtrlType.none: m_curStateHandle = selStateHandle; break; case CtrlType.tab: selSuccess = OnSelTab(selStateHandle, isDuration, byStateHandle); break; default: Debuger.LogError(string.Format("未作处理的控件类型", m_ctrlType)); break; } if (selSuccess && m_onSel != null) { m_onSel(selStateHandle, CurIdx); if (ms_globalStateHook != null) { ms_globalStateHook(this, CurIdx); } } }
static void _ChangeState(string stateMachineName, string newStateName, StateHandle onEnter = null, StateHandle onExcute = null, StateHandle onExit = null) { if (currentStateNames.ContainsKey(stateMachineName)) { if (!states.ContainsKey(stateMachineName + currentStateNames[stateMachineName])) { states.Add(stateMachineName + currentStateNames[stateMachineName], new State(currentStateNames[stateMachineName])); } if (states[stateMachineName + currentStateNames[stateMachineName]] != null) { states[stateMachineName + currentStateNames[stateMachineName]].OnExit(); } currentStateNames[stateMachineName] = newStateName; } else { currentStateNames.Add(stateMachineName, newStateName); } if (!states.ContainsKey(stateMachineName + newStateName)) { states.Add(stateMachineName + newStateName, new State(newStateName)); } if (states[stateMachineName + newStateName] != null) { states[stateMachineName + newStateName].OnEnter(); } }
private void query() { try { pageSize = Int32.Parse(tbxPage.Text.Trim()); StateHandle handle = new StateHandle(); int totalRows = handle.totalRows(dtpStart.Text.Trim(), dtpEnd.Text.Trim(), tbxOrderId.Text.Trim(), tbxPhoneNo.Text.Trim()); int totalPage = totalRows % pageSize >= 1 ? totalRows / pageSize + 1 : totalRows / pageSize; if (pageIndex < 1) { pageIndex = 1; } if (pageIndex > totalPage) { pageIndex = totalPage; } label5.Text = "总条数:" + totalRows; labelPage.Text = pageIndex.ToString() + "/" + totalPage; DataTable dt = handle.selectOrderList(dtpStart.Text.Trim(), dtpEnd.Text.Trim(), tbxOrderId.Text.Trim(), tbxPhoneNo.Text.Trim(), pageIndex, pageSize); dgvOrderShow.DataSource = dt; } catch (Exception ex) { MessageBox.Show("错误", ex.Message); } }
void OnEnable() { m_cur = target as StateHandle; if (Application.isEditor && !EditorApplication.isPlaying) { EditorApplication.update = m_cur.LateUpdate; } }
void Awake() { StateHandle stateHandle = this.GetComponent <StateHandle>(); if (stateHandle != null) { stateHandle.AddClick(playUIsound); } }
static void AddStateHandle(MenuCommand command) { StateHandle s = Selection.activeGameObject.AddComponent <StateHandle>(); //s.transition = UnityEngine.UI.Selectable.Transition.None; //var nav = s.navigation; //nav.mode = UnityEngine.UI.Navigation.Mode.None; //s.navigation = nav; EditorUtility.SetDirty(Selection.activeGameObject); }
//不在运行中时,Handle的类型或者m_go改变的时候会刷新值 public override void OnReset(Handle h, bool resetBegin = true, bool resetEnd = false) { if (h.m_go) { StateHandle s = h.m_go.GetComponent <StateHandle>(); if (s) { h.m_iBegin = s.CurStateIdx; } } }
public override void OnEnd(Handle h) { if (h.m_go == null) { return; } StateHandle s = h.m_go.GetComponent <StateHandle>(); if (s == null) { return; } s.SetState(h.m_iBegin, true); }
public bool OnSelTab(StateHandle selStateHandle, bool isDuration, bool byStateHandle) { if (byStateHandle && m_curStateHandle == selStateHandle && selStateHandle.CurStateIdx == 0) { return(false); } m_curStateHandle = selStateHandle; m_curStateHandle.SetState(1, isDuration); foreach (StateHandle s in m_stateHandles) { if (s == m_curStateHandle || s.m_curState != 1) { continue; } s.SetState(0, isDuration); } return(true); }
static void AddStateButton(GameObject go) { if (!go || go.GetComponent <StateHandle>()) { return; } //CanvasGroup g = go.GetComponent<CanvasGroup>(); //if(!g) // g = go.AddComponent<CanvasGroup>(); //g.interactable = true; //g.blocksRaycasts = true; //g.ignoreParentGroups = true; StateHandle s = go.AddComponent <StateHandle>(); ////初始化Selectable不需要用的地方 //s.transition = UnityEngine.UI.Selectable.Transition.None; //var nav = s.navigation; //nav.mode = UnityEngine.UI.Navigation.Mode.None; //s.navigation = nav; s.AddPublicHandle(Handle.Type.scale); //设置提起状态 Handle h1 = s.m_states[0].publicHandles[0]; s.m_states[0].isDuration = true; h1.m_vEnd = Vector3.one; h1.m_go = s.gameObject; //设置按下状态 Handle h2 = s.m_states[1].publicHandles[0]; s.m_states[1].isDuration = true; h2.m_vEnd = Vector3.one * 0.85f; h2.m_go = s.gameObject; //设置控制器类型为按钮 s.m_ctrlType = StateHandle.CtrlType.button; EditorUtility.SetDirty(go); }
void Find() { Transform t = this.transform; for (int i = 0; i < t.childCount; ++i) { StateHandle s = t.GetChild(i).GetComponent <StateHandle>();; if (s == null) { continue; } if (m_stateHandles.IndexOf(s) != -1) { continue; } m_stateHandles.Add(s); } EditorUtil.SetDirty(this); }
//框架,绘制属性(不包含游戏对象),syncGo的话结束值变化会同步到m_go。这里是最小化绘制,只绘制最需要的属性 public override void OnDrawMid(Component comp, Handle h, System.Action <Handle.WndType, object> onOpenWnd, bool syncGo = false) { if (h.m_go == null) { return; } GUI.changed = false; StateHandle s = h.m_go.GetComponent <StateHandle>(); int idx = UnityEditor.EditorGUILayout.Popup("状态", h.m_iBegin, s.StateName); if (GUI.changed) { EditorUtil.RegisterUndo("Handle Change", comp); h.m_iBegin = idx; EditorUtil.SetDirty(comp); if (syncGo && h.m_go) { End(h); EditorUtil.SetDirty(h.m_go); } } }
public static void UnregediStateCallBack(string stateMachineName, string stateName, StateCallBackType type, StateHandle handle) { if (!states.ContainsKey(stateMachineName + stateName)) { return; } if (type == StateCallBackType.TypeOnEnter) { states[stateMachineName + stateName].onEnter += handle; } else if (type == StateCallBackType.TypeOnExcute) { states[stateMachineName + stateName].onExcute += handle; } else if (type == StateCallBackType.TypeOnExit) { states[stateMachineName + stateName].onExit += handle; } }
public void SetAsCloneOf(StateHandle handle) { m_ParentState = handle; m_IsClone = true; }
public void OnSel(StateHandle selStateHandle) { OnSel(selStateHandle, true, true); }
//提供设置大小的功能 public void SetCount(int count) { Cache(); if (count == 0) { this.gameObject.SetActive(false); return; } else { this.gameObject.SetActive(true); } //多退少补 int curCount = m_stateHandles.Count; StateHandle s; if (count < curCount) { for (int i = count; i < curCount; ++i) { s = m_stateHandles[i]; //这里不要把m_itemTemplate对应的对象销毁了 if (m_itemTemplate == s) { s.gameObject.SetActive(false); } else { UnityEngine.Object.Destroy(s.gameObject); } } m_stateHandles.RemoveRange(count, curCount - count); } else if (count > curCount) { GameObject go; Transform t; for (int i = curCount; i < count; ++i) { StateHandle template = m_itemTemplate != null ? m_itemTemplate : m_stateHandles[m_stateHandles.Count - 1]; go = GameObject.Instantiate(template.gameObject) as GameObject; go.gameObject.name = "item" + i; t = go.transform; t.SetParent(this.transform, false); t.localPosition = Vector3.zero; t.localRotation = Quaternion.identity; t.localScale = m_stateHandles[m_stateHandles.Count - 1].gameObject.transform.localScale; if (go.layer != this.gameObject.layer) { go.layer = this.gameObject.layer; } if (go.activeSelf == false) { go.SetActive(true); } s = go.GetComponent <StateHandle>(); s.AddClickEx(OnSel); m_stateHandles.Add(s); } } }
static public void UnregediStateCallBack(string stateMachineName, string stateName, StateCallBackType type, StateHandle handle) { if (!states.ContainsKey(stateMachineName + stateName)) { return; } if (type == StateCallBackType.TypeOnEnter) { states[stateMachineName + stateName].onEnter += handle; } else if (type == StateCallBackType.TypeOnExcute) { states[stateMachineName + stateName].onExcute += handle; } else if (type == StateCallBackType.TypeOnExit) { states[stateMachineName + stateName].onExit += handle; } }
static public void RegediStateCallBack(string stateMachineName, string stateName, StateCallBackType type, StateHandle handle) { Init(); if (!states.ContainsKey(stateMachineName + stateName)) { states.Add(stateMachineName + stateName, new State(stateName)); } if (type == StateCallBackType.TypeOnEnter) { states[stateMachineName + stateName].onEnter += handle; } else if (type == StateCallBackType.TypeOnExcute) { states[stateMachineName + stateName].onExcute += handle; } else if (type == StateCallBackType.TypeOnExit) { states[stateMachineName + stateName].onExit += handle; } }
public override void Check() { base.Check(); handle = State.CreateState(varName, rowNo, colNo, initial); }
public static void RegediStateCallBack(string stateMachineName, string stateName, StateCallBackType type, StateHandle handle) { Init(); if (!states.ContainsKey(stateMachineName + stateName)) { states.Add(stateMachineName + stateName, new State(stateName)); } if(type == StateCallBackType.TypeOnEnter) { states[stateMachineName + stateName].onEnter += handle; } else if (type == StateCallBackType.TypeOnExcute) { states[stateMachineName + stateName].onExcute += handle; } else if (type == StateCallBackType.TypeOnExit) { states[stateMachineName + stateName].onExit += handle; } }
public QueuedState(StateHandle s, float t) { state = s; fadeTime = t; }