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

카테고리

분류 전체보기 (2850)
Unity3D (893)
Programming (479)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (189)
협업 (64)
3DS Max (3)
Game (12)
Utility (142)
Etc (99)
Link (34)
Portfolio (19)
Subject (90)
iOS,OSX (52)
Android (16)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (19)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday

[추가] 2024-04-17

#define으로 Editor, Device등 원하는 곳에 띄울 수 있게 약간 변형함

#if UNITY_EDITOR
#define MY_DEBUG
#endif

using UnityEngine;
using System.Collections;
using System;
using UnityEngine.Internal;


/// 
/// It overrides UnityEngine.Debug to mute debug messages completely on a platform-specific basis.
/// 
/// Putting this inside of 'Plugins' foloder is ok.
/// 
/// Important:
///     Other preprocessor directives than 'UNITY_EDITOR' does not correctly work.
/// 
/// Note:
///     [Conditional] attribute indicates to compilers that a method call or attribute should be 
///     ignored unless a specified conditional compilation symbol is defined.
/// 
/// See Also: 
///     http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx
/// 
/// 2012.11. @kimsama
///

/// - Unity 5.x 대응(5.x에 추가된 Debug 함수 추가)
/// - isDebugBuild("Development Build") 시 return.
/// 2016-07-25 by blueasa

public static class Debug
{
    public static bool developerConsoleVisible
    {
        get { return UnityEngine.Debug.developerConsoleVisible; }
    }

    public static bool isDebugBuild
    {
        //get { return UnityEngine.Debug.isDebugBuild; }
#if MY_DEBUG
        get { return true; }
#else
        get { return false; }
#endif
    }

    public static ILogger logger
    {
        get { return UnityEngine.Debug.unityLogger; }
    }

    public static void Assert(bool condition)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Assert(condition);
    }

    public static void Assert(bool condition, string message)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Assert(condition, message);
    }

    public static void Assert(bool condition, object message)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Assert(condition, message);
    }

    public static void Assert(bool condition, UnityEngine.Object context)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Assert(condition, context);
    }

    public static void Assert(bool condition, string message, UnityEngine.Object context)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Assert(condition, message, context);
    }

    public static void Assert(bool condition, object message, UnityEngine.Object context)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Assert(condition, message, context);
    }

    public static void AssertFormat(bool condition, string format, params object[] args)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.AssertFormat(condition, format, args);
    }

    public static void AssertFormat(bool condition, UnityEngine.Object context, string format, params object[] args)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.AssertFormat(condition, context, format, args);
    }

    public static void Break()
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Break();
    }

    public static void ClearDeveloperConsole()
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.ClearDeveloperConsole();
    }

    public static void DebugBreak()
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DebugBreak();
    }

    public static void DrawLine(Vector3 start, Vector3 end)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawLine(start, end);
    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawLine(start, end, color);
    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawLine(start, end, color, duration);
    }

    public static void DrawLine(Vector3 start, Vector3 end, [DefaultValue("Color.white")] Color color, [DefaultValue("0.0f")] float duration, [DefaultValue("true")] bool depthTest)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawLine(start, end, color, duration, depthTest);
    }

    public static void DrawRay(Vector3 start, Vector3 dir)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawRay(start, dir);
    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawRay(start, dir, color);
    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawRay(start, dir, color, duration);
    }

    public static void DrawRay(Vector3 start, Vector3 dir, [DefaultValue("Color.white")] Color color, [DefaultValue("0.0f")] float duration, [DefaultValue("true")] bool depthTest)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.DrawRay(start, dir, color, duration, depthTest);
    }

    public static void Log(object message)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Log(message);
    }

    public static void Log(object message, UnityEngine.Object context)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.Log(message, context);
    }

    public static void LogAssertion(object message)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogAssertion(message);
    }

    public static void LogAssertion(object message, UnityEngine.Object context)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogAssertion(message, context);
    }

    public static void LogAssertionFormat(string format, params object[] args)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogAssertionFormat(format, args);
    }

    public static void LogAssertionFormat(UnityEngine.Object context, string format, params object[] args)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogAssertionFormat(context, format, args);
    }

    public static void LogError(object message)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogError(message);
    }

    public static void LogError(object message, UnityEngine.Object context)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogError(message, context);
    }

    public static void LogErrorFormat(string format, params object[] args)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogErrorFormat(format, args);
    }

    public static void LogErrorFormat(UnityEngine.Object context, string format, params object[] args)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogErrorFormat(context, format, args);
    }

    public static void LogException(Exception exception)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogException(exception);
    }

    public static void LogException(string exception)
    {
        Exception ex = new Exception(exception);
        UnityEngine.Debug.LogException(ex);
    }

    public static void LogException(Exception exception, UnityEngine.Object context)
    {
        //if (false == isDebugBuild)
        //    return;

        UnityEngine.Debug.LogException(exception, context);
    }

    public static void LogFormat(string format, params object[] args)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.LogFormat(format, args);
    }

    public static void LogFormat(UnityEngine.Object context, string format, params object[] args)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.LogFormat(context, format, args);
    }

    public static void LogWarning(object message)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.LogWarning(message);
    }

    public static void LogWarning(object message, UnityEngine.Object context)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.LogWarning(message, context);
    }

    public static void LogWarningFormat(string format, params object[] args)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.LogWarningFormat(format, args);
    }

    public static void LogWarningFormat(UnityEngine.Object context, string format, params object[] args)
    {
        if (false == isDebugBuild)
            return;

        UnityEngine.Debug.LogWarningFormat(context, format, args);
    }
}

 

 

 

