/// <summary> /// Creates interactable objects based on the stored interactable data /// </summary> /// <param name="interactableParent">Transform that will serve as the parent for the loaded interactables</param> public static void LoadInteractables(Transform interactableParent) { // Get the amount of interactables ChildAmountData interactAmData = SaveSystem.LoadInteractableAmount(); int amountInteractables = interactAmData.GetChildAmount(); // Load each interactable for (int i = 0; i < amountInteractables; ++i) { // Get the data for the interactable InteractableData interactData = SaveSystem.LoadInteractable(i); // Get the key to which prefab to spawn off the interactData int key = interactData.GetPrefabKey(); // Use the key to get the prefab to load GameObject interactPref = SaveInteractablesController.GetInteractablePrefab(key); // Spawn the prefab as a child of the interactable parent GameObject interactObj = Object.Instantiate(interactPref, interactableParent); // Set its transform components interactObj.transform.position = interactData.GetPosition(); // Get its Interact script Interactable interactScriptRef = interactObj.GetComponent <Interactable>(); if (interactScriptRef == null) { Debug.LogError("No Interactable script was attached to " + interactObj.name); return; } // Set all the saved variables from that script interactScriptRef.SetCanInteractWith(interactData.GetCanInteractWith()); } }
private void Update() { if (currentInteractable.interactable != null) { if (currentInteractable.interactable.isScaleElement) { ManageScale(); } if (currentInteractable.interactable.isRotationElement) { ManageRotation(); } if (isSelected) { if (manipulableCopy.GetComponent <LineRenderer>() != null) { manipulableCopy.GetComponent <LineRenderer>().SetPosition(0, manipulableCopy.transform.position); manipulableCopy.GetComponent <LineRenderer>().SetPosition(1, currentInteractable.interactable.transform.position); } } else if (!isSelected && currentInteractable.interactable.transform.parent != null) { currentInteractable.ResetTransform(); currentInteractable = new InteractableData(); } } }
public bool SubmitAction(string action, string target) { bool actionExecuted = false; //Check obstacle if (ObstacleController.Instance.ObstaclePresent()) { actionExecuted = ObstacleController.Instance.SubmitObstacleAction(action, target); } if (!actionExecuted) { //Check through interactables for (int i = 0; i < StaticData.InteractableIds.Length; i++) { string interactableId = StaticData.InteractableIds[i]; InteractableData data = InteractableDatabase.GetInteractableData(interactableId); for (int j = 0; j < data.Interactions.Length; j++) { Interaction interaction = data.Interactions[j]; if ((Helpers.LooseCompare(target, interaction.Target) || Helpers.LooseCompare(target, data.Name)) && Helpers.LooseCompare(action, interaction.Action)) { interaction.ExecuteInteractionOutcome(); actionExecuted = true; } } } } return(actionExecuted); }
public override ObjectData Save(ObjectData dataToUse) { InteractableData data = (InteractableData)base.Save(dataToUse); data.on = on; return(data); }
public virtual void Load(InteractableData interactableData) { foreach (Interactable interactable in this.GetComponents <Interactable>()) { Destroy(interactable); } interactableId = interactableData.id; interactableData.CreateComponent(this.gameObject); }
public void EnableInteractionUI(InteractableData objectData) { if (!isOpen) { isOpen = true; interactionText.SetText("F to " + objectData.interactionText); animator.SetBool("IsOpen", true); } }
public void SetTargetUniqueID(string targetUniqueID) { InteractableData data = (InteractableData)GetSelectedExtension(PStrings.interactable); if (data == null) { return; } data.SetTarget(int.Parse(targetUniqueID)); }
public void Load(InteractableData data) { base.Load(data); on = data.on; if (on) { Enable(); } else { Disable(); } }
protected virtual void Awake() { #if ProjectCore if (interactableId != null && interactableId != "" && interactableId != "None") { InteractableData interactableData = Catalog.GetData <InteractableData>(interactableId); if (interactableData != null) { Load(interactableData.Clone() as InteractableData); } } #endif }
private void OnInteractableSelectEnter(XRBaseInteractor interactor) { isSelected = true; if (interactor.selectTarget.GetType() != typeof(XRManipulableInteractable)) { return; } if (currentInteractable.interactable == null) { currentInteractable = new InteractableData((XRManipulableInteractable)interactor.selectTarget); originalState = new OriginalState(transform.position, transform.localPosition, transform.localScale, transform.rotation); CreateManipulableCopy(); } }
private int GetDistance(InteractableData data, Vector3 point, Faction actorFaction, float maxDistance) { Vector3 dataPosition = data.dynamic ? data.interactable.GetWorldPosition() : data.position; bool wrongFaction = data.ownerFaction != null && data.ownerFaction != actorFaction; float limitDistance = (wrongFaction && maxDistance != -1) ? maxDistance * 0.3f : maxDistance; float distance = Vector3.Distance(dataPosition, point); if (maxDistance == -1 || distance < limitDistance) { return(Mathf.FloorToInt(distance)); } return(Int32.MaxValue); }
public bool SubmitExamineAction(string target) { for (int i = 0; i < StaticData.InteractableIds.Length; i++) { string interactableId = StaticData.InteractableIds[i]; InteractableData data = InteractableDatabase.GetInteractableData(interactableId); if (Helpers.LooseCompare(target, data.Name)) { MessageManager.SendStringMessage(data.Description); return(true); } } return(false); }
public static bool LoadInteractableData() { _interactableData = new Dictionary <string, InteractableData>(); InteractableArray interactableArray = GetInteractableArray(); if (interactableArray != null) { for (int i = 0; i < interactableArray.Interactables.Length; i++) { InteractableData interactable = interactableArray.Interactables[i]; _interactables.Add(interactable.InteractableId, interactable); } return(true); } return(false); }
private void Interact() { if (input.interactRequest == true) { CellData interactCell = GridData.GetCellAt(Coordinates.FromWorldSpace(input.interactPosition)); if (interactCell != null) { ExtensibleData extensible = null; if (interactCell.obstacle != null) { extensible = interactCell.obstacle; } else if (interactCell.item != null) { extensible = interactCell.item; } else if (interactCell.entity != null) { extensible = interactCell.entity; } if (extensible != null) { InteractableData interactable = (InteractableData)extensible.GetExtension(PStrings.interactable); if (interactable != null) { float sqrDistanceThreshold = 2.0f; Vector3 interactablePosition = new Vector3(extensible.gameObject.transform.position.x, 0, extensible.gameObject.transform.position.z); Vector3 interactorPosition = new Vector3(rigidbody.position.x, 0, rigidbody.position.z); if ((interactablePosition - interactorPosition).sqrMagnitude <= (sqrDistanceThreshold * sqrDistanceThreshold)) { interactable.Switch(); } } } } } }
public SearchInteraction(InteractableData data) : base(data) { }
public Connection(Room connectedRoom, InteractableData data) : base(data) { ConnectionDestination = connectedRoom; }
public Interactable(InteractableData data) { Data = data; }
private void Awake() { _rigidBody = GetComponent <Rigidbody>(); _initialData = new InteractableData(transform); }
public void Set(InteractableData data) { data.Restore(transform); }
private void Start() { currentInteractable = new InteractableData(); UpdateManipulables(); }