Пример #1
0
 void applyHeatLevel(HeatmapPoint beforePoint, HeatmapPoint currentPoint, int heatLevel)
 {
     if (beforePoint.id == currentPoint.id)
     {
         currentPoint.heatLevel = heatLevel;
     }
 }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        playerController = transform.GetComponent <PlayerController>();

        currentPoint.position  = transform.position;
        currentPoint.rotation  = transform.rotation;
        currentPoint.isRunning = playerController.isRunning.ToString().ToUpper();
        lastPoint = currentPoint;

        insideRange    = true;
        checkHeatLevel = true;

        positions.Add(currentPoint);

        string token = PlayerPrefs.GetString("user_token", null);

        if (token != null)
        {
            api.get("/create/game_session/" + level + "/" + token).on("success", GameSessionCreated);
        }
    }
Пример #3
0
    IEnumerator heatmapLevelCheck()
    {
        HeatmapPoint beforePoint = lastPoint;

        yield return(new WaitForSeconds(0.4f));

        HeatmapPoint p1 = positions.Find(x => x.id.Equals(lastPoint.id));

        applyHeatLevel(beforePoint, p1, 2);


        yield return(new WaitForSeconds(0.6f));

        HeatmapPoint p2 = positions.Find(x => x.id.Equals(lastPoint.id));

        applyHeatLevel(beforePoint, p2, 3);


        yield return(new WaitForSeconds(0.8f));

        HeatmapPoint p3 = positions.Find(x => x.id.Equals(lastPoint.id));

        applyHeatLevel(beforePoint, p3, 4);
    }
Пример #4
0
        /// <summary>
        /// Draw a point on the canvas
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="heatmapPoint"></param>
        /// <param name="radius"></param>
        private void DrawHeatPoint(Graphics canvas, HeatmapPoint heatmapPoint, int radius)
        {
            // Create points generic list of points to hold circumference points
            List <Point> circumferencePointsList = new List <Point>();

            // Create an empty point to predefine the point struct used in the circumference loop
            Point circumferencePoint;

            // Create an empty array that will be populated with points from the generic list
            Point[] circumferencePointsArray;

            // Calculate ratio to scale byte intensity range from 0-255 to 0-1
            float ratio = 1F / byte.MaxValue;
            // Precalulate half of byte max value
            byte half = byte.MaxValue / 2;
            // Flip intensity on it's center value from low-high to high-low
            int intensity = (byte)(heatmapPoint.Intensity - ((heatmapPoint.Intensity - half) * 2));
            // Store scaled and flipped intensity value for use with gradient center location
            float fIntensity = intensity * ratio;

            // Loop through all angles of a circle
            // Define loop variable as a double to prevent casting in each iteration
            // Iterate through loop on 10 degree deltas, this can change to improve performance
            for (double i = 0; i <= 360; i += 10)
            {
                // Replace last iteration point with new empty point struct
                circumferencePoint = new Point();

                // Plot new point on the circumference of a circle of the defined radius
                // Using the point coordinates, radius, and angle
                // Calculate the position of this iterations point on the circle
                circumferencePoint.X = Convert.ToInt32(heatmapPoint.X + radius * Math.Cos(ConvertDegreesToRadians(i)));
                circumferencePoint.Y = Convert.ToInt32(heatmapPoint.Y + radius * Math.Sin(ConvertDegreesToRadians(i)));

                // Add newly plotted circumference point to generic point list
                circumferencePointsList.Add(circumferencePoint);
            }

            // Populate empty points system array from generic points array list
            // Do this to satisfy the datatype of the PathGradientBrush and FillPolygon methods
            circumferencePointsArray = circumferencePointsList.ToArray();

            // Create new PathGradientBrush to create a radial gradient using the circumference points
            PathGradientBrush gradientShaper = new PathGradientBrush(circumferencePointsArray);
            // Create new color blend to tell the PathGradientBrush what colors to use and where to put them
            ColorBlend gradientSpecifications = new ColorBlend(3);

            // Define positions of gradient colors, use intesity to adjust the middle color to
            // show more mask or less mask
            gradientSpecifications.Positions = new float[3] {
                0, fIntensity, 1
            };
            // Define gradient colors and their alpha values, adjust alpha of gradient colors to match intensity
            gradientSpecifications.Colors = new Color[3]
            {
                Color.FromArgb(0, Color.White),
                Color.FromArgb(heatmapPoint.Intensity, Color.Black),
                Color.FromArgb(heatmapPoint.Intensity, Color.Black)
            };

            // Pass off color blend to PathGradientBrush to instruct it how to generate the gradient
            gradientShaper.InterpolationColors = gradientSpecifications;
            // Draw polygon (circle) using our point array and gradient brush
            canvas.FillPolygon(gradientShaper, circumferencePointsArray);
        }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (!buildSettings.production)
        {
            if (Input.GetKeyDown(KeyCode.Slash))
            {
                if (!heatmapUI.gameObject.activeSelf)
                {
                    heatmapUI.Show();
                }
                else
                {
                    heatmapUI.Hide();
                }
            }

            if (Input.GetKeyDown(KeyCode.Tab))
            {
                ShowHeatMap();
            }

            if (Input.GetKeyDown(KeyCode.BackQuote))
            {
                ShowPathMap();
            }
        }


        if (!sendEnabled)
        {
            return;
        }

        if (checkInsideRange(transform.position - lastPoint.position, currentPoint.pointSize))
        {
            insideRange = true;
            //Debug.Log(transform.position - lastPoint.position);
        }
        else
        {
            lastPoint           = new HeatmapPoint(positions.Count);
            lastPoint.position  = transform.position;
            lastPoint.rotation  = transform.rotation;
            lastPoint.isRunning = playerController.isRunning.ToString().ToUpper();
            insideRange         = false;
            checkHeatLevel      = true;
            positions.Add(lastPoint);

            if (!shouldSend)
            {
                shouldSend = true;
            }

            //Debug.Log("outside range");
        }

        if (insideRange && lastPoint.heatLevel < 3)
        {
            checkHeatLevel = true;
        }

        if (checkHeatLevel && insideRange)
        {
            //Debug.Log("inside range");
            StartCoroutine("heatmapLevelCheck");
            checkHeatLevel = false;
        }


        if (positions.Count % 5 == 0 && shouldSend && heatmapLastPoint != positions.Count)
        {
            shouldSend = false;
            SendMapToDB();
            heatmapLastPoint = positions.Count;
        }
    }