2022.02.09 추가

Unity 2020.1 이후 UnityLoader.js 에서 mobile warning 관련 코드가 사라지고

index.html 부분에서 처리하고 있어 해당부분을 삭제하는것으로 간단하게 해결된다.

 

 

2020.1 미만 버전에서만 대응 된 코드

아래 파일을

Assets/Editor/RemoveMobileSupportWarningWebBuild.cs  위치시킨다 

아래 출처 참고

RemoveMobileSupportWarningWebBuild.cs
0.00MB

출처

https://gist.github.com/JohannesDeml/f551b1e60c59e8472c3e843014d7bd10

// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveMobileSupportWarningWebBuild.cs">
//   Copyright (c) 2021 Johannes Deml. All rights reserved.
// </copyright>
// <author>
//   Johannes Deml
//   public@deml.io
// </author>
// --------------------------------------------------------------------------------------------------------------------

#if !UNITY_2020_1_OR_NEWER //Not needed anymore in 2020 and above
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace Supyrb
{
	/// <summary>
	/// removes a warning popup for mobile builds, that this platform might not be supported:
	/// "Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway."
	/// </summary>
	public class RemoveMobileSupportWarningWebBuild
	{
		[PostProcessBuild]
		public static void OnPostProcessBuild(BuildTarget target, string targetPath)
		{
			if (target != BuildTarget.WebGL)
			{
				return;
			}

			var buildFolderPath = Path.Combine(targetPath, "Build");
			var info = new DirectoryInfo(buildFolderPath);
			var files = info.GetFiles("*.js");
			for (int i = 0; i < files.Length; i++)
			{
				var file = files[i];
				var filePath = file.FullName;
				var text = File.ReadAllText(filePath);
				text = text.Replace("UnityLoader.SystemInfo.mobile", "false");

				Debug.Log("Removing mobile warning from " + filePath);
				File.WriteAllText(filePath, text);
			}
		}
	}
}
#endif

 

 

 

 

-- 기존 내용 --

유니티 webGL 빌드 후 모바일 디바이스로 접속시 아래와 같은 경고창을 볼 수 있다

Please note that Unity WebGL is not currently supported on mobiles.

 

Build/UnityLoader.js 를 안쪽에 모바일 디바이스 체크 부분을 수정해 주면 제거가 가능하다

빌드 때 마다 수동으로 수정을 하기는 힘드니 PostProcessBuild 콜백을 사용하여 빌드 후 해당 부분을 수정하도록 할 수있다.

 

아래 스크립트를 Assets > Editor 폴더에 넣어주면 간단하게 사용 가능하다

using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;

public class PostBuildAction
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string targetPath)
    {
        var path = Path.Combine(targetPath, "Build/UnityLoader.js");
        var text = File.ReadAllText(path);
        text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
        File.WriteAllText(path, text);
    }
}

참조 :

docs.unity3d.com/kr/2018.4/Manual/webgl-browsercompatibility.html

answers.unity.com/questions/1339261/unity-webgl-disable-mobile-warning.html

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Custom/FlatTransparent" {
	Properties{
		_Color("Main Color", Color) = (1,1,1,1)
		_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
	}

		SubShader{
			Tags{ "Queue" = "Transparent" "IgnoreProjector" = "False" "RenderType" = "Transparent" }

			/////////////////////////////////////////////////////////
			/// First Pass
			/////////////////////////////////////////////////////////

			Pass {
		// Only render alpha channel
		ColorMask A
		Blend SrcAlpha OneMinusSrcAlpha

		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag

		fixed4 _Color;

		float4 vert(float4 vertex : POSITION) : SV_POSITION {
			return UnityObjectToClipPos(vertex);
		}

		fixed4 frag() : SV_Target {
			return _Color;
		}

		ENDCG
	}

		/////////////////////////////////////////////////////////
		/// Second Pass
		/////////////////////////////////////////////////////////

		Pass {
			// Now render color channel
			ColorMask RGB
			Blend SrcAlpha OneMinusSrcAlpha

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			sampler2D _MainTex;
			fixed4 _Color;

			struct appdata {
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f {
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			v2f vert(appdata v) {
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = v.uv;
				return o;
			}

			fixed4 frag(v2f i) : SV_Target{
				fixed4 col = _Color * tex2D(_MainTex, i.uv);
				return col;
			}
			ENDCG
		}
	}

		Fallback "Diffuse"
}

 

출처: answers.unity.com/questions/290333/transparent-solid-color-shader.html


Transform.Rotate



Transform.Rorate(Vector3 eulerAngles)

ex)

