public void Constrain(string toName, params string[] fromNames) { List <StateListItem> fromItems = new List <StateListItem> (); StateListItem toItem = null; foreach (StateListItem nameItem in items) { if (nameItem.Equals(toName)) { toItem = (nameItem); } } if (toItem == null) { throw new UnityException("Cannot find item " + toName); } foreach (string name in fromNames) { foreach (StateListItem nameItem in items) { if (nameItem.Equals(name)) { fromItems.Add(nameItem); } } } controlledStateChanges.Add(toItem, fromItems.ToArray()); }
public void StateChanged(StateListItem fromItem, StateListItem toItem, bool allowed = true) { if (StateChangedEvent != null) // fire the event { StateChangedEvent(new StateChange(fromItem, toItem, list, allowed)); } }
public bool Change(string name) { foreach (StateListItem item in list.items) { if (item.Equals(name)) { // if there are controls over a given StateItem, enforce them if (list.controlledStateChanges.ContainsKey(item)) { // Debug.Log ("--- enforcing change limits for changing to " + item.ToString ()); foreach (StateListItem allowedItem in list.controlledStateChanges[item]) { // Debug.Log ("... can change from state " + allowedItem.ToString ()); if (allowedItem.Equals(myState)) { //Debug.Log (".... and that is what we are trying to do!"); StateChanged(myState, item); myState = item; return(true); } } StateChanged(myState, item, false); return(false); } StateChanged(myState, item); myState = item; return(true); } } return(false); }
public StateChange(StateListItem fromS, StateListItem toS, StateList li, bool a) { if (fromS.name == "" || toS.name == "") { throw new Exception("cannot change to empty states"); } fromState = fromS; toState = toS; list = li; allowed = a; }
public bool Change(string name, bool force) { if (force) { if (list.Contains(name)) { myState = list.Item(name); return(true); } else { return(false); } } else { return(Change(name)); } }
public State(string name, string itemName) { list = StateList.GetList(name); myState = list.Item(itemName); }
public State(string name) { list = StateList.GetList(name); myState = list.First(); }