public void SetInteractionPanel(Responsible responsible, Interactable.Base.Interactable target, object[] parameters, Vector3 panelPosition) { CreateInteractionPanel(panelPosition); HashSet <MethodInfo> methods = target.GetComponent <Interactable.Base.Interactable>().Methods; Debug.Log(methods.Count); foreach (var method in methods) { InteractableAttribute [] interactableAttributes = System.Attribute.GetCustomAttributes(method, typeof(InteractableAttribute)) as InteractableAttribute[]; if (interactableAttributes == null) { Debug.Log("Method's interactable type is missing!"); return; } foreach (var interactableAttribute in interactableAttributes) { if (interactableAttribute.InteractableType == responsible.GetType() || interactableAttribute.InteractableType == responsible.GetType().BaseType) { JobInfo jobInfo = new JobInfo(responsible, target, method, parameters); AddInteractionButton(jobInfo); } } } }
public JobInfo(Responsible responsible, Interactable.Base.Interactable target, MethodInfo method, object[] parameters) { _responsible = responsible; _target = target; _method = method; _parameters = parameters; }
public override bool Do(Responsible responsible) { Interactable.Base.Interactable interactable = null; MethodInfo method = null; foreach (var item in responsible.Inventory.Items) { var methodInfo = item.GetComponent<Interactable.Base.Interactable>() .FindAllowedAction(responsible, Type); if (methodInfo != null) { interactable = item.GetComponent<Interactable.Base.Interactable>(); method = methodInfo; break; } } Ground ground = null; var interactableObjects = Physics.OverlapSphere(responsible.gameObject.transform.position, 4f); if (interactableObjects.Length <= 0) return false; foreach (var interactableObject in interactableObjects) { var groundObject = interactableObject.GetComponent<Ground>(); if(groundObject == null) continue; if(groundObject.occupied) continue; ground = groundObject; } if (method == null || interactable == null) return false; var coroutineInfo = new JobInfo(responsible, ground, ground.GetType().GetMethod("Walk"), new object[] {responsible}); UIManager.SetInteractionAction(coroutineInfo); coroutineInfo = new JobInfo(responsible, interactable, method, new object[] {responsible}); UIManager.SetInteractionAction(coroutineInfo); return true; }