----

Unity에서 프로그래밍할 때 콘솔에 디버깅이나 경고 혹은 에러 문자열 출력을 위해서 Debug.Log 의 메시지 출력 메소드를 많이 사용합니다. 
 
문제는 Debug.Log 메소드의 이름과 달리 해당 콘솔 출력이 디바이스에 deploy해서 실행할 때에도 실행이 된다는 점입니다. 
 
처음부터 Debug.Log 메시지를 대체하는 별도의 wrapper 클래스나 메소드를 작성해서 사용한 경우라면 문제가 되지 않지만, 프로젝트 내에 이미 수 많은 Debug.Log 메시지들이 존재하는 경우, 변경이 번거로울 수 있습니다. 
 
이 때 사용할 수 있는 간단한 방법이 .NET의 System.Diagnostics.Conditional 속성을 사용하는 것입니다.
 
public static class Debug
{ 
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void Log (object message)
{
UnityEngine.Debug.Log (message);
}
}
 
전체 코드는 아래 링크의 gist에서 확인할 수 있습니다.
 
 
Debug 클래스에는 Debug.Log 뿐만 아니라 UnityEngine.Debug 클래스의 DrawLine, DrawRay 등을 포함한 모든 메소드들에 대한 대체 메소드들을 포함하고 있습니다.
 
사용 방법은 링크의 전체 코드를 Assets 폴더 내의 Editor 폴더에 저장하면 됩니다.
사용 방법은 링크의 전체 코드를 Assets 폴더 내의 Plugins 폴더에 저장하면 됩니다.

 

 

[출처] http://www.unitystudy.net/bbs/board.php?bo_table=writings&wr_id=60&page=0&sca=&sfl=&stx=&spt=0&page=0&cwin=#c_322

 

 

 

[추가][Unity 5.3 이상]

It works.
And, Unity 5.3 provides an easier solution: Debug.logger.logEnabled=false to disable it.



[출처] https://gist.github.com/kimsama/4123043

 

반응형
Posted by blueasa
, |

UnityVS가 드디어 Unity 콘솔창에서 더블클릭하면 라인 찾아가네요.


비록 Editor에 스크립트가 하나 들어가야 되지만..

지원하니 좋네요. =ㅅ=!!

