/// <summary>
 /// Gets the character info for a character given its actor ID and transform.
 /// </summary>
 /// <returns>
 /// The character info.
 /// </returns>
 /// <param name='id'>
 /// The character's actor ID in the dialogue database.
 /// </param>
 /// <param name='character'>
 /// The transform of the character's GameObject.
 /// </param>
 public CharacterInfo GetCharacterInfo(int id, Transform character)
 {
     if (!m_characterInfoCache.ContainsKey(id))
     {
         Actor actor         = null;
         var   dialogueActor = DialogueActor.GetDialogueActorComponent(character);
         if (dialogueActor != null)
         {
             actor = m_database.GetActor(dialogueActor.actor);
         }
         if (actor == null)
         {
             actor = m_database.GetActor(id);
         }
         string nameInDatabase = (actor != null) ? actor.Name : string.Empty;
         if (character == null && !string.IsNullOrEmpty(nameInDatabase))
         {
             character = CharacterInfo.GetRegisteredActorTransform(nameInDatabase);
         }
         var           actorID       = (actor != null) ? actor.id : id;
         CharacterInfo characterInfo = new CharacterInfo(actorID, nameInDatabase, character, m_database.GetCharacterType(id), GetPortrait(character, actor));
         m_characterInfoCache.Add(id, characterInfo);
     }
     return(m_characterInfoCache[id]);
 }
Esempio n. 2
0
 public void CheckSubtitleAnimator(Subtitle subtitle)
 {
     if (subtitle != null && useAnimatedPortraits && animator != null)
     {
         var dialogueActor = DialogueActor.GetDialogueActorComponent(subtitle.speakerInfo.transform);
         if (dialogueActor != null) // && dialogueActor.standardDialogueUISettings.portraitAnimatorController != null)
         {
             var speakerPanelNumber = dialogueActor.GetSubtitlePanelNumber();
             var isMyPanel          =
                 (actorOverridingPanel == subtitle.speakerInfo.transform) ||
                 (PanelNumberUtility.GetSubtitlePanelIndex(speakerPanelNumber) == this.panelNumber) ||
                 (speakerPanelNumber == SubtitlePanelNumber.Default && subtitle.speakerInfo.isNPC && isDefaultNPCPanel) ||
                 (speakerPanelNumber == SubtitlePanelNumber.Default && subtitle.speakerInfo.isPlayer && isDefaultPCPanel) ||
                 (speakerPanelNumber == SubtitlePanelNumber.Custom && dialogueActor.standardDialogueUISettings.customSubtitlePanel == this);
             if (isMyPanel)
             {
                 StartCoroutine(SetAnimatorAtEndOfFrame(dialogueActor.standardDialogueUISettings.portraitAnimatorController));
             }
         }
         else
         {
             StartCoroutine(SetAnimatorAtEndOfFrame(null));
         }
     }
 }
        protected virtual StandardUIMenuPanel GetPanel(Subtitle lastSubtitle, Response[] responses)
        {
            // Find player's DialogueActor:
            var playerTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.transform
                : (responses != null && responses.Length > 0) ? GetActorTransformFromID(responses[0].destinationEntry.ActorID)
                : DialogueManager.currentActor;

            if (playerTransform == null)
            {
                playerTransform = DialogueManager.currentActor;
            }

            if (playerTransform == null)
            {
                return(m_defaultPanel);
            }
            if (m_actorPanelCache.ContainsKey(playerTransform))
            {
                return(m_actorPanelCache[playerTransform]);
            }
            var dialogueActor = DialogueActor.GetDialogueActorComponent(playerTransform);

            // Check NPC for non-default menu panel:
            var playerUsesDefaultMenuPanel = dialogueActor == null || dialogueActor.standardDialogueUISettings.menuPanelNumber == MenuPanelNumber.Default;
            var otherTransform             = (lastSubtitle != null && lastSubtitle.speakerInfo.isNPC) ? lastSubtitle.speakerInfo.transform : DialogueManager.currentConversant;

            if (playerUsesDefaultMenuPanel && otherTransform != null && m_actorPanelCache.ContainsKey(otherTransform))
            {
                return(m_actorPanelCache[otherTransform]);
            }
            var otherDialogueActor = DialogueActor.GetDialogueActorComponent(otherTransform);

            if (otherDialogueActor != null &&
                (otherDialogueActor.standardDialogueUISettings.useMenuPanelFor == DialogueActor.UseMenuPanelFor.MeAndResponsesToMe ||
                 (otherDialogueActor.standardDialogueUISettings.menuPanelNumber != MenuPanelNumber.Default && playerUsesDefaultMenuPanel)))
            {
                if (otherTransform != null && m_actorPanelCache.ContainsKey(otherTransform))
                {
                    return(m_actorPanelCache[otherTransform]);
                }
                var otherPanel = GetDialogueActorPanel(otherDialogueActor);
                if (otherPanel != null)
                {
                    return(otherPanel);
                }
            }

            // Otherwise use player's menu panel:
            var panel = GetDialogueActorPanel(dialogueActor);

            if (panel == null)
            {
                panel = m_defaultPanel;
            }
            m_actorPanelCache.Add(playerTransform, panel);
            return(panel);
        }
