public bool TriggerInteraction(int index, bool interrupt) { if (!this.IsValid(true)) { return(false); } if (!this.TriggerIndexIsValid(index)) { return(false); } bool result = true; InteractionTrigger.Range range = this.triggersInRange[index].ranges[this.bestRangeIndexes[index]]; for (int i = 0; i < range.interactions.Length; i++) { for (int j = 0; j < range.interactions[i].effectors.Length; j++) { if (!this.StartInteraction(range.interactions[i].effectors[j], range.interactions[i].interactionObject, interrupt)) { result = false; } } } return(result); }
public bool TriggerInteraction(int index, bool interrupt, out InteractionTarget interactionTarget) { interactionTarget = null; if (!this.IsValid(true)) { return(false); } if (!this.TriggerIndexIsValid(index)) { return(false); } bool result = true; InteractionTrigger.Range range = this.triggersInRange[index].ranges[this.bestRangeIndexes[index]]; for (int i = 0; i < range.interactions.Length; i++) { for (int j = 0; j < range.interactions[i].effectors.Length; j++) { InteractionObject interactionObject = range.interactions[i].interactionObject; Transform target = interactionObject.GetTarget(range.interactions[i].effectors[j], base.tag); if (target != null) { interactionTarget = target.GetComponent <InteractionTarget>(); } if (!this.StartInteraction(range.interactions[i].effectors[j], interactionObject, interrupt)) { result = false; } } } return(result); }
public InteractionTarget GetClosestInteractionTargetInRange() { InteractionTrigger.Range closestInteractionRange = this.GetClosestInteractionRange(); if (closestInteractionRange == null) { return(null); } return(closestInteractionRange.interactions[0].interactionObject.GetTarget(closestInteractionRange.interactions[0].effectors[0], this)); }
public InteractionObject GetClosestInteractionObjectInRange() { InteractionTrigger.Range closestInteractionRange = this.GetClosestInteractionRange(); if (closestInteractionRange == null) { return(null); } return(closestInteractionRange.interactions[0].interactionObject); }
private void DrawRange(InteractionTrigger.Range range, int index) { range.name = string.Empty; for (int i = 0; i < range.interactions.Length; i++) { if (range.name.Length > 50) { range.name += "..."; break; } if (i > 0) { range.name += "; "; } for (int e = 0; e < range.interactions[i].effectors.Length; e++) { if (e > 0) { range.name += ", "; } range.name += range.interactions[i].effectors[e].ToString(); } if (range.interactions[i].interactionObject != null) { range.name += ": " + range.interactions[i].interactionObject.name; } } if (!range.show) { return; } Color color = GetColor(index); Handles.color = color; GUI.color = color; // Character Position DrawCharacterPosition(range, index); // Camera Position DrawCameraPosition(range, index); Handles.color = Color.white; GUI.color = Color.white; }
public InteractionObject[] GetClosestInteractionObjectsInRange() { InteractionTrigger.Range closestInteractionRange = this.GetClosestInteractionRange(); if (closestInteractionRange == null) { return(new InteractionObject[0]); } InteractionObject[] array = new InteractionObject[closestInteractionRange.interactions.Length]; for (int i = 0; i < closestInteractionRange.interactions.Length; i++) { array[i] = closestInteractionRange.interactions[i].interactionObject; } return(array); }
public InteractionTarget[] GetClosestInteractionTargetsInRange() { InteractionTrigger.Range closestInteractionRange = this.GetClosestInteractionRange(); if (closestInteractionRange == null) { return(new InteractionTarget[0]); } List <InteractionTarget> list = new List <InteractionTarget>(); foreach (InteractionTrigger.Range.Interaction interaction in closestInteractionRange.interactions) { foreach (FullBodyBipedEffector effectorType in interaction.effectors) { list.Add(interaction.interactionObject.GetTarget(effectorType, this)); } } return(list.ToArray()); }
public bool TriggerEffectorsReady(int index) { if (!this.IsValid(true)) { return(false); } if (!this.TriggerIndexIsValid(index)) { return(false); } for (int i = 0; i < this.triggersInRange[index].ranges.Length; i++) { InteractionTrigger.Range range = this.triggersInRange[index].ranges[i]; for (int j = 0; j < range.interactions.Length; j++) { for (int k = 0; k < range.interactions[j].effectors.Length; k++) { if (this.IsInInteraction(range.interactions[j].effectors[k])) { return(false); } } } for (int l = 0; l < range.interactions.Length; l++) { for (int m = 0; m < range.interactions[l].effectors.Length; m++) { if (this.IsPaused(range.interactions[l].effectors[m])) { for (int n = 0; n < range.interactions[l].effectors.Length; n++) { if (n != m && !this.IsPaused(range.interactions[l].effectors[n])) { return(false); } } } } } } return(true); }
private void DrawCameraPosition(InteractionTrigger.Range range, int index) { if (range.cameraPosition.lookAtTarget == null) { return; } Vector3 labelPosition = range.cameraPosition.lookAtTarget.transform.position - Vector3.up * index * 0.05f; if (range.cameraPosition.direction == Vector3.zero) { Handles.Label(labelPosition, "Camera Position direction is Vector3.zero for Range" + index.ToString() + ": " + range.name); return; } if (range.cameraPosition.maxAngle <= 0f) { Handles.Label(labelPosition, "Camera Position max angle is zero for Range" + index.ToString() + ": " + range.name); return; } range.cameraPosition.maxDistance = Mathf.Max(range.cameraPosition.maxDistance, 0f); if (range.cameraPosition.maxDistance <= 0f) { Handles.Label(labelPosition, "Camera Position Max Distance is zero for Range" + index.ToString() + ": " + range.name); return; } Quaternion targetRotation = range.cameraPosition.GetRotation(); Vector3 position = range.cameraPosition.lookAtTarget.transform.position; Vector3 direction = targetRotation * range.cameraPosition.direction; direction = direction.normalized * range.cameraPosition.maxDistance; Handles.DrawLine(position, position + direction); Handles.DotCap(0, position + direction, Quaternion.identity, 0.005f); Handles.Label(position + direction * 1.1f, "Camera Position for Range " + index.ToString() + ": " + range.name); if (range.cameraPosition.maxAngle >= 180f) { return; } float r = Mathf.Sin(range.cameraPosition.maxAngle * Mathf.Deg2Rad) * range.cameraPosition.maxDistance; float d = Mathf.Cos(range.cameraPosition.maxAngle * Mathf.Deg2Rad) * range.cameraPosition.maxDistance; Quaternion rotation = targetRotation * Quaternion.LookRotation(range.cameraPosition.direction); Handles.CircleCap(0, position + direction.normalized * d, rotation, r); if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null) { //Vector3 c = Vector3.Cross(direction, SceneView.lastActiveSceneView.camera.transform.forward); Vector3 c = Vector3.Cross(direction, (range.cameraPosition.lookAtTarget.transform.position - SceneView.lastActiveSceneView.camera.transform.position).normalized); c = Vector3.Cross(direction, c); Quaternion dirRotation = Quaternion.AngleAxis(range.cameraPosition.maxAngle, c); Vector3 dir3 = dirRotation * direction; Handles.DrawLine(position, position + dir3); Vector3 dir4 = Quaternion.Inverse(dirRotation) * direction; Handles.DrawLine(position, position + dir4); Handles.DrawWireArc(position, -c, dir3, range.cameraPosition.maxAngle * 2, range.cameraPosition.maxDistance); } }
private void DrawCharacterPosition(InteractionTrigger.Range range, int index) { Vector3 labelPosition = script.transform.position - Vector3.up * index * 0.05f; if (!range.characterPosition.use) { Handles.Label(labelPosition, "Character Position is not used for Range " + index.ToString() + ": " + range.name); return; } range.characterPosition.radius = Mathf.Max(range.characterPosition.radius, 0f); if (range.characterPosition.radius <= 0f) { Handles.Label(labelPosition, "Character Position radius is zero for Range " + index.ToString() + ": " + range.name); return; } if (range.characterPosition.maxAngle <= 0f) { Handles.Label(labelPosition, "Character Position max angle is zero for Range " + index.ToString() + ": " + range.name); return; } Vector3 f = script.transform.forward; if (range.characterPosition.fixYAxis) { f.y = 0f; } if (f == Vector3.zero) { Handles.Label(script.transform.position - Vector3.up * index * 0.05f, "Invalid rotation of InteractionTrigger for Range " + index.ToString() + ": " + range.name); return; // Singularity } Quaternion triggerRotation = Quaternion.LookRotation(f, (range.characterPosition.fixYAxis? Vector3.up: script.transform.up)); Vector3 position = script.transform.position + triggerRotation * range.characterPosition.offset3D; Vector3 direction = triggerRotation * range.characterPosition.direction3D; Quaternion rotation = direction == Vector3.zero? triggerRotation: Quaternion.LookRotation(direction, (range.characterPosition.fixYAxis? Vector3.up: script.transform.up)); Vector3 up = rotation * Vector3.up; Vector3 forward = rotation * Vector3.forward; Handles.DrawWireDisc(position, up, range.characterPosition.radius); if (range.characterPosition.orbit) { float mag = range.characterPosition.offset.magnitude; if (mag - range.characterPosition.radius > 0f) { Handles.DrawWireDisc(script.transform.position, up, mag - range.characterPosition.radius); } Handles.DrawWireDisc(script.transform.position, up, mag + range.characterPosition.radius); } Vector3 x = forward * range.characterPosition.radius; Quaternion q = Quaternion.AngleAxis(-range.characterPosition.maxAngle, up); Vector3 dir = q * x; if (direction != Vector3.zero && range.characterPosition.maxAngle < 180f) { Handles.DrawLine(position, position + x); Handles.DotCap(0, position + x, Quaternion.identity, range.characterPosition.radius * 0.01f); } Handles.Label(position - Vector3.up * index * 0.05f, "Character Position for Range " + index.ToString() + ": " + range.name); Color color = Handles.color; Color transparent = new Color(color.r, color.g, color.b, 0.3f); Handles.color = transparent; Handles.DrawSolidArc(position, up, dir, range.characterPosition.maxAngle * 2f, range.characterPosition.radius); Handles.color = color; }
private void DrawRange(InteractionTrigger.Range range, int index) { Color color = GetColor(index); Handles.color = color; GUI.color = color; Vector3 position = script.transform.position + script.transform.rotation * range.positionOffset; Vector3 direction = script.target.position - position; direction.y = 0f; range.maxDistance = Mathf.Clamp(range.maxDistance, 0f, range.maxDistance); bool noDirection = direction == Vector3.zero; if (noDirection) { range.angleOffset = 0f; range.maxAngle = 180f; } Quaternion rotation = noDirection? Quaternion.identity: Quaternion.LookRotation(direction); Vector3 up = rotation * Vector3.up; Vector3 forward = rotation * Vector3.forward; Handles.DrawWireDisc(position, up, range.maxDistance); if (range.orbit) { float mag = range.positionOffset.magnitude; if (mag - range.maxDistance > 0f) { Handles.DrawWireDisc(script.transform.position, up, mag - range.maxDistance); } Handles.DrawWireDisc(script.transform.position, up, mag + range.maxDistance); } Vector3 x = Quaternion.AngleAxis(range.angleOffset, up) * forward * range.maxDistance; Quaternion q = Quaternion.AngleAxis(-range.maxAngle, up); Vector3 dir = q * x; if (!noDirection && range.maxAngle < 180f) { Handles.DrawLine(position, position + x); Handles.DotCap(0, position + x, Quaternion.identity, range.maxDistance * 0.01f); } string name = range.interactions.Length > 0 && range.interactions[0].effectors.Length > 0? " (" + range.interactions[0].effectors[0].ToString() + ")": string.Empty; GUI.color = color; Handles.Label(position - up * index * 0.05f, "Character Position for Range " + index.ToString() + name); color.a = 0.3f; Handles.color = color; Handles.DrawSolidArc(position, up, dir, range.maxAngle * 2f, range.maxDistance); Handles.color = Color.white; GUI.color = Color.white; }