// Update is called once per frame void Update() { // Polling a new signal. if ((loadingSignal == null) && (bufferJetSignal.Count > 0)) { loadingSignal = _LoadSignal(); if ((loadingSignal != null) && (loadingSignal.GetSignal != null)) { JetPoint signal = loadingSignal.GetSignal; _AdjectValve(signal.type, signal.force, signal.interval); } } if ((loadingSignal != null) && loadingSignal.flagHited) { // Change particle material. if ((particle != null) && (matHit != null)) { particle.GetComponent <ParticleSystemRenderer>().material = matHit; } } else { // Change the particle matierial. if ((particle != null) && (matUnhit != null)) { particle.GetComponent <ParticleSystemRenderer>().material = matUnhit; } } }
public void RemoveJetSignal(HitPoint signal) { if (loadingSignal == signal) { loadingSignal = null; } bufferJetSignal.Remove(signal); Debug.Log("Remove the signal:" + signal); }
public void ReleaseHitPoint(HitPoint hiter) { if (haloHiter != null) { haloHiter.RemoveTarget(hiter); } if (valveController != null) { valveController.RemoveJetSignal(hiter); } }
public void RegisterHitPoint(HitPoint hiter) { if (haloHiter != null) { haloHiter.AddTarget(hiter); } if (valveController != null) { valveController.AddJetSignal(hiter); } }
// Update is called once per frame void Update() { // Register the hit flag, if the casting hit the detector and pressing the jeting button. if (flagHitDetector && flagPressButton && (transLastHited != null)) { lastHitPoint = transLastHited.GetComponent <HitPoint>(); if (lastHitPoint != null) { lastHitPoint.flagHited = true; } } }
HitPoint _LoadSignal() { HitPoint signal = null; foreach (HitPoint s in bufferJetSignal) { signal = s; bufferJetSignal.Remove(s); break; } return(signal); }
public void AddTarget(HitPoint _hiter) { //Debug.LogFormat("Add target hiter: {0}", _hiter); RectTransform ui = null; if (showHaloHitObject != null) { ui = Instantiate(showHaloHitObject, showCanvas.transform).GetComponent <RectTransform>(); ui.gameObject.SetActive(false); } listHaloer.Add(new Haloer(_hiter, ui)); }
IEnumerator _Casting() { Ray ray; RaycastHit hiter; Vector3 center = new Vector3(jetCamera.pixelWidth / 2, jetCamera.pixelHeight / 2, 0.0f); while (true) { ray = jetCamera.ScreenPointToRay(center); Debug.DrawRay(ray.origin, ray.direction, Color.yellow); if (Physics.Raycast(ray, out hiter, hitDistance, layerMask)) { //Debug.Log("hit: " + hiter.transform.name); transHited = hiter.transform; if (transLastHited != transHited) { transLastHited = transHited; // Check the hit obejct is the detector. lastHitPoint = transLastHited.GetComponent <HitPoint>(); if (lastHitPoint != null) { flagHitDetector = true; } } } else { transHited = null; // Unregister the hit flag. if (lastHitPoint != null) { lastHitPoint.flagHited = false; lastHitPoint = null; } } yield return(new WaitForSeconds(timeChecked)); } }
public void RemoveTarget(HitPoint hiter) { // Cancel the aiming color hiter. if ((lastHitPoint == hiter) && (aimingImage != null)) { aimingImage.DOColor(OutOfJetedDistanceColor, 0.1f); } for (int i = 0; i < listHaloer.Count; i++) { if (listHaloer[i].hitPoint == hiter) { if (listHaloer[i].uiTransform != null) { Destroy(listHaloer[i].uiTransform.gameObject); } listHaloer.RemoveAt(i); return; } } }
public void AddJetSignal(HitPoint signal) { bufferJetSignal.Add(signal); }
public Haloer(HitPoint _hiter, RectTransform _ui) { this.hitPoint = _hiter; this.uiTransform = _ui; }
// Update is called once per frame void Update() { // Update aiming Canvas position. if ((aimingCanvas != null) && (projectorCamera != null)) { Vector3 center = new Vector3(projectorCamera.pixelWidth / 2, projectorCamera.pixelHeight / 2, 0.0f); Ray ray = projectorCamera.ScreenPointToRay(center); RaycastHit hit; // Moveing the position. if (Physics.Raycast(ray, out hit, aimingDistance, aimingLayer)) { aimingCanvas.transform.position = hit.point; } // Looking the projector. aimingCanvas.transform.DOLookAt(projectorCamera.transform.position, 0.5f); } if (listHaloer.Count > 0) { //Debug.LogFormat("list haloer count: {0}", listHaloer.Count); float zRotate = 0.0f; HitPoint newHitPoint = null; bool showTheAimingImage = false; // Refresh the halo hit. for (int i = 0; i < listHaloer.Count; i++) { zRotate = GetDirection(transform, listHaloer[i].hitPoint.transform, acceptableAngle, offsetAngle); // In aiming. if (zRotate == -1) { newHitPoint = listHaloer[i].hitPoint; showTheAimingImage = true; if (listHaloer[i].uiTransform != null) { listHaloer[i].uiTransform.gameObject.SetActive(false); } } // Out of range. else { if (listHaloer[i].uiTransform != null) { listHaloer[i].uiTransform.DOLocalRotate(new Vector3(0, 0, zRotate), rotateDuration); listHaloer[i].uiTransform.gameObject.SetActive(true); } } //Debug.LogFormat("zRotate: {0}, transform: {1}, listHaloer{2}: {3}", zRotate, transform, i, listHaloer[i].hitPoint); } // Register the hit flag. if (newHitPoint != null) { // Release the hit flag. if ((lastHitPoint != null) && (lastHitPoint != newHitPoint)) { lastHitPoint.flagHited = false; } lastHitPoint = newHitPoint; // Registe the hit flag. lastHitPoint.flagHited = true; } // Change the aiming image material if (lastHitPoint != null) { JetPoint target = lastHitPoint.GetJetPoint(); if ((lastHitPoint.GetJetPoint() != null) && (target.trans != null)) { float distance = Vector3.Distance(transform.transform.position, target.trans.position); //Debug.Log("distance: " + distance); // The projector is in the jeted distance. if ((distance < target.GetJetDistance() + aimingDistanceOffset) && (distance > target.GetJetDistance() - aimingDistanceOffset)) { if (aimingImage != null) { aimingImage.DOColor(inJetedDistanceColor, 0.1f); //Debug.Log("in jeted distance."); } } else { // The projector isnot in the jeted distance. if (aimingImage != null) { aimingImage.DOColor(OutOfJetedDistanceColor, 0.1f); //Debug.Log("not in jeted distance."); } } string log = "now distance: " + distance.ToString("0.00") + "\ntarget distance: " + target.GetJetDistance().ToString("0.00"); if (debugLog != null) { debugLog.text = log; } } } else { } //end changeing the aiming image material. } //end if }