// Start is called before the first frame update
    public virtual void Start()
    {
        PlayerCharacter PC = ArticyDatabase.GetObject <PlayerCharacter>("Player_Character_Entity_Tech_Name");

        //Debug.Log("Our player name is: " + PC.Template.Basic_Character_Attributes.NPC_Feature_Name);
        StaticStuff.FlowDebug("Our player name is: " + PC.Template.Basic_Character_Attributes.NPC_Feature_Name);

        FlowPlayer = GetComponent <ArticyFlowPlayer>();
        Slot_Container sc = ArticyDatabase.GetObject <Slot_Container>("Start_On_Object");

        if (sc.Template.Slot_Feature.Slot_Feature_Slot != null)
        {
            //Debug.Log("CaptainsChairSceneRoot.Start() setting StartOn: " + sc.Template.Slot_Feature.Slot_Feature_Slot.name);
            StaticStuff.FlowDebug("CaptainsChairSceneRoot.Start() setting StartOn: " + sc.Template.Slot_Feature.Slot_Feature_Slot.name);
            SetFlowPlayerStartOn(sc.Template.Slot_Feature.Slot_Feature_Slot);
        }
        else
        {
            //Debug.Log("CaptainsChairSceneRoot.Start() no StartOn");
            StaticStuff.FlowDebug("CaptainsChairSceneRoot.Start() no StartOn");
        }

        if (DialogueUI != null)
        {
            DialogueUI.gameObject.SetActive(false);
        }
        //FlowPlayer.StartOn = sc.Template.Slot_Feature.Slot_Feature_Slot;
    }
    private void OnTriggerEnter(Collider other)
    {
        StaticStuff.FlowDebug(this.name + " OnTriggerEnter() other: " + other.name);

        ArticyReference colliderArtRef = other.gameObject.GetComponent <ArticyReference>();

        if (colliderArtRef == null)
        {
            //Debug.LogWarning("null ArticyReference on the thing we collided with.");
            StaticStuff.FlowDebugWarning("null ArticyReference on the thing we collided with.");
        }
        else
        {
            //Debug.Log("we connected with something that has an ArticyRef.  Now lets see if it's an NPC.");
            StaticStuff.FlowDebug("we connected with something that has an ArticyRef.  Now lets see what it is.");
            Dialogue dialogue = colliderArtRef.reference.GetObject() as Dialogue;
            if (dialogue != null)
            {
                StaticStuff.FlowDebug("we have a dialogue, so set the FlowPlayer to start on it");
                SceneRoot.SetFlowPlayerStartOn(dialogue);
                NavMeshAgent.SetDestination(this.transform.position);
            }
            else
            {
                StaticStuff.FlowDebugWarning("not sure what to do with this type yet: " + colliderArtRef.reference.GetObject().GetType());
            }
        }
    }
    protected void PrintBranchInfo(Branch b, string src = "")
    {
        string s = GetBranchInfo(b, src);

        //Debug.Log(s);
        StaticStuff.FlowDebug(s);
    }
    //To put it simple: IFlowObject is the basic type of anything the FlowPlayer can encounter while traversing..
    // That means every node, every pin and every connection is also an IFlowObject.If for some reason the passed
    // aObject is null, we have encountered a Dead End.
    protected override void DoOnFlowPlayerPaused(IFlowObject aObject)
    {
        // Debug.Log("**********************************************************************DoOnFlowPlayerPaused()");
        //Debug.Log("OnFlowPlayerPaused() IFlowObject Type: " + aObject.GetType() + ", with TechnicalName: " + ((ArticyObject)aObject).TechnicalName);
        StaticStuff.FlowDebug("**********************************************************************DoOnFlowPlayerPaused()");
        StaticStuff.FlowDebug("OnFlowPlayerPaused() IFlowObject Type: " + aObject.GetType() + ", with TechnicalName: " + ((ArticyObject)aObject).TechnicalName);
        CurPauseObject = aObject;
        // Note...a Dialogue Fragment is NOT a Flow Fragment
        var flowFragType = aObject as IObjectWithFeatureFlow_Fragment_Type;

        if (flowFragType != null)
        {
            Flow_Fragment_Type type     = flowFragType.GetFeatureFlow_Fragment_Type().Flow_Fragment_Type;
            FlowFragment       flowFrag = aObject as FlowFragment;
            //Debug.Log("Fragment name: " + flowFrag.DisplayName + ", has text: " + flowFrag.Text);
            //Debug.Log("enum val: " + type);
            StaticStuff.FlowDebug("Fragment name: " + flowFrag.DisplayName + ", has text: " + flowFrag.Text);
            StaticStuff.FlowDebug("enum val: " + type);
        }
        var dialogueFrag = aObject as Dialogue_Fragment;

        if (dialogueFrag != null)
        {
            //Debug.Log("We have a dialogue fragment...so DO SOMETHING");
            StaticStuff.FlowDebug("We have a dialogue fragment...so don't do anything since branch update will set up the dialogue fragment stuff there");
            // monote - "Ship.DoOnFlowPlayerPaused() about to show dialogue fragment"
            //Debug.LogWarning("We're changing the dialogue setup from Pause to BranchesUpdated because we can have more than 1");
            // base.ShowDialogueFragment(dialogueFrag);
        }
        //Debug.Log("**********DoOnFlowPlayerPaused() END");
        StaticStuff.FlowDebug("**********DoOnFlowPlayerPaused() END");
    }
 public void DialogueButtonCallback(int buttonIndex)
 {
     StaticStuff.FlowDebug("DialogueButtonCallback() buttonIndex: " + buttonIndex);
     NextBranch = CurBranches[buttonIndex];
     base.PrintBranchInfo(CurBranches[buttonIndex], "DialogueButtonCallback");
     if (CurBranches[buttonIndex].Target.GetType().Equals(typeof(Dialogue_Fragment)) == false)
     {
         //Debug.Log("we're done with the current dialogue tree, so shut off the UI and let the flow handle itself");
         StaticStuff.FlowDebug("Chosen branch isn't a dialogue fragment, so for now assume we're done talking and shut off the UI");
         base.ShutOffDialogueUI();
     }
     else
     {
         //Debug.LogWarning("Need to account for a flow fragment off of a dialogue UI button press");
         StaticStuff.FlowDebug("Chosen branch is a dialogue fragment, so just let the engine handle the next phase.");
     }
 }
    protected void GoToMiniGame(Branch branch)
    {
        var miniGameFrag = branch.Target as IObjectWithFeatureMini_Game_Name;

        if (miniGameFrag != null)
        {
            //Debug.Log("go to this mini game NOW: " + miniGameFrag.GetFeatureMini_Game__Name().Mini_Game_Name);
            StaticStuff.FlowDebug("go to this mini game NOW: " + miniGameFrag.GetFeatureMini_Game_Name().Mini_Game_Name);
            // FlowPlayer.StartOn = branch.Target as IArticyObject;
            Slot_Container slotContainer = ArticyDatabase.GetObject <Slot_Container>("Start_On_Object");
            slotContainer.Template.Slot_Feature.Slot_Feature_Slot = (ArticyObject)branch.Target;
            SceneManager.LoadScene(miniGameFrag.GetFeatureMini_Game_Name().Mini_Game_Name);
        }
        else
        {
            //Debug.LogError("ERROR: trying to go to a mini game with no name");
            StaticStuff.FlowDebug("ERROR: trying to go to a mini game with no name");
        }
    }
    protected void ShowDialogueFragment(Dialogue_Fragment dialogueFrag, List <Branch> dialogueOptions)
    {
        StaticStuff.FlowDebug("going to set up a dialogue fragment with speaker: " + dialogueFrag.Speaker + " with text: " + dialogueFrag.Text);
        StaticStuff.FlowDebug("this dialogue fragment has: " + dialogueOptions.Count + " options");

        DialogueUI.gameObject.SetActive(true);
        SetSpeakerImage(dialogueFrag.Speaker);
        SpeakerText.text = dialogueFrag.Text;

        foreach (GameObject go in DialogueOptions)
        {
            go.SetActive(false);
        }
        for (int i = 0; i < dialogueOptions.Count; i++)
        {
            DialogueOptions[i].SetActive(true);
            Dialogue_Fragment df = dialogueOptions[i].Target as Dialogue_Fragment;
            if (df != null)
            {
                DialogueOptions[i].GetComponentInChildren <Text>().text = df.MenuText;
            }
            else
            {
                string buttonText = dialogueFrag.Template.Dialogue_Fragment_Default_Button_Text.Default_Button_Text;
                StaticStuff.FlowDebug("ok we are not going to a dialogue fragment, so get the button text by the template: " + buttonText);
                if (buttonText.Equals("") == false)
                {
                    DialogueOptions[i].GetComponentInChildren <Text>().text = buttonText;
                }
                else
                {
                    string val = ArticyDatabase.DefaultGlobalVariables.GetVariableByString <string>("Misc_Globals.defaultDialogueFragmentButtonText");
                    DialogueOptions[i].GetComponentInChildren <Text>().text = val;
                }
            }
        }

        PlayerObject.ToggleMovementBlocked(true);
    }
 public void SetFlowPlayerStartOn(ArticyObject articyObject)
 {
     //Debug.Log("SetFlowPlayerStartOn(): type: " + articyObject.GetType() + ", name: " + articyObject.name);
     StaticStuff.FlowDebug("SetFlowPlayerStartOn(): type: " + articyObject.GetType() + ", name: " + articyObject.name);
     FlowPlayer.StartOn = articyObject;
 }
    // iFlowObject vs Branch
    //  Branch.Target is an iFlowObjects

    protected override void DoOnBranchesUpdated(IList <Branch> aBranches)
    {
        //Debug.Log("**********DoOnBranchesUpdated()");
        //Debug.Log("Num branches: " + aBranches.Count);
        StaticStuff.FlowDebug("**********DoOnBranchesUpdated()");
        StaticStuff.FlowDebug("Num branches: " + aBranches.Count);

        List <Branch> validBranches = new List <Branch>();

        CurBranches.Clear();
        string s = "";

        foreach (Branch b in aBranches)
        {
            base.PrintBranchInfo(b, "branch loop");
            Dialogue_Fragment d = b.Target as Dialogue_Fragment;
            if (d != null)
            {
                s += "Branch " + b.BranchId + ": ";
                s += d.InputPins[0].Text.RawScript + "\n";
            }
            //if (s != "") DebugText.text = s;
            CurBranches.Add(b);
            if (b.IsValid == true)
            {
                validBranches.Add(b);
            }
        }

        if (aBranches.Count == 1 && aBranches[0].IsValid && aBranches[0].Target.GetType().Equals(typeof(Hub)))
        {
            StaticStuff.FlowDebug("only one valid branch and it's a hub called: " + aBranches[0].DefaultDescription + " so Play() it");
            NextBranch = aBranches[0];
            base.PrintBranchInfo(NextBranch, "move to hub");
            //inventorySystem.RemoveItem(heldItem);
            //inventorySystem.RemoveItem(thisRepresentedItem);
        }
        else
        {
            if (validBranches.Count == 1 && CurPauseObject.GetType().Equals(typeof(Hub)))
            {
                s  = "1 valid branch on a hub pause object...check what it is: ";
                s += base.ReturnBranchInfo(validBranches[0], "checking 1 branch on hub");
                StaticStuff.FlowDebug(s);
                if (validBranches[0].Target.GetType().Equals(typeof(OutputPin)))
                {
                    StaticStuff.FlowDebug("only valid output is an OutputPin...which means that we're not linked to any other flow fragments so just sit tight and wait for something" +
                                          "like the player colliding with an NPC or something else to trigger the next StartOn");
                }
                else
                {
                    StaticStuff.FlowDebug("only valid output is something else that an OutputPin...so ROCK IT via Play(NextBranch)");
                    NextBranch = validBranches[0];
                }
            }
            else
            {
                StaticStuff.FlowDebug("--------------------------NOT in a situation where we have 1 valid Hub branch, so find out what to do.");
                if (CurPauseObject.GetType().Equals(typeof(Dialogue_Fragment)))
                {
                    StaticStuff.FlowDebug("We're on a dialogue fragment, so set up the dialogue via the CaptainsChairSceneRoot");
                    base.ShowDialogueFragment(CurPauseObject as Dialogue_Fragment, validBranches);
                }
                else
                {
                    StaticStuff.FlowDebug("on something other than a dialogue fragment, so find out what to do");
                    if (validBranches.Count == 1 && CurPauseObject.GetType().Equals(typeof(Jump)) && validBranches[0].Target.GetType().Equals(typeof(MiniGameFragment)))
                    {
                        StaticStuff.FlowDebug("we have 1 valid branch that's a Jump to a MiniGame so go to that mini game");
                        base.GoToMiniGame(validBranches[0]);
                    }
                    else
                    {
                        StaticStuff.FlowDebugWarning("not a 1 valid brach that's a Jump to a MiniGame so figure out what to do");
                    }
                }
            }
        }
        StaticStuff.FlowDebug("************************************************************DoOnBranchesUpdated() END");
    }