示例#1
0
    private void ParseFileIntoDialog(string fileName, InteractionData interactionData, out DialogData dialogData)
    {
        string path = Application.dataPath + "/StreamingAssets/Interactions/" + fileName + ".txt";

        if (!Directory.Exists(Application.dataPath + "/StreamingAssets/Interactions/"))
        {
            Directory.CreateDirectory(Application.dataPath + "/StreamingAssets/Interactions/");
        }
        if (!File.Exists(path))
        {
            dialogData = null;
        }
        else
        {
            dialogData         = ScriptableObject.CreateInstance <DialogData>();
            dialogData.actions = new List <DialogAction>();

            string[] dialog = File.ReadAllLines(path);

            DialogAction action = ScriptableObject.CreateInstance <DialogAction>();
            for (int i = 0; i < dialog.Length; ++i)
            {
                if (dialog[i].ToLower() == "[" + interactionData.firstInteractor.entityName.ToLower() + "]")
                {
                    action.interactee = interactionData.firstInteractor;
                    continue;
                }
                else if (dialog[i].ToLower() == "[" + interactionData.secondInteractor.entityName.ToLower() + "]")
                {
                    action.interactee = interactionData.secondInteractor;
                    continue;
                }

                if (dialog[i].Length > 0 && dialog[i][0] == '*')
                {
                    action.text = dialog[i].Replace("*", "");
                    if (action != null)
                    {
                        dialogData.actions.Add(action);
                    }
                    Interactee interactee = action.interactee;
                    action = ScriptableObject.CreateInstance <DialogAction>();
                    if (i + 2 < dialog.Length && dialog[i + 2].Length > 0 && dialog[i + 2][0] == '*')
                    {
                        action.interactee = interactee;
                    }
                }
                else
                {
                    if (action != null)
                    {
                        SetActionDefaults(ref action);
                        ParseAction(action, dialog[i]);
                    }
                }
            }
        }
    }
示例#2
0
    public Interactee CreateInteractee(Sprite sprite, string name)
    {
        Interactee interactee = ScriptableObject.CreateInstance <Interactee>();

        interactee.sprite     = sprite;
        interactee.entityName = name;

        return(interactee);
    }
示例#3
0
    public InteractionData CreateInteraction(Interactee firstInteractor, InteractionData.InteractionType type, string fileName, Interactee secondInteractor = null)
    {
        InteractionData data = ScriptableObject.CreateInstance <InteractionData>();

        data.firstInteractor  = firstInteractor;
        data.secondInteractor = secondInteractor;
        data.interactionType  = type;
        data.dialogFileName   = fileName;

        return(data);
    }
示例#4
0
    void TryInteract()
    {
        var hits = RaycastWhiskers(false, WhiskersOrigin.position,
                                   Quaternion.AngleAxis(minWhiskerAngle, Hands.right) * WhiskersOrigin.forward * MAX_RAYCAST_DISTANCE,
                                   Quaternion.AngleAxis(maxWhiskerAngle, Hands.right) * WhiskersOrigin.forward * MAX_RAYCAST_DISTANCE,
                                   whiskerNumber);

        Debug.Log($"{hits.Count()} Hits!");

        Interactee target = null;

        foreach (var hit in hits)
        {
            Debug.Log("Testing hit at distance: " + hit.distance);
            var collider = hit.collider;
            if (IsHoldingObject && collider.TryGetComponent <ObjectContainer>(out var container))
            {
                target = container;
                break;
            }
            else if (collider.TryGetComponent <Interactee>(out var interactee))
            {
                target = interactee;
                break;
            }
        }

        if (target != null)
        {
            target.OnInteraction(this);
        }
        else if (IsHoldingObject)
        {
            heldObject.OnInteraction(this);
        }
    }