Esempio n. 4
0
        private StandardUIMenuPanel GetPanel(Subtitle lastSubtitle)
        {
            // Find player's DialogueActor:
            var playerTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.transform : DialogueManager.currentActor;

            if (playerTransform == null)
            {
                return(m_defaultPanel);
            }
            if (m_actorPanelCache.ContainsKey(playerTransform))
            {
                return(m_actorPanelCache[playerTransform]);
            }
            var dialogueActor = DialogueActor.GetDialogueActorComponent(playerTransform);

            // If player is configured to use default menu panel, check NPC for non-default menu panel:
            if (dialogueActor == null || (dialogueActor != null && dialogueActor.standardDialogueUISettings.menuPanelNumber == MenuPanelNumber.Default))
            {
                var otherTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isNPC) ? lastSubtitle.speakerInfo.transform : DialogueManager.currentConversant;
                if (otherTransform != null && m_actorPanelCache.ContainsKey(otherTransform))
                {
                    return(m_actorPanelCache[otherTransform]);
                }
                var otherDialogueActor = DialogueActor.GetDialogueActorComponent(otherTransform);
                if (otherDialogueActor != null && otherDialogueActor.standardDialogueUISettings.menuPanelNumber != MenuPanelNumber.Default)
                {
                    var otherPanel = GetDialogueActorPanel(otherDialogueActor);
                    if (otherPanel != null)
                    {
                        return(otherPanel);
                    }
                }
            }

            // Otherwise use player's menu panel:
            var panel = GetDialogueActorPanel(dialogueActor);

            if (panel == null)
            {
                panel = m_defaultPanel;
            }
            m_actorPanelCache.Add(playerTransform, panel);
            return(panel);
        }
Esempio n. 5
0
 private StandardUISubtitlePanel GetActorTransformPanel(Transform speakerTransform, StandardUISubtitlePanel defaultPanel, out DialogueActor dialogueActor)
 {
     dialogueActor = null;
     if (speakerTransform == null)
     {
         return(defaultPanel);
     }
     if (m_dialogueActorCache.ContainsKey(speakerTransform))
     {
         dialogueActor = m_dialogueActorCache[speakerTransform];
     }
     else
     {
         dialogueActor = DialogueActor.GetDialogueActorComponent(speakerTransform);
         m_dialogueActorCache.Add(speakerTransform, dialogueActor);
     }
     if (m_actorPanelCache.ContainsKey(speakerTransform))
     {
         return(m_actorPanelCache[speakerTransform]);
     }
     if (m_useBarkUIs.Contains(speakerTransform))
     {
         return(null);
     }
     if (DialogueActorUsesBarkUI(dialogueActor))
     {
         m_useBarkUIs.Add(speakerTransform);
         return(null);
     }
     else
     {
         var panel = GetDialogueActorPanel(dialogueActor);
         if (panel == null)
         {
             panel = defaultPanel;
         }
         m_actorPanelCache.Add(speakerTransform, panel);
         return(panel);
     }
 }
 /// <summary>
 /// Gets the character info for a character given its actor ID and transform.
 /// </summary>
 /// <returns>
 /// The character info.
 /// </returns>
 /// <param name='id'>
 /// The character's actor ID in the dialogue database.
 /// </param>
 /// <param name='character'>
 /// The transform of the character's GameObject.
 /// </param>
 public CharacterInfo GetCharacterInfo(int id, Transform character)
 {
     if (!m_characterInfoCache.ContainsKey(id))
     {
         Actor actor         = null;
         var   dialogueActor = DialogueActor.GetDialogueActorComponent(character);
         if (dialogueActor != null)
         {
             actor = m_database.GetActor(dialogueActor.actor);
         }
         if (actor == null)
         {
             actor = m_database.GetActor(id);
         }
         string nameInDatabase = (actor != null) ? actor.Name : string.Empty;
         if (character == null && !string.IsNullOrEmpty(nameInDatabase))
         {
             character = CharacterInfo.GetRegisteredActorTransform(nameInDatabase);
         }
         var actorID  = (actor != null) ? actor.id : id;
         var portrait = (dialogueActor != null) ? dialogueActor.GetPortraitSprite() : null;
         if (portrait == null)
         {
             portrait = GetPortrait(character, actor);
         }
         CharacterInfo characterInfo = new CharacterInfo(actorID, nameInDatabase, character, m_database.GetCharacterType(id), portrait);
         if (characterInfo.portrait == null && actor != null)
         {
             actor.AssignPortraitSprite((sprite) => { characterInfo.portrait = sprite; });
         }
         // Don't cache null actor ID -1:
         if (id == -1)
         {
             return(characterInfo);
         }
         // Otherwise cache to speed up lookups:
         m_characterInfoCache.Add(id, characterInfo);
     }
     return(m_characterInfoCache[id]);
 }
