我正在尝试模拟具有内部重力的船舶/空间站。
为了实现这一点,我将玩家和飞船的所有内容都设为飞船的子级。飞船本身有对撞机,但没有刚体组件。这个想法是随着船的移动,它的所有内容也会移动。到目前为止非常简单。
为了模拟飞船中的重力,玩家控制器和所有刚体都关闭了默认重力。代替标准,每一帧都沿着母船的负向上向量施加一个力。
这种工作,但有一个主要问题我必须在这件事稳固之前解决。所有刚体都非常缓慢地在船内部滑动。
我知道这可能是由于地板的更新位置加上重力导致某种剪切力。物体总是逆着船的旋转而滑动。
我已经尝试过将物理材料的所有物理属性拖到质量上等等。这些都没有奏效,而且我很确定这是由于地板在移动的基本事实,即使 RB是地板所属对象的子项。
任何人都有解决方案,而不是某种胶带?我可以尝试使一切都成为动态的,并且仅在发生某些外部碰撞或其他事情时才“唤醒”,但这可能会变得非常麻烦。我需要它以尽可能多的通用方式工作。
一些代码:
在船上
void Update ()
{
transform.Rotate(new Vector3(Time.deltaTime * 0.125f,Time.deltaTime*0.5f,0));
}
void FixedUpdate()
{
Vector3 tempVec;
foreach(Rigidbody rb in rigidBodies)
{
//Gravity!!
tempVec = transform.up * -9.81f * rb.mass * Time.deltaTime;
rb.AddForce(tempVec, ForceMode.Acceleration);
}
}
Run Code Online (Sandbox Code Playgroud)
我还开发了一个版本,其中船跟随刚体的运动。我无法直接进行育儿,因此我必须简单地在每一帧手动设置变换以匹配物理代理。这仍然具有与上述相同的效果,尽管这可能是我最终想要移动船的方式,因为这将更恰当地与飞行机制联系起来。
.NET 4.0 ConditionalWeakTable<T>实际上是一个字典,其中字典的键被弱引用并且可以被收集,这正是我需要的.问题是我需要能够从这本字典中获取所有实时密钥,但MSDN声明:
它不包括字典通常具有的所有方法(例如GetEnumerator或Contains).
是否有可能从一个ConditionalWeakTable<T>?检索实时密钥或键值对?
通常我可以使用图像定位或云识别制作应用程序,但现在我需要使用物理建筑作为目标,所以我的问题是有谁知道如何通过vuforia + unity或vuforia android识别建筑物?
我在youtube上找到了一个应用程序,只是想知道它应该如何创建.
我们将从一个独立的故事开始,只是让你理解为什么:我想要处理任何针对同一个接口更改数据的操作:ICommand存在一些名为ICommandHandlers的东西,可以处理我想要的任何命令.所以,如果我想要一个CreatePersonCommand,我需要一个CreatePersonCommandHandler.
所以这是控制台应用程序的主体,它演示了这一点:(需要简单的注入器)
// The e.g. CreatePersonCommand, with TResult being Person, as an example.
public interface ICommand<TResult>
{
}
//This handles the command, so CreatePersonCommandHandler
public interface ICommandHandler<in TCommand, out TResult>
where TCommand : ICommand<TResult>
{
TResult Handle(TCommand command);
}
// Imagine a generic CRUD set of operations here where we pass
// in an instance of what we need made
public class CreateBaseCommand<TModel> : ICommand<TModel>
{
public TModel ItemToCreate { get; set; }
}
public class DeleteBaseCommand<TModel> : …Run Code Online (Sandbox Code Playgroud) c# generics dependency-injection inversion-of-control simple-injector
我正在尝试切换到Simple Injector Dependency Injection框架,因为我对它的速度印象深刻.
private static void RegisterServices(Container container)
{
container.RegisterPerWebRequest<IDbContext, DbContext1>();
////container.RegisterPerWebRequest<IDbContext, DbContext2>();
container.RegisterPerWebRequest<IUnitOfWork, UnitOfWork>();
container.RegisterPerWebRequest<IColourRepository, ColourRepository>();
Run Code Online (Sandbox Code Playgroud)
其中DbContext1和DbContext2继承自BaseDbContext类
public class BaseDbContext<TContext> : DbContext, IDbContext where TContext : DbContext
Run Code Online (Sandbox Code Playgroud)
它实现了一个相当简单的IDbContext接口(就像在SO上提供的许多接口),例如:
public interface IDbContext
{
IQueryable<TEntity> Find<TEntity>() where TEntity : class;
DbSet<TEntity> Set<TEntity>() where TEntity : class;
int SaveChanges();
void Dispose();
}
Run Code Online (Sandbox Code Playgroud)
如果我只使用一个DbContext类,它可以正常工作 - 存储库被注入,数据被拉出等.
但是,我还想在每个中使用带有少量DbSet的有界上下文(使用DDD有界上下文缩小EF模型),因为我的Code-First DbContext将包含数百个类
private static void RegisterServices(Container container)
{
container.RegisterPerWebRequest<IDbContext, DbContext1>();
container.RegisterPerWebRequest<IDbContext, DbContext2>();
container.RegisterPerWebRequest<IUnitOfWork, UnitOfWork>();
container.RegisterPerWebRequest<IColourRepository, ColourRepository>();
Run Code Online (Sandbox Code Playgroud)
然后我得到一个例外:
System.InvalidOperationException未由用户代码处理HResult = -2146233079消息=类型IDbContext已经注册,并且容器当前未配置为允许覆盖注册.要允许覆盖当前注册,请将Container.Options.AllowOverridingRegistrations设置为true.Source = …
我正在戴尔桌面上安装Ubuntu 13.10.我已经安装了sqldeveloper并在我的Desktop/dir中创建了一个sqldeveoper.desktop文件来启动该程序.见下面的代码.我的问题是:在我的桌面屏幕上,我看到.desktop文件是一个sqldeveloper图标(带有绿色箭头的圆形db图标).我双击图标,程序启动.图标出现在我的Unity栏中,然后图像变为'?' 问号符号.
任何想法为什么会这样?icon.png(图像)位于桌面文件指向的位置.也许文件没有从Unity栏中正确看到路径?
sqldeveloper.desktop代码:
[Desktop Entry]
Type=Application
Version=1.0
Name=SQL Developer
GenericName=Oracle Development Environment
Comment=Proprietary environment for managing Oracle databases
Exec=sqldeveloper %F
Icon=/opt/sqldeveloper/icon.png
Terminal=false
Categories=Development;IDE;
StartupNotify=true
Run Code Online (Sandbox Code Playgroud)
感谢您的任何指导.JohnC
我已经更新到structuremap 3,现在我不能使用FillAllPropertiesOfType进行setter注入.
它是否已被弃用,我应该使用什么呢?
c# structuremap dependency-injection ioc-container structuremap3
我有一堆与REST和SOAP一起使用的WCF服务.我创建了一个WCF属性,用于检查当前的httpcontext是否存在,如果存在,则使用cookie身份验证,其他方式使用自定义WCF身份验证.
我的属性如下所示:
Public Class AuthRequired
Inherits Attribute
Implements IOperationBehavior, IParameterInspector
Public Sub AddBindingParameters(operationDescription As OperationDescription, bindingParameters As Channels.BindingParameterCollection) Implements IOperationBehavior.AddBindingParameters
End Sub
Public Sub ApplyClientBehavior(operationDescription As OperationDescription, clientOperation As ClientOperation) Implements IOperationBehavior.ApplyClientBehavior
End Sub
Public Sub ApplyDispatchBehavior(operationDescription As OperationDescription, dispatchOperation As DispatchOperation) Implements IOperationBehavior.ApplyDispatchBehavior
dispatchOperation.ParameterInspectors.Add(Me)
End Sub
Public Sub Validate(operationDescription As OperationDescription) Implements IOperationBehavior.Validate
End Sub
Public Sub AfterCall(operationName As String, outputs() As Object, returnValue As Object, correlationState As Object) Implements IParameterInspector.AfterCall
End Sub
Public Function BeforeCall(operationName As String, inputs() …Run Code Online (Sandbox Code Playgroud) 我从 Autofac 收到此错误消息;:
在类型 'MyService`1[MyContext]' 上找到的带有 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' 的构造函数都不能用可用的服务和参数调用:无法解析构造函数 'Void .ctor 的参数 'MyContext context' (MyContext)'。
错误发生在这行代码上(也显示在下面的代码中):
IMyService myService = container.Resolve<IMyService>(); // error here
Run Code Online (Sandbox Code Playgroud)
我有兴趣注意到,当我在我的注册中包含这一行时,一切正常:
builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
Run Code Online (Sandbox Code Playgroud)
当我注册 AnyConcreteType 时,这一切都有效...这一事实让我相信我没有注册某些东西。我的问题是我没有注册什么?错误消息似乎将 MyContext 命名为罪魁祸首,但显然我正在按如下所示进行注册。
我真的不想使用 AnyConcreteType ......因为我只想明确注册我需要的类。
我的服务是这样构建的:
public class MyService<T> : BaseService<T>, IMyService where T:DbContext,IMyContext
{
public MyService(T context) : base(context)
{
}
}
Run Code Online (Sandbox Code Playgroud)
MyService 派生自 BaseService:
public abstract class BaseService<T> : IDisposable where T:DbContext, IMyContext
{
internal T db;
public BaseService(T context)
{
db = context;
}
}
Run Code Online (Sandbox Code Playgroud)
MyContext 传递给 MyService 并构造如下: …
我有一个类需要IPrinciple根据当前经过身份验证的用户设置构造对象.
我找到了一些我试过的其他代码,但它没有用:
private readonly Lazy<IPrincipal> _principal;
public MyService(Lazy<IPrincipal> principal)
{
_principal = principal;
}
Run Code Online (Sandbox Code Playgroud)
我像这样配置了Simple Injector:
container.Register(() => new Lazy<IPrincipal>(() => HttpContext.Current.User));
Run Code Online (Sandbox Code Playgroud)
_principal当我尝试运行它时,显然是未定义/未设置为对象的实例.
我也尝试过:
container.Register(() => new Lazy<IPrincipal>(() => Thread.CurrentPrincipal));
Run Code Online (Sandbox Code Playgroud)
这让我可以检查,_principal.Value.Identity.IsAuthenticated但总是回来false.
c# ×6
.net ×2
android ×1
asp.net-mvc ×1
attributes ×1
autofac ×1
generics ×1
icons ×1
physics ×1
rigid-bodies ×1
structuremap ×1
ubuntu-13.10 ×1
ubuntu-unity ×1
vuforia ×1
wcf ×1