Exemple #1
0
 public void UpdateSummary(RotationObserver observer)
 {
     for (int i = 0; i < observer.TargetRotations.Count; i++)
     {
         RotationTarget rt = observer.TargetRotations[i];
         summaryText.text += i.ToString() + ": " + rt.ToString() + " was hit " + observer.GetTargetHits(i) + " time[s]\n";
     }
 }
Exemple #2
0
        private void _BuildRotation(Single deltaTime, Single to, Boolean isBaseRotating)
        {
            var step = deltaTime * BuildRotationSpeed;

            if (isBaseRotating)
            {
                _Base.Rotation = _Base.Rotation.AdvanceZ(step, to);
                _BaseCollider.SetOrientation(_Base.Rotation);
                if (_IsRotationTarget)
                {
                    _StoredRotation = _StoredRotation.AdvanceZ(step, to);
                }
                else
                {
                    RotationTarget = RotationTarget.AdvanceZ(step, to);
                }
            }
            var r = Rotation = Rotation.AdvanceZ(step, to);
        }
Exemple #3
0
        //==================================================
        //Methods
        //==================================================

        //Called when the part is instantiated
        //Initializes the transforms
        public override void OnStart(StartState state)
        {
            fromTransform = KSPUtil.FindInPartModel(transform, fromRotation);
            toTransform   = KSPUtil.FindInPartModel(transform, toRotation);

            string[] rotationValues      = targetValues.Split(',');
            string[] rotationTargetNames = targets.Split(',');

            rotationTargets.Clear();

            //get all the rotation targets
            if (rotationValues.Length == rotationTargetNames.Length)
            {
                for (int i = 0; i < rotationValues.Length; i++)
                {
                    RotationTarget rotationTarget = new RotationTarget();
                    rotationTarget.target = KSPUtil.FindInPartModel(transform, rotationTargetNames[i].Replace(" ", string.Empty));

                    bool valid = true;
                    //try to get the value for the interpolation
                    try
                    {
                        rotationTarget.value = float.Parse(rotationValues[i].Replace(" ", string.Empty));
                    }
                    catch
                    {
                        valid = false;
                    }

                    //when we have
                    if ((rotationTarget.target != null) && (valid))
                    {
                        rotationTargets.Add(rotationTarget);
                    }
                }
            }

            numTargets = rotationTargets.Count;

            //valid when all transforms have been found
            isValid = (fromTransform) & (toTransform);
        }
Exemple #4
0
    public void OnRotationVisualized(Rotator rotator, Vector3 rotation)
    {
        // Check if rotation within range.
        for (int i = 0; i < TargetRotations.Count; i++)
        {
            RotationTarget rt = TargetRotations[i];

            if (rt.targetX && !(rotation.x >= rt.xMin && rotation.x <= rt.xMax))
            {
                continue;
            }

            if (rt.targetY && !(rotation.y >= rt.yMin && rotation.y <= rt.yMax))
            {
                continue;
            }

            if (rt.targetZ && !(rotation.z >= rt.zMin && rotation.z <= rt.zMax))
            {
                continue;
            }

            // Record target hits.
            if (targetRotationHits.ContainsKey(i))
            {
                targetRotationHits[i] += 1;
            }
            else
            {
                targetRotationHits.Add(i, 1);
            }

            rotator.FreezeFrame();

            OnTargetHit.Invoke(this, i, rotation);
        }
    }
Exemple #5
0
    public void DisplayTargetHit(RotationTarget rt, Vector3 rotation, int totalHits, float displayTime)
    {
        targetText.text += rotation.ToString() + " hit target " + rt.ToString() + " (Total Hits: " + totalHits.ToString() + ")";

        StartCoroutine(DelayedDestroy(displayTime));
    }
    protected void RotationUpdate(float deltaTime)
    {
        GameObject currTarget = GetCameraTarget();

        if (!currTarget)
        {
            return;
        }

        float   tweenRatio;
        Vector3 tempVector = new Vector3(0f, 0f, 0f);

        RotationTarget currRotationTarget = GetCameraTargetType();

        if (currRotationTarget == rotationTarget)
        {
            // count how long we've been tweening to this target
            tweenTimer = Mathf.Min(tweenTime, tweenTimer + deltaTime);
        }
        else
        {
            tweenTimer     = 0f;
            rotationTarget = currRotationTarget;
            if (rotationTarget == RotationTarget.world)
            {
                // we only need to be concerned with the players yaw
                tempVector.z = currTarget.transform.eulerAngles.z;
                tweenOrigin  = Quaternion.Euler(tempVector);
            }
            else
            {
                // need to snap to camera. tween the rotation between the camera's current
                // rotation and the target rotation so the transition isn't disorienting.
                tweenOrigin = transform.rotation;
            }
        }

        // get our tween target
        if (rotationTarget == RotationTarget.target)
        {
            // we only need to be concerned with the players yaw
            tempVector.z = currTarget.transform.eulerAngles.z;
            tweenTarget  = Quaternion.Euler(tempVector);
        }
        else
        {
            tweenTarget = defaultRotation;
        }

        // get how far into the tween we are(avoiding division by zero)
        tweenRatio = Mathf.Abs(tweenTimer / Mathf.Max(tweenTime, 0.000001f));
        if (tweenRatio >= 0.99999f)
        {
            tweenRatio = 1f;
        }

        if (tweenRatio == 0f)
        {
            transform.rotation = tweenOrigin;
        }
        else if (tweenRatio == 1f)
        {
            transform.rotation = tweenTarget;
        }
        else
        {
            transform.rotation = Quaternion.Slerp(tweenOrigin, tweenTarget, tweenRatio);
        }
    }
 public HitRecord(RotationTarget rt, Vector3 rotation, int totalHits)
 {
     Target    = rt;
     Rotation  = rotation;
     TotalHits = totalHits;
 }