unity3d

(2)ASP.NET Core 依赖关系注入(服务)

五迷三道 提交于 2021-02-10 11:25:27
1.前言 面向对象设计(OOD)里有一个重要的思想就是依赖倒置原则(DIP),并由该原则牵引出依赖注入(DI)、控制反转(IOC)及其容器等老生常谈的概念,初学者很容易被这些概念搞晕(包括我在内),在学习Core依赖注入服务之前,下面让我们先了解下依赖倒置原则(DIP)、依赖注入(DI)、控制反转(IOC)等概念,然后再深入学习Core依赖注入服务。 2.依赖倒置原则(DIP) 高层模块不依赖于低层模块的实现,而低层模块依赖于高层模块定义的接口 。通俗来讲,就是高层模块定义接口,低层模块负责实现。 2.依赖注入(DI) 2.1依赖(D) 当一个类需要另一个类协作来完成工作的时候就产生了依赖。 示例1: public class MyDependency { public MyDependency() { } public Task WriteMessage( string message) { Console.WriteLine($ " MyDependency.WriteMessage called. Message: {message} " ); return Task.FromResult( 0 ); } } public class IndexModel : PageModel { MyDependency _dependency = new MyDependency();

(C#) How to copy classes by value type and not reference type?

做~自己de王妃 提交于 2021-02-10 06:40:28
问题 Take the following code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyClass { public int myNumber; } public class Test : MonoBehaviour { MyClass class1 = new MyClass(); MyClass class2 = new MyClass(); void Start() { class1.myNumber = 1; class2 = class1; class2.myNumber = 2; Debug.Log(class1.myNumber); //output: 2 (I'd want it to output 1!!!) } } Now, if I understood correctly, in C# classes are a reference type and not a value type, so this

How to change animation curves to be linear in editor?

放肆的年华 提交于 2021-02-10 06:31:07
问题 I add a rotation animation to a wheel but the wheel does not rotate smoothly. I find the reason is because the curve of the rotation animation is not linear. However after trying out almost all the buttons and options in the editor, I can not find a way to make the curve of the animation to be linear. Does anyone know how to get animations with linear curve in unity editor. 回答1: I found the solution by myself and it is very simple. You just open up the animation in the animation window and

Unity: Texture2D ReadPixels for specific Display

£可爱£侵袭症+ 提交于 2021-02-10 06:21:15
问题 Unity has had support for multiple display outputs for a while now (up to 8). With the ReadPixels function, you can specify an area to read from, and an origin coordinate. But I cannot specify a display number to perform the read on. I need to be able to read pixels from a specific display (1-8) with a specific area and origin point. How can I do this, please? 回答1: You can achieve ReadPixels for a specific screen/display. You have to do the following: Before I start, I assume you have a

What does Unity's Mathf.PingPong actually do?

安稳与你 提交于 2021-02-10 05:43:52
问题 The Unity Docs for Mathf.PingPong says: PingPongs the value t , so that it is never larger than length and never smaller than 0 . I get that it's rotating a value between 0 and length , what I don't get is what is the value t doing and how does it relate to how PingPong works? If I set t to any constant, I always get that value back void Update() { // always prints: 1 print(Mathf.PingPong(1f, 1f)); // always prints 0 print(Mathf.PingPong(0f, 1f)); } Every time I see PingPong used in examples

Moving a 2D physics body on a parabolic path with initial impulse in unity

送分小仙女□ 提交于 2021-02-10 05:10:27
问题 What I have: A projectile in Unity 5 2D, affected by gravity, that I want to move from point A to point B with initial impulse on a parabolic path What I know: The 2D coordinates of a random starting position (A) The 2D coordinates of a random target position (B) The time (X) I want the body to reach the target position after What I want to know: The initial impulse (as in unity applyforce with forcemode impulse) that I have to apply to the body onetime in order for it to reach the desired

Unity3d和Android之间互相调用

女生的网名这么多〃 提交于 2021-02-09 11:09:24
摘抄博客 Unity3d Android SDK接入解析(一)Unity3d 与 Android之间的互相调用 ,一共四章,一定要看完 No1: 总体来说Unity3d与Android之间的互相调用,是通过Unity3d提供的classes.jar来实现的 No2: 常见的方法就是 1)在Android层定义好接口 2)在Unity中通过反射调用(反射大法好啊,真是好) No3: UnityPlayer是FrameLayout的一个子类,而currentActivity则是UnityPlayer类中的静态对象。 No3: 我们一般建立了一个新的MyActivity继承UnityPlayerActivity,并在AndroidManifest中把MyActivity设置为启动的Activity,然后使用currentActivity这个jo来调用方法。 No4: 新版Unity生成的unity-class.jar中类的继承关系变简单了: UnityPlayerActivity->Activity,之前的UnityPlayerNativeActivity被废弃了 No5: UnityPlayerActivity中 mUnityPlayer = new UnityPlayer( this ); 把上下文传进去 在UnityPlayer中 public UnityPlayer

Unity Shader - How to efficiently recolor specific coordinates?

做~自己de王妃 提交于 2021-02-08 13:23:50
问题 First, please allow me to explain what I've got and then I'll go over what I'm trying to figure out next. What I've got I've got a textured custom mesh with some edges that exactly align with integer world coordinates in Unity. To the mesh I've added my own crude yet effective custom surface shader that looks like this: Shader "Custom/GridHighlightShader" { Properties { [HideInInspector]_SelectionColor("SelectionColor", Color) = (0.1,0.1,0.1,1) [HideInInspector]_MovementColor("MovementColor",

how to Combine between playfab and photon friend's info

寵の児 提交于 2021-02-08 09:49:17
问题 I am using pun 2 and playfab. I did that every time you add a new friend it adds him to a playfab list, this is good because I can add a friend in any time, not like pun 2 but I can't see if friends are online and get the friends room name(photon option). the problem is that I convert from playfab to photon. is there a way to do it? here is my playfab code private void DisplayPlayfabFriends(List<PlayFab.ClientModels.FriendInfo> friendCache) { foreach (PlayFab.ClientModels.FriendInfo f in

Closing threads in Unity with C#

梦想与她 提交于 2021-02-08 08:30:31
问题 I'm wanting to make sure that when my application quits that any and all open threads are closed. However when I try to do so I get the error telling me that there is no reference object for what I'm trying to do, even though it's all in the same class. Can someone please help me out? Starting / opening threads: Thread listen_thread; TcpListener tcp_listener; Thread clientThread; // Use this for initialization void Start () { IPAddress ip_addy = IPAddress.Parse(ip_address); tcp_listener = new