블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-25 09:56

Link : http://forum.unity3d.com/threads/unity-4-5-new-hierarchy-window-sorting.248298/#post-1642742


[File]


$AlphaNumericSort.cs





기존의 이름이 아닌 트랜스폼 기준으로 변경되었는데요.


(전 처음에 4.5 버전 버그인줄 알고 당황-_-;)



링크의 글 중간에 보시면

$AlphaNumericsort.cs

파일을 다운 받으시고

프로젝트 폴더/Assets/Editor/ 

에 넣어주세요.

유니티를 다시 띄우면 그림처럼 아이콘이 하나가 추가됩니다.

이 아이콘을 누르시면 소팅 방식을 트랜스폼 혹은 이름으로 변경 가능해집니다.




출처 : http://www.gamecodi.com/board/zboard.php?id=GAMECODI_Talkdev&page=1&sn1=&divpage=1&sn=on&ss=on&sc=on&keyword=sort&select_arrange=headnum&desc=asc&no=2703

반응형

'Unity3D > Tips' 카테고리의 다른 글

Scene뷰에서 Handles.Label()  (0) 2015.05.08
[링크] 유니티5 업그레이드 가이드  (0) 2015.03.30
BBCode tags reference  (0) 2015.02.08
안드로이드 유니티 리모트 4 연동 문제 해결하기  (0) 2015.02.04
Unity Platform Defines  (0) 2015.01.28
Posted by blueasa
, |

  [수정]

- Unity2019 대응[2020-11-03]


[파일]

iTween Visual Editor version 0.6.1(with_Unity2019+).zip



[링크]

http://u3d.as/1tM

반응형

'Unity3D > iTween' 카테고리의 다른 글

iTween의 easetype  (0) 2015.03.04
iTween  (0) 2012.11.24
Posted by blueasa
, |

iTween의 easetype

Unity3D/iTween / 2015. 3. 4. 19:48

iTween's  Ease type

 

iTween 은 간편하게 오브젝트의 이동 에니메션을 쉽게 처리해 줍니다. 

 

그런데 오브젝트가 로보트처럼 딱딱하게 움직이면 좀 보기가 좋지 않겠죠.

 

그래서 iTween은 여러가지 ease type를 지정할수 있습니다. 

 

  EaseInQuad = 0,

EaseOutQuad, EaseInOutQuad, EaseInCubic, EaseOutCubic, EaseInOutCubic, EaseInQuart, EaseOutQuart, EaseInOutQuart, EaseInQuint, EaseOutQuint, EaseInOutQuint, EaseInSine, EaseOutSine, EaseInOutSine, EaseInExpo, EaseOutExpo, EaseInOutExpo, EaseInCirc, EaseOutCirc, EaseInOutCirc, Linear, Spring, EaseInBounce, EaseOutBounce, EaseInOutBounce, EaseInBack, EaseOutBack, EaseInOutBack, EaseInElastic, EaseOutElastic, EaseInOutElastic

 

이 리스트에 보이는 것처럼 상당히 많은 양의 타입을 지정하는데요. 

 

  iTween.MoveBy(

gameObject,

iTween.Hash(

"x", 2, 

"easeType", "easeInOutExpo", 

"loopType", "pingPong", 

"delay", 1

)

);

 

위의 코드에서 보시다 시피, 해시테이블을 만들때, easeType을 지정하면 됩니다. 

 





[출처] iTween의 easetype|작성자 Jell


반응형

'Unity3D > iTween' 카테고리의 다른 글

iTween Visual Editor v0.6.1(with Unity2019+)  (0) 2015.03.04
iTween  (0) 2012.11.24
Posted by blueasa
, |


출처 : http://www.tasharen.com/forum/index.php?topic=406.0


반응형
Posted by blueasa
, |

NGUI Emoticons

Unity3D/NGUI / 2015. 2. 12. 01:16
我也没记清NGUI是哪个版本开始增加了表情这个功能,不过好像是3.0以后的,现在我就来简单的说说如何使用NGUI中新增的这个输入表情的功能的用法。

我们要准备表情图片,去网上随便找些表情来,我这是在百度后经过ps后得到表情,大家也可以自己去网上找下表情的图片,然后自己PS下得到自己所要的。我的如下:

1.png 

我们在这里要注意一下,表情图片最好是20X20大小,因为在外部是修改不了大小的,这个估计是NGUI作者封装在内部了,要去修改内部代码才行的哦。还有一个是如果想输入表情,暂时不支持动态字体的哦。所以得自己用BMFont去制作Bitmap字体。我将我已经制作好的Bitmap字体放进来了,如图:



