Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.38 KB | None | 0 0
  1.     [ORKEditorHelp("Change Scale Float", "Sets or fades the scale of a game object.", "")]
  2.     [ORKEventStep(typeof(BaseEvent))]
  3.     [ORKNodeInfo("Movement/Movement")]
  4.     public class ChangeScaleFloatStep : BaseEventStep
  5.     {
  6.         // scaling object
  7.         [ORKEditorInfo(labelText="Scaling Object")]
  8.         public EventObjectSetting scaleObject = new EventObjectSetting();
  9.  
  10.         [ORKEditorHelp("Time Between (s)", "The time in seconds between scaling two objects.\n" +
  11.             "Only used if greater than 0 and more than one object will be scaled.", "")]
  12.         [ORKEditorLimit(0.0f, false)]
  13.         public float timeBetween = 0;
  14.  
  15.         [ORKEditorHelp("Wait Between", "Wait for all objects to start scaling before executing the next step.\n" +
  16.             "If disabled, the next step will execute immediately while this step continues.", "")]
  17.         public bool waitBetween = true;
  18.  
  19.         [ORKEditorInfo(separator=true, labelText="ScaleX")]
  20.         public EventFloat scaleX = new EventFloat();
  21.         [ORKEditorInfo(separator = true, labelText = "ScaleY")]
  22.         public EventFloat scaleY = new EventFloat();
  23.         [ORKEditorInfo(separator = true, labelText = "ScaleZ")]
  24.         public EventFloat scaleZ = new EventFloat();
  25.  
  26.         Vector3 scale(BaseEvent baseEvent)
  27.         {
  28.             return new Vector3(scaleX.GetValue(baseEvent), scaleY.GetValue(baseEvent), scaleZ.GetValue(baseEvent));
  29.         }
  30.  
  31.         // fade
  32.         [ORKEditorHelp("Fade Scale", "The scale is changed over time to the new scale.\n" +
  33.             "If disabled, the object's scale is set to the new scale immediately.", "")]
  34.         [ORKEditorInfo(separator=true, labelText="Fade Settings")]
  35.         public bool fade = false;
  36.  
  37.         [ORKEditorInfo(separator=true, labelText="Time (s)", label=new string[] {
  38.             "The time in seconds used to scale."
  39.         })]
  40.         [ORKEditorLayout("fade", true, autoInit=true)]
  41.         public EventFloat time;
  42.  
  43.         [ORKEditorHelp("Wait", "Wait until the scaling has finished before the next step is executed.", "")]
  44.         [ORKEditorLayout("waitBetween", true, endCheckGroup=true)]
  45.         public bool wait = false;
  46.  
  47.         // interpolate
  48.         [ORKEditorHelp("Interpolation", "The interpolation used for fading the scale.", "")]
  49.         [ORKEditorLayout(endCheckGroup=true)]
  50.         public EaseType interpolation = EaseType.Linear;
  51.  
  52.  
  53.         // ingame
  54.         private List<GameObject> list;
  55.  
  56.         private int index = 0;
  57.  
  58.         private float tmpTime = 0;
  59.  
  60.         public ChangeScaleFloatStep()
  61.         {
  62.  
  63.         }
  64.  
  65.         public override void SetData(DataObject data)
  66.         {
  67.             base.SetData(data);
  68.  
  69.             if(data.Contains<float>("time"))
  70.             {
  71.                 this.time = new EventFloat();
  72.                 this.time.type = NumberValueType.Value;
  73.                 data.Get("time", ref this.time.value);
  74.             }
  75.         }
  76.  
  77.         public override void Execute(BaseEvent baseEvent)
  78.         {
  79.             this.list = this.scaleObject.GetObject(baseEvent);
  80.             this.index = 0;
  81.  
  82.             if(this.list.Count > 0)
  83.             {
  84.                 this.tmpTime = this.time != null ? this.time.GetValue(baseEvent) : 0;
  85.                 this.Continue(baseEvent);
  86.  
  87.                 if(!this.waitBetween)
  88.                 {
  89.                     baseEvent.StepFinished(this.next);
  90.                 }
  91.             }
  92.             else
  93.             {
  94.                 baseEvent.StepFinished(this.next);
  95.             }
  96.         }
  97.  
  98.         public override void Continue(BaseEvent baseEvent)
  99.         {
  100.             if(this.list[this.index] != null)
  101.             {
  102.                 if(this.fade)
  103.                 {
  104.                     ActorEventScaler scaler = ComponentHelper.Get<ActorEventScaler>(this.list[this.index]);
  105.                     scaler.Scale(this.list[this.index].transform, this.tmpTime, this.scale(baseEvent), this.interpolation);
  106.                 }
  107.                 else
  108.                 {
  109.                     this.list[this.index].transform.localScale = this.scale(baseEvent);
  110.                 }
  111.             }
  112.  
  113.             this.index++;
  114.             // execute next
  115.             if(this.index < this.list.Count)
  116.             {
  117.                 if(this.timeBetween > 0)
  118.                 {
  119.                     baseEvent.StartContinue(this.timeBetween, this);
  120.                 }
  121.                 else
  122.                 {
  123.                     this.Continue(baseEvent);
  124.                 }
  125.             }
  126.             // finish
  127.             else
  128.             {
  129.                 if(this.waitBetween)
  130.                 {
  131.                     if(this.fade && this.wait)
  132.                     {
  133.                         baseEvent.StartTime(this.tmpTime, this.next);
  134.                     }
  135.                     else
  136.                     {
  137.                         baseEvent.StepFinished(this.next);
  138.                     }
  139.                 }
  140.                 // clear data
  141.                 this.list = null;
  142.                 this.index = 0;
  143.             }
  144.         }
  145.  
  146.  
  147.         /*
  148.         ============================================================================
  149.         Node name functions
  150.         ============================================================================
  151.         */
  152.         public override string GetNodeDetails()
  153.         {
  154.             return (this.fade ?
  155.                 "Fade scale, " + this.time.GetInfoText() + "s " + (this.wait ? "(wait)" : "") :
  156.                 "Set scale");
  157.         }
  158.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement