
开源Unity软件包与 DeepSeek API 无缝集成,在 Unity 项目中实现高级推理、聊天和任务自动化。包括示例场景、简单的 API 设置和全面的脚本,供开发人员构建更智能的交互式体验
适用于 Unity 项目的 DeepSeek AI API 的轻量级、易于使用的开源集成软件包。此开源软件包允许 Unity 开发人员使用 DeepSeek 强大的语言模型快速实现 AI 驱动的聊天功能。
·
一、软件介绍
文末提供程序和源码下载
适用于 Unity 项目的 DeepSeek AI API 的轻量级、易于使用的开源集成软件包。此开源软件包允许 Unity 开发人员使用 DeepSeek 强大的语言模型快速实现 AI 驱动的聊天功能。
二、软件特征
- 在 Unity 项目中与 DeepSeek API 轻松集成
- 支持流式和非流式聊天完成
- 与多个 DeepSeek 模型(DeepSeek Chat、DeepSeek Reasoner)兼容
- 用于聊天交互的即用型 UI 组件
- 通过 Unity Inspector 进行可自定义的 API 设置
- 适用于 Unity 支持的所有平台
三、要求
- Unity 2020.3 LTS 或更高版本
- TextMeshPro 包(包含在较新的 Unity 版本中)
- DeepSeek API 密钥(从 DeepSeek 网站获取)
安装
选项 1:Unity Package Manager (文末提供下载)
- 打开 Unity 项目
- 转到 Window > Package Manager
- 点击左上角的“+”按钮
- 选择 “Add package from git URL...”
- 输入存储库 URL:
https://github.com/yagizeraslan/DeepSeek-Unity.git
- 点击 “Add”
选项 2:手动安装
- 下载或克隆此存储库
- 将
DeepSeek
文件夹复制到 Unity 项目的Assets
文件夹中
选项 3:Unity Asset Store
- 在浏览器中或通过 Unity 打开 Unity Asset Store
- 搜索 “DeepSeek API Integration”
- 购买或下载软件包
- 将包导入到您的项目中
快速开始
- 将
DeepSeekChat
预制件添加到场景中 - 在 Inspector 中输入您的 DeepSeek API 密钥
- 通过 Inspector 自定义聊天外观和行为
- 按 Play 开始测试
四、示例用法
基本聊天实现
using UnityEngine;
using DeepSeek;
public class DeepSeekExample : MonoBehaviour
{
[SerializeField] private string apiKey = "YOUR-API-KEY";
private DeepSeekApi deepSeekApi;
private void Start()
{
// Initialize the API
deepSeekApi = new DeepSeekApi(apiKey);
// Send a simple request
SendSimpleMessage();
}
private async void SendSimpleMessage()
{
var request = new ChatCompletionRequest
{
Model = DeepSeekModel.DeepSeekV3.ToModelString(),
Messages = new System.Collections.Generic.List<ChatMessage>
{
new ChatMessage { Role = "system", Content = "You are a helpful assistant." },
new ChatMessage { Role = "user", Content = "Hello, who are you?" }
},
Temperature = 0.7f,
Stream = false
};
var response = await deepSeekApi.CreateChatCompletion(request);
if (response != null && response.Choices != null && response.Choices.Count > 0)
{
Debug.Log("DeepSeek Response: " + response.Choices[0].Message.Content);
}
}
}
流式处理响应示例
private async void SendStreamingMessage()
{
var request = new ChatCompletionRequest
{
Model = DeepSeekModel.DeepSeekV3.ToModelString(),
Messages = new System.Collections.Generic.List<ChatMessage>
{
new ChatMessage { Role = "system", Content = "You are a helpful assistant." },
new ChatMessage { Role = "user", Content = "Write a short story about a robot." }
},
Temperature = 0.7f,
Stream = true
};
await deepSeekApi.CreateChatCompletionStreaming(request, HandleStreamingResponse);
}
private void HandleStreamingResponse(ChatMessage partialMessage, bool isDone)
{
// Update UI with partial response
Debug.Log("Partial response: " + partialMessage.Content);
if (isDone)
{
Debug.Log("Streaming complete!");
}
}
高级配置
可用型号
该集成支持多个 DeepSeek 模型:
// Use DeepSeek Chat
var model = DeepSeekModel.DeepSeekV3;
// Use DeepSeek Reasoner
var model = DeepSeekModel.DeepSeekR1;
自定义聊天 UI
您可以通过修改场景中的预制件或 UI 组件来自定义聊天界面的外观:
- 在场景中选择 DeepSeekChat GameObject
- 在 Inspector 中修改属性:
- 聊天滚动视图的高度和宽度
- 消息气泡出现
- 输入字段大小和位置
- 字体样式和颜色
五、软件下载
本文信息来源于GitHub作者地址:https://github.com/yagizeraslan/DeepSeek-Unity
更多推荐
所有评论(0)