Unity 4.2로 업그레이드 하면서 UnityVS에도 뭔가 있나하고 사이트 놀러갔다가 득템한 느낌이네요. ㅎㅎ



UnityVS 스크립트 소스 및 내용  링크 : http://unityvs.com/news/




[File] 


반응형

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

Visual Studio Tools for Unity 1.9(for Free)  (2) 2014.07.30
Posted by blueasa
, |


링크 : http://blog.naver.com/khagaa/30128920649

반응형
Posted by blueasa
, |


1-1. 유니티 안드로이드 플러그인 만들기 - Android 개발 환경 구축 하기 - JDK 설치 및 윈도우 설정 


1-2. 유니티 안드로이드 플러그인 만들기 - Android 개발 환경 구축 하기 - Android SDK 설치 및 eclipse 설치 


1-3. 유니티 안드로이드 플러그인 만들기 - Unity 안드로이드 빌드


1-4. 유니티 안드로이드 플러그인 만들기 - Unity 안드로이드 Plugin 만들기




안드로이드플러그인.docx


반응형
Posted by blueasa
, |

링크 1: http://forum.unity3d.com/threads/188441-Retrieving-MAC-address-on-Android-device


링크 2: http://stackoverflow.com/questions/6064510/how-to-get-ip-address-of-the-device/13007325#13007325

반응형
Posted by blueasa
, |

Toon/Tf2Shader

Unity3D/Shader / 2013. 7. 19. 22:28


Tf2Shader.shader


Tf2ShaderWithCutoff.shader


Tf2ShaderWithCutoffAndOutline.shader




출처 : http://batimals.googlecode.com/svn-history/r210/trunk/Batimals/Assets/Scripts/Shaders/

반응형

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

UnityDiffuseLightmap.shader by jimfleming  (0) 2014.06.23
쉐이더 자료 많은 사이트..  (0) 2014.04.03
Toon/Basic with Alpha  (0) 2013.07.19
Toon/Lighted with Alpha  (0) 2013.07.19
toon-water shader  (0) 2012.11.07
Posted by blueasa
, |

Toon/Basic with Alpha

Unity3D/Shader / 2013. 7. 19. 22:27

출처에 있는 SubShader의 해당 부분만 교체..(실행 확인)



Toony-BasicWithAlpha.shader




