/// <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());
        }
    }
Example #2
0
    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();
            }
        }
    }
Example #3
0
    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);
    }
Example #4
0
    public override ObjectData Save(ObjectData dataToUse)
    {
        InteractableData data = (InteractableData)base.Save(dataToUse);

        data.on = on;

        return(data);
    }
Example #5
0
 public virtual void Load(InteractableData interactableData)
 {
     foreach (Interactable interactable in this.GetComponents <Interactable>())
     {
         Destroy(interactable);
     }
     interactableId = interactableData.id;
     interactableData.CreateComponent(this.gameObject);
 }
Example #6
0
 public void EnableInteractionUI(InteractableData objectData)
 {
     if (!isOpen)
     {
         isOpen = true;
         interactionText.SetText("F to " + objectData.interactionText);
         animator.SetBool("IsOpen", true);
     }
 }
Example #7
0
    public void SetTargetUniqueID(string targetUniqueID)
    {
        InteractableData data = (InteractableData)GetSelectedExtension(PStrings.interactable);

        if (data == null)
        {
            return;
        }

        data.SetTarget(int.Parse(targetUniqueID));
    }
Example #8
0
 public void Load(InteractableData data)
 {
     base.Load(data);
     on = data.on;
     if (on)
     {
         Enable();
     }
     else
     {
         Disable();
     }
 }
Example #9
0
        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
        }
Example #10
0
 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);
        }
Example #12
0
    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);
    }
Example #13
0
    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();
                        }
                    }
                }
            }
        }
    }
Example #15
0
 public SearchInteraction(InteractableData data) : base(data)
 {
 }
Example #16
0
 public Connection(Room connectedRoom, InteractableData data) : base(data)
 {
     ConnectionDestination = connectedRoom;
 }
Example #17
0
 public Interactable(InteractableData data)
 {
     Data = data;
 }
Example #18
0
 private void Awake()
 {
     _rigidBody   = GetComponent <Rigidbody>();
     _initialData = new InteractableData(transform);
 }
Example #19
0
 public void Set(InteractableData data)
 {
     data.Restore(transform);
 }
Example #20
0
 private void Start()
 {
     currentInteractable = new InteractableData();
     UpdateManipulables();
 }