public Tween(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) : this(name, func, callback, time, pingpong, loop) { CurrentDirection = initialDirection; InitialDirection = initialDirection; if (initialDirection == TweenDirection.Reverse) CurrentTime = TargetTime; }
public Tween Create(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) { Tween t = new Tween(name, func, callback, time, pingpong, loop, initialDirection); Tweens.Add(t); return t; }
public Tween(string name, TweenFunc func, Action<Tween> callback, double time, bool pingpong, bool loop) { Name = name; _callback = callback; _tweenFunc = func; TargetTime = time; Looping = loop; PingPong = pingpong; CurrentTime = 0; CurrentDirection = TweenDirection.Forward; InitialDirection = TweenDirection.Forward; Value = 0f; if (PingPong) TargetTime /= 2; // If we're pingponging, halve the time so that TargetTime is one complete cycle }
public void Show(TweenDirection direction) { Tween(true, DefaultTimeout, direction); }
private static Vector3 GetVector(TweenDirection tweenDirection, float aspect) { switch (tweenDirection) { case TweenDirection.Left: return -Vector2.right * aspect; case TweenDirection.Right: return Vector2.right * aspect; case TweenDirection.Up: return Vector2.up*1000; case TweenDirection.Down: return -Vector2.up*1000; default: throw new Exception(); } }
public void Hide(TweenDirection direction) { Tween(false, DefaultTimeout, direction); }
public void Show(TweenDirection direction) { Hide(direction, 0); Tween(true, DefaultTimeout, direction); }
/// <summary> /// Set the direction that the tween will play in /// </summary> public Tween <T> SetPlayDirection(TweenDirection direction) { this.PlayDirection = direction; return(this); }
private void Tween(bool show, float timeout, TweenDirection tweenDirection) { TaskScheduler.Kill(Id); Vector3 vector; if (show) { if (Opened) { return; } Hide(tweenDirection, 0f); } if (show) { vector = Vector3.zero; gameObject.SetActive(true); } else { if (UseCustomTweenPosition) { vector = new Vector2(CustomTweenPosition.x * transform.localScale.x, CustomTweenPosition.y * transform.localScale.y); } else { vector = GetVector(tweenDirection, 1000 * Camera.main.aspect); } if (timeout > 0) { TaskScheduler.CreateTask(() => gameObject.SetActive(false), Id, timeout); } else { gameObject.SetActive(true); } } if (timeout > 0) { TweenPosition.Begin(gameObject, timeout, vector).animationCurve = AnimationCurve; if (Transparency) { TaskScheduler.CreateTask(() => TweenAlpha.Begin(gameObject, timeout / 2, show ? 1 : 0), Id, show ? timeout / 2 : 0); } } else { transform.localPosition = vector; if (Transparency) { GetComponent<UIPanel>().alpha = show ? 1 : 0; } } }
public Tween(string name, TweenFunc func, Action <Tween> callback, double time, bool pingpong, bool loop, TweenDirection initialDirection) : this(name, func, callback, time, pingpong, loop) { CurrentDirection = initialDirection; InitialDirection = initialDirection; if (initialDirection == TweenDirection.Reverse) { CurrentTime = TargetTime; } }
private void Tween(bool open, float timeout, TweenDirection tweenDirection) { if (open && (State == TweenPanelState.Opened || State == TweenPanelState.Opening)) { return; } if (!open && (State == TweenPanelState.Hidden || State == TweenPanelState.Hiding)) { return; } TaskScheduler.Kill(Id); State = open ? TweenPanelState.Opening : TweenPanelState.Hiding; TaskScheduler.CreateTask(() => State = open ? TweenPanelState.Opened : TweenPanelState.Hidden, Id, timeout); Vector3 target; if (open && State != TweenPanelState.Hiding) { transform.localPosition = GetHiddenPosition(tweenDirection); if (Transparency) { GetComponent <UIPanel>().alpha = 0; } } if (open) { target = Vector3.zero; gameObject.SetActive(true); } else { target = GetHiddenPosition(tweenDirection); if (timeout > 0) { TaskScheduler.CreateTask(() => gameObject.SetActive(false), Id, timeout); } else { gameObject.SetActive(true); } } if (timeout > 0) { TweenPosition.Begin(gameObject, timeout, target).animationCurve = AnimationCurve; if (Transparency) { TaskScheduler.CreateTask(() => TweenAlpha.Begin(gameObject, timeout / 2, open ? 1 : 0), Id, open ? timeout / 2 : 0); } } else { transform.localPosition = target; if (Transparency) { GetComponent <UIPanel>().alpha = open ? 1 : 0; } } }
public void Shake() { Move (shakeDirection, Random.Range (-shakeStrength,shakeStrength)); shakeDirection = shakeDirection == TweenDirection.X ? TweenDirection.Z:TweenDirection.X; if(Vector3.Distance(startPosition,transform.position) > shakeStrength) { transform.position = startPosition; } }
public void Move(TweenDirection dir, float amount) { Vector3 position = transform.position; switch(dir) { case TweenDirection.X: position.x += amount; break; case TweenDirection.Z: position.z += amount; break; case TweenDirection.Y: position.y += amount; break; } transform.position = position; }
/// <summary> /// Reverses the direction of play /// </summary> public virtual TweenBase ReversePlayDirection() { this.PlayDirection = (this.PlayDirection == TweenDirection.Forward) ? TweenDirection.Reverse : TweenDirection.Forward; return(this); }
public void Hide(TweenDirection direction, float timeout) { Tween(false, timeout, direction); }
public void Update(GameTime gameTime) { if (State != TweenState.Running) { return; } switch (CurrentDirection) { case TweenDirection.Forward: CurrentTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (CurrentTime >= TargetTime) { if (PingPong) { if (InitialDirection == TweenDirection.Reverse) { if (Looping) { CurrentDirection = TweenDirection.Reverse; } else { State = TweenState.Finished; } } else { CurrentDirection = TweenDirection.Reverse; } CurrentTime -= (CurrentTime - TargetTime); } else { if (Looping) { CurrentTime = (CurrentTime - TargetTime); } else { State = TweenState.Finished; } } } break; case TweenDirection.Reverse: CurrentTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (CurrentTime <= 0) { if (PingPong) { if (InitialDirection == TweenDirection.Forward) { if (Looping) { CurrentDirection = TweenDirection.Forward; } else { State = TweenState.Finished; } } else { CurrentDirection = TweenDirection.Forward; } CurrentTime = -CurrentTime; } else { if (Looping) { CurrentTime = TargetTime + CurrentTime; } else { State = TweenState.Finished; } } } break; default: throw new ArgumentOutOfRangeException(); } float pos = (1f / (float)TargetTime) * (float)CurrentTime; Value = _tweenFunc(pos); _callback(this); }
public void Update(GameTime gameTime) { if(State!=TweenState.Running) return; switch (CurrentDirection) { case TweenDirection.Forward: CurrentTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (CurrentTime >= TargetTime) { if (PingPong) { if (InitialDirection == TweenDirection.Reverse) { if(Looping) CurrentDirection = TweenDirection.Reverse; else State = TweenState.Finished; } else CurrentDirection = TweenDirection.Reverse; CurrentTime -= (CurrentTime - TargetTime); } else { if (Looping) CurrentTime = (CurrentTime-TargetTime); else State = TweenState.Finished; } } break; case TweenDirection.Reverse: CurrentTime -= gameTime.ElapsedGameTime.TotalMilliseconds; if (CurrentTime <= 0) { if (PingPong) { if (InitialDirection == TweenDirection.Forward) { if(Looping) CurrentDirection = TweenDirection.Forward; else State = TweenState.Finished; } else CurrentDirection = TweenDirection.Forward; CurrentTime = -CurrentTime; } else { if (Looping) CurrentTime = TargetTime+CurrentTime; else State = TweenState.Finished; } } break; default: throw new ArgumentOutOfRangeException(); } float pos = (1f/(float)TargetTime) * (float)CurrentTime; Value = _tweenFunc(pos); _callback(this); }
private static bool DrawTween(TSSTween tween, List <TSSTween> holder, Object parent, TSSItemValues values) { GUI.backgroundColor = new Color(0f, 0f, 0f, 0.5f); EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); GUI.backgroundColor = Color.white; EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref tween.enabled, parent); EditorGUI.BeginDisabledGroup(!tween.enabled); ItemEffect tweenEffect = tween.effect; TSSEditorUtils.DrawGenericProperty(ref tween.effect, parent); if (tween.effect != tweenEffect) { if (tween.effect == ItemEffect.property) { tween.matProperty = new TSSMaterialProperty(MaterialPropertyType.single); } if (tween.effect != ItemEffect.property) { tween.matProperty = null; tween.matPropertyType = MaterialPropertyType.single; } } EditorGUI.BeginDisabledGroup(tween.direction == TweenDirection.Button); if (tween.mode == TweenMode.Multiple) { EditorGUI.BeginDisabledGroup(tween.direction == TweenDirection.Close); TSSEditorUtils.DrawGenericProperty(ref tween.type, TSSEditorUtils.greenColor, null, parent); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(tween.direction == TweenDirection.Open); TSSEditorUtils.DrawGenericProperty(ref tween.closingType, TSSEditorUtils.redColor, null, parent); EditorGUI.EndDisabledGroup(); } else { TSSEditorUtils.DrawGenericProperty(ref tween.type, parent); } TSSEditorUtils.DrawGenericProperty(ref tween.mode, parent); EditorGUI.EndDisabledGroup(); TweenDirection tweenDirection = tween.direction; TSSEditorUtils.DrawGenericProperty(ref tween.direction, parent); if (tween.direction != tweenDirection) { if (tween.direction == TweenDirection.Button) { tween.type = TweenType.Custom; tween.mode = TweenMode.Single; } } EditorGUI.EndDisabledGroup(); if (DrawTweenDeleteButton(tween, holder, parent)) { return(false); } EditorGUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(!tween.enabled); GUILayout.Space(3); TSSEditorUtils.DrawMinMaxSliderProperty(ref tween.startPoint, ref tween.endPoint, parent); if (tween.mode == TweenMode.Multiple && tween.direction == TweenDirection.OpenClose) { TSSEditorUtils.DrawSliderProperty(ref tween.blendFactor, parent, blndTweenLabelContent); } if ((tween.type == TweenType.Custom && tween.direction != TweenDirection.Close) || (tween.mode == TweenMode.Multiple && tween.closingType == TweenType.Custom && tween.direction != TweenDirection.Open)) { EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref tween.customEase, parent); EditorGUILayout.EndHorizontal(); } if (tween.effect == ItemEffect.property) { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); MaterialPropertyType tssMatPropType = tween.matPropertyType; string tssMatPropName = tween.matProperty.name; TSSEditorUtils.DrawGenericProperty(ref tween.matPropertyType, parent); if (tssMatPropType != tween.matPropertyType) { tween.matProperty = new TSSMaterialProperty(tween.matPropertyType); } tween.matProperty.name = tssMatPropName; TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.name, parent); EditorGUILayout.EndHorizontal(); switch (tween.matPropertyType) { case MaterialPropertyType.single: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.singleValues[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.singleValues[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case MaterialPropertyType.integer: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.integerValues[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.integerValues[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case MaterialPropertyType.color: TSSEditorUtils.useHDRcolors = false; EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case MaterialPropertyType.colorHDR: TSSEditorUtils.useHDRcolors = true; EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.colorValues[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case MaterialPropertyType.vector2: TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector2values[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector2values[1], TSSEditorUtils.greenColor, parent); break; case MaterialPropertyType.vector3: TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector3values[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector3values[1], TSSEditorUtils.greenColor, parent); break; case MaterialPropertyType.vector4: TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector4values[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.vector4values[1], TSSEditorUtils.greenColor, parent); break; case MaterialPropertyType.curve: TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.curve, parent); break; case MaterialPropertyType.gradient: TSSEditorUtils.DrawGenericProperty(ref tween.matProperty.gradient, parent); break; } EditorGUILayout.EndVertical(); } if (TSSPrefsEditor.showTweenProperties) { EditorGUILayout.BeginVertical(); switch (tween.effect) { case ItemEffect.transform: EditorGUILayout.LabelField("Position"); EditorGUILayout.BeginVertical(); TSSEditorUtils.DrawGenericProperty(ref values.positions[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.positions[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndVertical(); GUILayout.Space(4); EditorGUILayout.LabelField("Rotation"); EditorGUILayout.BeginVertical(); TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndVertical(); GUILayout.Space(4); EditorGUILayout.LabelField("Scale"); EditorGUILayout.BeginVertical(); TSSEditorUtils.DrawGenericProperty(ref values.scales[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.scales[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndVertical(); break; case ItemEffect.position: TSSEditorUtils.DrawGenericProperty(ref values.positions[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.positions[1], TSSEditorUtils.greenColor, parent); break; case ItemEffect.rotation: TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.eulerRotations[1], TSSEditorUtils.greenColor, parent); break; case ItemEffect.scale: TSSEditorUtils.DrawGenericProperty(ref values.scales[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.scales[1], TSSEditorUtils.greenColor, parent); break; case ItemEffect.directAlpha: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref values.alphas[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.alphas[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case ItemEffect.alpha: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref values.alphas[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.alphas[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case ItemEffect.color: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.useHDRcolors = false; TSSEditorUtils.DrawGenericProperty(ref values.colors[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.colors[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case ItemEffect.imageFill: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref values.imageFills[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.imageFills[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case ItemEffect.text: TSSEditorUtils.DrawGenericProperty(ref values.texts[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.texts[1], TSSEditorUtils.greenColor, parent); break; case ItemEffect.number: EditorGUILayout.BeginHorizontal(); TSSEditorUtils.DrawGenericProperty(ref values.numbers[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.numbers[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case ItemEffect.light: EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Color", TSSEditorUtils.max80pxWidth); TSSEditorUtils.DrawGenericProperty(ref values.colors[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.colors[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); GUILayout.Space(4); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Intensity", TSSEditorUtils.max80pxWidth); TSSEditorUtils.DrawGenericProperty(ref values.intensities[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.intensities[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); GUILayout.Space(4); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Range", TSSEditorUtils.max80pxWidth); TSSEditorUtils.DrawGenericProperty(ref values.lightRange[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.lightRange[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; case ItemEffect.range: EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Light", TSSEditorUtils.max80pxWidth); TSSEditorUtils.DrawGenericProperty(ref values.lightRange[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.lightRange[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); GUILayout.Space(4); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Collider", TSSEditorUtils.max80pxWidth); TSSEditorUtils.DrawGenericProperty(ref values.sphereRange[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.sphereRange[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); GUILayout.Space(4); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Sound", TSSEditorUtils.max80pxWidth); TSSEditorUtils.DrawGenericProperty(ref values.soundRange[0], TSSEditorUtils.redColor, parent); TSSEditorUtils.DrawGenericProperty(ref values.soundRange[1], TSSEditorUtils.greenColor, parent); EditorGUILayout.EndHorizontal(); break; } EditorGUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); GUILayout.Space(3); return(true); }