protected virtual void OnSceneGUI() { BaseTrigger trigger = (BaseTrigger)target; if (!trigger.isActiveAndEnabled) { return; } Vector3 position = trigger.transform.position; Collider collider = trigger.GetComponent <Collider>(); if (collider != null) { position = collider.bounds.center; position.y = (collider.bounds.center.y - collider.bounds.extents.y); } Color color = Handles.color; Color green = Color.green; green.a = 0.05f; Handles.color = green; Handles.DrawSolidDisc(position, Vector3.up, trigger.useDistance); Handles.color = Color.white; Handles.DrawWireDisc(position, Vector3.up, trigger.useDistance); Handles.color = color; }
/*Returns true if this is the best trigger. Used for TriggerInputType.Key and TriggerInputType.OnTriggerEnter * Calculated based on distance and rotation of the player to the trigger.*/ protected virtual bool IsBestTrigger() { if (gameObject == PlayerInfo.gameObject) { return(true); } BaseTrigger tMin = null; float minDist = Mathf.Infinity; Vector3 currentPos = PlayerInfo.transform.position; foreach (BaseTrigger t in BaseTrigger.m_TriggerInRange) { if (t.key != key) { continue; } Vector3 dir = t.transform.position - currentPos; float angle = 0f; if (dir != Vector3.zero) { angle = Quaternion.Angle(PlayerInfo.transform.rotation, Quaternion.LookRotation(dir)); } float dist = Vector3.Distance(t.transform.position, currentPos) * angle; if (dist < minDist) { tMin = t; minDist = dist; } } return(tMin == this); }
/*Returns true if this is the best trigger. Used for TriggerInputType.Key and TriggerInputType.OnTriggerEnter * Calculated based on distance and rotation of the player to the trigger.*/ public virtual bool IsBestTrigger() { if (gameObject == PlayerInfo.gameObject) { return(true); } BaseTrigger tMin = null; float minDist = Mathf.Infinity; Vector3 currentPos = PlayerInfo.transform.position; foreach (BaseTrigger t in BaseTrigger.m_TriggerInRange) { if (t.key != key) { continue; } Vector3 dir = t.transform.position - currentPos; float angle = 0f; if (dir != Vector3.zero) { angle = Quaternion.Angle(PlayerInfo.transform.rotation, Quaternion.LookRotation(dir)); } //Pickup items only in front /*if (angle > 90) { * continue; * } * Debug.Log(Vector3.Angle(t.transform.position - PlayerInfo.transform.position, PlayerInfo.transform.forward)+" != "+angle);*/ float dist = Vector3.Distance(t.transform.position, currentPos) * angle; if (dist < minDist) { tMin = t; minDist = dist; } } return(tMin == this); }
private void NotifyUnUsed() { ExecuteEvent <ITriggerUnUsedHandler>(Execute, true); BaseTrigger.currentUsedTrigger = null; OnTriggerUnUsed(); }
private void NotifyUsed() { BaseTrigger.currentUsedTrigger = this; ExecuteEvent <ITriggerUsedHandler>(Execute); OnTriggerUsed(); }