1 Shader "Toon/Basic with Alpha" { 2 Properties { 3 _Color ("Main Color", Color) = (.5,.5,.5,1) 4 _MainTex ("Base (RGB)", 2D) = "white" {} 5 _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } 6 } 7 8 9 SubShader { 10 Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} 11 Pass { 12 Name "BASE" 13 Cull Back 14 Blend SrcAlpha OneMinusSrcAlpha 15 16 CGPROGRAM 17 #pragma vertex vert 18 #pragma fragment frag 19 #pragma fragmentoption ARB_precision_hint_fastest 20 21 #include "UnityCG.cginc" 22 23 sampler2D _MainTex; 24 samplerCUBE _ToonShade; 25 float4 _MainTex_ST; 26 float4 _Color; 27 28 struct appdata { 29 float4 vertex : POSITION; 30 float2 texcoord : TEXCOORD0; 31 float3 normal : NORMAL; 32 }; 33 34 struct v2f { 35 float4 pos : POSITION; 36 float2 texcoord : TEXCOORD0; 37 float3 cubenormal : TEXCOORD1; 38 }; 39 40 v2f vert (appdata v) 41 { 42 v2f o; 43 o.pos = mul (UNITY_MATRIX_MVP, v.vertex); 44 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); 45 o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0)); 46 return o; 47 } 48 49 float4 frag (v2f i) : COLOR 50 { 51 float4 col = _Color * tex2D(_MainTex, i.texcoord); 52 float4 cube = texCUBE(_ToonShade, i.cubenormal); 53 return float4(2.0f * cube.rgb * col.rgb, col.a); 54 } 55 ENDCG 56 } 57 } 58 59 SubShader { 60 Tags { "RenderType"="Opaque" } 61 Pass { 62 Name "BASE" 63 Cull Back 64 SetTexture [_MainTex] { 65 constantColor [_Color] 66 Combine texture * constant 67 } 68 SetTexture [_ToonShade] { 69 combine texture * previous DOUBLE, previous 70 } 71 } 72 } 73 74 Fallback "VertexLit" 75 } 76



출처 : http://forum.unity3d.com/threads/103030-Toon-shader-with-Transparency

반응형

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

쉐이더 자료 많은 사이트..  (0) 2014.04.03
Toon/Tf2Shader  (0) 2013.07.19
Toon/Lighted with Alpha  (0) 2013.07.19
toon-water shader  (0) 2012.11.07
스크립트로 Shader 변경  (0) 2012.11.06
Posted by blueasa
, |



Toony-LightedWithAlpha.shader




Shader "Toon/Lighted with Alpha" { 

Properties { 

_Color ("Main Color", Color) = (0.5,0.5,0.5,1)

_MainTex ("Base (RGB)", 2D) = "white" {} 

_Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} 

}


    SubShader {

       Tags {"Queue"="Transparent" "RenderType"="Transparent"}

       Blend SrcAlpha OneMinusSrcAlpha

       LOD 200

 

CGPROGRAM

#pragma surface surf ToonRamp

 

sampler2D _Ramp;

 

// custom lighting function that uses a texture ramp based

// on angle between light direction and normal

#pragma lighting ToonRamp exclude_path:prepass

inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)

{

    #ifndef USING_DIRECTIONAL_LIGHT

    lightDir = normalize(lightDir);

    #endif

 

    half d = dot (s.Normal, lightDir)*0.5 + 0.5;

    half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;

 

    half4 c;

    c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);

    c.a = s.Alpha;

    return c;

}

 

 

sampler2D _MainTex;

float4 _Color;

 

struct Input {

    float2 uv_MainTex : TEXCOORD0;

};

 

void surf (Input IN, inout SurfaceOutput o) {

    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;

    o.Albedo = c.rgb;

    o.Alpha = c.a;

}

ENDCG

 

    } 

 

    Fallback "Diffuse"

}


링크 : http://answers.unity3d.com/questions/180977/toon-lighted-alpha.html


참조 :http://stackoverflow.com/questions/13417458/unity-diffuse-shader-with-global-alpha

반응형

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

Toon/Tf2Shader  (0) 2013.07.19
Toon/Basic with Alpha  (0) 2013.07.19
toon-water shader  (0) 2012.11.07
스크립트로 Shader 변경  (0) 2012.11.06
AlphaVertexColor  (0) 2012.11.04
Posted by blueasa
, |

작업을 하다가 필요에 의해서 문득 든 궁금증..


컴포넌트로 추가 된 스크립트는 명시적인 자신의 이름으로만 찾아(GetComponent)지는가?


그래서 간단히 테스트 해봤다.


1) 클래스 2개 만들고,

public class Test : MonoBehaviour

{

    public int m_iCount = 0;   // 접근 테스트용

    ....

}


public class Test2 : Test

{

    ....

}


2) Test2를 Component로 추가

3) 이 상태에서 Test 클래스로 GetComponent를 해봤다.

Test scTest = gameObject.GetComponent<Test>();

if (scTest)

{

    Debug.Log(scTest.m_iCount);

}



[결론]

잘된다. 쓰자~

반응형
Posted by blueasa
, |

Photon Cloud 강좌

Unity3D/Photon / 2013. 7. 16. 00:49

Photon Cloud 강좌 1


Photon Cloud 강좌 2


Photon Cloud 강좌 3


Photon Cloud 강좌 4



출처 : http://www.wolfpack.pe.kr

반응형

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

포튼서버 예제 관련 사이트 입니다.  (0) 2013.09.14
Posted by blueasa
, |