Exemple #1
0
        /// <summary>
        /// Saves data on transitions and properties from a CrayonState.
        /// </summary>
        public void SaveData(CrayonState state)
        {
            _crayonStateType = state._crayonStateType;
            _customStateType = state._customStateType;
            _crayonMatchKey  = state._crayonMatchKey;

            _duration     = state._duration;
            _easing       = state._easing;
            _customEasing = state._customEasing;

            _tweenAppearance     = state._tweenAppearance;
            _tweenAppearanceMode = state._tweenAppearanceMode;
            _material            = state._material;
            _color   = state._color;
            _opacity = state._opacity;

            _tweenPosition    = state._tweenPosition;
            _relativePosition = state._relativePosition;

            _tweenRotation    = state._tweenRotation;
            _relativeRotation = state._relativeRotation;

            _tweenScale    = state._tweenScale;
            _relativeScale = state._relativeScale;
        }
Exemple #2
0
        /// <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);
            }
        }
 /// <summary>
 /// Sets the state of a GameObject using the CrayonState and CrayonStateManager components.
 /// </summary>
 /// <param name="gameObject">The GameObject to modify.</param>
 /// <param name="stateType">The state to transition to.</param>
 /// <param name="customState">If the state is a custom, user-defined state, this is the custom state's ID as a string.</param>
 public static void SetState(this GameObject gameObject, CrayonStateType stateType, string customState = "")
 {
     gameObject.GetComponent <CrayonStateManager> ().ChangeState(stateType, customState);
 }
 /// <summary>
 /// Shortcut for calling a standard state.
 /// </summary>
 /// <param name="stateType">State type.</param>
 public void ChangeState(CrayonStateType stateType)
 {
     ChangeState(stateType, "");
 }