public override void BeginInteraction(IInteractionSource interactionSource) { base.BeginInteraction(interactionSource); // TODO: Add SFX, make fruit fall off trees ShakeTree(); }
/// <summary> /// Gets all possible interactions, given a ray /// </summary> /// <param name="ray">The ray to use in ray casting</param> /// <param name="interactionEvent">The produced interaction event</param> /// <returns>A list of possible interactions</returns> private List <InteractionEntry> GetViableInteractions(Ray ray, out InteractionEvent interactionEvent) { // Get source that's currently interacting (eg. hand, tool) IInteractionSource source = GetActiveInteractionSource(); if (source == null) { interactionEvent = null; return(new List <InteractionEntry>()); } List <IInteractionTarget> targets = new List <IInteractionTarget>(); // Raycast to find target game object Vector3 point = Vector3.zero; if (Physics.Raycast(ray, out RaycastHit hit, float.PositiveInfinity, selectionMask, QueryTriggerInteraction.Ignore)) { point = hit.point; GameObject targetGo = hit.transform.gameObject; targets = GetTargetsFromGameObject(source, targetGo); } interactionEvent = new InteractionEvent(source, targets[0], point); return(GetInteractionsFromTargets(source, targets, interactionEvent)); }
private void CmdRunInventoryInteraction(GameObject target, GameObject sourceObject, int index, string name) { IInteractionSource source = sourceObject.GetComponent <IInteractionSource>(); List <IInteractionTarget> targets = GetTargetsFromGameObject(source, target); InteractionEvent interactionEvent = new InteractionEvent(source, null); List <InteractionEntry> entries = GetInteractionsFromTargets(source, targets, interactionEvent); // TODO: Validate access to inventory // Check for valid interaction index if (index < 0 || entries.Count <= index) { Debug.LogError($"Inventory interaction with invalid index {index}", target); return; } var chosenEntry = entries[index]; interactionEvent.Target = chosenEntry.Target; if (chosenEntry.Interaction.GetName(interactionEvent) != name) { Debug.LogError($"Interaction at index {index} did not have the expected name of {name}", target); return; } InteractionReference reference = interactionEvent.Source.Interact(interactionEvent, chosenEntry.Interaction); if (chosenEntry.Interaction.CreateClient(interactionEvent) != null) { RpcExecuteClientInventoryInteraction(target, sourceObject, index, name, reference.Id); } }
private List <IInteraction> GetViableInteractions(Ray ray, out InteractionEvent interactionEvent) { IInteractionSource source = GetActiveInteractionSource(); if (source == null) { interactionEvent = null; return(new List <IInteraction>()); } IInteractionTarget target = null; Vector3 point = Vector3.zero; if (Physics.Raycast(ray, out RaycastHit hit, float.PositiveInfinity, selectionMask)) { point = hit.point; GameObject targetGo = hit.transform.gameObject; target = targetGo.GetComponent <IInteractionTarget>() ?? new InteractionTargetGameObject(targetGo); if (!source.CanInteractWithTarget(target)) { interactionEvent = null; return(new List <IInteraction>()); } } interactionEvent = new InteractionEvent(source, target, point); IInteraction[] availableInteractions = source.GenerateInteractions(target != null ? new[] { target } : new IInteractionTarget[0]); InteractionEvent @event = interactionEvent; return(availableInteractions.Where(i => i.CanInteract(@event)).ToList()); }
private IInteractionSource GetActiveInteractionSource() { IToolHolder toolHolder = GetComponent <IToolHolder>(); IInteractionSource activeTool = toolHolder?.GetActiveTool(); return(activeTool ?? GetComponent <IInteractionSource>()); }
public override void BeginInteraction(IInteractionSource interactionSource) { base.BeginInteraction(interactionSource); m_cameraManager.RegisterTarget(m_uniqueID.ToString(), m_cameraTarget); Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; }
public override void BeginInteraction(IInteractionSource interactionSource) { base.BeginInteraction(interactionSource); m_boat.ToggleSailSpeed(); ReleaseInteraction(); }
public static IInteractionSource GetRootSource(this IInteractionSource source) { IInteractionSource current = source; while (current.Parent != null) { current = current.Parent; } return(current); }
public override void BeginInteraction(IInteractionSource interactionSource) { base.BeginInteraction(interactionSource); if (m_boatController.IsDamaged) { m_boatController.ChangeHealth(-5); } ReleaseInteraction(); }
/// <summary> /// Gets all valid interaction targets from a game object /// </summary> /// <param name="source">The source of the interaction</param> /// <param name="gameObject">The game objects the interaction targets are on</param> /// <returns>A list of all valid interaction targets</returns> private List <IInteractionTarget> GetTargetsFromGameObject(IInteractionSource source, GameObject gameObject) { List <IInteractionTarget> targets = new List <IInteractionTarget>(); // Get all target components which are not disabled and the source can interact with targets.AddRange(gameObject.GetComponents <IInteractionTarget>().Where(x => (x as MonoBehaviour)?.enabled != false && source.CanInteractWithTarget(x))); if (targets.Count < 1) { targets.Add(new InteractionTargetGameObject(gameObject)); } return(targets); }
/// <summary> /// Generates all possible interactions, given both a source and targets /// </summary> /// <param name="source">The interaction source</param> /// <param name="targets">The interaction targets</param> /// <param name="event">The interaction event data</param> /// <returns>A list of all possible interaction entries</returns> private List <InteractionEntry> GetInteractionsFromTargets(IInteractionSource source, List <IInteractionTarget> targets, InteractionEvent @event) { // Generate interactions on targets List <InteractionEntry> interactions = targets.SelectMany(t => t.GenerateInteractionsFromTarget(new InteractionEvent(source, t, @event.Point)) .Select(i => new InteractionEntry(t, i)) ).ToList(); // Allow the source to add its own interactions source.GenerateInteractionsFromSource(targets.ToArray(), interactions); // Filter interactions to possible ones return(interactions.Where(i => i.Interaction.CanInteract(new InteractionEvent(source, i.Target, @event.Point))).ToList()); }
public IInteractionSource GetActiveTool() { Item itemInHand = ItemInHand; if (itemInHand == null) { return(null); } IInteractionSource interactionSource = itemInHand.prefab.GetComponent <IInteractionSource>(); if (interactionSource != null) { interactionSource.Parent = this; } return(interactionSource); }
private void RpcExecuteClientInventoryInteraction(GameObject target, GameObject sourceObject, int index, string name, int referenceId) { IInteractionSource source = sourceObject.GetComponent <IInteractionSource>(); List <IInteractionTarget> targets = GetTargetsFromGameObject(source, target); InteractionEvent interactionEvent = new InteractionEvent(source, null); List <InteractionEntry> entries = GetInteractionsFromTargets(source, targets, interactionEvent); var chosenInteraction = entries[index]; interactionEvent.Target = chosenInteraction.Target; if (chosenInteraction.Interaction.GetName(interactionEvent) != name) { return; } interactionEvent.Source.ClientInteract(interactionEvent, chosenInteraction.Interaction, new InteractionReference(referenceId)); }
public static T GetComponentInTree <T>(this IInteractionSource source) where T : class { IInteractionSource current = source; while (current != null) { if (current is IGameObjectProvider provider) { T component = provider.GameObject.GetComponent <T>(); if (component != null) { return(component); } } current = current.Parent; } return(null); }
public void InteractInHand(GameObject target, GameObject sourceObject, bool showMenu = false) { IInteractionSource source = sourceObject.GetComponent <IInteractionSource>(); if (source == null) { return; } List <IInteractionTarget> targets = GetTargetsFromGameObject(source, target); InteractionEvent interactionEvent = new InteractionEvent(source, null); List <InteractionEntry> entries = GetInteractionsFromTargets(source, targets, interactionEvent); if (entries.Count < 1) { return; } interactionEvent.Target = entries[0].Target; if (showMenu && entries.Select(x => x.Interaction).ToList().Count > 0) { var obj = Instantiate(menuPrefab, transform.root.transform); activeMenu = obj.GetComponentInChildren <UI.RadialInteractionMenuUI>(); Vector3 mousePosition = Input.mousePosition; mousePosition.y = Mathf.Max(obj.transform.GetChild(0).GetComponent <RectTransform>().rect.height, mousePosition.y); activeMenu.Position = mousePosition; activeMenu.Event = interactionEvent; activeMenu.Interactions = entries.Select(x => x.Interaction).ToList(); activeMenu.onSelect = interaction => { CmdRunInventoryInteraction(target, sourceObject, entries.FindIndex(x => x.Interaction == interaction), interaction.GetName(interactionEvent)); }; } else { CmdRunInventoryInteraction(target, sourceObject, 0, entries[0].Interaction.GetName(interactionEvent)); } }
public static Creature GetCreature(this IInteractionSource source) { return(source.GetRootSource().GetComponent <Creature>()); }
public void BeginInteraction(IInteractionSource interactionSource) { throw new System.NotImplementedException(); }
public override void BeginInteraction(IInteractionSource interactionSource) { base.BeginInteraction(interactionSource); m_boat.OnWheelInteractBegin(this); }
public InteractionEvent(IInteractionSource source, IInteractionTarget target, Vector3 point = new Vector3()) { Source = source; Target = target; Point = point; }
public virtual void BeginInteraction(IInteractionSource interactionSource) { m_interactionSource = interactionSource; m_interactionSource.OnInteractionBegin(this); }
public static Hands GetHands(this IInteractionSource source) { return(source.GetComponentInTree <Hands>()); }
public static Entity GetEntity(this IInteractionSource source) { return(source.GetRootSource().GetComponent <Entity>()); }
public static RangeLimit GetRange(this IInteractionSource source) { IInteractionRangeLimit limit = source.GetComponentInTree <IInteractionRangeLimit>(); return(limit?.GetInteractionRange() ?? RangeLimit.Max); }
public static T GetComponentInTree <T>(this IInteractionSource source) where T : class { return(GetComponentInTree <T>(source, out IGameObjectProvider _)); }
public static T GetComponent <T>(this IInteractionSource source) where T : class { GameObject gameObject = (source as IGameObjectProvider)?.GameObject; return(gameObject != null?gameObject.GetComponent <T>() : null); }
public void ReleaseInteraction() { m_interactionSource?.OnInteractionEnd(this); m_interactionSource = null; }
public override void BeginInteraction(IInteractionSource interactionSource) { base.BeginInteraction(interactionSource); _audioSource.PlayOneShot(_audioSource.clip); }