/** * This can be overridden in subclass if you want to roll a die in another specific way. * @param pRollable the rollable to roll * @param pGroupIndex the index of the rollable within the complete collection * @param pActiveIndex the index of the rollable within the active group to roll * For the Roll() call these will be the same, for the RollNonExact there will be a difference. */ protected virtual void rollSingleDie(ARollable pRollable, int pGroupIndex, int pActiveIndex) { if (pRollable.gameObject.activeSelf) { pRollable.Roll(); } }
private void statusChanged(string pEvent, ARollable pSourceA = null, ARollable pSourceB = null) { //collect info about all the dice info (one level deep) and print it _stringBuilder.Length = 0; if (logEvents) { _stringBuilder.AppendLine(pEvent + (pSourceA == null ? "" : " / " + pSourceA.name) + (pSourceB == null ? "" : " / " + pSourceB.name)); } for (int i = 0; i < _dieCollection.Count; i++) { ARollable die = _dieCollection.Get(i); IRollResult result = die.GetRollResult(); string resultColor = (die.HasEndResult() && result.isExact) ? "green" : "blue"; //only show values if we are NOT rolling OR updating every frame string resultValues = (!die.isRolling || updateEveryFrame) ? result.valuesAsString : "*"; _stringBuilder.AppendFormat("<color={0}>{1}={2}</color> ", resultColor, die.name, resultValues); } _stringBuilder.AppendLine("\nAny dice still rolling? " + (_dieCollection.isRolling ? "Yes (" + _dieCollection.RollingCount + ")" : "No")); IRollResult collectionResult = _dieCollection.GetRollResult(); string collectionResultValues = (!_dieCollection.isRolling || updateEveryFrame) ? collectionResult.valuesAsString : "*"; _stringBuilder.AppendLine("Dice collection value totals:" + collectionResultValues); Debug.Log(_stringBuilder.ToString()); }
void Awake() { ARollable die = GetComponent <ARollable>(); if (die != null) { die.OnRollBegin += onRollBegin; die.OnRollEnd += onRollEnd; } }
private void onRollEnd(ARollable die) { IRollResult result = die.GetRollResult(); Debug.Log( name + " roll ended with value: " + result.valuesAsString + " " + (result.isExact ? "(Exact)" : "(Closest)") ); }
private void onChildRollBegin(ARollable pRollable) { if (ignoreIndependentChildEvents && !isRolling) return; if (_rollingRollables.Add(pRollable)) { //if we actually added the item, make sure isRolling is true, this wont trigger an event if //we were already rolling isRolling = true; OnChildRollBegin(this, pRollable); } }
private void onChildRollEnd(ARollable pRollable) { if (ignoreIndependentChildEvents && !isRolling) return; if (_rollingRollables.Remove(pRollable)) { //if we actually removed the item from the rolling administration, trigger child event OnChildRollEnd(this, pRollable); //and possibly our own end event, if the result didn't change, no event will be triggered isRolling = _rollingRollables.Count > 0; } }
/** * Only reroll those items that do not have an endresult or where the endresult is not exact. */ public void RollNonExact() { isRolling = true; int activeCount = 0; ARollable rollable = null; for (int i = 0; i < _rollables.Count; i++) { rollable = _rollables[i]; if (!rollable.HasEndResult() || !rollable.GetRollResult().isExact) { rollSingleDie(rollable, i, activeCount ++); } } isRolling = _rollingRollables.Count > 0; }
void Awake() { _audioSource = GetComponent <AudioSource>(); if (_rollable == null) { _rollable = GetComponent <ARollable>(); } if (_rollable == null) { Debug.Log("RollableAudio requires a reference to ARollable instance"); } else { _rollable.OnRollBegin += onRollBegin; _rollable.OnRollEnd += onRollEnd; } }
private void onChildEndResultCleared(ARollable pRollable) { //if we are clearing the whole collection, just pass on the child event //the call to Clear will already have reset the result cache and triggered our own main event if (_clearingWholeCollection) { OnChildEndResultCleared(this, pRollable); return; } //if this event is triggered because Clear has been called on an item in our collection //check if we want to ignore it or not. If we are not ignoring it, and we have an endresult //clear our end result if (!ignoreIndependentChildEvents) { if (HasEndResult()) base.ClearEndResult(); OnChildEndResultCleared(this, pRollable); } }
private void statusChanged(string pEvent, ARollable pSourceA = null, ARollable pSourceB = null) { if (_dieCollection == null) { return; } if (logEvents && pEvent != null) { Debug.Log(pEvent + (pSourceA == null?"": "/" + pSourceA.name) + (pSourceB == null ? "" : "/" + pSourceB.name)); } int diceTextsCount = Mathf.Min(_diceTexts.Count, _dieCollection.Count); for (int i = 0; i < diceTextsCount; i++) { ARollable die = _dieCollection.Get(i); IRollResult result = die.GetRollResult(); string resultColor = (die.HasEndResult() && result.isExact)?"green":"blue"; //only show values if we are NOT rolling OR updating every frame string resultValues = (!die.isRolling || updateEveryFrame) ? result.valuesAsString : "*"; _diceTexts[i].text = string.Format("<color={0}>{1}={2}</color>", resultColor, die.name, resultValues); } _dieCountText.text = "" + _dieCollection.Count; if (pEvent != null) { _lastEventText.text = pEvent; } _rollingInfoText.text = _dieCollection.isRolling ? ("Yes (" + _dieCollection.RollingCount + ")") : "No"; IRollResult collectionResult = _dieCollection.GetRollResult(); string collectionResultValues = (!_dieCollection.isRolling || updateEveryFrame) ? collectionResult.valuesAsString : "*"; _dieTotalText.text = collectionResultValues; }
/** * Stores name of this event. */ private void onDieRollEnd(ARollable pDie) { _lastDieEvent = "OnRollEnd"; }
/** * Stores name of this event. */ private void onDieRollBegin(ARollable pDie) { _lastDieEvent = "OnRollBegin"; }
/** * Removes the given ARollable instance from the collection so its events will no longer be tracked. */ public void Remove(ARollable pRollable) { unregisterForChildEvents(pRollable); _rollables.Remove(pRollable); }
/** * Adds the given ARollable instance to the collection so its events can be tracked. */ public void Add(ARollable pRollable) { registerForChildEvents(pRollable); _rollables.Add(pRollable); }
private void onRollBegin(ARollable die) { Debug.Log(name + " roll began..."); }
private void unregisterForChildEvents(ARollable pRollable) { pRollable.OnRollBegin -= onChildRollBegin; pRollable.OnRollEnd -= onChildRollEnd; pRollable.OnEndResultCleared -= onChildEndResultCleared; }
private void onRollEnd(ARollable obj) { //stop sound here? _audioSource.Stop(); }
private void onRollBegin(ARollable obj) { //play sound here? _audioSource.Play(); }