Exemplo n.º 1
0
    void DoWander()
    {
        if (GameManager.instance.selectedPerson == gameObject)
        {
            Invoke("DoWander", Random.Range(MIN_IDLE_TIME, MAX_IDLE_TIME));
            return;
        }

        Vector2 point;
        Vector3 targetPosition;
        Vector3 bounds = GetComponent <SpriteRenderer>().bounds.extents;

        do
        {
            point          = Random.insideUnitCircle * MAX_MOVE_DISTANCE;
            targetPosition = transform.position + new Vector3(point.x, point.y, 0f);
        }while (targetPosition.x < bounds.x || targetPosition.x > Screen.width - bounds.x || targetPosition.y < bounds.y || targetPosition.y > Screen.height - bounds.y);

        float distance = Vector3.Distance(transform.position, targetPosition);
        float time     = distance / MOVE_SPEED;

        moveTween = TweenFactory.Tween(null, transform.position, targetPosition, time, TweenScaleFunctions.Linear, (t) =>
        {
            transform.position = t.CurrentValue;
        }, (t) =>
        {
            moveTween = null;
            Invoke("DoWander", Random.Range(MIN_IDLE_TIME, MAX_IDLE_TIME));
        });
    }
Exemplo n.º 2
0
        public static Vector3Tween ShakePosition(this Transform obj, float duration, Vector3 magnitude, bool relativeWorld = false)
        {
            Vector3      position = relativeWorld ? obj.position : obj.localPosition;
            Vector3Tween node     = Vector3Tween.Allocate(duration, position, position);

            node.SetUpdate(
                (result) =>
            {
                if (relativeWorld)
                {
                    obj.position = result;
                }
                else
                {
                    obj.localPosition = result;
                }
            });
            node.SetLerp(
                (from, to, progress) =>
            {
                return(TweenMath.Shake(magnitude, from, progress));
            });
            node.SetLoop(ETweenLoop.PingPong, 1);
            return(node);
        }
Exemplo n.º 3
0
        public static Vector3Tween TweenScale(this Transform obj, float duration, Vector3 from, Vector3 to)
        {
            Vector3Tween node = Vector3Tween.Allocate(duration, from, to);

            node.SetUpdate((result) => { obj.localScale = result; });
            return(node);
        }
Exemplo n.º 4
0
 public void StopWander()
 {
     if (moveTween != null)
     {
         moveTween.Stop(TweenStopBehavior.Complete);
         moveTween = null;
     }
 }
Exemplo n.º 5
0
        public override void PostDraw()
        {
            base.PostDraw();

            // Children & Pregnancy || Werewolves transformed
            if (this.Pawn.Map == null || !this.Pawn.Spawned || this.Pawn.Dead)
            {
                return;
            }

            if (Find.TickManager.Paused)
            {
                if (!HarmonyPatchesFS.AnimatorIsOpen() || MainTabWindow_BaseAnimator.Pawn != this.Pawn)
                {
                    return;
                }
            }

            if (this.Props.bipedWithHands)
            {
                this.BodyAnimator.AnimatorTick();
            }

            // Tweener
            Vector3Tween eqTween = this.Vector3Tweens[(int)HarmonyPatchesFS.equipment];

            FloatTween   angleTween = this.AimAngleTween;
            Vector3Tween leftHand   = this.Vector3Tweens[(int)TweenThing.HandLeft];
            Vector3Tween rightHand  = this.Vector3Tweens[(int)TweenThing.HandRight];

            if (leftHand.State == TweenState.Running)
            {
                leftHand.Update(1f * Find.TickManager.TickRateMultiplier);
            }
            if (rightHand.State == TweenState.Running)
            {
                rightHand.Update(1f * Find.TickManager.TickRateMultiplier);
            }
            if (eqTween.State == TweenState.Running)
            {
                eqTween.Update(1f * Find.TickManager.TickRateMultiplier);
            }

            if (angleTween.State == TweenState.Running)
            {
                this.AimAngleTween.Update(3f * Find.TickManager.TickRateMultiplier);
            }

            this.CheckMovement();
        }
Exemplo n.º 6
0
    public void DoAttract(Vector3 targetPosition)
    {
        Vector3 bounds = GetComponent <SpriteRenderer>().bounds.extents;

        float distance = Vector3.Distance(transform.position, targetPosition);
        float time     = distance / MOVE_SPEED;

        moveTween = TweenFactory.Tween(null, transform.position, targetPosition, time, TweenScaleFunctions.Linear, (t) =>
        {
            transform.position = t.CurrentValue;
        }, (t) =>
        {
            moveTween = null;
        });
    }
