Example #1
0
        void UpdatePointsAcquired()
        {
                        #if UNITY_EDITOR
            drawingSession.greenPointsAcquired      += 1;
            drawingSession.avgDistanceOfGreenPoints += 0.1f;
                        #else
            Vector3[] greenPoints = Utils2.PlaceNoteGreenPoints(drawingSession.greenPointsAtStart);
            float     totalDist   = 0;
            foreach (Vector3 p in greenPoints)
            {
                totalDist += (transform.position - p).magnitude;
            }
            float avgDist = totalDist / (float)greenPoints.Length;
            avgDistText.text = "avg dist: " + avgDist.ToString("#.00");
            drawingSession.avgDistanceOfGreenPoints = avgDist;
            drawingSession.greenPointsAcquired      = greenPoints.Length;

            gpCurrent.text = greenPoints.Length.ToString();
            gpTotal.text   = Utils2.PlaceNoteGreenPoints(0).Length.ToString();
            gpStart.text   = drawingSession.greenPointsAtStart.ToString();
                        #endif

            fill.fillAmount = Mathf.Max(fill.fillAmount, drawingSession.progress);
            // Debug
        }
        public GameObject GetNearestPlane(Transform nearObj, float r)
        {
            PlacenotePlaneMeshRender[] planes = FindObjectsOfType <PlacenotePlaneMeshRender> ();
            Dictionary <PlacenotePlaneMeshRender, float> scoredPlanes = new Dictionary <PlacenotePlaneMeshRender, float> ();

            for (int i = 0; i < planes.Length; i++)
            {
                float     score = 0;
                Vector3[] pts   = Utils2.PlaceNoteGreenPoints();

                for (int j = 0; j < pts.Length; j++)
                {
                    Vector3 meshCenter = Utils2.GetPlaneCenter(planes[i]);                     //planes[i].GetPlaneCenter ();
                    score += Mathf.Min(1, 1 / (pts [j] - meshCenter).magnitude);
                }
                scoredPlanes.Add(planes [i], score);
            }
            PlacenotePlaneMeshRender[] maxArr = (from x in scoredPlanes where x.Value == scoredPlanes.Max(v => v.Value) select x.Key).ToArray();

            if (maxArr.Length == 0)
            {
                // in case no planes are found, just return the center of the previously discovered "best" quadrant.
                GameObject fake = new GameObject();
                fake.transform.position = cachedTarget;                 // nearObj.transform.position + GetBestQuadrant ();
                return(fake);
            }
            else
            {
                return(maxArr[0].gameObject);
            }
        }
Example #3
0
 public void Hide()
 {
     if (group.gameObject.activeSelf && Utils2.FadeAllMaterialsAndUI(group, 0, 3))
     {
         group.gameObject.SetActive(false);
     }
 }
Example #4
0
        void Start()
        {
            bool foundPlane = false;
            List <PlacenotePlaneMeshRender> planes = new List <PlacenotePlaneMeshRender>();

            foreach (PlacenotePlaneMeshRender plane in FindObjectsOfType <PlacenotePlaneMeshRender>())
            {
                if (Utils2.DeterminePlaneType(plane) == Utils2.PlaneType.Horizontal)
                {
                    foundPlane = true;
                    planes.Add(plane);
                }
            }



            if (foundPlane)
            {
                Vector3 p = planes[Random.Range(0, planes.Count)].transform.position;
                transform.position = p + Vector3.up * Mathf.Max(0.4f, Camera.main.transform.position.y - p.y);                // place one meter above the first horizontal plane detected
            }
            else
            {
                Debug.LogError("No planes found! Placing dish in front of camera.");
                transform.position = Camera.main.transform.position + Camera.main.transform.forward * 1f;
            }

            if (stateOnStart)
            {
                SetState(state);
            }
        }
Example #5
0
 void InitDrawingSession()
 {
     ft.FlashMessage(Color.white, "Tap to begin drawing.");
     drawingSession = new DrawingSession();
     drawingSession.trackedPosiitons = new List <Vector3>();
     distanceNeededText.text         = distanceNeeded.ToString("#.0");
     fill.fillAmount = 0;
     SetState(State.Ready);
     drawingSession.greenPointsAtStart  = Utils2.PlaceNoteGreenPoints(0).Length;
     drawingSession.greenPointsAcquired = 0;
 }
