/// <summary> /// Update the unique match key for this state. /// </summary> /// <returns>The match key as a string.</returns> public string UpdateMatchKey() { _crayonMatchKey = _crayonStateType.ToString().ToLower(); if (_crayonStateType == CrayonStateType.Custom) { _crayonMatchKey += _customStateType; } return(_crayonMatchKey); }
/// <summary> /// Begins a new transition between states. /// </summary> public void ChangeState(CrayonStateType stateType, string customState = "") { // Call the delegate so any downstream items know to change as well. if (OnChangeState != null) { OnChangeState(stateType, customState); } // Find the state by match key string matchKey = stateType.ToString().ToLower() + customState; // Don't do anything if we're already on the right state if (matchKey == _currentMatchKey) { return; } CrayonState state; _allStatesByMatchKey.TryGetValue(matchKey, out state); if (state != null) { if (state._tweenAppearance) { // Determine the tween method based on the enum selected switch (state._tweenAppearanceMode) { case CrayonTweenAppearanceMode.Material: gameObject.SetMaterial(state._material, state._duration, state._easing, state._customEasing); break; case CrayonTweenAppearanceMode.Color: gameObject.SetColor(state._color, state._duration, state._easing, state._customEasing); break; } } if (state._tweenPosition) { Vector3 relativePosition = new Vector3(_originalPosition.x + state._relativePosition.x, _originalPosition.y + state._relativePosition.y, _originalPosition.z + state._relativePosition.z); gameObject.SetPosition(relativePosition, state._duration, state._easing, state._customEasing); } if (state._tweenRotation) { Vector3 relativeRotation = new Vector3(_originalRotation.eulerAngles.x + state._relativeRotation.x, _originalRotation.eulerAngles.y + state._relativeRotation.y, _originalRotation.eulerAngles.z + state._relativeRotation.z); gameObject.SetRotation(relativeRotation, state._duration, state._easing, state._customEasing); } if (state._tweenScale) { Vector3 relativeScale = new Vector3(_originalScale.x * state._relativeScale.x, _originalScale.y * state._relativeScale.y, _originalScale.z * state._relativeScale.z); gameObject.SetScale(relativeScale, state._duration, state._easing, state._customEasing); } // Update the StateManager to reflect the new CrayonState. _currentMatchKey = matchKey; _currentState = state; } else { Debug.LogWarning("State '" + stateType + "' has not been assigned for " + gameObject.name); } }