Exemplo n.º 7
0
        internal static Vector3Tween GetVector3Tween(Vector3 from, Vector3 to, float time)
        {
            Vector3Tween tween;

            if (TryGetTween(vector3Tweens, out tween))
            {
                tween.Init(from, to, time);
            }
            else
            {
                tween         = new Vector3Tween(from, to, time, GenerateId());
                tween.Recycle = FinishTween;
            }
            _activeTweens.Add(tween);
            return(tween);
        }
Exemplo n.º 8
0
        public BaseTween Move(Transform obj, Vector3 to, float t)
        {
            Vector3Tween tween = TweenPool.GetVector3Tween(obj.position, to, t);

            tween.PauseReset += () => tween.Init(obj.position, to, t);
            tween.SetOnUpdateVector3((Vector3 pos) =>
            {
                if (obj == null)
                {
                    CancelTween(tween);
                    return;
                }

                obj.position = pos;
            });
            return(ProcessTween(tween));
        }
Exemplo n.º 9
0
        public static Vector3Tween TweenAngles(this Transform obj, float duration, Vector3 from, Vector3 to, bool relativeWorld = false)
        {
            Vector3Tween node = Vector3Tween.Allocate(duration, from, to);

            node.SetUpdate(
                (result) =>
            {
                if (relativeWorld)
                {
                    obj.eulerAngles = result;
                }
                else
                {
                    obj.localEulerAngles = result;
                }
            });
            return(node);
        }
Exemplo n.º 10
0
        public BaseTween ScaleTween(Transform t, Vector3 to, float time)
        {
            Vector3Tween tween = TweenPool.GetVector3Tween(t.localScale, to, time);

            tween.PauseReset += () => tween.Init(t.localScale, to, time);
            tween.SetOnUpdateVector3(delegate(Vector3 v)
            {
                if (t == null)
                {
                    CancelTween(tween);
                    return;
                }


                t.localScale = v;
            });
            return(ProcessTween(tween));
        }
Exemplo n.º 11
0
        public async Task InitPosition(Transform transform, float xPos)
        {
            transform.SetParent(null, true);

            var posTween = new Vector3Tween(transform.position, new Vector3(xPos, 1, 1), pos => { transform.position = pos; }, 1, EaseType.OutCubic);

            var rotTween = new Vector3Tween(transform.eulerAngles, new Vector3(-10, 0, 0), pos => { transform.eulerAngles = pos; }, 1,
                                            EaseType.OutCubic);

            var t = 0f;

            while (t < 1)
            {
                t += 0.01f;
                posTween.GetValue(t);
                rotTween.GetValue(t);
                await Task.Delay(10);
            }
        }
Exemplo n.º 12
0
    public static PTween createTween <T>() where T : struct
    {
        PTween tween = null;
        Type   t     = typeof(T);

        if (t == typeof(int))
        {
            tween = new IntTween();
        }
        else if (t == typeof(float))
        {
            tween = new FloatTween();
        }
        else if (t == typeof(Vector2))
        {
            tween = new Vector2Tween();
        }
        else if (t == typeof(Vector3))
        {
            tween = new Vector3Tween();
        }
        else if (t == typeof(Vector4))
        {
            tween = new Vector4Tween();
        }
        else if (t == typeof(Color))
        {
            tween = new ColorTween();
        }
        else if (t == typeof(Quaternion))
        {
            tween = new QuaternionTween();
        }
        else
        {
            Debug.LogError("PTween createTween: invalid type: " + t); return(null);
        }
        add(tween);
        return(tween);
    }
