From 1d69dfd8f3ce6f82ba0a6e7a3b9ea97b0e58311d Mon Sep 17 00:00:00 2001 From: "Ivan \"KaiSD\" Korystin" Date: Thu, 19 Jun 2014 00:47:02 +0400 Subject: [PATCH] Optimization: caching unity components new actions: ActionBezierRel.cs ActionBlink.cs ActionJumpBy.cs ActionJumpTo.cs --- README.md | 10 ++-- src/ActionsBase/Action.cs | 4 ++ src/ActionsInstant/ActionHide.cs | 2 +- src/ActionsInstant/ActionSetPlace.cs | 2 +- src/ActionsInstant/ActionSetRotation.cs | 8 +-- src/ActionsInstant/ActionSetTint.cs | 2 +- src/ActionsInstant/ActionShow.cs | 2 +- src/ActionsInstant/ActionToggleVisibility.cs | 2 +- src/ActionsInterval/ActionBezierAbs.cs | 15 ++---- src/ActionsInterval/ActionBezierRel.cs | 51 ++++++++++++++++++++ src/ActionsInterval/ActionBlink.cs | 33 +++++++++++++ src/ActionsInterval/ActionFadeBy.cs | 6 +-- src/ActionsInterval/ActionFadeTo.cs | 10 ++-- src/ActionsInterval/ActionJumpBy.cs | 43 +++++++++++++++++ src/ActionsInterval/ActionJumpTo.cs | 39 +++++++++++++++ src/ActionsInterval/ActionMoveBy.cs | 2 +- src/ActionsInterval/ActionMoveTo.cs | 4 +- src/ActionsInterval/ActionRotateBy.cs | 6 +-- src/ActionsInterval/ActionRotateTo.cs | 8 +-- src/ActionsInterval/ActionScaleBy.cs | 6 +-- src/ActionsInterval/ActionScaleTo.cs | 4 +- src/ActionsInterval/ActionTintBy.cs | 6 +-- src/ActionsInterval/ActionTintTo.cs | 10 ++-- src/Examples/SampleActions.cs | 10 ++-- src/UnityComponents/SkewModifier.cs | 10 +++- 25 files changed, 234 insertions(+), 61 deletions(-) create mode 100644 src/ActionsInterval/ActionBezierRel.cs create mode 100644 src/ActionsInterval/ActionBlink.cs create mode 100644 src/ActionsInterval/ActionJumpBy.cs create mode 100644 src/ActionsInterval/ActionJumpTo.cs diff --git a/README.md b/README.md index 8d9879e..ba3395c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can also subclass the Actor and add all the actions you want to the Start() ### Included actions (ready and WIP) All actions are designed to word in 3D scene (i.e. using Vector3 for movement, rotation and scaling). -You can use it in 2D with appropriate vectors, but i'm going to add support for 2D actions soon. +You can use it in 2D with apropriate vectors, but i'm going to add support for 2D actions soon. Base actions - [x] Sequence @@ -39,11 +39,11 @@ Interval actions - [x] FadeIn *if you want to manipulate alpha, your material must support transparency* - [x] FadeTo *if you want to manipulate alpha, your material must support transparency* - [x] FadeBy *if you want to manipulate alpha, your material must support transparency* -- [ ] JumpTo -- [ ] JumpBy - [x] BezierAbs -- [ ] BezierRel -- [ ] Blink +- [x] BezierRel +- [x] JumpTo *uses Bezier action to move the object* +- [x] JumpBy *uses Bezier action to move the object* +- [x] Blink Instant actions - [x] Place *renamed to SetPlace* diff --git a/src/ActionsBase/Action.cs b/src/ActionsBase/Action.cs index 5fa089f..1d11bd4 100644 --- a/src/ActionsBase/Action.cs +++ b/src/ActionsBase/Action.cs @@ -6,6 +6,8 @@ public class Action { protected Actor target; public float duration = 0; + protected Transform transform; + protected Renderer renderer; public Action() { @@ -36,6 +38,8 @@ public class Action { if (target == null) throw new Exception("Can start the action only after it's atached to the actor"); + transform = target.gameObject.transform; + renderer = target.gameObject.renderer; } /// diff --git a/src/ActionsInstant/ActionHide.cs b/src/ActionsInstant/ActionHide.cs index ad683f4..43ec31e 100644 --- a/src/ActionsInstant/ActionHide.cs +++ b/src/ActionsInstant/ActionHide.cs @@ -18,6 +18,6 @@ class ActionHide : Action public override void start() { base.start(); - target.gameObject.renderer.enabled = false; + renderer.enabled = false; } } \ No newline at end of file diff --git a/src/ActionsInstant/ActionSetPlace.cs b/src/ActionsInstant/ActionSetPlace.cs index 10062f2..f8ef495 100644 --- a/src/ActionsInstant/ActionSetPlace.cs +++ b/src/ActionsInstant/ActionSetPlace.cs @@ -20,6 +20,6 @@ class ActionSetPlace : Action public override void start() { base.start(); - target.gameObject.transform.position = place; + transform.position = place; } } \ No newline at end of file diff --git a/src/ActionsInstant/ActionSetRotation.cs b/src/ActionsInstant/ActionSetRotation.cs index bcf62f2..4b1e65b 100644 --- a/src/ActionsInstant/ActionSetRotation.cs +++ b/src/ActionsInstant/ActionSetRotation.cs @@ -23,10 +23,10 @@ class ActionSetRotation : Action Vector3 path = new Vector3(); for (int i = 0; i < 3; i++) { - path[i] = value[i] - target.gameObject.transform.rotation.eulerAngles[i]; + path[i] = value[i] - transform.rotation.eulerAngles[i]; } - target.gameObject.transform.Rotate(Vector3.up, path.y); - target.gameObject.transform.Rotate(Vector3.right, path.x); - target.gameObject.transform.Rotate(Vector3.forward, path.z); + transform.Rotate(Vector3.up, path.y); + transform.Rotate(Vector3.right, path.x); + transform.Rotate(Vector3.forward, path.z); } } \ No newline at end of file diff --git a/src/ActionsInstant/ActionSetTint.cs b/src/ActionsInstant/ActionSetTint.cs index 70dba09..5b98adf 100644 --- a/src/ActionsInstant/ActionSetTint.cs +++ b/src/ActionsInstant/ActionSetTint.cs @@ -16,6 +16,6 @@ class ActionSetTint : Action public override void start() { base.start(); - target.gameObject.renderer.material.color = new Color(color[0], color[1], color[2], color[3]); + renderer.material.color = new Color(color[0], color[1], color[2], color[3]); } } \ No newline at end of file diff --git a/src/ActionsInstant/ActionShow.cs b/src/ActionsInstant/ActionShow.cs index e47b567..0265bf1 100644 --- a/src/ActionsInstant/ActionShow.cs +++ b/src/ActionsInstant/ActionShow.cs @@ -18,6 +18,6 @@ class ActionShow : Action public override void start() { base.start(); - target.gameObject.renderer.enabled = true; + renderer.enabled = true; } } \ No newline at end of file diff --git a/src/ActionsInstant/ActionToggleVisibility.cs b/src/ActionsInstant/ActionToggleVisibility.cs index 799f04e..51f7ae3 100644 --- a/src/ActionsInstant/ActionToggleVisibility.cs +++ b/src/ActionsInstant/ActionToggleVisibility.cs @@ -13,6 +13,6 @@ class ActionToggleVisibility : Action public override void start() { base.start(); - target.gameObject.renderer.enabled = !target.gameObject.renderer.enabled; + renderer.enabled = !renderer.enabled; } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionBezierAbs.cs b/src/ActionsInterval/ActionBezierAbs.cs index 7079d51..0bc9bb1 100644 --- a/src/ActionsInterval/ActionBezierAbs.cs +++ b/src/ActionsInterval/ActionBezierAbs.cs @@ -4,10 +4,10 @@ using UnityEngine; class ActionBezierAbs : ActionInterval { - public Vector3 startPoint; - public Vector3 endPoint; - public Vector3 startControlPoint; - public Vector3 endControlPoint; + protected Vector3 startPoint; + protected Vector3 endPoint; + protected Vector3 startControlPoint; + protected Vector3 endControlPoint; public ActionBezierAbs(Vector3 tgtStart, Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration) : base(tgtDuration) @@ -28,11 +28,6 @@ class ActionBezierAbs : ActionInterval return new ActionBezierAbs(endPoint, endControlPoint, startControlPoint, startPoint, duration); } - public override void start() - { - base.start(); - } - public override void stepInterval(float dt) { float t = timer / duration; @@ -40,6 +35,6 @@ class ActionBezierAbs : ActionInterval + 3 * (startControlPoint - endControlPoint) + endPoint) * t + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t + 3 * (startControlPoint - startPoint)) * t + startPoint; - target.gameObject.transform.position = newPosition; + transform.position = newPosition; } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionBezierRel.cs b/src/ActionsInterval/ActionBezierRel.cs new file mode 100644 index 0000000..3cbb43d --- /dev/null +++ b/src/ActionsInterval/ActionBezierRel.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionBezierRel : ActionInterval +{ + protected Vector3 ep; + protected Vector3 cp1; + protected Vector3 cp2; + protected Vector3 startPoint; + protected Vector3 endPoint; + protected Vector3 startControlPoint; + protected Vector3 endControlPoint; + + public ActionBezierRel(Vector3 tgtSCP, Vector3 tgtECP, Vector3 tgtEnd, float tgtDuration) + : base(tgtDuration) + { + ep = tgtEnd; + cp1 = tgtSCP; + cp2 = tgtECP; + } + + public override Action clone() + { + return new ActionBezierRel(startControlPoint, endControlPoint, endPoint, duration); + } + + public override Action reverse() + { + return new ActionBezierRel(-startControlPoint, -endControlPoint, -endPoint, duration); + } + + public override void start() + { + base.start(); + startPoint = target.transform.position; + endPoint = startPoint + ep; + startControlPoint = startPoint + cp1; + endControlPoint = startControlPoint + cp2; + } + + public override void stepInterval(float dt) + { + float t = timer / duration; + Vector3 newPosition = (((-startPoint + + 3 * (startControlPoint - endControlPoint) + endPoint) * t + + (3 * (startPoint + endControlPoint) - 6 * startControlPoint)) * t + + 3 * (startControlPoint - startPoint)) * t + startPoint; + transform.position = newPosition; + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionBlink.cs b/src/ActionsInterval/ActionBlink.cs new file mode 100644 index 0000000..2c57df1 --- /dev/null +++ b/src/ActionsInterval/ActionBlink.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionBlink : ActionRepeat +{ + protected bool randomDelay; + protected ActionDelay delay = new ActionDelay(0); + protected Action[] blinkSeq; + + public ActionBlink(int tgtBlinks, float tgtDuration) + : base(null, tgtBlinks) + { + duration = tgtDuration; + count = (tgtBlinks) * 2; + blinkSeq = new Action[] + { + new ActionToggleVisibility(), + new ActionDelay(tgtDuration / tgtBlinks) + }; + action = new ActionSequence(blinkSeq); + } + + public override Action clone() + { + return new ActionBlink(count / 2 - 1, duration); + } + + public override Action reverse() + { + return new ActionBlink(count / 2 - 1, duration); + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionFadeBy.cs b/src/ActionsInterval/ActionFadeBy.cs index 7ee39c9..56b9123 100644 --- a/src/ActionsInterval/ActionFadeBy.cs +++ b/src/ActionsInterval/ActionFadeBy.cs @@ -4,7 +4,7 @@ using UnityEngine; class ActionFadeBy : ActionInterval { - public float delta; + protected float delta; public ActionFadeBy(float tgtDelta, float tgtDuration) : base(tgtDuration) @@ -25,8 +25,8 @@ class ActionFadeBy : ActionInterval public override void stepInterval(float dt) { float d = dt / duration; - Color tgtColor = target.gameObject.renderer.material.color; + Color tgtColor = renderer.material.color; tgtColor[3] += delta * d; - target.gameObject.renderer.material.color = tgtColor; + renderer.material.color = tgtColor; } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionFadeTo.cs b/src/ActionsInterval/ActionFadeTo.cs index 7784a71..ba9b84b 100644 --- a/src/ActionsInterval/ActionFadeTo.cs +++ b/src/ActionsInterval/ActionFadeTo.cs @@ -4,8 +4,8 @@ using UnityEngine; class ActionFadeTo : ActionInterval { - public float value; - public float delta; + protected float value; + protected float delta; public ActionFadeTo(float tgtValue, float tgtDuration) : base(tgtDuration) @@ -21,14 +21,14 @@ class ActionFadeTo : ActionInterval public override void start() { base.start(); - delta = value - target.gameObject.renderer.material.color.a; + delta = value - renderer.material.color.a; } public override void stepInterval(float dt) { float d = dt / duration; - Color tgtColor = target.gameObject.renderer.material.color; + Color tgtColor = renderer.material.color; tgtColor[3] += delta * d; - target.gameObject.renderer.material.color = tgtColor; + renderer.material.color = tgtColor; } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionJumpBy.cs b/src/ActionsInterval/ActionJumpBy.cs new file mode 100644 index 0000000..490589a --- /dev/null +++ b/src/ActionsInterval/ActionJumpBy.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionJumpBy : ActionSequence +{ + protected Vector3 point; + float height; + int jumps; + + public ActionJumpBy(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration) + : base(new Action[tgtJumps]) + { + point = tgtPoint; + jumps = tgtJumps; + height = tgtHeight; + duration = tgtDuration; + } + + public override Action clone() + { + return new ActionJumpBy(point, height, jumps, duration); + } + + public override Action reverse() + { + return new ActionJumpBy(-point, height, jumps, duration); + } + + public override void start() + { + float coeff = 1F / jumps; + Vector3 end = point * coeff; + Vector3 cp1 = Vector3.up * height; + Vector3 cp2 = end + cp1; + ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff); + for (int i = 0; i < jumps; i++) + { + actions[i] = singleJump; + } + base.start(); + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionJumpTo.cs b/src/ActionsInterval/ActionJumpTo.cs new file mode 100644 index 0000000..e991e61 --- /dev/null +++ b/src/ActionsInterval/ActionJumpTo.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +class ActionJumpTo : ActionSequence +{ + protected Vector3 point; + float height; + int jumps; + + public ActionJumpTo(Vector3 tgtPoint, float tgtHeight, int tgtJumps, float tgtDuration) + : base(new Action[tgtJumps]) + { + point = tgtPoint; + jumps = tgtJumps; + height = tgtHeight; + duration = tgtDuration; + } + + public override Action clone() + { + return new ActionJumpTo(point, height, jumps, duration); + } + + public override void start() + { + float coeff = 1F / jumps; + Vector3 start = target.gameObject.transform.position; + Vector3 end = (point - start) * coeff; + Vector3 cp1 = Vector3.up * height; + Vector3 cp2 = end + cp1; + ActionBezierRel singleJump = new ActionBezierRel(cp1, cp2, end, duration * coeff); + for (int i = 0; i < jumps; i++) + { + actions[i] = singleJump; + } + base.start(); + } +} \ No newline at end of file diff --git a/src/ActionsInterval/ActionMoveBy.cs b/src/ActionsInterval/ActionMoveBy.cs index cfe19b1..a5ae133 100644 --- a/src/ActionsInterval/ActionMoveBy.cs +++ b/src/ActionsInterval/ActionMoveBy.cs @@ -26,6 +26,6 @@ class ActionMoveBy : ActionInterval { float d = dt / duration; Vector3 tgt = delta * d; - target.gameObject.transform.Translate(tgt, Space.World); + transform.Translate(tgt, Space.World); } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionMoveTo.cs b/src/ActionsInterval/ActionMoveTo.cs index 954cd31..a6df596 100644 --- a/src/ActionsInterval/ActionMoveTo.cs +++ b/src/ActionsInterval/ActionMoveTo.cs @@ -22,13 +22,13 @@ class ActionMoveTo : ActionInterval public override void start() { base.start(); - path = value - target.gameObject.transform.position; + path = value - transform.position; } public override void stepInterval(float dt) { float d = dt / duration; Vector3 tgt = path * d; - target.gameObject.transform.Translate(tgt, Space.World); + transform.Translate(tgt, Space.World); } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionRotateBy.cs b/src/ActionsInterval/ActionRotateBy.cs index 5d299f4..ab0d7be 100644 --- a/src/ActionsInterval/ActionRotateBy.cs +++ b/src/ActionsInterval/ActionRotateBy.cs @@ -26,8 +26,8 @@ class ActionRotateBy : ActionInterval { float d = dt / duration; Vector3 tgt = delta * d; - target.gameObject.transform.Rotate(Vector3.up, tgt.y); - target.gameObject.transform.Rotate(Vector3.right, tgt.x); - target.gameObject.transform.Rotate(Vector3.forward, tgt.z); + transform.Rotate(Vector3.up, tgt.y); + transform.Rotate(Vector3.right, tgt.x); + transform.Rotate(Vector3.forward, tgt.z); } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionRotateTo.cs b/src/ActionsInterval/ActionRotateTo.cs index 446c2de..859f435 100644 --- a/src/ActionsInterval/ActionRotateTo.cs +++ b/src/ActionsInterval/ActionRotateTo.cs @@ -25,7 +25,7 @@ class ActionRotateTo : ActionInterval for (int i = 0; i < 3; i++) { float t = value[i]; - float f = target.gameObject.transform.rotation.eulerAngles[i]; + float f = transform.rotation.eulerAngles[i]; if (Math.Abs(t - f) < Math.Abs(t + 360 - f)) path[i] = t - f; else @@ -36,8 +36,8 @@ class ActionRotateTo : ActionInterval { float d = dt / duration; Vector3 tgt = path * d; - target.gameObject.transform.Rotate(Vector3.up, tgt.y); - target.gameObject.transform.Rotate(Vector3.right, tgt.x); - target.gameObject.transform.Rotate(Vector3.forward, tgt.z); + transform.Rotate(Vector3.up, tgt.y); + transform.Rotate(Vector3.right, tgt.x); + transform.Rotate(Vector3.forward, tgt.z); } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionScaleBy.cs b/src/ActionsInterval/ActionScaleBy.cs index 7270e01..bfba18b 100644 --- a/src/ActionsInterval/ActionScaleBy.cs +++ b/src/ActionsInterval/ActionScaleBy.cs @@ -26,18 +26,18 @@ class ActionScaleBy : ActionInterval public override void start() { base.start(); - Vector3 scale = target.gameObject.transform.localScale; + Vector3 scale = transform.localScale; scale.x *= delta.x; scale.y *= delta.y; scale.z *= delta.z; - path = scale - target.gameObject.transform.localScale; + path = scale - transform.localScale; } public override void stepInterval(float dt) { float d = dt / duration; Vector3 tgt = path * d; - target.gameObject.transform.localScale += tgt; + transform.localScale += tgt; } public override void stop() diff --git a/src/ActionsInterval/ActionScaleTo.cs b/src/ActionsInterval/ActionScaleTo.cs index 29696d3..2d89856 100644 --- a/src/ActionsInterval/ActionScaleTo.cs +++ b/src/ActionsInterval/ActionScaleTo.cs @@ -21,14 +21,14 @@ class ActionScaleTo : ActionInterval public override void start() { base.start(); - path = value - target.gameObject.transform.localScale; + path = value - transform.localScale; } public override void stepInterval(float dt) { float d = dt / duration; Vector3 tgt = path * d; - target.gameObject.transform.localScale += tgt; + transform.localScale += tgt; } public override void stop() diff --git a/src/ActionsInterval/ActionTintBy.cs b/src/ActionsInterval/ActionTintBy.cs index 5440f4c..2ad5824 100644 --- a/src/ActionsInterval/ActionTintBy.cs +++ b/src/ActionsInterval/ActionTintBy.cs @@ -4,7 +4,7 @@ using UnityEngine; class ActionTintBy : ActionInterval { - public Vector4 color; + protected Vector4 color; protected const float coeff = 1F / 255F; public ActionTintBy(Vector4 tgtColor, float tgtDuration) @@ -32,11 +32,11 @@ class ActionTintBy : ActionInterval { float d = dt / duration; Vector4 tgt = color * d; - Color tgtColor = target.gameObject.renderer.material.color; + Color tgtColor = renderer.material.color; tgtColor[0] += tgt[0]; tgtColor[1] += tgt[1]; tgtColor[2] += tgt[2]; tgtColor[3] += tgt[3]; - target.gameObject.renderer.material.color = tgtColor; + renderer.material.color = tgtColor; } } \ No newline at end of file diff --git a/src/ActionsInterval/ActionTintTo.cs b/src/ActionsInterval/ActionTintTo.cs index 0707956..61a1618 100644 --- a/src/ActionsInterval/ActionTintTo.cs +++ b/src/ActionsInterval/ActionTintTo.cs @@ -4,8 +4,8 @@ using UnityEngine; class ActionTintTo : ActionInterval { - public Vector4 color; - public Vector4 path; + protected Vector4 color; + protected Vector4 path; protected const float coeff = 1F / 255F; public ActionTintTo(Vector4 tgtColor, float tgtDuration) @@ -28,7 +28,7 @@ class ActionTintTo : ActionInterval public override void start() { base.start(); - Color tgtColor = target.gameObject.renderer.material.color; + Color tgtColor = renderer.material.color; path[0] = color[0] - tgtColor[0]; path[1] = color[1] - tgtColor[1]; path[2] = color[2] - tgtColor[2]; @@ -39,11 +39,11 @@ class ActionTintTo : ActionInterval { float d = dt / duration; Vector4 tgt = path * d; - Color tgtColor = target.gameObject.renderer.material.color; + Color tgtColor = renderer.material.color; tgtColor[0] += tgt[0]; tgtColor[1] += tgt[1]; tgtColor[2] += tgt[2]; tgtColor[3] += tgt[3]; - target.gameObject.renderer.material.color = tgtColor; + renderer.material.color = tgtColor; } } \ No newline at end of file diff --git a/src/Examples/SampleActions.cs b/src/Examples/SampleActions.cs index 10567cb..0da1066 100644 --- a/src/Examples/SampleActions.cs +++ b/src/Examples/SampleActions.cs @@ -9,8 +9,7 @@ public class SampleActions : MonoBehaviour { new ActionFadeIn(2), new ActionParallel(new Action[] { - new ActionMoveBy(new Vector3(10, 0, 0), 1), - new ActionMoveBy(new Vector3(0, 10, 0), 1), + new ActionMoveBy(new Vector3(10, 10, 0), 1), new ActionRotateBy(new Vector3(90, 0, 0), 1), new ActionTintBy(new Vector4(-50, 50, -150), 1) }), @@ -24,11 +23,14 @@ public class SampleActions : MonoBehaviour new ActionDelay(0F, 0.2F), }), 5), new ActionDelay(1), - new ActionMoveBy(new Vector3(-10, 0, 0), 1), + new ActionJumpBy(new Vector3(-10, 0, 0), 1, 4, 1), + new ActionJumpTo(new Vector3(10, 10, 10), 1, 3, 1), + new ActionJumpBy(new Vector3(-10, 0, 0), 1, 2, 1), new ActionDelay(0.5F), - new ActionMoveTo(new Vector3(0, 0, 10), 1), + new ActionBezierRel(new Vector3 (5, 0, 0), new Vector3(5, -10, 0), new Vector3 (0, -10, 0), 2), new ActionScaleTo(new Vector3(2, 2, 2), 1), new ActionRotateTo(new Vector3(0, 0, 0), 1), + new ActionBlink(2, 1), new ActionFadeOut(2), new ActionSetTint(new Vector4(67, 105, 181)) }), 5); diff --git a/src/UnityComponents/SkewModifier.cs b/src/UnityComponents/SkewModifier.cs index 2348d1b..b2cc83f 100644 --- a/src/UnityComponents/SkewModifier.cs +++ b/src/UnityComponents/SkewModifier.cs @@ -9,6 +9,12 @@ public class SkewModifier : MonoBehaviour protected Vector3 angles1prev = Vector3.zero; protected Vector3 angles2prev = Vector3.zero; protected const float coeff = Mathf.PI/180; + protected Mesh mesh; + + void Awake() + { + mesh = gameObject.GetComponent().mesh; + } void Update() { @@ -30,7 +36,7 @@ public class SkewModifier : MonoBehaviour m[2, 0] = Mathf.Tan(angles1.z * coeff) - Mathf.Tan(angles1prev.z * coeff); // skewing in zx m[2, 1] = Mathf.Tan(angles2.z * coeff) - Mathf.Tan(angles2prev.z * coeff); // skewing in zy - Vector3[] verts = gameObject.GetComponent().mesh.vertices; + Vector3[] verts = mesh.vertices; int i = 0; while (i < verts.Length) { @@ -38,7 +44,7 @@ public class SkewModifier : MonoBehaviour i++; } - gameObject.GetComponent().mesh.vertices = verts; + mesh.vertices = verts; angles1prev = angles1; angles2prev = angles2; }