Пример #1
0
 // Use this for initialization
 void Start()
 {
     if (!metalOnion)
     {
         metalOnion = transform.root.GetComponentInChildren <MetalOnion> ();
     }
 }
Пример #2
0
    void Update()
    {
        t -= Time.deltaTime;
        if (t < 0)
        {
            t = 0.1f;
            Ray   ray           = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            float radius        = 0.05f;
            bool  hitt          = false;
            bool  detectedOnion = false;

            foreach (RaycastHit hit in Physics.SphereCastAll(ray, radius))
            {
                hitt = true;
                MetalOnion mo = hit.collider.gameObject.GetComponent <MetalOnion> ();
                if (mo)
                {
                    detectedOnion = true;
                    mo.CameraHovering();                      // has a timeout, should last 1 second or so
                    switch (mo.state)
                    {
                    case MetalOnion.State.Unwrapping:
//						ItemPopup.inst.Show (hit.point, "Destroy this! " + mo.DishesRemainingInfo[0].ToString() + " of  "+mo.DishesRemainingInfo[1].ToString() +" dishes remaining." );
                        ItemPopup.inst.Show(mo.transform.position, "Destroy this! " + mo.DishesRemainingInfo[0].ToString() + " of  " + mo.DishesRemainingInfo[1].ToString() + " dishes remaining.");
                        break;

                    default:
                        ItemPopup.inst.Hide();
                        break;
                    }
//					DebugText.SetCamHoverObj ("cam hit:" + hit.collider.name);
                }

                DamageReceiver dr = hit.collider.gameObject.GetComponent <DamageReceiver> ();
                if (dr || (mo && (mo.state != MetalOnion.State.Unwrapped)))
                {
                    CC.crosshair.SetState(Crosshair.State.Destructible);
                    if (detectedOnion)
                    {
                        break;                         // don't need to check other colliders; we already determined Onion and DamageReceiver
                    }
                }
                else
                {
                    CC.crosshair.SetState(Crosshair.State.Nominal);
                }
            }
            if (!hitt)
            {
                CC.crosshair.SetState(Crosshair.State.Nominal);
            }
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit = new RaycastHit();

        if (Physics.Raycast(Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)), out hit))
        {
            MetalOnion mo = hit.collider.gameObject.GetComponent <MetalOnion> ();
            if (mo)
            {
                mo.CameraHovering();
                Debug.Log("Cam hit;" + mo.name);
                DebugText.SetCamHoverObj("cam hit:" + hit.collider.name);
            }
        }
        else
        {
            DebugText.SetCamHoverObj("cam hit: no hit");
        }
    }
Пример #4
0
    public bool FoundTargetNearOnion(MetalOnion 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
            Vector3[] greenPoints = CC.featuresVisualizer.CurrentGreenPoints;
            DebugText.SeekPlanes("greenpts:" + greenPoints.Length);
            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);
                            }
                        }
                    }
                }
            }
//
//			foreach (Vector3 k in QuadrantScores.Keys) {
//				GameObject d = GameObject.CreatePrimitive (PrimitiveType.Sphere);
//				d.transform.position = k;
//				d.transform.localScale = .002f * QuadrantScores [k] * Vector3.one;
//				d.transform.position = mo.transform.position + k * searchRadius;
//				d.name = "debSphere";
////				d.GetComponent<Renderer>().material.color = new Color(
//			}


//			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);
    }
Пример #5
0
 public bool FeatureClusterNearby(MetalOnion mo)
 {
     // Iterate through all Map[] points and see if enough green ones are close to mo.tran.pos
     // save/cache (or dump) the current target feature position
     return(false);
 }