Exemplo n.º 13
0
        private void DrawTweenedHand(Vector3 position, Mesh handsMesh, Material material, Quaternion quat,
                                     TweenThing tweenThing,
                                     bool portrait, bool noTween)
        {
            if (position == Vector3.zero || handsMesh == null || material == null || quat == null || tweenThing == null)
            {
                return;
            }
            if (!this.Pawn.Downed || !this.Pawn.Dead)
            {
                if (!HarmonyPatchesFS.AnimatorIsOpen() &&
                    Find.TickManager.TicksGame == this.CompAnimator.LastPosUpdate[(int)tweenThing] ||
                    HarmonyPatchesFS.AnimatorIsOpen() && MainTabWindow_BaseAnimator.Pawn != this.Pawn)
                {
                    position = this.CompAnimator.LastPosition[(int)tweenThing];
                }
                else
                {
                    if (this.Pawn.pather.MovedRecently(5))
                    {
                        noTween = true;
                    }

                    this.CompAnimator.LastPosUpdate[(int)tweenThing] = Find.TickManager.TicksGame;


                    Vector3Tween tween = this.CompAnimator.Vector3Tweens[(int)tweenThing];


                    switch (tween.State)
                    {
                    case TweenState.Running:
                        if (noTween || this.CompAnimator.IsMoving)
                        {
                            tween.Stop(StopBehavior.ForceComplete);
                        }

                        position = tween.CurrentValue;
                        break;

                    case TweenState.Paused:
                        break;

                    case TweenState.Stopped:
                        if (noTween || (this.CompAnimator.IsMoving))
                        {
                            break;
                        }

                        ScaleFunc scaleFunc = ScaleFuncs.SineEaseOut;


                        Vector3 start    = this.CompAnimator.LastPosition[(int)tweenThing];
                        float   distance = Vector3.Distance(start, position);
                        float   duration = Mathf.Abs(distance * 50f);
                        if (start != Vector3.zero && duration > 12f)
                        {
                            start.y = position.y;
                            tween.Start(start, position, duration, scaleFunc);
                            position = start;
                        }

                        break;
                    }

                    this.CompAnimator.LastPosition[(int)tweenThing] = position;
                }
            }

            //  tweener.PreThingPosCalculation(tweenThing, noTween);

            GenDraw.DrawMeshNowOrLater(
                handsMesh, position,
                quat,
                material,
                portrait);
        }