我们将我们千辛万苦弄来的表情来制作成一个图集吧,待会会用到,我这如下:

3.png 

现在我将BMFont制作好的字体放进NGUI里面,然后用来创建字体图集。大家会发现这里和原来有点不一样了,在Output栏里面多了个Atlas这一栏,这个其实就是表情图集了。我们将我们的表情图集拖放到这一栏就可以了,然后点击创建吧。如图:

4.png 

我们现在来给表情定义特殊字体集合吧,其实就是解析这些定义的文字,然后用表情来代替他们显示,我们选择我们刚才创建的字体,就会发现有这个了:

    6.png 
然后我们点击展开一下,就会把我们的表情和一个特殊文字对应吧。我把一些对应的表情设置的如下:

7.png 

6  好了,现在我们可以来输入我们的自定义的表情了,我输入<:kx (就是开心那个表情对应的特殊字码)  如图:

8.png    9.png 

不要怀疑啊,就是这样简单。  没了。




5.png (13.65 KB, 下载次数: 5)

5.png



转:http://www.narkii.com/club/thread-313296-1.html




반응형
Posted by blueasa
, |

1、可以使用BBCode标记

[b]Bold[/b]                      粗体
[i]italic[/i]                         斜体
[u]underline[/u]               下划线
[s]strikethrough[/s]         删除线
[sub]sub[/sub]               下标
[sup]sup[/sup]               上标
[00ff00]设置颜色[-]           设置显示颜色

[url=http://www.cnblogs.com/mrzivchu/][u]博客[/u][/url] 链接

例如设置颜色:

UILabel的Text内容为:[99ff00]n[-]gui: tools

展示效果则为:

这里主要说一下设置连接:

单单的在UILabel的Text里面写入这个是不够的:[url=http://www.cnblogs.com/mrzivchu/][u]博客[/u][/url] 链接

点击是不会产生效果的,我们还要为此UILabel添加一个Collider和一个脚本

脚本如下:

 

 void OnClick()
    {
        UILabel lbl = GetComponent<UILabel>();
        string url = lbl.GetUrlAtPosition(UICamera.lastWorldPosition);
        Application.OpenURL(url);
    }

 

脚本中的OnClick方法要想被触发,就必须要添加一个Collider,这个道理我想大家都懂得!

但要注意一点,假如UILabel的Text内容为:请点击[url=http://www.cnblogs.com/mrzivchu/]我的博客[/url]进入,欢迎大家来批评指正!

我只想点击《我的博客》四个字才去打开连接,而不是点击上面的任何字都可以打开连接,假如上面的文字尺寸是700x40,而《我的博客》四个字的尺寸是200x40,这时我们就可以设置Collider的Center和Size属性来设置点击的区域大小以满足我们的需求,可是当我运行程序的时候Center和Size会自动变为700x40,原来UILabel的Widget有个选项Collider,这个auto-adjust to match表示Collider大Size大小自动匹配为UILabel的Size大小,我们只要把这个勾取消即可!

如果你不想使用BBCode,那么UILabel有个选项BBCode,不勾选的话,就表示不使用BBCode

2、使用图片

我们只要在UILabel的Text里面写了:zwh:) 那么就会出现了一个笑脸图片:

 

为什么会这么神奇呢,原因在于你选择的Font,此处我选择的Font是Arimo20

Arimo20有三个关联的文件:

类型依次为:tga,prefab,txt

这时,我们点击类型为prefab文件,在Inspector窗口的UIFont可以看到

其中可以看到我们熟悉的 :) 笑脸标记,我们这时点击笑脸对应的Emotion - Smile ,展现出来的就是那个笑脸图片,而这个笑脸图片是存在Wooden Atlas图集里面的,如果我们想用其他图片的话,我们可以向Wooden Atlas图集里面增加我们需要展现的图片,然后在下面填写一个约定好的标记,类似于 :) 这样的标记,选择我们想要展现的图片,Add即可,图片的尺寸最好是20x20,以保证和文字上下在一条水平线上!

UILabel的Text为:zwh(bird)zwh 

显示为:

因为我的图片是60x60的,所以和文字上下不一样齐了,这也是我为什么建议图片尺寸是20x20的原因了!

另外说一个问题,我也不知道是不是存在的bug

