For AI agents: the complete documentation index is available at /npc-mentality/zh/llms.txt, the full documentation bundle is available at /npc-mentality/zh/llms-full.txt, and this page is available as Markdown at /npc-mentality/zh/usage/emotion.md.
  • 简体中文
  • 基于情感的动画系统

    一行代码自动设置移动速度、动画器触发器和眨眼频率。

    概述

    传统:
      anim.Play("Idle");
    
    NPC Mentality:
      emotion.Set(Emotion.Angry);
      → 自动: 步行速度增加 / 头部摇晃 / 表情变化 / 眨眼减少

    EmotionType 枚举

    public enum EmotionType
    {
        Neutral, Happy, Angry, Sad, Afraid, Surprised, Disgusted
    }

    各情感效果

    情感NavMesh速度动画器触发器BlinkRate
    Neutral×1.0"Idle"1.0
    Happy×1.0"Happy"1.0
    Angry×1.5"Angry"0.3(减少)
    Sad×0.7"Sad"0.8
    Afraid×1.3"Afraid"1.5(增加)

    示例

    using NpcMentality;
    
    public class NPCReaction : MonoBehaviour
    {
        private NPCMemory _memory;
        private EmotionController _emotion;
    
        private void Awake()
        {
            _memory  = GetComponent<NPCMemory>();
            _emotion = GetComponent<EmotionController>();
        }
    
        public void OnTalkWithPlayer()
        {
            float attitude = _memory.GetAttitude();
    
            if (attitude < -8f)      _emotion.Set(EmotionType.Angry);
            else if (attitude < -2f) _emotion.Set(EmotionType.Disgusted);
            else if (attitude > 8f)  _emotion.Set(EmotionType.Happy);
            else                     _emotion.Set(EmotionType.Neutral);
        }
    }