Example #6
0
 void LateUpdate()
 {
     SetPopupPosition();
     timeout       -= Time.deltaTime;
     offsetTimeout -= Time.deltaTime;
     if (timeout < 0)
     {
         Hide();
     }
     else
     {
         Utils2.FadeAllMaterialsAndUI(group, 1, 3);
     }
 }
Example #7
0
        void GetPlaneWithHighestPointScore()
        {
            GameObject nearest = OnionLocationHelper.instance.GetNearestPlane(this.transform, 1.5f);

            if (nearest)
            {
                PlacenotePlaneMeshRender pi = nearest.GetComponent <PlacenotePlaneMeshRender> ();
                if (pi)
                {
                    SetTarget(Utils2.GetPlaneCenter(pi));
                }
                else
                {
                    // it was a fake!
                    SetTarget(nearest.transform.position);
                }
            }
            else
            {
                Debug.LogError("no nearest!");
            }
        }
Example #8
0
        void Update()
        {
            t -= Time.deltaTime;
            //		Debug.Log ("t;" + t);
            if (t < 0)
            {
                //			interval = Random.Range (2, 6f);
                t = Random.Range(8, 16f);
                SetTarget(Utils2.FlattenVector(startPos + Random.insideUnitSphere * range) + Vector3.up * Random.Range(-upRange, upRange));
                //			Debug.Log ("swap");
            }
            float moveSpeed = 0.3f;

            transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * moveSpeed);
            float   rotSpeed = 4f;
            Vector3 lookRot  = target - transform.position;

            if (lookRot != Vector3.zero)
            {
                Quaternion r = Quaternion.LookRotation(lookRot);
                transform.rotation = Quaternion.Slerp(transform.rotation, r, Time.deltaTime * rotSpeed);
            }
        }
        public bool FoundTargetNearOnion(FlyingOnion mo)
        {
            if (targetFeatureClusterTimer < 0)
            {
                foundAnyQuadrant = false;
                if (lastOnionWhoRequested != mo)
                {
                    searchRadius = 8f;
                }
                lastOnionWhoRequested     = mo;
                targetFeatureClusterTimer = targetFeatureClusterInterval;
                //			InitQuadrantScores ();
                QuadrantScores.Clear();
                // Let's make 27 quadrants relative to onion's world position
                // Check each quadrant for total green features
                // The quadrant with the most green features is where the onion moves.

                // iterate through all Green map points

                                #if !UNITY_EDITOR
                Vector3[] greenPoints = Utils2.PlaceNoteGreenPoints(0);
                                #else
                Vector3[] greenPoints = GenerateFakeGreenPointsForEditor();
                                #endif
                Debug.Log("Greenpoints:" + greenPoints);


                foreach (Vector3 gp in greenPoints)
                {
                    for (int i = -1; i < 2; i++)
                    {
                        for (int j = -1; j < 2; j++)
                        {
                            for (int k = -1; k < 2; k++)
                            {
                                // For each point compare its distance to one of 27 quadrants surrounding the onion
                                // Closer quadrants are scored more highly
                                // Result should be that the quadrant with the most green dots gets the highest score.
                                float   distFromThisQuadrantToGreenPoint = Vector3.SqrMagnitude(mo.transform.position + new Vector3(i, j, k) * searchRadius - gp);
                                Vector3 key = new Vector3(i, j, k);
                                float   val = Mathf.Min(1, 1 / distFromThisQuadrantToGreenPoint);
                                // Debug.Log ("val for " + i + "," + j + "," + k + ": " + val);
                                // if (QuadrantScores.ContainsKey (key)) {
                                //  QuadrantScores [key] += val; // never more than 1
                                // } else {
                                //  QuadrantScores.Add (key, val);
                                // }
                            }
                        }
                    }
                }


                //			float max = 0;
                Vector3 bestQuadrant = GetBestQuadrant();

                if (foundAnyQuadrant)
                {
                    Debug.Log("set cached target;" + mo.transform.position + " plus <color=green>" + bestQuadrant + "</color>");
                    cachedTarget = mo.transform.position + bestQuadrant;
                    // If the best quadrant is zero, shrink the radius
                    if (bestQuadrant == Vector3.zero)
                    {
                        searchRadius /= 2f;
                        Debug.Log("<color=blue>Decereased by half. New radius:" + searchRadius + "</color>");
                    }
                }
                else
                {
                    Debug.Log("Found no quads");
                }
                Debug.Log("<color=blue>Cached :" + cachedTarget + "</color>");
            }
            return(foundAnyQuadrant);
        }