此处我们为UIFont选择的图集是Wooden Atlas,Sprite是Arimo 20,Arimo 20大概对应的是字符格式,如果此时我们点击Sprite,将会弹出Wooden Atlas里面包含的所有sprite精灵,当我们点击Arimo 14或者Arimo 18的话,那么应用此Arimo20的UILabel将会变形:

原本是这样的:,变成了这样:

 

为Sprite选择Arimo20已经还原不会来了,还是会变形!

解决方案:

就是点击UIFont下的Import Data,也就是导入和Arimo20关联的三个类型(tga,prefab,txt)的文件中的txt文件即可!从而使Arimo的字符集格式还原回来!

另外:

UILabel还有一个Symbols选项,他有三个值:None,Normal,Colored,选择None,那么以 :) 这样形式显示的图片将不会展示,选择Normal(默认)将正常展示,选择Colored,那么图片将会被UILabel下的Color Tint所选择的颜色遮盖!其实这个Color Tint是对文字进行着色的,选择Colored那么也就是意味着图片也和文字应用同样的颜色!

其他属性

overflow:

1.ShrinkContent,总是显示所有文字,根据当前的width和height进行缩放
2.ClampContent,一看到Clamp就想起Clamp函数,也就是不管文本多少个字,根据当前的width和height来显示,超出部分 
不显示
3.ResizeFreely,会对当前的文字长度和行数来调整,UILabel的width和height,基本上是只在一行显示,超出的部分不显示
4.ResizeHeight,保持宽度不变,必要时增加高度。


Spacing :

X:设置字与字之间到间隔,可以为负数,设置得当可以反序

Y: 设置行与行之间的间隔。


Gradient :

设置 渐变字

Max Lines:

用来控制最多要多少行。用0表示不限制。如果设置成n的话,那么超过n的行的文字将不会显示!

 

实现动态文字展现的效果:

先上效果图:

 

层次:

content显示的是文字

bg显示是背景图(uisprite)

title是标题

第一步:先给content添加UIlabel和typewriter effect脚本:此脚本选项的解释如下:

chars per second:每秒显示多少个字符

fade in time:淡入时间

delay on period:延迟期

delay on new line:开始新行延迟时间

scroll view:需要指定scroll view

keep full dimentions:保持全部尺寸

第二步:

设置content组件uilabel的overflow(溢出方式)为ResizeHeight

第三步:

typewriter effect脚本的keep full dementions不要勾选,其他的默认即可

第四步:

设置bg背景图的UISprite的Anchors的Type为Unified(统一),Execute为OnUpdate,Target为mylabel即可!

Anchors的功能是:

物体A相对于所指定物体B的位置设置情况。可以设置离指定物体的上,下,左,右的偏移值,从而实现对齐,主要用在动态的效果的情况下,例如上面的title的位置就是相对于content而设置的,随着content文字的动态增加,title的位置也在不断的上移,实现对齐,避免位置错乱!这大概就是设置Anchors的好处吧!

这里我的title的anchors里面,只要设置了top+50即可,保持与content的顶部的距离即可,其他的可以不用设置!

target为指定物体B,而bg就是A,Execute指在更新时还是可用时去执行,type表示统一的还是高级的


출처 : http://www.cnblogs.com/MrZivChu/p/UILabel.html

반응형

'Unity3D > NGUI' 카테고리의 다른 글

NGUI: Symbols & Emoticons  (0) 2015.02.12
NGUI Emoticons  (0) 2015.02.12
Coloring individual characters in an NGUI UILabel text  (0) 2014.12.31
NGUI UILabel Reference  (0) 2014.12.31
NGUI UILabel BBCode  (0) 2014.12.31
Posted by blueasa
, |

BBCode tags reference

Unity3D/Tips / 2015. 2. 8. 17:47

BBCode tags reference

