示例#1
0
    /// <summary>
    /// Necessary so that the gameObject can be exposed to the radiation.
    /// Performs all the needed steps for calculating and recieving the radiation.
    /// </summary>
    private void GetAndApplyDose()
    {
        if (RaySource.Instance == null)
        {
            return;
        }

        // update vertices
        controller.UpdateVertices(RaySource.Instance.transform.position);
        controller.SortOutUnhittedVertices(RaySource.Instance.RayTracer);

        // get doses
        float[] distances  = RaySource.Instance.RayTracer.GetDistances(controller.GetRelevantVerticePositions());
        float[] addedDoses = DoseCalculator.Calculate(distances, RaySource.Instance.BaseEnergy, Time.fixedDeltaTime);

        // store doses
        controller.StoreDoses(addedDoses);

        // calculate colors and avg. dose
        float[] accumulatedDoses = controller.VerticeData.Select(x => x.Dose).ToArray();
        float   avgDose          = DoseCalculator.GetAVGDose(accumulatedDoses);

        Color32[] colors = ColorCalculator.Calculate(accumulatedDoses);

        // appy colors and avg. dose
        container.ApplyColors(colors);
        DoseInfo.Instance.Controller.SetAVGDose(avgDose);
    }
    public void GetRelevantVerticePositionsReturnsCorrectNumberOfPositions_Test()
    {
        // setup
        SetUp();
        controller.RelevantVertices = new List <int> {
            0, 1, 2
        };
        controller.VerticeData = new VertexData[]
        {
            new VertexData(new Vector3(1f, 0f, 0f), 0f),
            new VertexData(new Vector3(0f, 1f, 0f), 0f),
            new VertexData(new Vector3(0f, 0f, 1f), 0f),
        };

        // perform
        Vector3[] positions = controller.GetRelevantVerticePositions();

        // assert
        Assert.AreEqual(3, positions.Length);
    }