public static object Lerp(System.Type type, ActionValue av1, ActionValue av2, float lerp) { if (av1 == null || av2 == null) { return(null); } //lerp = Mathf.Clamp01(lerp); if (type == typeof(float)) { return(Tools.GetMinMaxValue(av1.GetFloat(), av2.GetFloat(), lerp)); } else if (type == typeof(int)) { return(Mathf.RoundToInt(Tools.GetMinMaxValue(av1.GetInt(), av2.GetInt(), lerp))); } else if (type == typeof(Color)) { return(Color.Lerp(av1.GetColor(), av2.GetColor(), lerp)); } else if (type == typeof(Vector2)) { return(Vector2.Lerp(av1.GetVector2(), av2.GetVector2(), lerp)); } else if (type == typeof(Vector3)) { return(Vector3.Lerp(av1.GetVector3(), av2.GetVector3(), lerp)); } else if (type == typeof(bool)) { return(lerp < 0.5f ? av1.GetBool() : av2.GetBool()); } return(null); }
void Activate() { _everActivated = true; //Debug.Log ("action enter! " + type, parent); if (type == Type.ChangeValue) { //TriggerManager.ChangeValueOverTime(target, time, value); //TODO: get type of a subproperty to properly put the right field object value = PropertyChange.GetValue(changeValue_component, changeValue_property, changeValue_subproperty); if (value != null) { if (!parent.isTypeConstant) { _previousValue = value; value = changeValue_value.Get(value.GetType()); ChangeValueTo(value, _previousValue); } else { float d = Vector3.Distance(constantValueFromPosition, constantValueToPosition); d -= changeValue_constant_nearDistance; d /= changeValue_constant_farDistance - changeValue_constant_nearDistance; d = 1 - Mathf.Clamp01(d); d = changeValue_constant_curve.Evaluate(d); value = ActionValue.Lerp(value.GetType(), changeValue_constant_finalRange_from, changeValue_constant_finalRange_to, d); UpdateValue(value); } } } else if (type == Type.MovePlayer) { if (movePlayer_movementType == PlayerMovementType.ForcePosition) { changeValue_component = Player.instance.transform; changeValue_property = "position"; changeValue_subproperty = ""; ChangeValueTo(changeValue_value.GetVector3(), Player.instance.transform.position); } else if (movePlayer_movementType == PlayerMovementType.Poke) { Player.instance.controller.Move(changeValue_value.GetVector3()); } } else if (type == Type.MoveObject) { if (movePlayer_movementType == PlayerMovementType.ForcePosition) { changeValue_component = target.transform; changeValue_property = "position"; changeValue_subproperty = ""; ChangeValueTo(changeValue_value.GetVector3(), target.transform.position); } else if (movePlayer_movementType == PlayerMovementType.Poke) { changeValue_component = target.transform; changeValue_property = "position"; changeValue_subproperty = ""; ChangeValueTo(target.transform.position + changeValue_value.GetVector3(), target.transform.position); } } else if (type == Type.ActivateObject) { bool state = activate_flipValue ? !target.activeSelf : changeValue_value.GetBool(); target.SetActive(state); } else if (type == Type.PlayAnimation) { if (playAnimation_loop) { playAnimation_animation.clip.wrapMode = WrapMode.Loop; } if (playAnimation_queue) { playAnimation_animation.PlayQueued(playAnimation_animation_clip, QueueMode.CompleteOthers); } else { playAnimation_animation.Play(playAnimation_animation_clip); } } else if (type == Type.ChangeScene) { // TODO: transition through a manager TransitionManager.instance.TransitionTo(System.IO.Path.GetFileNameWithoutExtension(changeScene_scenePath), changeScene_duration, changeScene_transitionTexture, changeScene_transitionWaveTexture, changeScene_transitionSound); } else if (type == Type.PlaySound) { foreach (var sound in GetSounds()) { if (sound != null && sound.gameObject.activeSelf) { sound.Play(); } } } else if (type == Type.FadeSound) { if (sound_changeType == SoundChangeType.Single) { changeValue_component = sound_audioSource; changeValue_property = "volume"; changeValue_subproperty = ""; ChangeValueTo(changeValue_value.GetFloat(), sound_audioSource.volume); } else if (sound_changeType == SoundChangeType.All) { Scene.current.FadeAllSounds(changeValue_value.GetFloat(), duration); } } else if (type == Type.StopSound) { /* * changeValue_component = sound_audioSource; * changeValue_property = "volume"; * changeValue_subproperty = ""; * changeValue_value.Set(0f); * ChangeValueTo(changeValue_value.GetFloat(), sound_audioSource.volume); */ foreach (var sound in GetSounds()) { if (sound != null) { sound.Stop(); } } } else if (type == Type.ChangeCameraMode) { CameraController.instance.MoveCamera(changeCameraMode_mode, changeCameraMode_time, changeCameraMode_target); if (changeCameraMode_mode == CameraController.CameraMode.TopDownWithMouseControls) { CameraController.instance._topdown_follow = changeCameraMode_topdownFollow; } } else if (type == Type.ChangeAvatar) { Player.instance.SwitchAvatar(changeAvatar_prefab); } else if (type == Type.ChangePlayerSounds) { Player.instance.SwitchSounds(playerSound_footsteps, playerSound_jump, playerSound_land, playerSound_air); } else if (type == Type.ShowMusicalDialog) { if (musicalDialog_dialog) { musicalDialog_dialog.Play(); } } else if (type == Type.ChangeMouseCursor) { if (texture != null) { Cursor.SetCursor(texture, new Vector2(texture.width * changeCursor_hotspot.x, texture.height * changeCursor_hotspot.y), CursorMode.Auto); } } else if (type == Type.SwapSkybox) { if (changeMaterial_material != null) { RenderSettings.skybox = changeMaterial_material; } } }