Beispiel #1
0
    public Node ImportNode(SODialogBox dialogBox)
    {
        if (nodes == null)
        {
            nodes = new List <Node>();
        }
        Node node = new Node(new Vector2(dialogBox.x, dialogBox.y), 200, 50, nodeStyle, entryNodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint, OnClickRemoveNode);

        nodes.Add(node);
        if (nodes.Count == 1)
        {
            SetEntryNode(node);
        }
        node.dialogBox   = dialogBox;
        node.dialogBox.x = node.rect.x;
        node.dialogBox.y = node.rect.y;
        if (dialogBox.next != null)
        {
            for (int i = 0; i < dialogBox.next.Length; ++i)
            {
                node.outPoints.Add(new ConnectionPoint(node, ConnectionPointType.Out, outPointStyle, OnClickOutPoint));
            }
        }
        return(node);
    }
Beispiel #2
0
    void changeDialog()
    {
        if (next_dialog != null)
        {
            timeSinceLastSentence = 0.0f;
            current_dialog        = next_dialog;
            go_to_next            = false;
            if (current_dialog.next.Length == 0)
            {
                shouldLoadNextScene = true;
            }

            RefreshCanvas();
        }
    }
Beispiel #3
0
    public Node AddNode(float x, float y)
    {
        SODialogBox asset = ScriptableObject.CreateInstance <SODialogBox>();
        string      path  = AssetDatabase.GetAssetPath(scene.GetInstanceID());

        path  = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(scene.GetInstanceID())), "");
        path += "DialogBoxes";
        asset.Awake();
        string pathname = AssetDatabase.GenerateUniqueAssetPath(path + "/DB" + asset.id + ".asset");

        AssetDatabase.CreateAsset(asset, pathname);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
        asset.x = x;
        asset.y = y;
        return(ImportNode(asset));
    }
Beispiel #4
0
    private void            SaveNodes(SODialogBox data)
    {
        if (loadedNodes.ContainsKey(data.id))
        {
            return;
        }
        EditorUtility.SetDirty(data);
        loadedNodes.Add(data.id, null);
        if (data.next == null)
        {
            return;
        }

        for (int i = 0; i < data.next.Length; ++i)
        {
            if (data.next[i].dialogBox)
            {
                SaveNodes(data.next[i].dialogBox);
            }
        }
    }
Beispiel #5
0
    // Start is called before the first frame update
    void Start()
    {
        has_success_story = Gamemachine.instance.isSuccessful;
        scene             = Gamemachine.instance.GetData().scene;
        current_dialog    = scene.root;
        RefreshCanvas();

        StepData data = Gamemachine.instance.GetData();

        if (data != null)
        {
            if (data.foreground == null)
            {
                foreground.enabled = false;
            }
            else
            {
                foreground.sprite = data.foreground;
            }
            background.sprite = data.background;
        }
    }
Beispiel #6
0
    private Node            LoadNodes(SODialogBox data)
    {
        if (loadedNodes.ContainsKey(data.id))
        {
            return(loadedNodes[data.id]);
        }
        Node newNode = NodeBasedEditor.instance.ImportNode(data);

        loadedNodes.Add(data.id, newNode);
        if (data.next == null)
        {
            return(newNode);
        }

        for (int i = 0; i < data.next.Length; ++i)
        {
            if (data.next[i].dialogBox)
            {
                Node node = LoadNodes(data.next[i].dialogBox);
                NodeBasedEditor.instance.AddConnection(newNode, node);
            }
        }
        return(newNode);
    }
Beispiel #7
0
    void RefreshCanvas()
    {
        //Reset text
        displayed_speaker.text = current_dialog.speaker.ToString();
        displayed_text.text    = "";
        current_pos            = 0;

        next_dialog = null;

        if (current_dialog.next.Length > 1)
        {
            for (int i = 0; i < current_dialog.next.Length && !next_dialog; i++)
            {
                Choice c = current_dialog.next[i];
                if (c.successStory == has_success_story && string.IsNullOrEmpty(c.name))
                {
                    next_dialog = c.dialogBox;
                }
            }
        }
        else if (current_dialog.next.Length == 1 && string.IsNullOrEmpty(current_dialog.next[0].name))
        {
            next_dialog = current_dialog.next[0].dialogBox;
        }

        if (string.IsNullOrEmpty(current_dialog.content))
        {
            go_to_next = true;
        }

        //GetComponent<Image>().sprite = current_dialog.background;


        //Change sprite and music
        if (current_dialog.speaker == Characters.Protagonist)
        {
            character.sprite = ResourcesManager.instance.getSpriteForEmotion(current_dialog.emotion);
        }
        //music.clip = ResourcesManager.instance.GetAudioClipForEmotion(current_dialog.emotion);

        /*
         * bool hasSuccessStory = false;
         *
         * }*/

        //Choice management
        Button[] choice_buttons = GetComponentsInChildren <Button>(true);
        Debug.Log("Number of chhoices : " + choice_buttons.Length);
        for (int i = 0; i < choice_buttons.Length; i++)
        {
            choice_buttons[i].gameObject.SetActive(false);
        }
        if (next_dialog == null && (current_dialog.next.Length > 1 || (current_dialog.next.Length == 1 && !string.IsNullOrEmpty(current_dialog.next[0].name))))
        {
            for (int i = 0; i < current_dialog.next.Length; i++)
            {
                Choice choice = current_dialog.next[i];
                Debug.Log("BONJOUR " + choice.successStory + " et " + has_success_story);
                if (choice.successStory == has_success_story || !choice.successStory)
                {
                    Debug.Log("Salut");
                    Button b = choice_buttons[i];
                    b.name = choice.name;
                    b.GetComponentInChildren <Text>().text = choice.name;

                    if (b.GetComponentInChildren <Text>().cachedTextGenerator.lineCount > 1)
                    {
                        b.image.sprite = box_large;
                    }
                    else
                    {
                        b.image.sprite = box_small;
                    }

                    b.gameObject.SetActive(true);
                    b.onClick.AddListener(delegate { next_dialog = choice.dialogBox; go_to_next = true; });// changeDialog(choice.dialogBox);});
                }
            }
        }
    }