unity

Unity 自定义编辑器窗口的使用

六月ゝ 毕业季﹏ 提交于 2019-12-03 13:46:44
Unity 自定义编辑器窗口功能强大,可以实现所有希望实现的功能。我在近期的项目中仿照魔兽争霸3开发了一套简单的游戏单位功能组件,其中包括单位数据、移动方式、动画播放、武器系统等等。如果用传统的Inspector来修改各项属性十分不方便,所以实现一个简单直观的自定义编辑器窗口来进行属性管理成了一个很好的选择。 创建自定义编辑器窗口并将每一项属性显示出来是十分简单的,我们只需要通过Selection.activeGameObject 来获取当前选中的物体,并在从该物体上获取相关的脚本就可以进行属性的读取。但是,如何将修改后的属性传递回指定物体并保存起来呢? 我的第一想法是通过直接访问物体上的脚本这种方法来赋值,下面将举一个简单的例子。 假设我的单位系统的移动组件命名为 MovementController 其中speed属性为移动速度,我在自定义窗口的类中写如下代码: MovementController mc = Selection .activeGameObject .GetComponent <MovementController>() ; if (mc != null) { mc .speed = EditorGUILayout .FloatField (new GUIContent( "Speed" ), mc .speed ) ; } 这些代码完成了获取组件和赋值的功能

Unity GPU Instance 无尽草地渲染

只谈情不闲聊 提交于 2019-12-03 10:49:24
问题 项目中需要渲染一大片草地,最初始的实现是使用Unity自带的地形插件,直接在地形中绘制大量的草。这种方法会导致场景中的模型顶点数爆炸,一棵草的顶点数虽然不多,但是大量的草叠加到场景中时,场景中的模型顶点数过度,会造成卡顿。 方案 shader geometry 有一个解决方案是,通过shader来绘制草,在GPU中绘制草的顶点,模拟风等动画。但是对于某些GPU,并不支持shader的顶点绘制。 GPU Instance 另外的一个方案是使用Unity 提供的 GPU Instance 方式,使用 Graphics.DrawMeshInstanced 接口传入模型,材质,位置等信息,然后由GPU批量渲染。对于手机游戏,有一定的限制,例如,单次的渲染的数量不能超过1024。具体可以参考 https://docs.unity3d.com/2019.1/Documentation/Manual/GPUInstancing.html shader code shader中需要在 pass 中声明 #pragma multi_compile_instancing ,在输入输出的结构体中声明宏 UNITY_VERTEX_INPUT_INSTANCE_ID 。 需要在shader 中模拟风吹动的效果,调用GetWinWave计算风影响的顶点位移, 然后根据顶点的高度计算位移的大小

Getting mouse position in unity

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to move a object to the mouse position. But it's giving me large x value like 300 but at that place the pre placed object's x position is -4. rigidBody.velocity = new Vector3(Input.mousePosition.x, EndPointY, 0)*4; So how can I get the current mouse position? Thank you.. 回答1: That is the current mouse position. The issue is that your objects are in world coordinates and the mouse is using screen coordinates. You need to convert the mouse position using Camera.ScreenToWorldPoint() . 回答2: Input.mousePosition will give you the

Unity - 绘制正五边形网格

妖精的绣舞 提交于 2019-12-03 10:14:22
本文简述了Unity中绘制正五边形网格的基本方法:计算顶点信息、设置三角形覆盖信息、创建配置mesh 绘制方法 基本思路:计算出 五边形顶点坐标信息 作为数组,设置 三角形包围方式 ,再创建新的mesh配置 vertices、triangle参数 ,最终赋值到当前mesh上 项目实现: 创建DrawPentagon.cs,挂在于带有mesh的物体上(本例为Quad 编写代码如下: 查看所创建的mesh信息 public class DrawPentagon : MonoBehaviour { private Vector3[] newVertices; //五边形顶点数组 private int[] newTriangles; //五边形网格内的三角形网格信息 void Start() { //1. 创建五边形顶点坐标数组:顶点编号0~4 newVertices = new Vector3[5] { Vector3.zero, new Vector3(Mathf.Cos(Mathf.Deg2Rad * 36), 0, Mathf.Sin(Mathf.Deg2Rad * 36)), new Vector3(2 * Mathf.Cos(Mathf.Deg2Rad * 36), 0, 0), new Vector3(Mathf.Cos(Mathf.Deg2Rad * 72) + 1, 0

UNITY ET 框架

梦想的初衷 提交于 2019-12-03 09:27:00
GITHUB上近3000星的开源框架,包括了服务器客户端,IL RUNTIME热等特点,对于新项目,值得拥有 来源: https://www.cnblogs.com/timeObjserver/p/11785394.html

EXIF lat/long from image in Unity

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need a c# script for unity that can read the EXIF lat/long data from a photo. i would like to place a posTransform at that location. not sure if this is possible within Unity. i would like to load my images into unity and have a script read the EXIF: 1-GPS lat/long, 2-rotation, 3-timestamp from photographs. i haven't found any info that says this can be done within unity, however, i've read about exiflib github project and other ways outside of unity. THANKS in advance for help 回答1: I maintain a project for extracting metadata from images

How to use/configure Unity Container IOC in my situation

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some trouble implementing the Unity IOC into my project reading from config file. Here is what I have 1) ClasslibraryA 2) ClasslibraryB that references ClasslibraryA 3) Winforms App that references ClasslibraryB Note: SomeOther app will reference ClassLibraryA, eg. a web service. ClasslibraryA will have to be configured for IOC depending on where it is used. eg. IDataSource will be different if it is called in the web service and when it is called from a local app. ClasslibraryB will have its own set of dependencies as well to be

Google Authentication in Android Unity Plugin

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working on an Android application that includes communication with the Amazon S3 servers. The app is being developed in Unity and I would like to include a system so that the users can authenticate with their Google Accounts and then use those credentials to access the S3 server through Cognito. To do that, I need to implement a Google Authenticator system in Unity, and I am having a hard time figuring out how to do it. My current approach consists in creating a Plugin with Android Studio to access the Google Sign In API, but every time

unity game can not be simulated on iPhone 4s

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was trying to run my unity game on iPhone 4s simulator using Xcode to produce some screen shots for iTunes connect. There are several problems I encountered on the way and tons of confusion hoping someone might shine some light here. I have tried all other simulators (iPads, iPhones) and never had any problems. When I select simulator SDK in the player setting i notice that "architecture" field is greyed out and changed from "Universal" to "x86_64" When I open Xcode I can't select iPhone 4s as a simulator to run this build on. In order to