/* * Func: SetStateForItems (state, itemsNames) * Set state for several items * * (start code) * GetComponent<UIStateGroup>().SetStateForItems(UIStateItem.STATE_ACTIVE, new string [] {"item (1)", "item (3)"}); * (end code) * * Parameters: * state - state name * itemsNames - string array of <UIStateItem> items names */ public void SetStateForItems(string state, string [] itemsNames) { if (OnStateChange != null) { OnStateChange.Invoke(); // call OnStateChange event } for (int i = 0; i < itemsNames.Length; i++) { UIStateItem StateItem = GetItem(itemsNames[i]) as UIStateItem; if (StateItem != null) { StateItem.SetState(state); } } }
/* * Func: SetStateForAllItems (state) * Set state for all items * * (start code) * GetComponent<UIStateGroup>().SetStateForAllItems(UIStateItem.STATE_INACTIVE); * (end code) * * Parameters: * state - state name */ public void SetStateForAllItems(string state) { if (OnStateChange != null) { OnStateChange.Invoke(); // call OnStateChange event } for (int i = 0; i < items.Length; i++) { UIStateItem StateItem = items[i] as UIStateItem; if (StateItem != null) { StateItem.SetState(state); } } }
// TESTING void DrawStateItemTesting() { // current state EditorGUILayout.LabelField("Current state: ", scriptStateItem.CurrentState, guistyleBold); EditorGUILayout.LabelField("Set state to: "); if (GUILayout.Button("Set to default")) { scriptStateItem.SetStateDefault(true); } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); if (GUILayout.Button(UIStateItem.STATE_INACTIVE)) { scriptStateItem.SetStateInactive(true); } if (GUILayout.Button(UIStateItem.STATE_ACTIVE)) { scriptStateItem.SetStateActive(true); } if (GUILayout.Button(UIStateItem.STATE_DISABLED)) { scriptStateItem.SetStateDisabled(true); } GUILayout.EndHorizontal(); // custom States if (scriptStateItem.States.Length > 3) { EditorGUILayout.BeginHorizontal(); for (int i = 3; i < scriptStateItem.States.Length; i++) { if (i % 3 == 0) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } if (GUILayout.Button(scriptStateItem.States[i])) { scriptStateItem.SetState(scriptStateItem.States[i], true); } } EditorGUILayout.EndHorizontal(); } }