Exemplo n.º 14
0
        //ToDO: Move this and the Face PostDraw to Postfix // Verse.Pawn_DrawTracker.DrawTrackerTick()
        public override void PostDraw()
        {
            base.PostDraw();

            // Children & Pregnancy || Werewolves transformed
            if (this.Pawn.Map == null || !this.Pawn.Spawned || this.Pawn.Dead || this.Pawn.GetCompAnim().Deactivated)
            {
                return;
            }

            //if (Find.TickManager.Paused)
            //{
            //    if (!HarmonyPatchesFS.AnimatorIsOpen() || MainTabWindow_BaseAnimator.Pawn != this.Pawn)
            //    {
            //        if (!Pawn.IsChild()) return;
            //    }
            //}

            if (this.Props.bipedWithHands)
            {
                this.BodyAnimator.AnimatorTick();
            }

            // Tweener
            Vector3Tween eqTween = this.Vector3Tweens[(int)HarmonyPatchesFS.equipment];

            FloatTween   angleTween = this.AimAngleTween;
            Vector3Tween leftHand   = this.Vector3Tweens[(int)TweenThing.HandLeft];
            Vector3Tween rightHand  = this.Vector3Tweens[(int)TweenThing.HandRight];

            if (!Find.TickManager.Paused)
            {
                if (leftHand.State == TweenState.Running)
                {
                    leftHand.Update(1f * Find.TickManager.TickRateMultiplier);
                }
                if (rightHand.State == TweenState.Running)
                {
                    rightHand.Update(1f * Find.TickManager.TickRateMultiplier);
                }
                if (eqTween.State == TweenState.Running)
                {
                    eqTween.Update(1f * Find.TickManager.TickRateMultiplier);
                }

                if (angleTween.State == TweenState.Running)
                {
                    this.AimAngleTween.Update(3f * Find.TickManager.TickRateMultiplier);
                }

                this.CheckMovement();

                if (this.Pawn.IsChild())
                {
                    this.TickDrawers(this.Pawn.Rotation, new PawnGraphicSet(this.Pawn));
                }
            }


            if (this.Pawn.IsChild())
            {
                float      angle    = this.Pawn.Drawer.renderer.BodyAngle();
                Quaternion bodyQuat = Quaternion.AngleAxis(angle, Vector3.up);
                Vector3    rootLoc  = this.Pawn.Drawer.DrawPos;
                if (Controller.settings.UseHands)
                {
                    this.DrawHands(bodyQuat, rootLoc, false, null, false, this.Pawn.GetBodysizeScaling());
                }
                if (Controller.settings.UseFeet)
                {
                    this.DrawFeet(bodyQuat, bodyQuat, rootLoc, false);
                }
            }
        }
        //  private static float RecoilMax = -0.15f;
        //  private static  Vector3 curOffset = new Vector3(0f, 0f, 0f);
        //  public static void AddOffset(float dist, float dir)
        //  {
        //      curOffset += Quaternion.AngleAxis(dir, Vector3.up) * Vector3.forward * dist;
        //      if (curOffset.sqrMagnitude > RecoilMax        * RecoilMax)
        //      {
        //          curOffset *= RecoilMax / curOffset.magnitude;
        //      }
        //  }
        public static void DoWeaponOffsets(Pawn pawn, Thing eq, ref Vector3 drawLoc, ref float weaponAngle,
                                           ref Mesh weaponMesh)
        {
            CompProperties_WeaponExtensions extensions = eq.def.GetCompProperties <CompProperties_WeaponExtensions>();

            bool flipped = weaponMesh == MeshPool.plane10Flip;

            if ((pawn == null) || (!pawn.GetCompAnim(out CompBodyAnimator animator)) || (extensions == null))
            {
                return;
            }

            float sizeMod = 1f;

            //  if (Controller.settings.IReallyLikeBigGuns) { sizeMod = 2.0f; }
            //     else if (Controller.settings.ILikeBigGuns)
            //  {
            //      sizeMod = 1.4f;
            //  }
            //  else
            //  {
            //      sizeMod = 1f;
            //  }

            if (Find.TickManager.TicksGame == animator.LastPosUpdate[(int)equipment] ||
                MainTabWindow_WalkAnimator.IsOpen && MainTabWindow_WalkAnimator.Pawn != pawn)
            {
                drawLoc     = animator.LastPosition[(int)equipment];
                weaponAngle = animator.LastWeaponAngle;
            }
            else
            {
                animator.LastPosUpdate[(int)equipment] = Find.TickManager.TicksGame;

                CalculatePositionsWeapon(pawn,
                                         ref weaponAngle,
                                         extensions,
                                         out Vector3 weaponPosOffset,
                                         out bool aiming,
                                         flipped);

                // weapon angle and position offsets based on current attack keyframes sequence

                DoAttackAnimationOffsetsWeapons(pawn, ref weaponAngle, ref weaponPosOffset, flipped, animator,
                                                out bool noTween);

                drawLoc += weaponPosOffset * sizeMod;

                Vector3Tween eqTween = animator.Vector3Tweens[(int)equipment];

                if (pawn.pather.MovedRecently(5))
                {
                    noTween = true;
                }

                switch (eqTween.State)
                {
                case TweenState.Running:
                    if (noTween || animator.IsMoving)
                    {
                        eqTween.Stop(StopBehavior.ForceComplete);
                    }

                    drawLoc = eqTween.CurrentValue;
                    break;

                case TweenState.Paused:
                    break;

                case TweenState.Stopped:
                    if (noTween || (animator.IsMoving))
                    {
                        break;
                    }

                    ScaleFunc scaleFunc = ScaleFuncs.SineEaseOut;


                    Vector3 start    = animator.LastPosition[(int)equipment];
                    float   distance = Vector3.Distance(start, drawLoc);
                    float   duration = Mathf.Abs(distance * 50f);
                    if (start != Vector3.zero && duration > 12f)
                    {
                        start.y = drawLoc.y;
                        eqTween.Start(start, drawLoc, duration, scaleFunc);
                        drawLoc = start;
                    }

                    break;
                }


                // // fix the reset to default pos is target is changing
                // bool isAimAngle = (Math.Abs(aimAngle - angleStanding) <= 0.1f);
                // bool isAimAngleFlipped = (Math.Abs(aimAngle - angleStandingFlipped) <= 0.1f);
                //
                // if (aiming && (isAimAngle || isAimAngleFlipped))
                // {
                //     // use the last known position to avoid 1 frame flipping when target changes
                //     drawLoc = animator.lastPosition[(int)equipment];
                //     weaponAngle = animator.lastWeaponAngle;
                // }
                // else
                {
                    animator.LastPosition[(int)equipment] = drawLoc;
                    animator.LastWeaponAngle = weaponAngle;
                    animator.MeshFlipped     = flipped;
                }
            }

            // Now the remaining hands if possible
            if (animator.Props.bipedWithHands && Controller.settings.UseHands)
            {
                SetPositionsForHandsOnWeapons(
                    drawLoc,
                    flipped,
                    weaponAngle,
                    extensions, animator, sizeMod);
            }
        }
Exemplo n.º 16
0
        public BaseTween VectorTween(Vector3 from, Vector3 to, float t)
        {
            Vector3Tween tween = TweenPool.GetVector3Tween(from, to, t);

            return(ProcessTween(tween));
        }