void Update(){

this.Transform.Rotate(new vector3(0,10,0));

}

//y축을 10도씩 회전한다. 


Transform.Rorate(Vector3 eulerAngles,Space relativeTo)

ex)

void Update(){

this.Transform.Rotate(new vector3(0,10,0),Space.World); //Space.Self

}

//Space.World 또는 Space.Self 인자를 통하여 

//월드축을 기준으로 할지 로컬축을 기준으로 할지 정할수있다.

//만약 오브젝트가 회전한 상태일지라도 위와 같은 코드에서는 월드의 y축을

//기준으로 회전하는것을 볼 수 있다.


Ex

특정 RectTransform 안에 있는 오브젝트를 마우스위치로 이동시키고자할때

 if (RectTransformUtility.ScreenPointToLocalPointInRectangle(

            this.transform.parent.GetComponent<RectTransform>(),

            new Vector2(Input.mousePosition.x, Input.mousePosition.y),

            parentCanvase.worldCamera,

            out pos))

        {

            this.transform.localPosition = pos;


        }else

        {


        }



RectTransformUtility.ScreenPointToLocalPointInRectangle

public static bool ScreenPointToLocalPointInRectangle(RectTransform rectVector2 screenPointCamera cam, outVector2 localPoint);

Parameters

rectThe RectTransform to find a point inside.
camThe camera associated with the screen space position.
screenPointScreen space position.
localPointPoint in local space of the rect transform.

Returns

bool Returns true if the plane of the RectTransform is hit, regardless of whether the point is inside the rectangle.

Description

Transform a screen space point to a position in the local space of a RectTransform that is on the plane of its rectangle.

The cam parameter should be the camera associated with the screen point. For a RectTransform in a Canvas set to Screen Space - Overlay mode, the cam parameter should be null.

When ScreenPointToLocalPointInRectangle is used from within an event handler that provides a PointerEventData object, the correct camera can be obtained by using PointerEventData.enterEventData (for hover functionality) orPointerEventData.pressEventCamera (for click functionality). This will automatically use the correct camera (or null) for the given event.

출처:

http://docs.unity3d.com/ScriptReference/RectTransformUtility.ScreenPointToLocalPointInRectangle.html

public void writeStringToFile( string str, string filename )
{
#if !WEB_BUILD
string path = pathForDocumentsFile( filename );
FileStream file = new FileStream (path, FileMode.Create, FileAccess.Write);

StreamWriter sw = new StreamWriter( file );
sw.WriteLine( str );

sw.Close();
file.Close();
#endif 
}


public string readStringFromFile( string filename)//, int lineIndex )
{
#if !WEB_BUILD
string path = pathForDocumentsFile( filename );

if (File.Exists(path))
{
FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader( file );

string str = null;
str = sr.ReadLine ();

sr.Close();
file.Close();

return str;
}

else
{
return null;
}
#else
return null;
#endif 
}

public string pathForDocumentsFile( string filename ) 

if (Application.platform == RuntimePlatform.IPhonePlayer)
{
string path = Application.dataPath.Substring( 0, Application.dataPath.Length - 5 );
path = path.Substring( 0, path.LastIndexOf( '/' ) );
return Path.Combine( Path.Combine( path, "Documents" ), filename );
}

else if(Application.platform == RuntimePlatform.Android)
{
string path = Application.persistentDataPath; 
path = path.Substring(0, path.LastIndexOf( '/' ) ); 
return Path.Combine (path, filename);


else 
{
string path = Application.dataPath; 
path = path.Substring(0, path.LastIndexOf( '/' ) );
return Path.Combine (path, filename);
}
}


출처::http://blog.naver.com/nameisljk/110157303742


+ Recent posts