我创建了一个新的 Unity 项目并安装了新输入系统的包。基本上我只想存储点击(桌面)/点击(移动)的位置,就是这样。
我知道旧系统提供了解决方案
但我想用新的输入系统解决它。
我从这个输入地图配置开始(我将显示每个选定项目的配置)
我创建了一个新脚本记录每个点击/点击位置
public class FooBar : MonoBehaviour
{
public void Select(InputAction.CallbackContext context)
{
Vector2 selectPosition = context.ReadValue<Vector2>();
Debug.Log($"Select position is: {selectPosition.x}|{selectPosition.y}");
}
}
Run Code Online (Sandbox Code Playgroud)
在场景中我创建了一个空的游戏对象并在检查器中配置它
不幸的是,在运行播放模式时,每次移动鼠标时都会出现这些错误
这是第一条错误消息的堆栈跟踪
这是第二条错误消息的堆栈跟踪
所以我假设我的输入地图配置是错误的。
有人介意帮我设置一个输入配置,将点击/点击位置传递给脚本吗?
因此,为了快速解决此问题,我目前将此代码与旧输入系统一起使用,但我真的不喜欢它;)
public sealed class SelectedPositionStateController : MonoBehaviour
{
private void Update()
{
#if UNITY_ANDROID || UNITY_IOS
if (UnityEngine.Input.touchCount > 0)
{
Touch touch = UnityEngine.Input.GetTouch(0);
// do things with touch.position
}
#elif UNITY_STANDALONE
if (UnityEngine.Input.GetMouseButtonDown(0))
{
// do things with Input.mousePosition
}
#endif
} …Run Code Online (Sandbox Code Playgroud) I created an extension method to add all JSON configuration files to the IConfigurationBuilder
public static class IConfigurationBuilderExtensions
{
public static IConfigurationBuilder AddJsonFilesFromDirectory(
this IConfigurationBuilder configurationBuilder,
IFileSystem fileSystem,
string pathToDirectory,
bool fileIsOptional,
bool reloadConfigurationOnFileChange,
string searchPattern = "*.json",
SearchOption directorySearchOption = SearchOption.AllDirectories)
{
var jsonFilePaths = fileSystem.Directory.EnumerateFiles(pathToDirectory, searchPattern, directorySearchOption);
foreach (var jsonFilePath in jsonFilePaths)
{
configurationBuilder.AddJsonFile(jsonFilePath, fileIsOptional, reloadConfigurationOnFileChange);
}
return configurationBuilder;
}
}
Run Code Online (Sandbox Code Playgroud)
and want to create tests for it using xUnit. Based on
GameObjects我场景中的一些实现了交互ISaveable。在我的脚本中,我想找到所有这些接口并存储它们。稍后我可以遍历它们并调用它们的实现方法SaveData()。
我目前找到这些接口的解决方法:
List<ISaveable> saveables = new List<ISaveable>();
MonoBehaviour[] sceneObjects = FindObjectsOfType<MonoBehaviour>();
for (int i = 0; i < sceneObjects.Length; i++)
{
MonoBehaviour currentObj = sceneObjects[i];
ISaveable currentComponent = currentObj.GetComponent<ISaveable>();
if (currentComponent != null)
{
saveables.Add(currentComponent);
}
}
Run Code Online (Sandbox Code Playgroud)
代码工作正常,但有更好的方法吗?我不想在场景中搜索每个 Monobehaviour 然后尝试获取其界面组件。
所以这里有一个官方的例子
https://github.com/kamilmysliwiec/nest-cqrs-example
我尝试为三个简单的功能创建自己的功能:
我正在使用 TypeORM 并且有一个基本的 User 实体。因此,基于官方示例代码,我创建了一个用于创建用户 ( create.user.handler.ts)的命令处理程序:
@CommandHandler(CreateUserCommand)
export class CreateUserHandler implements ICommandHandler<CreateUserCommand> {
constructor(
private readonly usersRepository: UsersRepository,
private readonly eventPublisher: EventPublisher,
) {}
public async execute(command: CreateUserCommand): Promise<void> {
const createdUser: User = await this.usersRepository.createUser(
command.username,
command.password,
);
// const userAggregate: UserAggregate = this.eventPublisher.mergeObjectContext(
// createdUser,
// );
// userAggregate.doSomething(createdUser);
// userAggregate.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
它所做的只是将一个新的用户实体持久化到数据库中。但是我现在没有得到的是如何处理 User 聚合。合并对象上下文时,我无法传入创建的用户实体。而且我不知道聚合应该处理哪个逻辑。因此,基于此用户聚合 ( user.model.ts):
export class User extends AggregateRoot {
constructor(private readonly id: …Run Code Online (Sandbox Code Playgroud) 目前我使用该class-transformer包将可选值转换为默认值
@IsString()
@IsOptional()
@Transform((description: string) => description || '')
public description: string;
Run Code Online (Sandbox Code Playgroud)
出现了两个问题。
所以基本上我想创建一个将可选值转换为默认值的函数,我当前的方法是:
function transformValueIfUndefined<TValue>(value: TValue, fallbackValue: TValue): TValue {
if (value === undefined) {
return fallbackValue;
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
Transform现在我可以在装饰器中使用这个函数
@Transform((description: string) => transformValueIfUndefined(description, ''))
Run Code Online (Sandbox Code Playgroud)
但正如您所看到的,这不值得付出努力。有没有一种方法可以创建我自己的转换装饰器以及class-validator转换class-transformer可选值?
我的自定义装饰器应该是这样的
@TransformOptionalValueIfUndefined('')
Run Code Online (Sandbox Code Playgroud) 我有一个 Github 存储库,在本地安装了commitlint 和 husky,并希望在验证拉取请求时设置一个在每次推送提交时运行 commitlint 的工作流。在主分支上,较旧的提交不遵循传统的提交规则。
我根据此评论创建了一个单独的分支
https://github.com/conventional-changelog/commitlint/issues/586#issuecomment-657226800
我从这个工作流程开始
name: Run commitlint on pull request
on: pull_request
jobs:
run-commitlint-on-pull-request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Install dependencies
run: npm install
- name: Validate all commits from PR
run: npx commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD --verbose
Run Code Online (Sandbox Code Playgroud)
我按照传统的提交规则又做了两次提交并开始了拉取请求
我想到的第一个解决方案是重新设置所有内容并重命名每个提交以遵循规则,但这需要付出巨大的努力。
我不确定我是否必须在这里改进这条线
npx commitlint --from HEAD~${{ github.event.pull_request.commits }} …
我想为我的 Vue 应用程序提供游戏手柄支持。我想听来自Gamepad API的事件。
我不想将这些侦听器附加到组件上,因为我必须全局处理它们。那么我应该在哪里附加这些听众呢?我是否应该将每个事件添加到App.vue组件中,因为它是应用程序的根?
我想用 Vuex 处理游戏手柄输入和状态。有没有办法可以通过操作(/或突变)直接监听浏览器事件?设置我的动作像......
export default {
on_browser_gamepadconnected: ({ commit }, e) => {
// do something
},
};
Run Code Online (Sandbox Code Playgroud) 我创建了一个非常小的复制存储库。
还请查看下面我可能的修复方法。
我有一个图形和一个图形节点实体。图只知道它的起始图节点,节点本身知道它属于哪个图及其后继图。
@Entity()
export class Graph extends BaseEntity {
@PrimaryGeneratedColumn("uuid")
public id: string;
@Column({ nullable: true })
public startNodeId?: string;
@ManyToOne(() => GraphNode)
@JoinColumn({ name: "startNodeId" })
public startNode?: GraphNode;
}
@Entity()
export class GraphNode extends BaseEntity {
@PrimaryGeneratedColumn("uuid")
public id: string;
@PrimaryColumn("uuid")
public graphId: string;
@ManyToOne(() => Graph, { onDelete: "CASCADE" })
@JoinColumn({ name: "graphId" })
public graph: Graph;
@Column({ nullable: true })
public successorGraphNodeId?: string;
@ManyToOne(() => GraphNode)
@JoinColumn({ name: "successorGraphNodeId" })
public successorGraphNode?: GraphNode; …Run Code Online (Sandbox Code Playgroud) 我想使用 Tailwind CSS 创建一个新的 Angular 项目。我当前的 CLI 版本是 10.1.1。到目前为止我做过的事情:
ng new my-appnpm i tailwindcss postcss-import postcss-loader postcss-scss @angular-builders/custom-webpack -D.
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
Run Code Online (Sandbox Code Playgroud)
npx tailwind init.
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
loader: "postcss-loader",
options: {
ident: "postcss",
syntax: "postcss-scss",
plugins: () => [
require("postcss-import"),
require("tailwindcss"),
require("autoprefixer"),
],
},
},
],
},
};
Run Code Online (Sandbox Code Playgroud)
我创建了一个新的 .Net 5 项目并想使用 EF Core。我使用自动生成了多个 migration.cs 文件
dotnet ef migrations add MyMigration
并希望应用它们(用于开发和生产)。我知道这个MigrateAsync方法,所以我阅读了如何在启动时调用这个方法
https://andrewlock.net/running-async-tasks-on-app-startup-in-asp-net-core-part-1/
但在我读到的任何地方,这种方法都不应该用于生产,因为这些迁移不会在单个事务中执行(没有错误回滚)。
不幸的是,无论环境如何,都没有太多关于如何做到这一点的资源,我找到了这篇文章
一种选择可能是调用迁移的控制台应用程序
但我无法理解这种方法的区别,因为它没有解决事务问题?
在开发/生产期间应用迁移的最佳实践是什么?
在自动生成迁移之后,我非常喜欢简单性,dotnet ef database update这项工作不需要我使用其他工具吗?
创建一个控制台应用程序,从迁移生成 .sql 文件,安装 DbUp 并将其用于迁移部分?
c# ×4
javascript ×2
nestjs ×2
typescript ×2
angular ×1
angular-cli ×1
cqrs ×1
dbup ×1
git ×1
postgresql ×1
pull-request ×1
push ×1
tailwind-css ×1
typeorm ×1
vue.js ×1
vuex ×1
webpack ×1