In this section, a reference table for all of the more popular bbcode tags, is provided. Some are considered to be standard and should be supported in just about any bbcode implementation. Other are less likely to be supported, but nonetheless popular (hence the reason they've been included here).

Tags reference table

NameSyntaxPurposeExample
Bold[b]{text}[/b]Makes {text} boldBold example
Italic[i]{text}[/i]Makes {text} italicItalic example
Underline[u]{text}[/u]Underlines {text}Underline example
Line-through[s]{text}[/s]Create a line-through/strike through on {text}Line-through example
Font-size[size={number}]{text}[/size]Changes the font-size of {text}Font-size example
Font colour[color={colour}]{text}[/color]Changes the colour of {text}Font colour example
Center text[center]{text}[/center]Centers {text} on screenCenter text example
Quote[quote]{text}[/quote]Creates a quotation box containing {text}Quote example
Quote (named)[quote={name}]{text}[/quote]Creates a quotation box quoting {name} as saying {text}Quote (named) example
Link[url]{url}[/url]Makes a link to {url}Link example
Link (named)[url={url}]{text}[/url]Makes a named link to {url}Link (named) example
Image[img]{url}[/img]Shows the image indicated by {url}Image example
Image (resized)Full version: [img width={width} height={height} ...]{url}[/img]
Another variant (shorthand): [img={width}x{height}]{url}[/img]
Shows {url} image resized to {width} and {height}Image (resized) example
ListUnordered list: [ul]{items}[/ul]
Ordered list: [ol]{items}[/ol]
Another variant: [list]{items}[/list]
Displays a list of {items}List example
List item[li]{text}[/li]
Shorthand: [*]{text}\newline
Species an {item} within a listList item example
Code[code]{text}[/code]Renders the {text} while maintaing all white spacingCode example
Tables[table]{rows}[/table]Show a table with {rows} in itTables example
Table rows[tr]{cells}[/tr]Renders a table row containing {cells}Table rows example
Table content cellsHeading cell: [th]{content}[/th]
Content cell: [td]{content}[/td]
Shows {content} in a table (heading) cellTable content cells example
Youtube videos[youtube]{id}[/youtube]Shows the youtube video indicated by {id}Youtube videos example
Google videos[gvideo]{id}[/gvideo]Shows the google video indicated by {id}Google videos example

Something missing?

If you think that some tags are missing here, please do not hesitate to contact us!

BBCode examples

Go to the examples section to find many examples of how you can use these tags.





출처 : http://www.bbcode.org/reference.php

반응형
Posted by blueasa
, |

안드로이드 유니티 리모트 4 연동 문제 해결하기

안드로이드에서 유니티 리모트를 연동하기 법은 구글형이 잘 알려준다. 여기서는 자주 발생하는 문제에 대한 해결책을 정리한다.
  1. 폰이 인식되지 않는다
  2. 인증되지 않았다
  3. 유니티에서 Play를 해도 반응이 없다

폰이 인식되지 않는다

일단 USB를 꽂으면, 인식이 되고, 탐색기로 봤을 때, 폰이 보이고, 폴더에 접근하여 파일을 복사하거나 삭제할 수 있어야 한다.

확인방법

  1. 탐색기에서 보이는지 확인
  2. adb로 확인
  3. 폰의 개발자 모드에서 USB 디버깅 활성화 체크

해결방법

  1. USB 통합 드라이브를 설치한다. (구글형에게 문의)
  2. 콘솔명령창에서 adb devices를 실행한다.
  3. 폰 설정에 들어가서 USB 디버깅을 활성화 한다. (구글형에게 문의)

폰이 인증되지 않았다

폰이 인식되면, USB 디버깅을 활성화하면, 유니티에서 Play를 할 때, 개발 컴퓨터의 접속을 허가할 지, 폰에서 묻는다. 이 때, 잘 응답하면 문제가 없으나, 잘못하면 인증이 안된 상태가 된다.

확인방법

  1. adb devices를 했을 때, 폰은 나오나 Unauthorized라고 나온다.

해결방법

콘솔 창에서 다음 명령을 실행한다
  1. adb kill-server
  2. adb start-server
위의 명령을 하고 다시 유니티에서 Play를 하면 폰에서 인증창이 다시 나온다.

유니티에서 Play를 해도 반응이 없다

유니티가 실행된 후에 폰을 연결한 경우, 유니티가 인식을 못하는 경우가 있다

확인방법

  1. 위의 문제의 확인 방법을 통해서 문제가 없는데도 Play를 하면 안된다

해결방법

  1. 유니티 에디터를 재실행한다


출처 : http://junhan627.blogspot.kr/2014/11/4.html

반응형
Posted by blueasa
, |

[파일]

SetTexture.cs



작업을 하다보니..

 

새로 등록한 이미지들의 Import Setting 바꿔주는 부분이 귀찮아서...

기존 작업방식은 추가한것들 한꺼번에 클릭후 Inspector 에서 동일하게 바꿔주는 방법이였는데..

 

정말 귀찮아서..만든 클래스.

 

사용법은

 

Assets 폴더 안에 Editor 폴더를 만들고 혹은 거기에 넣고

 

텍스쳐들이 들어있는 폴더나 바꾸고자 하는텍스쳐에 마우스 오른버튼을 클릭하면.

 

생성되어있는 MySpriteSet  이라는 메뉴를 클릭하면 사용자가 기본설정해논 텍스쳐 옵션대로 모든 텍스쳐가 셋팅된다.

 

스크립트 속 기본이 되는 텍스쳐 옵션은 사용자에 맞춰 변경하면 됨.



출처 : http://hanamoni.tistory.com/20

반응형

'Unity3D > Extensions' 카테고리의 다른 글

[Unity] Play Streaming Music From Server  (0) 2018.02.06
[펌] ADDING TO UNITY'S BUILT-IN CLASSES USING EXTENSION METHODS  (0) 2016.10.20
Extension Methods  (0) 2014.08.18
Nullable Types  (0) 2014.08.18
ObjectPool  (0) 2014.04.22
Posted by blueasa
, |

Unity Platform Defines

Unity3D/Tips / 2015. 1. 28. 15:50

[출처] http://docs.unity3d.com/Manual/PlatformDependentCompilation.html



Platform dependent compilation

Unity’s Platform Dependent Compilation feature consists of some preprocessor directives that let you partition your scripts to compile and execute a section of code exclusively for one of the supported platforms.

You can run this code within the Unity Editor, so you can compile the code specifically for your target platform and test it in the Editor.

Platform #define directives

The platform #define directives that Unity supports for your scripts are as follows:

DefineFunction
UNITY_EDITOR#define directive to call Unity Editor scripts from your game code.
UNITY_EDITOR_WIN#define directive for Editor code on Windows.
UNITY_EDITOR_OSX#define directive for Editor code on Mac OS X.
UNITY_EDITOR_LINUX#define directive for Editor code on Linux.
UNITY_STANDALONE_OSX#define directive to compile or execute code specifically for Mac OS X (including Universal, PPC and Intel architectures).
UNITY_STANDALONE_WIN#define directive for compiling/executing code specifically for Windows standalone applications.
UNITY_STANDALONE_LINUX#define directive for compiling/executing code specifically for Linux standalone applications.
UNITY_STANDALONE#define directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux).
UNITY_WII#define directive for compiling/executing code for the Wii console.
UNITY_IOS#define directive for compiling/executing code for the iOS platform.
UNITY_IPHONEDeprecated. Use UNITY_IOS instead.
UNITY_ANDROID#define directive for the Android platform.
UNITY_PS4#define directive for running PlayStation 4 code.
UNITY_XBOXONE#define directive for executing Xbox One code.
UNITY_LUMIN#define directive for the Magic Leap OS platform. You can also use PLATFORM_LUMIN.
UNITY_TIZEN#define directive for the Tizen platform.
UNITY_TVOS#define directive for the Apple TV platform.
UNITY_WSA#define directive for Universal Windows Platform. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core and using .NET scripting backend.
UNITY_WSA_10_0#define directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C# files against .NET Core.
UNITY_WINRTSame as UNITY_WSA.
UNITY_WINRT_10_0Equivalent to UNITY_WSA_10_0
UNITY_WEBGL#define directive for WebGL.
UNITY_FACEBOOK#define directive for the Facebook platform (WebGL or Windows standalone).
UNITY_ANALYTICS#define directive for calling Unity Analytics methods from your game code. Version 5.2 and above.
UNITY_ASSERTIONS#define directive for assertions control process.
UNITY_64#define directive for 64-bit platforms.

You can also compile code selectively. The options available depend on the version of the Editor that you are working on. Given a version number X.Y.Z (for example, 2.6.0), Unity exposes three global #define directives in the following formats: UNITY_XUNITY_X_Y and UNITY_X_Y_Z.

Here is an example of #define directives exposed in Unity 5.0.1:

DefineFunction
UNITY_5#define directive for the release version of Unity 5, exposed in every 5.X.Y release.
UNITY_5_0#define directive for the major version of Unity 5.0, exposed in every 5.0.Z release.
UNITY_5_0_1#define directive for the minor version of Unity 5.0.1.

Starting from Unity 5.3.4, you can compile code selectively based on the earliest version of Unity required to compile or execute a given portion of code. Given the same version format as above (X.Y.Z), Unity exposes one global #define in the format UNITY_X_Y_OR_NEWER, that can be used for this purpose.

The supported #define directives are:

DefineFunction
CSHARP_7_3_OR_NEWERDefined when building scripts with support for C# 7.3 or newer.
ENABLE_MONOScripting backend #define for Mono.
ENABLE_IL2CPPScripting backend #define for IL2CPP.
NET_2_0Defined when building scripts against .NET 2.0 API compatibility level on Mono and IL2CPP.
NET_2_0_SUBSETDefined when building scripts against .NET 2.0 Subset API compatibility level on Mono and IL2CPP.
NET_LEGACYDefined when building scripts against .NET 2.0 or .NET 2.0 Subset API compatibility level on Mono and IL2CPP.
NET_4_6Defined when building scripts against .NET 4.x API compatibility level on Mono and IL2CPP.
NET_STANDARD_2_0Defined when building scripts against .NET Standard 2.0 API compatibility level on Mono and IL2CPP.
ENABLE_WINMD_SUPPORTDefined when Windows Runtime support is enabled on IL2CPP. See Windows Runtime Support for more details.
ENABLE_INPUT_SYSTEMDefined when the Input System package is enabled in Player Settings.
ENABLE_LEGACY_INPUT_MANAGERDefined when the legacy Input Manager is enabled in Player Settings.

You use the DEVELOPMENT_BUILD #define to identify whether your script is running in a player which was built with the “Development Build” option enabled.

You can also compile code selectively depending on the scripting back-end.

Testing precompiled code

Below is an example of how to use the precompiled code. It prints a message that depends on the platform you have selected for your target build.

First of all, select the platform you want to test your code against by going to File > Build Settings. This displays the Build Settings window; select your target platform from here.

Build Settings window with PC, Mac & Linux selected as the target platforms
Build Settings window with PC, Mac & Linux selected as the target platforms

Select the platform you want to test your precompiled code against and click Switch Platform to tell Unity which platform you are targeting.

Create a script and copy/paste the following code:

// C#
using UnityEngine;
using System.Collections;

public class PlatformDefines : MonoBehaviour {
  void Start () {

    #if UNITY_EDITOR
      Debug.Log("Unity Editor");
    #endif
    
    #if UNITY_IOS
      Debug.Log("Iphone");
    #endif

    #if UNITY_STANDALONE_OSX
    Debug.Log("Stand Alone OSX");
    #endif

    #if UNITY_STANDALONE_WIN
      Debug.Log("Stand Alone Windows");
    #endif

  }          
}

To test the code, click Play Mode. Confirm that the code works by checking for the relevant message in the Unity console, depending on which platform you selected - for example, if you choose iOS, the message “Iphone” is set to appear in the console.

In C# you can use a CONDITIONAL attribute which is a more clean, less error-prone way of stripping out functions. See ConditionalAttribute Class for more information. Note that common Unity callbacks (ex. Start(), Update(), LateUpdate(), FixedUpdate(), Awake()) are not affected by this attribute because they are called directly from the engine and, for performance reasons, it does not take them into account.

In addition to the basic #if compiler directive, you can also use a multiway test in C#:


#if UNITY_EDITOR
    Debug.Log("Unity Editor");

#elif UNITY_IOS
    Debug.Log("Unity iPhone");

#else
    Debug.Log("Any other platform");

#endif


Platform custom #defines

It is also possible to add to the built-in selection of #define directives by supplying your own. Open the Other Settings panel of the Player settings and navigate to the Scripting Define Symbols text box.

Enter the names of the symbols you want to define for that particular platform, separated by semicolons. These symbols can then be used as the conditions for #if directives, just like the built-in ones.

Global custom #defines

You can define your own preprocessor directives to control which code gets included when compiling. To do this you must add a text file with the extra directives to the Assets folder. The name of the file depends on the language you are using. The extension is .rsp:

C# (player and editor scripts)<Project Path>/Assets/mcs.rsp

As an example, if you include the single line -define:UNITY_DEBUG in your mcs.rsp file, the #define directive UNITY_DEBUG exists as a global #define for C# scripts, except for Editor scripts.

Every time you make changes to .rsp files, you need to recompile in order for them to be effective. You can do this by updating or reimporting a single script (.js or .cs) file.

Note:__If you want to modify only global #define directives, use Scripting Define Symbols__ in Player settings, because this covers all the compilers. If you choose the .rsp files instead, you need to provide one file for every compiler Unity uses.

The use of .rsp files is described in the ‘Help’ section of the mcs application, which is included in the Editor installation folder. You can get more information by running mcs -help.

Note that the .rsp file needs to match the compiler being invoked. For example:

  • when targeting the .NET 3.5 Equivalent (deprecated) scripting runtime version, mcs is used with mcs.rsp, and
  • when targeting the .NET 4.x Eqivalent scripting runtime version compiler, csc is used with csc.rsp.


반응형
Posted by blueasa
, |