Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. //animationPlaySpeed = windSpeed * 0.363636f;
  2. //note: Circumference of anemometer is 2.75m
  3. //1m/s wind would cause a 0.363636m/s rotation which means a play speed of 0.36%
  4. //name of animation for rotation is anemRotationSpeed
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using UnityEngine;
  11. using KSP.IO;
  12. using Weather;
  13.  
  14. namespace Animations
  15. {
  16. class KWSTurbineAnimationGeneric : PartModule
  17. {
  18. [KSPField]
  19. public string animationName;
  20. [KSPField]
  21. public bool goToBeginningWhenStopped = true;
  22. [KSPField]
  23. public int layer = 1;
  24.  
  25. private Animation anim;
  26. public bool isAnimating = true;
  27.  
  28. public override void OnUpdate()
  29. {
  30. //Debug.Log("Update");
  31. setPlayMode(isAnimating);
  32. base.OnUpdate();
  33. }
  34.  
  35. private void setPlayMode(bool isAnimating)
  36. {
  37. //Debug.Log("SetPlayMode");
  38. if (isAnimating == true)
  39. {
  40. Debug.Log(anim[animationName].speed);
  41. Debug.Log(Wind.windSpeed);
  42. anim.Play(animationName);
  43. if(Wind.windSpeed < 0.01f)
  44. {
  45. Debug.Log("Windspeed is 0");
  46. anim[animationName].speed = 0f;
  47. isAnimating = false;
  48. }
  49. else
  50. {
  51.  
  52. anim[animationName].speed = Wind.windSpeed * 0.3636f;
  53. isAnimating = true;
  54. }
  55.  
  56. }
  57. else
  58. {
  59. Debug.Log("Animation Stopped");
  60. if (goToBeginningWhenStopped)
  61. {
  62. anim[animationName].normalizedTime = 0f;
  63. }
  64.  
  65. anim[animationName].speed = 0f;
  66. }
  67. }
  68.  
  69. public override void OnStart(PartModule.StartState state)
  70. {
  71. Debug.Log("OnStart");
  72. //isAnimating = true;
  73. anim = part.FindModelAnimators(animationName).FirstOrDefault();
  74. if (anim != null)
  75. {
  76. anim[animationName].layer = layer;
  77. //anim[animationName].speed = Wind.windSpeed * 0.363636f;
  78. anim.wrapMode = WrapMode.Loop;
  79. setPlayMode(isAnimating);
  80. }
  81. else
  82. {
  83. Debug.Log("Could not find anim " + animationName);
  84. }
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement