unity 建筑可视化怎么把挡在人物前面的建筑隐藏

How to use Git for Unity3D source control? - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 7.5 million programmers, just like you, helping each other.
J it only takes a minute:
What are best practices for using
source control with Unity 3D, particularly in dealing with the binary nature of Unity 3D projects? Please describe the workflow, what paths would be included in .gitignore, what settings should be set in Unity and/or the project, and any other special things that should be noted.
Note: I realize that using the Asset Server is the Unity-recommended way, but I would like to use Git for a variety of reasons. Please no answers that state or argue that I should just use the Asset Server. The Asset Server really isn't an option for me.
4,88922050
4,21331432
The following is an excerpt from .
Using Git with 3D Games
Update Oct 2015: GitHub has since released a plugin for Git called
that directly deals with the below problem. You can now easily and efficiently version large binary files!
Git can work fine with 3D games out of the box. However the main caveat here is that versioning large (>5&MB) media files can be a problem over the long term as your commit history bloats. We have solved this potential issue in our projects by only versioning the binary asset when it is considered final. Our 3D artists use
to work on
assets, both for the reason above and because it's much faster and simpler (not many artists will actively want to use Git!).
Git Workflow
Your Git workflow is very much something you need to decide for yourself given your own experiences as a team and how you work together. However. I would strongly recommend the appropriately named Git Flow methodology .
I won't go into too much depth here on how the methodology works as the author describes it perfectly and in quite few words too so it's easy to get through. I have been using with my team for awhile now, and it's the best workflow we've tried so far.
Git GUI Client Application
This is really a personal preference here as there are quite a few options in terms of Git GUI or whether to use a GUI at all. But I would like to suggest the free
as it plugs in perfectly with the Git Flow extension. Read the
on implementing the Git Flow methodology in their application.
Unity3D Ignore Folders
For an up to date version checkout
without OS specifics.
# =============== #
# Unity generated #
# =============== #
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
*.userprefs
*.unityproj
# ============ #
# OS generated #
# ============ #
.DS_Store?
.Spotlight-V100
ehthumbs.db
Unity3D Settings
For versions of Unity 3D v4.3 and up:
(Skip this step in v4.5 and up) Enable External option in Unity → Preferences → Packages → Repository.
Open the Edit menu and pick Project Settings → Editor:
Switch Version Control Mode to Visible Meta Files.
Switch Asset Serialization Mode to Force Text.
Save the scene and project from File menu.
Additional Configuration
One of the few major annoyances one has with using Git with Unity3D projects is that Git doesn't care about directories and will happily leave empty directories around after removing files from them. Unity3D will make *.meta files for these directories and can cause a bit of a battle between team members when Git commits keep adding and removing these meta files.
to the /.git/hooks/ folder for repositories with Unity3D projects in them. After any Git pull/merge, it will look at what files have been removed, check if the directory it existed in is empty, and if so delete it.
5,55712244
6,90932342
In Unity 4.3 you also had to enable External option from preferences, but since Unity 4.5 they dropped option for that, so full setup process looks like:
Switch to Visible Meta Files in Editor → Project Settings → Editor → Version Control Mode
Switch to Force Text in Editor → Project Settings → Editor → Asset Serialization Mode
Save scene and project from File menu
Also our team is using a bit more extended .gitignore file:
# =============== #
# Unity generated #
# =============== #
# ===================================== #
# Visual Studio / MonoDevelop generated #
# ===================================== #
ExportedObj/
*.userprefs
*.unityproj
# ============ #
# OS generated #
# ============ #
.DS_Store?
.Spotlight-V100
ehthumbs.db
Note that the only folders you need to keep under source control are Assets and ProjectSettings.
More information about keeping Unity Project under source control you can find in .
1,21811320
What is GIT?
Git is a free and open source
distributed version control system (SCM) developed by Linus Torvalds in 2005 ( Linux OS founder). It is created to control everything rom small to large projects with speed and efficiency. Leading companies like Google, Facebook, Microsoft uses GIT everyday.
If you want to learn more about GIT check this ,
First of all make sure you have your Git environment set up.You need to set up both your local environment and a Git repository (I ).
GIT client application Mac/Windows
For GIT gui client application i recommended you to go ,
GitHub is the place to share code with friends, co-workers, classmates, and complete strangers. Over five million people use GitHub to build amazing things together.
Unity3d settings
You need to do these settings
Switch to Visible Meta Files in Edit → Project Settings → Editor → Version Control Mode.
Enable External option in Unity → Preferences → Packages → Repository
Switch to Force Text in Edit → Project Settings → Editor → Asset Serialization Mode.
To add to everything stated, it it also ideal to use
with Unity. I have been using this since it came out and it has had no trouble.
You will want to add this .gitattributes next to your .gitignore file
*.cs diff=csharp text
*.cginc text
*.shader text
*.mat merge=unityyamlmerge eol=lf
*.anim merge=unityyamlmerge eol=lf
*.unity merge=unityyamlmerge eol=lf
*.prefab merge=unityyamlmerge eol=lf
*.physicsMaterial2D merge=unityyamlmerge eol=lf
*.physicsMaterial merge=unityyamlmerge eol=lf
*.asset merge=unityyamlmerge eol=lf
*.meta merge=unityyamlmerge eol=lf
*.controller merge=unityyamlmerge eol=lf
*.a filter=lfs diff=lfs merge=lfs -text
*.mp3 filter=lfs diff=lfs merge=lfs -text
*.wav filter=lfs diff=lfs merge=lfs -text
*.aif filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.exr filter=lfs diff=lfs merge=lfs -text
*.fbx filter=lfs diff=lfs merge=lfs -text
*.FBX filter=lfs diff=lfs merge=lfs -text
*.rns filter=lfs diff=lfs merge=lfs -text
*.reason filter=lfs diff=lfs merge=lfs -text
*.lxo filter=lfs diff=lfs merge=lfs -text
That is my rolling file list. If you use additional binary files not lists, add them.
I also have files configured to use yamlmerge, you would need to set this up. You can read about it here:
I thought that I might post a simpler .gitignore for anyone that is interested:
# Ignore Everything
# Except for these:
!/.gitignore
!/ProjectSettings
6,8111453118
Edit -& Project Settings -& Editor
Set Version Control to meta files. Set Asset Serialization to force text.
I think this is what you want.
Bitbucket is also a very user-friendly git source agent for Unity.
With the help of "Source tree " software. you can push your entire code to server in a team.
Only the Assets and ProjectSettings folders need to be under git version control.
You can make a gitignore like this.
[Ll]ibrary/
# Autogenerated VS/MD solution and project files
*.unityproj
*.userprefs
Thumbs.db.meta
Unity also Provide its own Source version control. before unity5 it was unityAsset Server but now its depreciated. and launch a new SVN control system called unity collaborate.but the main problem using unity and any SVN is committing and merging scene . but Non of svn give us way to solve this kind of conflicts or merge scene . so depend upon you which SVN you are familiar with . I am using SmartSVN tool on Mac . and turtle on windows .
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Upcoming Events
The week's top questions and answers
Important community announcements
Questions that need answers
Stack Overflow works best with JavaScript enabledunity 面片在摄像头面前隐藏但却实际上起着遮挡效果怎么实现呢?
想咨询在这个效果怎么实现一个面片要求在摄像机面前是不被渲染的,也就是看不见。(尝试过分层把它归其他层使其在镜头前看不见了,但是其起的遮挡作用也没有了。)其他物体从它身后移动过去会被它遮挡住。这个物体要怎么设置呢??要写script?还是shade?怎么写呢?我是新手,求指教。。。。
要评论请先&或者&
不是很理解 什么叫 看不见的遮挡?遮挡了不就看见了么。。?
726 || this.offsetHeight>700){if(this.offsetWidth/726 > this.offsetHeight/700){this.width=726;}else{this.height=700;}}" style="max-width:726max-height:700" title="点击查看原图" onclick="if(this.parentNode.tagName!='A') window.open('/forum/attachment/Mon_8_cb64b.jpg');" />附上图片可能好理解点
& 跪求~!!!!
如果是用Unity3D里的plane,把面片的方向调成和摄像机的方向一样就可以了,Unity3D的plane是单面的,如果是自己的双面的,把Mesh Renderer的勾去掉或者直接移除也行……
就是 物体在隐形的遮罩后面消隐的意思吧可以作 但是会很烦把球和遮挡物放在一层,其他放在不同层 增加一个disable的辅助摄像机位置和主摄像机相同,这个摄像机不拍摄球和遮挡物的那一层。&把遮挡物用特殊的shader渲染,辅助摄像机用RenderToTexture截取整个场景,作为贴图赋给这个shader,然后shader内部用遮挡物屏幕坐标换算贴图(不能用缺省的UV换算,那样就会把整个场景全部贴在遮挡物上了,视角也不对),用投射的方式查找贴图,贴出来的正好就是透过遮挡物看到的场景,并且不包括球。&&&&&&
为什么不把红色挡板和背景的颜色改成一样的呢?如果要移动球,可以用射线直接打球的那一层来控制球。
& 所说的两种方法都行不通。跟摄像机一个朝向后是会看见整个球的, & & & & & & & & & & & & 遮挡效果消失。&& & & & & & & & & & &勾选选项Mesh Renderer,也是一样。看不见面的同时遮挡的效果也 & & & & & & & & & & & 消失了。 & & 因为挡板上市打算放视频动画的。。。。
:@riifk1215
所说的两种方法都行不通。跟摄像机一个朝向后是会看见整个球的,
&.. ( 13:13) 那你就放两个相机,放视频的那个相机的大小就是你的挡板的大小,而且这个相机的层比另一个的相机高。这个相机只渲染视频的层,其他的层不渲染。另一个相机不渲染视频这个层。
& 你这做法是不是跟hog的思路一样的?Unity3D使用溶解技术解决障碍物遮挡 - 姜雪伟个人博客 - CSDN博客
博客专家
Unity3D使用溶解技术解决障碍物遮挡
笔者介绍:,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:《手把手教你3D游戏引擎》电子工业出版社和《实战核心技术详解》电子工业出版社等。CSDN视频网址: 在开发过程中,我们面临的首要挑战之一,就是在全3D的场景中让主角保持在头顶视角的镜头之内。也就是说,如果有东西挡住了主角,是选择避免这些遮挡,还是把遮挡物隐藏掉?假使选择隐藏的话,如何采用一个视觉上令人可以愉快接受的方式,来让隐藏的过程符合游戏风格?我们如何保持不会妨碍游戏体验的空间感? 已有的方案解决此类问题: 鸟瞰模式 第一个方案是禁止关卡中出现任何横亘玩家与摄像机之间的巨大障碍物。这意味着大部分区域必须非常广阔,而墙壁和障碍物需要尽可能保持低矮,或干脆完全避免使用它们,并且摄像机与玩家角色要有一个特定的距离,尽可能垂直向下看。这种形式非常适合于“街机”类游戏,或场景中所有物体都面向同一个方向的传统顶视角RPG。然而在我们的案例中,视角与角色的距离拉远会导致玩家与主角产生疏远感。同时,也会使场景显得更加不自然,从而使玩家难以感知我们的游戏性、沉浸感以及视觉风格。 切割方案 您可以把场景想象为一个多层蛋糕,基于当前镜头关注的区域,玩家只能看到某一层的内容。 当主角站在建筑外部时,可以看到建筑的屋顶;而当他进入建筑内部时,整个屋顶以及高楼层就被全部隐藏,只显示当前楼层的墙壁和地板。大多数情况下不显示屋顶,这样能避免额外的设置工作。这种方法能够给玩家自然进出建筑物的感觉,让游戏能有更复杂的关卡设计和更强的空间感。虽然我们依旧需要将镜头定位在一个合适的距离并向下看,但由于障碍物可以被隐藏或显示,构造环境的方法可以更加自由。为了进一步优化这个方法,我们隐藏墙壁和其他各种物体,决定它们是否遮挡我们的视野,是否允许更低的镜头角度及玩家角色视野更近。这种方法唯一的缺点是会让人感觉不太自然。虽然可以通过淡出和使用透明材质来减轻这种感觉,但总体来说,我们希望尽可能远离这些东西,以避免重绘性能问题和全屏透明覆盖。这种方法确实更加符合需求,但对于我们的游戏而言仍然不是非常理想。 在考察了常规的解决方案后,我们仍旧感觉有些问题。这些方法在大多数游戏中都工作得很好,但在这个项目上,我们总感到似乎缺了点什么。所以我们具体想要达成什么样的目标呢?障碍物应当能在平滑而自然的过渡之后被隐藏。& & & &&关卡设计师应当能控制哪些东西能够被隐藏,于是我们就可以保留一部分依然能够遮挡视野的物体,在环境中增加纵深感。 & & & &镜头和角色之间的距离发生变化时,系统应当运作如常。遮挡处理应当在任何角度下都能工作。障碍物被隐藏后,玩家需要依然能够感受到它的存在。& & & &&设置工作需要尽可能简化。我们最终得出的方案整合了之前所有的方法,并增加了额外的障碍物隐藏风格。游戏中实现的效果图如下所示:角色刚进入拱桥下面,即将通过拱桥,大家注意一下它的变化。拱桥出现了一点变化,少了一部分,继续看下面的图片。拱桥大部分都消失了,但是还保留一点,那是因为角色还没完全过去,继续看下面的图片:角色完全通过拱桥,拱桥完全消失,这就是使用了融解技术解决遮挡问题。首先将纹理类型设为“Advanced”并启用“Bypass sRGB Sampling”标志。下面的动画展示了启用该设置前后的区别。在处理一些用到了纹理数据的更加复杂的着色器效果时,这个设置尤其重要。下面给读者展示实现融解的Shader代码如下所示:Shader &Custom/dissolution& {
Properties {
_Color (&Color&, Color) = (1,1,1,1)
_NoisTex(&Dissolution&,3D) = &white&{}
_Glossiness (&Smoothness&, Range(0,1)) = 0.5
_Metallic (&Metallic&, Range(0,1)) = 0.0
_DissolvePercentage(&DissolvePercentage&,Range(0,1))=1
SubShader {
Tags { &RenderType&=&Opaque& }
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler3D _NoisT
struct Input {
float2 uv_MainT
float3 worldP
float _DissolveP
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
//根据像素世界坐标获取3D贴图中的颜色:基本色
//这里的 c 可以直接用_Color代替,这样物体表面就是纯色了
fixed4 c = tex3D (_NoisTex,float3( IN.worldPos.rgb)) * _C
o.Albedo = c.
// Metallic and smoothness come from slider variables
o.Metallic = _M
o.Smoothness = _G
o.Alpha = c.a;
//根据像素世界坐标获取3D贴图中的颜色计算溶解
half gradient = tex3D(_NoisTex, float3( IN.worldPos.rgb)).r;
clip(gradient- _DissolvePercentage);
FallBack &Diffuse&
另外附上对Shader操作的脚本,代码如下所示:using UnityE
using System.C
public class TextureUtility : MonoBehaviour {
public Texture3D
public int TexSize=32;
public Material M
// Use this for initialization
void Start () {
if (TexSize & 8) {
TexSize = 8;
} else if (TexSize & 64) {
TexSize = 64;
//生成噪点
Color[] ColorPool = new Color[TexSize*TexSize*TexSize];
for(int i =0 ;i&ColorPool.Li++){
ColorPool [i] = getC
//生成贴图并赋值到材质
tex = new Texture3D (TexSize,TexSize,TexSize, TextureFormat.ARGB32, true);
tex.SetPixels (ColorPool);
tex.Apply ();
Mat.SetTexture (&_NoisTex&,tex);
//只获取纯黑和接近纯白的浅灰色
Color getColor{
float c = Random.Range (-1f, 1f);
if (c &= 0) {
c = 0.95f;
return new Color (c, c, c, c);
这样就可以实现游戏中的融解效果,从而解决遮挡问题。
我的热门文章
即使是一小步也想与你分享unity3d 摄像机跟随角色时被物体遮挡解决方案 - 阿升哥哥 - 博客园
随笔 - 24, 文章 - 0, 评论 - 238, 引用 - 0
参考文章:
在看此文章时请先看上面的参考文章
看完以上文章后,你也许会想人家都已经给出所有代码了,你还写个毛啊
别急,现在进入主题
在我的项目中,我采用的是物体遮挡作半透明处理,如果按照上述文章中的思路来写代码的话,那么结果就是当多个物体遮挡角色时,只有第一个物体会半透明,如图:
角色被墙和屋顶遮挡住了,但是可以清楚的看见左下角的墙呈半透明状态,而屋顶依旧不透明
为了解决这个问题,我们不采用上述文章中的 physics.Linecast,在这里我们需要用到 Physics.RaycastAll;使用方法详见圣典
ok,现在我们开始敲代码
首先&,我们引入命名空间 System.Collections.Generic,然后在声明三个需要用到的变量
using System.Collections.G//引入命名空间
public class MyCamera1 : MonoBehaviour
//观察目标
public Transform T
//上次碰撞到的物体
private List&GameObject& lastColliderO
//本次碰撞到的物体
private List&GameObject& colliderO
我们需要发射一条射线,这条射线从角色当前位置发射置摄像机的方向
/*射线可以从头部起始*/
//这里是计算射线的方向,从主角发射方向是射线机方向
Vector3 aim = Target.
//得到方向
Vector3 ve = (Target.position - transform.position).
float an = transform.eulerAngles.y;
aim -= an *
//在场景视图中可以看到这条射线
//Debug.DrawLine(target.position, aim, Color.red);
RaycastHit[]
hit = Physics.RaycastAll(Target.position, aim, 100f);//起始位置、方向、距离
射线发送完毕后,我们获取发送射线时碰撞到的所有物体,并且添加进本次碰撞到的物体(colliderObject)变量中
因为我的地图、护栏碰撞(不可见)、地面碰撞(不可见)是三个模型,也就是说地图本身是没有任何碰撞的
所以当碰撞到的物体名为护栏或地面时,就不修改其透明度,因为他本身就不可见
这里我偷懒了,直接判断物体名称,可自行改为判断物体 tag
当视角旋转的时候,射线有时候会碰撞到角色,所以,我们获取 tag 判断是否碰撞的物体为角色
//将 colliderObject 中所有的值添加进 lastColliderObject
for (int i = 0; i & colliderObject.C i++)
lastColliderObject.Add(colliderObject[i]);
colliderObject.Clear();//清空本次碰撞到的所有物体
for (int i = 0; i & hit.L i++)//获取碰撞到的所有物体
if (hit[i].collider.gameObject.name != "Editable Poly 1"//护栏
&& hit[i].collider.gameObject.name != "Editable Poly"//地面
&& hit[i].collider.gameObject.tag != "Player")//角色
//Debug.Log(hit[i].collider.gameObject.name);
colliderObject.Add(hit[i].collider.gameObject);
SetMaterialsColor(hit[i].collider.gameObject.renderer, 0.4f);//置当前物体材质透明度
当获取到所碰撞到的所有物体后,我们要修改他的材质透明度,有些物体有很多材质,不知道怎么解决的请看我下面这个方法:
/// 置物体所有材质球颜色 &summary&
/// 置物体所有材质球颜色
/// &/summary&
/// &param name="_renderer"&材质&/param&
/// &param name="Transpa"&透明度&/param&
private void SetMaterialsColor(Renderer _renderer, float Transpa)
//获取当前物体材质球数量
int materialsNumber = _renderer.sharedMaterials.L
for (int i = 0; i & materialsN i++)
//获取当前材质球颜色
Color color = _renderer.materials[i].
//设置透明度
取值范围:0~1;
0 = 完全透明
color.a = T
//置当前材质球颜色
_renderer.materials[i].SetColor("_Color", color);
如果本次碰撞到的物体存在于上个物体,那么则说明当前物体还处于遮挡角色状态,所以我们赋值为null
//上次与本次对比,本次还存在的物体则赋值为null
for (int i = 0; i & lastColliderObject.C i++)
for (int ii = 0; ii & colliderObject.C ii++)
if (colliderObject[ii] != null)
if (lastColliderObject[i] == colliderObject[ii])
lastColliderObject[i] = null;
还处于遮挡状态的物体已被赋值为null,那么剩下的物体就是没有处于遮挡状态的,所以我们要重置该物体材质为不透明
1 //当值为null时则可判断当前物体还处于遮挡状态
//值不为null时则可恢复默认状态(不透明)
for (int i = 0; i & lastColliderObject.C i++)
if (lastColliderObject[i] != null)
SetMaterialsColor(lastColliderObject[i].renderer, 1f);//恢复上次物体材质透明度
好了,所有代码已完成,我们看一下运行结果
未遮挡时:
怎么样,有木有感觉很酷炫呢,哈哈哈
最后,附上完整代码链接: 密码:pbrd
原文链接:你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
一般2D类型RPG游戏中常见的效果
场景A:地图上有一棵树和玩家控制的人物A,当人物A移动到树前面时,会遮挡住身后的树的一部分;当人物A移动到树后面时,会被树所遮挡住一部分。
场景B:地图上有玩家A和玩家B,当A移动到B前面时,A会挡住身后的B一部分;当B移动到A前面时,会遮挡住A身体的一部分。
一般这种效果的实现原理是通过计算对象的XY坐标来决定的,我想问的是在Unity中,有没有什么简单实用的方法实现这种效果?
要简单就是3D场景2D视角,你的2D的Sprite都有z轴上的层次关系。
直接使用z轴,z轴和y关联,y越大z也就越大。。
如果你的角色都在一个z轴平面内,可以设置层次的。
根据z轴的大小来动态的设置物体的层次。
要回复问题请先或
浏览: 1820
关注: 4 人

我要回帖

更多关于 unity3d 建筑 的文章

 

随机推荐