Esempio n. 7
0
        /// @endcond

        /// <summary>
        /// Initializes a new CharacterInfo.
        /// </summary>
        /// <param name='actorID'>
        /// Actor ID.
        /// </param>
        /// <param name='actorName'>
        /// Name of the actor as defined in the dialogue database.
        /// </param>
        /// <param name='transform'>
        /// Transform.
        /// </param>
        /// <param name='characterType'>
        /// Character type.
        /// </param>
        /// <param name='portrait'>
        /// Portrait.
        /// </param>
        public CharacterInfo(int id, string nameInDatabase, Transform transform, CharacterType characterType, Sprite portrait)
        {
            this.id             = id;
            this.nameInDatabase = nameInDatabase;
            this.characterType  = characterType;
            this.portrait       = portrait;
            this.transform      = transform;
            if ((transform == null) && !string.IsNullOrEmpty(nameInDatabase))
            {
                GameObject go = SequencerTools.FindSpecifier(nameInDatabase, true);
                if (go != null)
                {
                    this.transform = go.transform;
                }
            }
            var dialogueActor = DialogueActor.GetDialogueActorComponent(transform);

            if (dialogueActor == null)
            {
                Name = GetLocalizedDisplayNameInDatabase(nameInDatabase);
            }
            else
            {
                Name = dialogueActor.GetActorName();
                var actor = DialogueManager.masterDatabase.GetActor(dialogueActor.actor);
                var dialogueActorPortrait = dialogueActor.GetPortraitSprite();
                if (dialogueActorPortrait != null)
                {
                    this.portrait = dialogueActorPortrait;
                }
                else if (actor != null)
                {
                    if (portrait == null)
                    {
                        this.portrait = actor.GetPortraitSprite();
                    }
                }
            }
        }
        public virtual StandardUIMenuPanel GetPanel(Subtitle lastSubtitle, Response[] responses)
        {
            // Find player's transform & DialogueActor:
            var playerTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.transform
                : (responses != null && responses.Length > 0) ? GetActorTransformFromID(responses[0].destinationEntry.ActorID)
                : (lastSubtitle != null && lastSubtitle.listenerInfo.isPlayer) ? lastSubtitle.listenerInfo.transform
                : DialogueManager.currentActor;

            if (playerTransform == null)
            {
                playerTransform = DialogueManager.currentActor;
            }

            var playerDialogueActor = DialogueActor.GetDialogueActorComponent(playerTransform);

            // Check NPC for non-default menu panel:
            var playerUsesDefaultMenuPanel = playerDialogueActor != null && playerDialogueActor.standardDialogueUISettings.menuPanelNumber == MenuPanelNumber.Default;
            var npcTransform = (lastSubtitle != null && lastSubtitle.speakerInfo.isNPC) ? lastSubtitle.speakerInfo.transform
                : (lastSubtitle != null) ? lastSubtitle.listenerInfo.transform : DialogueManager.currentConversant;

            if (npcTransform == null)
            {
                npcTransform = DialogueManager.currentConversant;
            }
            if (playerUsesDefaultMenuPanel && npcTransform != null && m_actorPanelCache.ContainsKey(npcTransform))
            {
                // We've already cached a menu panel to use when responding to this NPC, so return it:
                return(m_actorPanelCache[npcTransform]);
            }
            var npcDialogueActor = DialogueActor.GetDialogueActorComponent(npcTransform);

            if (npcDialogueActor != null &&
                (npcDialogueActor.standardDialogueUISettings.useMenuPanelFor == DialogueActor.UseMenuPanelFor.MeAndResponsesToMe ||
                 (npcDialogueActor.standardDialogueUISettings.menuPanelNumber != MenuPanelNumber.Default &&
                  playerUsesDefaultMenuPanel)))
            {
                // NPC's DialogueActor specifies a menu panel to use when responding to it, so cache and return it:
                var npcMenuPanel = GetDialogueActorPanel(npcDialogueActor);
                if (npcMenuPanel != null)
                {
                    m_actorPanelCache[npcTransform] = npcMenuPanel;
                    return(npcMenuPanel);
                }
            }

            if (playerTransform != null)
            {
                // If NPC doesn't specify a menu panel, check for an override by player's transform:
                if (m_actorPanelCache.ContainsKey(playerTransform))
                {
                    return(m_actorPanelCache[playerTransform]);
                }
            }
            else
            {
                // If no player transform, check for an override by player actor ID:
                var playerID = (lastSubtitle != null && lastSubtitle.speakerInfo.isPlayer) ? lastSubtitle.speakerInfo.id
                    : (responses != null && responses.Length > 0) ? responses[0].destinationEntry.ActorID : -1;
                if (m_actorIdPanelCache.ContainsKey(playerID))
                {
                    return(m_actorIdPanelCache[playerID]);
                }
            }

            // Otherwise use player's menu panel:
            var panel = GetDialogueActorPanel(playerDialogueActor);

            if (panel == null)
            {
                panel = m_defaultPanel;
            }
            if (playerTransform != null)
            {
                m_actorPanelCache.Add(playerTransform, panel);
            }
            return(panel);
        }