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

카테고리

분류 전체보기 (2861)
Unity3D (899)
Programming (479)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (192)
협업 (65)
3DS Max (3)
Game (12)
Utility (142)
Etc (99)
Link (34)
Portfolio (19)
Subject (90)
iOS,OSX (53)
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

이번에는 HTTP 서버에 데이터 요청을 보내고 데이터를 얻어오기, 혹은 데이터를 보내는 방법입니다.


목차

1. WWW 클래스로 구현(권장하지 않습니다.)

2-1. Get 방식

2-2. Post 방식

2. UnityWebRequest 클래스로 구현(권장)

2-1. Get 방식

2-2. Post 방식

3. 요약 및 정리


1. WWW 클래스로 구현

1-1 GET 방식

아래는 제가 작성한 간단한 GET 방식의 코드입니다.

GET 방식 테스트를 위해 이곳을 이용하겠습니다.

https://developers.neople.co.kr/contents/apiDocs

 

Neople Developers

## 참고 사항 >- 타임라인 코드 다중 입력 시 콤마(,)를 이용해서 구분 처리   ex) /timeline?code=101,102,103 - startDate, endDate 요청 변수 사용 예시   ex) /timeline?startDate=20180901T0000&endDate=20180930T2359           /timeline?startDate=2018-09-01 00:00&endDate=2018-09-30 23:59   ※ 기간 검색

developers.neople.co.kr

 

APIKey는 로그인을 하시고 발급받으시면 보입니다.

응답 요청은 코루틴을 이용해서 보내도록 하겠습니다.

코루틴을 이용하는 이유는 응답을 보내고 오는 시간이 걸리기 때문입니다.

다른 곳에서 작성하시면 응답이 오기 전에 처리하게 되어 오류가 출력됩니다.

위에 코드는 예시 코드입니다.

홈페이지에서 발급받은 apikey를 저기에 입력하시면 됩니다.

url을 보시면 servers? apikey=하고 요청을 보내게 되는데

헤더 부분에 정보를 넣어서 보내는 곳이 저곳입니다.

코드에 주석을 넣었으니 읽으면서 확인해보세요.

코드를 실행해보시면 이렇게 응답이 옵니다.

1-2 POST 방식

위에는 POST 방식입니다.

POST 방식은 따로 동작을 처리해야 하기 때문에 개인적으로 만든 서버를 이용하여 설명하겠습니다.(저건 사설 ip 주소이기 때문에 똑같이 적으셔도 동작 안 합니다.)

(테스트해보고 싶으신 분들은 따로 서버를 만드셔서 실험해보세요)

POST 방식은? apikey= 이런 게 없습니다.

필드명에 apikey를 넣고 데이터를 넣으시면 됩니다.

필요한 내용은 주석 처리했습니다.

서버에서 로그인 정보가 맞으면 응답을 보냅니다.


2. unitywebrequest 클래스

이제 www 클래스는 Unity에서 사용을 권장하지 않습니다.

사용하시면 주의로 unitywebrequest를 사용하라고 나올 텐데요.

이것을 사용하는 방법을 알려드리겠습니다.

UnityEngine.Networking을 추가해줍니다.

2-1 GET 방식

아래는 WWW 클래스를 UnityWebRequest 클래스 방식으로 수정한 것입니다.

수정한 부분은 빨간 줄로 밑줄을 쳤습니다.

2-2 POST 방식

수정한 부분은 밑줄 쳤습니다.


3. 요약 및 정리

정리 : 통신방식에는 GET과 POST가 있다.

GET은 쉬우나 보안 취약, 용량 제한

POST는 어려우나 보안에 좋고, 용량 제한이 없다.

WWW 클래스는 이제 사용하지 않는다.

UnityWepRequest를 사용하자.(설명은 WWW 클래스에 적어놓았다.)

 

 

[출처] mungto.tistory.com/190

 

www 클래스, UnityWebRequest 클래스 사용하기(HTTP 서버에 데이터 가져오기, 보내기 등)

이번에는 HTTP 서버에 데이터 요청을 보내고 데이터를 얻어오기, 혹은 데이터를 보내는 방법입니다. 목차 1. WWW 클래스로 구현(권장하지 않습니다.) 2-1. Get 방식 2-2. Post 방식 2. UnityWebRequest 클래스

mungto.tistory.com

 

[참조] docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Post.html

반응형
Posted by blueasa
, |

[출처] www.raywenderlich.com/9671886-new-unity-input-system-getting-started

 

New Unity Input System: Getting Started

In this Unity Input System tutorial, you’ll learn how to convert player input in your existing projects from the old Input Manager to the new Input System.

www.raywenderlich.com

 

In this Unity Input System tutorial, you’ll learn how to convert player input in your existing projects from the old Input Manager to the new Input System.

 

Version

  • C# 7.3, Unity 2020.1, Unity

Handling input is a pillar of creating a successful game. Input devices help player characters perform actions inside the game such as walking, jumping and climbing.

Recently, many new platforms have come out, introducing more Unity input devices. These include touch screens, VR controllers and gamepads from different game consoles. If you want your game to support different platforms, you need to write code to handle the logic for different devices. The more platforms you support, the more complex your code will be.

Luckily, there’s a new Unity Input System that helps developers deal with this situation, making input-related code easier to manage.

In this tutorial, you’ll learn:

  • The features of the new Input System.
  • How the new system works.
  • How to migrate apps to the new Input System from the old Input Manager.

The materials for this tutorial were built in Unity version 2020.1. You can get this version of Unity from the Unity website or install it with the Unity Hub.

Note: Although this tutorial is for beginners, you’ll need to have some basic knowledge of Unity development and how to work with Unity Editor to complete it. If you’re new to Unity development, check out our tutorial on Getting Started In Unity.

Getting Started

First, download the starter project for this tutorial using the Download Materials button at the top or bottom of this page. Unzip its contents and open NewUnityInputSystem-Starter in Unity.

After the project loads, you’ll see the RW folder in the Project Window:

Take a look at the organization of the folder:

  • Fonts: Fonts used in the scene.
  • Materials: Materials for the scene.
  • Models: 3D meshes for the player character and game environments.
  • Prefabs: Pre-built components composed of Scripts and Models.
  • Scenes: The game scene.
  • Scripts: Scripts with game logic.
  • Settings: The settings file, which is where you’ll put the input settings.
  • Shaders: Shaders for special effects like the player’s shadow.
  • Textures: The graphics used by Materials and UIs.

The starter project is a simple platformer game. You control the player character by moving around and jumping to collect coins.

The game is ready to play. Open GameScene from the Scenes folder and click Play to try the game for yourself!

Currently, the Move and Jump controls use the old Unity Input Manager. You’ll learn how to use the new Input System to replace the old system later in the tutorial.

What’s New in the Unity Input System

Before diving into the code, take a look at the new Input System’s features.

Simpler Action and Binding Architecture

The old input system checked input from different devices every frame to determine whether players took an action.

The following code, which supports both gamepads and keyboards, is an example of the old way of doing things:

bool isGamepad = Input.GetAxis("Gamepad Fire") != 0f; if (isGamepad) { return Input.GetAxis("Gamepad Fire") >= triggerAxisThreshold; } else { return Input.GetButton("Fire"); }

The code uses if-else branching to handle support for different devices and their associated actions.

The new Input System separates device input from code actions. That means you only have to handle the actions the players trigger. You don’t need to know which device the player is using or which button they’re clicking.

An input event in the new system is called an action, while the mapping between an action and an input device is a binding.

Gathering Information With the Input Debug Tool

The Input System provides you with a new tool called Input Debugger. Open it by selecting Window ▸ Analysis ▸ Input Debugger from the menu.

The Input Debugger helps developers by gathering the following information in one place:

The state of the Input System, including:

  • Device: Information about the connected devices.
  • Layout: Which controls those devices provide.
  • Setting: The configuration of the input system.

It also provides real-time information about a specific device. Open this by double-clicking the device from the device list in the Input Debugger window.

Here’s a demo of the Input Debugger in action:

Feel free to keep the Input Debugger open while you work through the tutorial.

Support for Multiple Devices and Platforms

With the increased flexibility from the Input System’s new architecture, Unity can support many different input devices, including:

  • Keyboard
  • Mouse
  • Pen
  • TouchScreen
  • Sensor
  • Joystick
  • GamePad

Note: The Input System also supports devices that implement the USB HID specification. For more details, check out Unity’s Supported Devices Documentation.

Understanding the New Input System

The new Input System has four building blocks that funnel events from player devices to your game code:

  • Input Action Assets: A settings file that contains the properties of the actions and their associated bindings.
  • Actions: Actions define the logical meanings of the input. You can find that information in the Input Action Assets.
  • Bindings: Bindings describe the connection between an action and the input device controls. You’ll find this information in the Input Action Assets, too.
  • PlayerInput: PlayerInput is a script that manages and links action events to the corresponding code logic.

Sometimes it’s easier to understand a new workflow if you can visualize it, so take a look at the image below:

Break this down into its simplest steps:

  • First, the Unity Engine collects information from the connected devices and sends corresponding events, like a button click, to the Input System.
  • The Input System then translates those events into actions, based on the action and binding information stored in the Input Action Assets.
  • It then passes the actions to the PlayerInput script, which invokes the corresponding methods.

Now that you know a little more about how the Input System works, you’ll use it to control the game character in the coming sections.

Installing the New Input System

The first thing you’ll do is install the new Input System package. The standard Unity installation doesn’t include it.

Open Window ▸ Package Manager in the menu bar. Make sure that you select Unity Registry in the Packages dropdown, if you haven’t already.

Find Input System on the list. Select it and click Install.

Creating an Input Action Asset

Once you’ve installed the Input System package, you’ll create an Input Action Asset to store the settings for your actions and bindings.

Open the Project window and select Settings from RW. Right-click, select Create ▸ Input Actions and rename it to MyControl.

Setting up the Action Editor

Double-click MyControl in Settings to open the Action Editor, which helps you manipulate actions and control bindings.

Since this is a new window, take a look at the sections:

  1. Action Maps: Groups of actions that occur in the game. You can group actions for different purposes, like player, gameplay or UI.
  2. Actions: The list of actions and bindings associated with the selected Action Map. In this panel, you create, modify or delete actions and bindings.
  3. Properties: Edit the action or binding properties in this panel, such the type of action and the controls you associated with the binding.
  4. Save Assets: This is a very important function: You must click Save Asset after making any changes to the Input Action Asset. If you forget to save, the setting won’t work. Thus, you won’t see the expected result and may think there’s a bug in the code.

    You can switch on Auto Save to prevent the problem, but it’s quite slow.

Now you’re ready to create your first action, the Jump action.

Creating a Jump Action

First, open the Action Editor and click the + icon in the ActionMap to create a new Action Map. Rename it from the default, New Action Map, to Player.

Then, in the Action panel, double-click New Action and rename it to a meaningful name: Jump.

Finally, you need to add a binding to the Jump action. You’ll bind the Spacebar and Left Mouse Button to this action by following these steps:

  1. Select the Jump action, click the + icon and select Add Binding.
  2. Click the new binding item, <No binding>.
  3. Click the Path field in the Binding properties panel.
  4. Type Spacebar Keyboard and select Space [Keyboard] to create the binding for the Spacebar.
  5. Repeat steps 1–3 to create another binding for the Left Mouse Button.
  6. Type Left Button in the Path field and select Left Button [Mouse] to create the binding.

Congratulations, you’ve now associated the Jump action with the Spacebar on the keyboard and the left button on the mouse.

Now to hook up those actions with your code!

Implementing the Jump Logic

First of all, you need to remove the old input logic from the project. Open Player.cs and navigate to the Update() method.

void Update() { UpdateAnimation(); if (!jumping && Input.GetKeyDown(KeyCode.Space)) { HandleJump(); } }

As you can see, the current code triggers the animation updates, then it checks if the player has pressed the space bar in order to start a jump.

Now that the Jump action and its control bindings are ready, the next thing to do is link the action to the code.

Linking the Jump Action to the Code

Start by deleting the code in Update to remove the implementation of the old Input Manager so you can add Jump logic using the new Input System. Update will now only control the animations.

void Update() { UpdateAnimation(); }

Save the script and go back to the editor. Select the Player object in the Hierarchy and add a PlayerInput component from the Inspector.

Next, you’ll drag MyControl to PlayerInput’s Actions. Make sure to set the Default Map to Player.

Finally, open Player.cs and add a new method called OnJump() with the following code:

public void OnJump() { HandleJump(); }

You’ve associated this method with the Jump action by using this pattern to name it: public void On[Action Name Goes Here]().

For example, the Jump action invokes OnJump(), while the Attack action invokes OnAttack().

Click Save Asset in the Action Editor and run the game. Now you can use the SpaceBar or the left mouse button to make the player character jump. It’s really that easy!

Creating the Move Action

You’ve learned how to use the Input System to create a Jump action. Next up is the Move action! Move is similar to Jump, but it has a few key differences.

For example, the Jump action is a simple trigger event, while the Move action is an event that carries values: the movement direction, which comes from user input.

Again, you need to create the action and its binding. Start by going to Action Editor (double click MyControl if you lost the window) and click the + icon in the Actions panel to create a new action. Rename it to Move.

Next, open the Action properties panel, change Action Type to Value and Control Type to Vector 2.

Finally, remove <No Binding> by right-clicking and selecting Delete.

Now, you need to create the Move action’s bindings.

First, you’ll click the + icon in the header of the Move action. Then, select Add 2D Vector Composite, which will create four binding items corresponding to the up, down, left and right directions.

Now, you’ll set the path of each binding as follows:

  • Up: Up Arrow [Keyboard]
  • Down: Down Arrow [Keyboard]
  • Left: Left Arrow [Keyboard]
  • Right: Right Arrow [Keyboard]

Don’t forget to save the asset in the Action Editor!

Implementing the Move Logic

Before adding new movement logic, you need to remove the implementation of the old Unity input.

Open Player.cs and go to FixedUpdate():

private void FixedUpdate() { // 1 float speedX = Input.GetAxisRaw("Horizontal"); // Left, Right float speedY = Input.GetAxisRaw("Vertical"); // Back, Forward moveVec = new Vector3(speedX, 0, speedY); if (jumping == false) { // 2 UpdateWhenGrounded(); } else { // 3 UpdateWhenJumping(); } }

Note that FixedUpdate() is called in every fixed frame-rate frame.

Now, break this down:

  1. Input.GetAxisRaw returns the value of Axis. Input.GetAxisRaw("Horizontal") gives the value of the X-Axis, while Input.GetAxisRaw("Vertical") gives the value of Y-Axis.

    These two values define the movement vector moveVec, which you use to control the direction of the player movement.

  2. The logic of the player character’s behavior while it’s on the ground.
  3. The logic of the player character’s behavior while it’s jumping.

Now, delete all the code prior to the if statement to remove the old input logic. Add the following code above the class definition:

using UnityEngine.InputSystem;

This allows you to access values from the new Input System.

Then, add OnMove(), which the Move action invokes.

public void OnMove(InputValue input) { Vector2 inputVec = input.Get<Vector2>(); moveVec = new Vector3(inputVec.x, 0, inputVec.y); }

When a player presses the Up, Down, Left or Right keys, it passes a Move action to this method, along with the values. Here’s how the key presses affect the values:

  • Up: (0, 1)
  • Down: (0, -1)
  • Left: (-1, 0)
  • Right: (1, 0)
  • No Key: (0, 0)
  • Up and Left: (1, -1)

InputValue is a new type you may not know. This class has a Get\() method that you can use to access its values. In this instance, you want the 2D Vector Composite you set in the binding to calculate the movement vector.

Click Play to test the logic.

Handling Actions

The new Input System provides four ways to handle action events.

In this tutorial, you used the SendMessages approach. You can change this option in the Behavior field in the PlayerInput component.

SendMessage and BroadcastMessage are the simplest ways to handle actions. When you use these two options, the system invokes the method with a name matching the name of the action.

For example, in this tutorial, the Jump action invokes OnJump() and the Move action invokes OnMove().

BroadcastMessage is similar to SendMessage, except it can invoke the methods on any child GameObject. These two options are easy to use because you don’t need to configure anything to use them.

Using Invoke Unity Events

When using Invoke Unity Events, you configure the action much as you’d configure a button click in Unity UI.

This approach is more flexible, letting you use different methods in different objects. Those GameObjects don’t even need to have the PlayerInput component.

Using Invoke C# Events

This approach is as flexible as Invoke Unity Events. You can define the methods you want to use instead of using methods with a specific name. However, if you use this approach, you need to write code to control which methods to invoke.

Here is a sample of how this looks:

private void Awake() { animator = GetComponentInChildren<Animator>(); rigidbody = GetComponent<Rigidbody>(); // 1 GetComponent<PlayerInput>().onActionTriggered += HandleAction; } private void HandleAction(InputAction.CallbackContext context) { // 2 if(context.action.name == "Jump") { HandleJump(); } }

Here’s what this code does:

  1. Gets the PlayerInput component and registers the method to onActionTriggered.
  2. Controls which method to call for different actions.

Using the Update Cycle of the New Input System

In the old Unity Input Manager, you checked the input in every frame using Update(). In the new Input System, you may wonder when actions are being sent, and if they’re sent before every Update().

The new Input System uses a different update cycle that’s independent of MonoBehaviour‘s lifecycle. You can read more about it in Unity’s Execution Order documentation.

The system offers three Update Modes to control the update cycle. You can configure them in Project Settings ▸ Input System Package ▸ Update Mode.

Take a look at each of these nodes:

  • Dynamic Update: Processes events at irregular intervals determined by the current frame rate. This is the default setting.
  • Fixed Update: Processes events at fixed-length intervals. Time.fixedDeltaTime determines the length of the interval.
  • Manually: Events aren’t processed automatically; you process them when you call InputSystem.Update(). If you want a check similar to the old system, you can call InputSystem.Update() in Update().

These new options, as part of the new Input System, give you a lot more control over input, whilst also making it easier to support multiple input devices :]

Where to Go from Here?

Download the completed project using the Download Materials button at the top or bottom of this tutorial.

In this Unity Input tutorial, you’ve learned:

  • The basic layout of the new Input System.
  • How to use actions and bindings.
  • How to handle different kinds of player input efficiently.

To test your skill, try to add a Pause action to the game!

To learn more about the new Input System, you can read the Unity Input System manual.

I hope you have enjoyed this tutorial! If you have any questions or comments, please join the forum discussion below.

반응형
Posted by blueasa
, |

[링크] www.elopezr.com/photoshop-blend-modes-in-unity/

 

Photoshop Blend Modes Without Backbuffer Copy

[latexpage] For the past couple of weeks, I have been trying to replicate the Photoshop blend modes in Unity. It is no easy task; despite the advances of modern graphics hardware, the blend unit st…

www.elopezr.com

Photoshop Blend Modes Without Backbuffer Copy

 BY ADMINOCTOBER 7, 2016GRAPHICS, UNITY

For the past couple of weeks, I have been trying to replicate the Photoshop blend modes in Unity. It is no easy task; despite the advances of modern graphics hardware, the blend unit still resists being programmable and will probably remain fixed for some time. Some OpenGL ES extensions implement this functionality, but most hardware and APIs don’t. So what options do we have?

1) Backbuffer copy

A common approach is to copy the entire backbuffer before doing the blending. This is what Unity does. After that it’s trivial to implement any blending you want in shader code. The obvious problem with this approach is that you need to do a full backbuffer copy before you do the blending operation. There are certainly some possible optimizations like only copying what you need to a smaller texture of some sort, but it gets complicated once you have many objects using blend modes. You can also do just a single backbuffer copy and re-use it, but then you can’t stack different blended objects on top of each other. In Unity, this is done via a GrabPass. It is the approach used by the Blend Modes plugin.

2) Leveraging the Blend Unit

Modern GPUs have a little unit at the end of the graphics pipeline called the Output Merger. It’s the hardware responsible for getting the output of a pixel shader and blending it with the backbuffer. It’s not programmable, as to do so has quite a lot of complications (you can read about it here) so current GPUs don’t have one.

The blend mode formulas were obtained here and here. Use it as reference to compare it with what I provide. There are many other sources. One thing I’ve noticed is that provided formulas often neglect to mention that Photoshop actually uses modified formulas and clamps quantities in a different manner, especially when dealing with alpha. Gimp does the same. This is my experience recreating the Photoshop blend modes exclusively using a combination of blend unit and shaders. The first few blend modes are simple, but as we progress we’ll have to resort to more and more tricks to get what we want.

Two caveats before we start. First off, Photoshop blend modes do their blending in sRGB space, which means if you do them in linear space they will look wrong. Generally this isn’t a problem, but due to the amount of trickery we’ll be doing for these blend modes, many of the values need to go beyond the 0 – 1 range, which means we need an HDR buffer to do the calculations. Unity can do this by setting the camera to be HDR in the camera settings, and also setting Gamma for the color space in the Player Settings. This is clearly undesirable if you do your lighting calculations in linear space. In a custom engine you would probably be able to set this up in a different manner (to allow for linear lighting).

If you want to try the code out while you read ahead, download it here.

 

[File]

BlendModesNoBackbuffer.zip
0.00MB

 

A) Darken

Formula min(SrcColor, DstColor)
Shader Output color.rgb = lerp(float3(1, 1, 1), color.rgb, color.a);
Blend Unit Min(SrcColor · One, DstColor · One)

Darken

As alpha approaches 0, we need to tend the minimum value to DstColor, by forcing SrcColor to be the maximum possible color float3(1, 1, 1)

 

B) Multiply

Formula SrcColor · DstColor
Shader Output color.rgb = color.rgb * color.a;
Blend Unit SrcColor · DstColor + DstColor · OneMinusSrcAlpha

Multiply

 

C) Color Burn

Formula 1 – (1 – DstColor) / SrcColor
Shader Output color.rgb = 1.0 - (1.0 / max(0.001, color.rgb * color.a + 1.0 - color.a)); // max to avoid infinity
Blend Unit SrcColor · One + DstColor · OneMinusSrcColor

Color Burn

 

D) Linear Burn

Formula SrcColor + DstColor – 1
Shader Output color.rgb = (color.rgb - 1.0) * color.a;
Blend Unit SrcColor · One + DstColor · One

Linear Burn

 

E) Lighten

Formula Max(SrcColor, DstColor)
Shader Output color.rgb = lerp(float3(0, 0, 0), color.rgb, color.a);
Blend Unit Max(SrcColor · One, DstColor · One)

Lighten

 

F) Screen

Formula 1 – (1 – DstColor) · (1 – SrcColor) = Src + Dst – Src · Dst
Shader Output color.rgb = color.rgb * color.a;
Blend Unit SrcColor · One + DstColor · OneMinusSrcColor

Screen

 

G) Color Dodge

Formula DstColor / (1 – SrcColor)
Shader Output color.rgb = 1.0 / max(0.01, (1.0 - color.rgb * color.a));
Blend Unit SrcColor · DstColor + DstColor · Zero

Color Dodge

You can see discrepancies between the Photoshop and the Unity version in the alpha blending, especially at the edges.

 

H) Linear Dodge

Formula SrcColor + DstColor
Shader Output color.rgb = color.rgb;
Blend Unit SrcColor · SrcAlpha + DstColor · One

Linear Dodge

This one also exhibits color “bleeding” at the edges. To be honest I prefer the one to the right just because it looks more “alive” than the other one. Same goes for Color Dodge. However this limits the 1-to-1 mapping to Photoshop/Gimp.

All of the previous blend modes have simple formulas and one way or another they can be implemented via a few instructions and the correct blending mode. However, some blend modes have conditional behavior or complex expressions (complex relative to the blend unit) that need a bit of re-thinking. Most of the blend modes that follow needed a two-pass approach (using the Pass syntax in your shader). Two-pass shaders in Unity have a limitation in that the two passes aren’t guaranteed to render one after the other for a given material. These blend modes rely on the previous pass, so you’ll get weird artifacts. If you have two overlapping sprites (as in a 2D game, such as our use case) the sorting will be undefined. The workaround around this is to move the Order in Layer property to force them to sort properly.

 

I) Overlay

Formula 1 – (1 – 2 · (DstColor – 0.5)) · (1 – SrcColor), if DstColor > 0.5
2 · DstColor · SrcColor, if DstColor <= 0.5
Shader Pass 1 color.rgb *= color.a;
float3 A = (4.0 * color.rgb - 1.0) / (2.0 - 4.0 * color.rgb);
float3 B = (1.0 * color.a) / ((2.0 - 4.0 * color.rgb) * max(0.001, color.a));
color.rgb = A + B;
Blend Pass 1 SrcColor · DstColor + DstColor · DstColor
Shader Pass 2 color.rgb = (2.0 - 4.0 * color.rgb * color.a) max(0.001, color.a);
Blend Pass 2 SrcColor · DstColor + DstColor · Zero

Overlay

How I ended up with Overlay requires an explanation. We take the original formula and approximate via a linear blend:

We simplify as much as we can and end up with this

The only way I found to get DstColor · DstColor is to isolate the term and do it in two passes, therefore we extract the same factor in both sides:

However this formula doesn’t take alpha into account. We still need to linearly interpolate this big formula with alpha, where an alpha of 0 should return Dst. Therefore

If we include the last term into the original formula, we can still do it in 2 passes. We need to be careful to clamp the alpha value with max(0.001, a) because we’re now potentially dividing by 0. The final formula is

 

J) Soft Light

Formula 1 – (1 – DstColor) · (1 – (SrcColor – 0.5)), if SrcColor > 0.5
DstColor · (SrcColor + 0.5), if SrcColor <= 0.5
Shader Pass 1

float3 A = 2.0 * color.rgb * color.a / (1.0 - 2.0 * color.rgb * color.a);
float3 B = (1.0 - color.a) / ((1.0 - 2.0 * color.rgb * color.a) * max(0.001, color.a));
color.rgb = A + B;

Blend Pass 1 SrcColor · DstColor + SrcColor · DstColor
Shader Pass 2 color.rgb = (1.0 - 2.0 * color.rgb * color.a) * max(0.001, color.a);
Blend Pass 2 SrcColor · DstColor + SrcColor * Zero

Soft Light

For the Soft Light we apply a very similar reasoning to Overlay, which in the end leads us to Pegtop’s formula. Both are different from Photoshop’s version in that they don’t have discontinuities. This one also has a darker fringe when alpha blending.

 

K) Hard Light

Formula 1 – (1 – DstColor) · (1 – 2 · (SrcColor – 0.5)), if SrcColor> 0.5
DstColor · (2 · SrcColor), if SrcColor <= 0.5
Shader Pass 1

float3 A (2.0 * color.rgb * color.rgb - color.rgb) * color.a;

float3 B max(0.001, (4.0 * color.rgb - 4.0 * color.rgb * color.rgb) * color.a + 1.0 - color.a);

color.rgb = A B;

Blend Pass 1 SrcColor · One + DstColor · One
Shader Pass 2 color.rgb = max(0.001, (4.0 * color.rgb - 4.0 * color.rgb * color.rgb) * color.a + 1.0 - color.a);
Blend Pass 2 SrcColor · DstColor + SrcColor * Zero

Hard Light

Hard Light has a very delicate hack that allows it to work and blend with alpha. In the first pass we divide by some magic number, only to multiply it back in the second pass! That’s because when alpha is 0 it needs to result in DstColor, but it was resulting in black.

 

L) Vivid Light

Formula 1 – (1 – DstColor) / (2 · (SrcColor – 0.5)), if SrcColor > 0.5
DstColor / (1 – 2 · SrcColor), if SrcColor <= 0.5
Shader Pass 1

color.rgb *= color.a;

color.rgb = color.rgb &gt;0.5 ? 1.0 / max(0.0001, 2.0 - 2.0 * color.rgb) : 1.0);

Blend Pass 1 SrcColor · DstColor + SrcColor · Zero
Shader Pass 2 color.rgb = color.rgb &lt; 0.5 ? (color.a - color.a / max(0.0001, 2.0 * color.rgb)) : 0.0;
Blend Pass 2 SrcColor · One + SrcColor · OneMinusSrcColor

Vivid Light

 

M) Linear Light

Formula DstColor + 2 · (SrcColor – 0.5), if SrcColor > 0.5
DstColor + 2 · SrcColor – 1, if SrcColor <= 0.5
Shader Output color.rgb = (2 * color.rgb - 1.0) * color.a;
Blend Unit  SrcColor · One + DstColor · One

Linear Light

[29/04/2019] Roman in the comments below reports that he couldn’t get Linear Light to work using the proposed method and found an alternative. His reasoning is that the output color becomes negative which gets clamped. I’m not sure what changed in Unity between when I did it and now but perhaps it relied on having an RGBA16F render target which may have changed since then to some other HDR format such as RG11B10F or RGB10A2 which do not support negative values. His alternative becomes (using RevSub as the blend op):

Formula DstColor + 2 · (SrcColor – 0.5), if SrcColor > 0.5
DstColor + 2 · SrcColor – 1, if SrcColor <= 0.5
Shader Output color.rgb = -(2 * color.rgb - 1.0) * color.a;
Blend Unit DstColor · One – SrcColor · One

 

 

 
반응형
Posted by blueasa
, |

[결론]

GoogleMobileAds iOS SDK 7.68 이상은 Firebase 7.x 이상에서 지원합니다.

Firebase 업데이트 하세요


Unity: 2019.4.8f1

AdMob v5.4.0

Firebase v6.16.1 (Messaging & Analytics)

Target minimum iOS Version 12.0

Problem

I can't build the project. XCode error:

../Libraries/Plugins/iOS/GADUAdLoader.h:5:9: 'GoogleMobileAds/GoogleMobileAds.h' file not found

When I trying to update pods terminal throw the next error:

[!] CocoaPods could not find compatible versions for pod "GoogleAppMeasurement":
  In Podfile:
    Firebase/Analytics (= 6.32.2) was resolved to 6.32.2, which depends on
      Firebase/Core (= 6.32.2) was resolved to 6.32.2, which depends on
        FirebaseAnalytics (= 6.8.2) was resolved to 6.8.2, which depends on
          GoogleAppMeasurement (= 6.8.2)

    Google-Mobile-Ads-SDK (~> 7.68) was resolved to 7.68.0, which depends on
      GoogleAppMeasurement (~> 7.0)

Attempts

  1. Add 'pod 'GoogleAppMeasurement', '7.0'' to Podfile.

Result

CocoaPods could not find compatible versions for pod "GoogleAppMeasurement":
  In Podfile:
    Firebase/Analytics (= 6.32.2) was resolved to 6.32.2, which depends on
      Firebase/Core (= 6.32.2) was resolved to 6.32.2, which depends on
        FirebaseAnalytics (= 6.8.2) was resolved to 6.8.2, which depends on
          GoogleAppMeasurement (= 6.8.2)

    Google-Mobile-Ads-SDK (~> 7.68) was resolved to 7.68.0, which depends on
      GoogleAppMeasurement (~> 7.0)

    GoogleAppMeasurement (= 7.0)
  1. Uninstall and install cocoapods

Result

Same error

Project Podfile

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/CocoaPods/Specs'
platform :ios, '12.0'

target 'UnityFramework' do
  pod 'Firebase/Analytics', '6.32.2'
  pod 'Firebase/Core', '6.32.2'
  pod 'Firebase/Messaging', '6.32.2'
  pod 'Google-Mobile-Ads-SDK', '~> 7.68'
end

 

How can I resolve this problem?

 

 

[Answer]

Google-Mobile-Ads-SDK version 7.68 is only compatible with Firebase 7.x. If you want to use Firebase 6.x, you need to use 7.67 or earlier.

 

 

[출처] stackoverflow.com/questions/64850730/unity-firebase-admob-conflict-googleappmeasurement

 

Unity Firebase + AdMob conflict (GoogleAppMeasurement)

Unity: 2019.4.8f1 AdMob v5.4.0 Firebase v6.16.1 (Messaging & Analytics) Target minimum iOS Version 12.0 Problem I can't build the project. XCode error: ../Libraries/Plugins/iOS/GADUAdLoader.h:5...

stackoverflow.com

 

반응형
Posted by blueasa
, |

[iOS14+ 대응 관련 FAN SDK 6.2 적용 시 구현 이슈 2가지]

Audience Network SDK(6.2) 최신 버전은 10월 26일에 릴리스되었습니다. 최신 버전에서 강조할 만한 중요한 요구 사항은 두 가지가 있습니다.

 

1. 미디에이션 사용과 무관하게 ‘setAdvertiserTrackingEnabled’ 플래그를 구현하여 데이터로 개인화된 광고를 게재하는지 알려야 합니다.

2.  추천된 SKAdNetwork ID를 Xcode 프로젝트의 Info.plist에 추가하여 광고주가 광고 캠페인의 성공을 측정하도록 합니다.


iOS14에 대응하기 위해 AN SDK 6.2 이상을 적용해야 되는데, iOS에서 FAN SDK 6.2는 위와 같은 2가지 필수 구현사항을 요구하고 있다.

 

현재 나는 Admob 미디에이션을 사용하고, Admob의 FAN 미디에이션 플러그인을 적용해놨는데,

미디에이션이라 하더라도 위 2가지는 적용해야 된다고 한다.

 

위 2가지를 어떻게 적용했는지 정리해 둔다.

 

(※ iOS 플랫폼 대응이니 Android에서는 작동 안하도록 해두자)

1.   ‘setAdvertiserTrackingEnabled’ (이하 ATE) flag 구현

1.1. 광고 추적 활성화

1.1.1. 미디에이션 미 사용 시(AN SDK 직접 적용)

     [링크] developers.facebook.com/docs/audience-network/guides/advertising-tracking-enabled

1.1.2. 미디에이션 사용 시

1.1.2.1. 미디에이션 사용 시에는 아래와 같이 직접 구현해서 사용하라고 설명이 적혀 있다.

          [참조] 미디에이션을 사용 중인 경우 setAdvertiserTrackingEnabled 플래그를 구현한 다음, 미디에이션 SDK를 초기화해야 Facebook에서 입찰 요청을 통해 이를 수신할 수 있습니다.

          ※ 나는 Unity를 사용하고, Admob 미디에이션(GoogleMobileAds)을 사용하기 때문에 유니티에 적용할 수 있는 방식으로 직접 구현이 필요하다.

1.1.2.2. (직접 구현하는 건 귀찮으니)아래 파일을 다운받고, 패키지를 실행해서 AdSettings.cs 파일만 프로젝트에 추가

          [다운로드] Audience Network SDK for Unity

1.1.2.3. Admob 제어 하는 곳에서 Admob 초기화 전에 아래 소스를 추가해서 셋팅해 주자.

         (1.1.2.2.의 파일을 추가하면 아래 소스 실행이 가능해진다.)

// iOS에서만 실행하도록 한다.
#if UNITY_IPHONE && !UNITY_EDITOR
// Set the flag as true 
AudienceNetwork.AdSettings.SetAdvertiserTrackingEnabled(true);
#endif

 

2.   SKAdNetwork IDs Xcode 프로젝트의 Info.plist 추가

2.1. SKAdNetwork ID를 발급받는다.

     [참조 링크] www.wisetracker.co.kr/wp-content/uploads/2020/09/iOS_14_update_guide.pdf

2.2. ID를 Inpo.plist에 추가한다. (아래 보이는 ID는 예시입니다.)

2.2.1. Inpo.Plist에 직접 추가하는 방법(developer.apple.com/documentation/storekit/skadnetwork/configuring_the_participating_apps)

 

※ 아래 2개 SKAdNetworkID는 페이스북 공용 ID이니, FAN을 붙이는거면 그대로 사용하면 된다.

    [참조링크] developers.facebook.com/docs/audience-network/guides/SKAdNetwork

<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>v9wttpbfk9.skadnetwork</string>
    </dict>
    <dict>   
         <key>SKAdNetworkIdentifier</key>
         <string>n38lu8286q.skadnetwork</string>
    </dict>
</array>

 

2.2.2. Unity에서 PostProcessor로 추가하는 방법(추천)

namespace blueasa
{
    public class XcodeSettingsPostProcessor
    {

        [PostProcessBuild(444)]
        public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
        {

            /// Stop processing if targe is NOT iOS
            if (buildTarget != BuildTarget.iOS)
                return;

            /// Initialize PbxProject
            var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
            PBXProject pbxProject = new PBXProject();
            pbxProject.ReadFromFile(projectPath);
            string targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");

            /// Add string setting
            // SKAdNetwork IDs integration(for iOS14+)
            // https://blueasa.tistory.com/2482
            // https://blueasa.tistory.com/2493
            var arraySKAdNetworkItems = plist.root.CreateArray("SKAdNetworkItems");
            // for FAN
            // https://developers.facebook.com/docs/audience-network/guides/SKAdNetwork
            var dictSKAdNetworkIdentifier_FAN_1 = arraySKAdNetworkItems.AddDict();
            dictSKAdNetworkIdentifier_FAN_1.SetString("SKAdNetworkIdentifier", "v9wttpbfk9.skadnetwork"); // FAN 1
            var dictSKAdNetworkIdentifier_FAN_2 = arraySKAdNetworkItems.AddDict();
            dictSKAdNetworkIdentifier_FAN_2.SetString("SKAdNetworkIdentifier", "n38lu8286q.skadnetwork"); // FAN 2
            
            /// Apply editing settings to Info.plist
            plist.WriteToFile(plistPath);

        }
    }
}

 

 

[참조사이트]

developers.facebook.com/blog/post/2020/10/29/preparing-our-partners-ios-14-latest-guidance-on-skadnetwork/?locale=ko_KR

developers.google.com/admob/ios/mediation/facebook?hl=en#swift

 

[SKAdNetwork IDs 참조]

[Admob] developers.google.com/admob/ios/ios14#skadnetwork

[Unity] unityads.unity3d.com/help/ios/skadnetwork-ids?fbclid=IwAR3T6BWG6-SIdWipZaB-PEtUQhg1DAnU_kQ22iiSv4Z5Q6nItq2edtpIIkM

[Unity.xml] skan.mz.unity3d.com/v2/partner/skadnetworks.plist.xml?_ga=2.140049011.1591405619.1607905486-1813266944.1603773122

[Vungle] support.vungle.com/hc/en-us/articles/360002925791-Integrate-Vungle-SDK-for-iOS#3-add-the-%E2%80%9C-objc%E2%80%9D-linker-flag-0-9

[Vungle.xml] vungle.com/skadnetworkids.xml

[AppsFlyer 제공 리스트] docs.google.com/spreadsheets/d/e/2PACX-1vSqwIBW3FzbrXKqluDQ2hEec7zcvVrxQ02ivWsHnGQTvLMeFmHHjGz1R5TVy6_cqAIVh0pAy4Yud7Qx/pubhtml

반응형
Posted by blueasa
, |

Error: 

Finally solved the problem. Need to update CocoPods.sudo gem install cocoapods

 

sudo gem install cocoapods

 

 

[출처]

stackoverflow.com/questions/64623288/framework-not-found-usermessagingplatform-xcframework-in-react-native

 

framework not found UserMessagingPlatform.xcframework in react native

I update my react native project after I encountered an error in xcode there is no problem in android Error: My new package.json "@react-native-firebase/admob": "^7.6.10", "@

stackoverflow.com

 

반응형
Posted by blueasa
, |

원문 : Unity Application.persistentDataPath のパスは Android のバージョンと Write Access によって異なる。

Unity Application.persistentDataPath의 경로는 Android의 버전과 Write Access에 따라 달라짐

Android에서 Application.persistentDataPath가 돌려주는 값이 Write Access에 따라 달라지기에 조사해봤습니다.
Unity 5.3.6에서 돌려주는 경로에 사양변경이 있었으므로, Unity 5.3.6 이전 버전에서 작성한 애플리케이션을 Unity 5.3.6 이후로 버전업할 때 주의를 기울이지 않으면 데이터가 사라질 위험이 있습니다.
갖고 있는 Android기기와 Unity 4.7.2f1, 5.3.6f1에서 검증했습니다.

Application.persistentDataPath

지속되는 데이터 디렉토리 경로.
세이브 데이터 등 유저 데이터를 저장하는 장소.
https://docs.unity3d.com/kr/current/ScriptReference/Application-persistentDataPath.html

Player Settings / Write Access

Internal Only로 지정해도 Application.persistentDataPath이 개발환경과 실제환경에서 돌려주는 값이 다를 수 있으므로 주의가 필요합니다!
외부 저장소라면 특별히 권한을 요구하지 않고 읽어들일 수 있으므로 디버그하기 쉽기 때문일지도?

External (SDCard)로 설정하면, SD 카드같은 외부 저장소에 대한 쓰기 접근을 가능하게 합니다. 개발 빌드(Development Build)에서는 자동적으로 켜집니다. https://docs.unity3d.com/kr/current/Manual/class-PlayerSettingsAndroid.html

External Storage

외부 저장소라고 불리는 영역이지만 SD 카드가 아니라 빼낼 수 없게 내장된 저장소를 참조하는 기기도 있음.
Android 4.4 이후에는 권한을 요구하지 않고 외부 저장소에 읽고 쓰기가 가능.

Windows PC를 예로 들면
오래된 Android 기기
C드라이브: 내장 드라이브 (Android 내부 저장소)
D드라이브: USB로 접속된 외장 하드디스크 (Android 외부 저장소)
최신 Android 기기
C드라이브: 내장 드라이브 파티션 0 (Android 내부 저장소)
D드라이브: 내장 드라이브 파티션 1 (Android 외부 저장소)
E드라이브: USB로 접속된 외장 하드디스크 (Android 외부 저장소)

모든 Android 호환 기기는 파일을 저장하는 데 사용할 수 있는 공유된 "외부 저장소"를 지원합니다. 해당 저장소는 제거할 수 있는 저장소 미디어(예: SD 카드) 또는 (제거할 수 없는) 내부 저장소일 수 있습니다.
https://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Android 4.4 이상에서 앱 전용 디렉터리 파일 읽기 또는 쓰기는 READ_EXTERNAL_STORAGE 또는 WRITE_EXTERNAL_STORAGE 권한이 필요하지 않습니다.
https://developer.android.com/guide/topics/data/data-storage.html#AccessingExtFiles

일부 기기는 이동식 저장 장치 없이도 영구 저장소 공간을 "내부" 그리고 "외부" 파티션으로 나누어 항상 두 개의 저장소 공간을 제공하며, API의 동작은 외부 저장소의 이동식 유무에 상관없이 일관적입니다.
https://developer.android.com/training/basics/data-storage/files.html#InternalVsExternalStorage

Unity 5.3.6에서의 사양변경

Android: Application.temporaryCachePath and Application.persistentDataPath always return external paths starting KITKAT. (789870) https://unity3d.com/kr/unity/whats-new/unity-5.3.6

KITKAT은 Android 4.4의 코드네임. Android 4.4 이후에는 Write Access의 값에 관계없이 외부 저장소의 경로를 돌려주도록 사양변경. Android 4.4 이후 권한을 요구하지 않고 읽고 쓰기가 가능하게 되었기 때문일 것.

Player Settings / Write Access 별 Application.persistentDataPath의 값

Write Access: Internal Only

Unity 4.7.2

AndroidPath실체

4.1.2 (200SH) /data/data/{package name}/files/ 내부 저장소
4.2.2 (SO-02F) /data/data/{package name}/files/ 내부 저장소
5.0.2 (HTV31) /data/data/{package name}/files/ 내부 저장소
6.0.1 (SCV31) /data/user/0/{package name}/files/ -> /data/data/{package name}/files/ 내부 저장소

Unity 5.3.6

AndroidPath실체

4.1.2 (200SH) /data/data/{package name}/files/ 외부 저장소
4.2.2 (SO-02F) /data/data/{package name}/files/ 외부 저장소
5.0.2 (HTV31) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
6.0.1 (SCV31) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소

Write Access: External (SDCard)

Unity 4.7.2

AndroidPath실체

4.1.2 (200SH) /storage/sdcard0/Android/data/{package name}/files/ SD 카드
4.2.2 (SO-02F) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
5.0.2 (HTV31) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
6.0.1 (SCV31) (Permissions Storage: ALLOW) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
6.0.1 (SCV31) (Permissions Storage: DENY) /data/user/0/{package name}/files/ -> /data/data/{package name}/files/ 내부 저장소

Unity 5.3.6

AndroidPath실체

4.1.2 (200SH) /storage/sdcard0/Android/data/{package name}/files/ SD 카드
4.2.2 (SO-02F) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
5.0.2 (HTV31) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
6.0.1 (SCV31) (Permissions Storage: ALLOW) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소
6.0.1 (SCV31) (Permissions Storage: DENY) /storage/emulated/0/Android/data/{package name}/files/ 외부 저장소

결과

Write Access: External (SDCard)로 지정하면 androidmanifest.xml에 외부 저장소에 읽고 쓰기 권한 요구가 추가됩니다.
WRITE_EXTERNAL_STORAGE 권한으로 읽고 쓰기도 가능.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

WRITE_EXTERNAL_STORAGE를 추가한 경우, Android 6 이후에는 Permissions Storage의 물음에서 ALLOW를 선택할 때까지는 기동할 때마다 물어봄.
ALLOW를 선택한 후에도 Application의 설정에서 Permissions Storage 허가의 변경은 가능.
4.1.2 (200SH): Write Access: External (SDCard) 만이 SD 카드의 경로를 돌려줌.
SD 카드를 뽑았을 경우에는 Internal Only와 같은 경로를 돌려줌.
그 외에는 내부 저장소를 참조.
Unity 4.7.2 Android 6.0.1는 Permissions Storage의 허가 유무로 돌려주는 경로가 달라짐.
Unity 5.3.6 Android 4.4 이후는 Permissions Storage의 허가 유무와 상관없이 돌려주는 값이 같음.

Unity 4.7.2에서 작성한 애플리케이션에서 Application.persistentDataPath에 저장한 데이터를 Unity 5.3.6에서 작성한 애플리케이션에서 덮어씌웠을 경우 읽어들일 수 있을까?

internal-storage: /data/data/{package name}/files/
external-storage: /storage/emulated/0/Android/data/{package name}/files/

Android 4.1.2 (200SH)

Unity 4.7.2 Write AccessUnity 5.3.6 Write Access읽기 가능?거동

Internal Only Internal Only
Internal Only External (SDCard)
External (SDCard) Internal Only UnauthorizedAccessException: Access to the path "/storage/sdcard0/Android/data/{package name}/files/{file name}" is denied. external-storage를 internal-storage에 복사하려고 해서 실패?
External (SDCard) External (SDCard)

Android 4.2.2 (SO-02F)

Unity 4.7.2 Write AccessUnity 5.3.6 Write Access읽기 가능?거동

Internal Only Internal Only
Internal Only External (SDCard)
External (SDCard) Internal Only UnauthorizedAccessException: Access to the path "/storage/sdcard0/Android/data/{package name}/files/{file name}" is denied. external-storage를 internal-storage에 복사하려고 해서 실패?
External (SDCard) External (SDCard)

Android 5.0.2 (HTV31)

Unity 4.7.2 Write AccessUnity 5.3.6 Write Access읽기 가능?거동

Internal Only Internal Only
Internal Only External (SDCard)
External (SDCard) Internal Only UnauthorizedAccessException: Access to the path "/{file name}" is denied. external-storage를 internal-storage에 복사하려고 해서 실패?
External (SDCard) External (SDCard)

Android 6.0.1 (SCV31)

Unity 4.7.2 Write AccessUnity 5.3.6 Write Access읽기 가능?거동

Internal Only Internal Only internal-storage를 external-storage에 복사
Internal Only External (Permissions Storage: ALLOW)
Internal Only External (Permissions Storage: DENY) internal-storage를 external-storage에 복사
External (Permissions Storage: ALLOW) Internal Only 같은 경로
External (Permissions Storage: ALLOW) External (Permissions Storage: ALLOW) 같은 경로
External (Permissions Storage: ALLOW) External (Permissions Storage: DENY) 같은 경로
External (Permissions Storage: DENY) Internal Only internal-storage를 external-storage에 복사
External (Permissions Storage: DENY) External (Permissions Storage: ALLOW)
External (Permissions Storage: DENY) External (Permissions Storage: DENY) internal-storage를 external-storage에 복사

결과

Internal Only, External (Permissions Storage: DENY)일 때에는 internal-storage를 external-storage에 복사한 후에 읽어들이도록 되어 있음.
external-storage로 변경해도 internal-storage는 복사 시점 그대로 변경은 되지 않음.

정리

Internal Only -> External (SDCard)로의 변경은 데이터를 이어받지 못하는 경우가 있음. 그 경우, 수동으로 /data/data/{package name}/files/ 를 복사하는 등의 대응이 필요.
External (SDCard) -> Internal Only로의 변경은 오래된 Android 기기기에서 정상으로 처리되지 않을 가능성이 있음.
Android 6 이후에는 Unity 4.7.2의 Write Access가 어느쪽이든 Unity 5.3.6의 Write Access: Internal Only로 해두면 데이터를 이어받아 읽고 쓰기가 가능.

 

 

[출처] gist.github.com/overworks/541fcb519bc23cd14cf622c2baa28d3b

 

유니티와 안드로이드 버전에 따른 Application.persistentDataPath의 경로 정리

유니티와 안드로이드 버전에 따른 Application.persistentDataPath의 경로 정리 - Unity-Android-persitentDataPath.md

gist.github.com

 

반응형
Posted by blueasa
, |

[추가] Android / iOS 방식이 달라서 플랫폼에 따라 Two Letter ISO 받는 방식을 다르게 적용

 

    /// <summary>
    /// Two Letter ISO Language
    /// [참조] https://lonewolfonline.net/list-net-culture-country-codes/
    /// [참조] https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
    /// </summary>
    /// <returns></returns>
    public static string GetTwoLetterISOLanguage()
    {
        string strCurrentCultureName = "en";
#if UNITY_EDITOR
        strCurrentCultureName = "en";
#elif UNITY_ANDROID
        strCurrentCultureName = GetTwoLetterISOLanguage_Android();
#elif UNITY_IOS || UNITY_IPHONE
        strCurrentCultureName = GetTwoLetterISOLanguage_iOS();
#endif
        return strCurrentCultureName;
    }

    public static string GetTwoLetterISOLanguage_iOS()
    {
        string strTwoLetterISOLanguageName = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        Debug.LogFormat("[GetCurrentCultureName_iOS] {0}", strTwoLetterISOLanguageName);
        return strTwoLetterISOLanguageName;
    }

    // returns "en" / "de" / "hi" / "th" / "ar" / ...
    public static string GetTwoLetterISOLanguage_Android()
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        try
        {
            var locale = new AndroidJavaClass("java.util.Locale");
            var localeInst = locale.CallStatic<AndroidJavaObject>("getDefault");
            var name = localeInst.Call<string>("getLanguage");
            Debug.LogFormat("[getLanguage] {0}", name);
            return name;
        }
        catch (System.Exception e)
        {
            return "Error";
        }
#else
        return "Not supported";
#endif
    }

    // returns "eng" / "deu" / "hin" / ...
    public static string GetThreeLetterISOLanguage_Android()
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        try
        {
            var locale = new AndroidJavaClass("java.util.Locale");
            var localeInst = locale.CallStatic<AndroidJavaObject>("getDefault");
            var name = localeInst.Call<string>("getISO3Language");
            Debug.LogFormat("[getISO3Language] {0}", name);
            return name;
        }
        catch (System.Exception e)
        {
            return "Error";
        }
#else
        return "Not supported";
#endif
    }

[출처]

answers.unity.com/questions/729801/using-applicationsystemlanguage-returns-unknown.html?_ga=2.105896064.227436567.1600081424-730033693.1580204381

 

Using Application.systemLanguage returns Unknown - Unity Answers

 

answers.unity.com

 

 

[참조]

You should also be able to use .NET to get the current culture instead:

using System;
using System.Globalization;
using System.Threading;

CultureInfo myCulture = Thread.CurrentThread.CurrentCulture;


// You can then use all these member variables
myCulture.DisplayName
myCulture.EnglishName
myCulture.Name (e.g. es-ES / en-GB)
myCulture.Parent (e.g. es / en)
myCulture.ThreeLetterISOLanguageName (e.g. spa/eng/hin)
myCulture.TwoLetterISOLanguageName (e.g. es/en/hi)

 

Here's a selection of the Indian 3 and 2 letter ISO codes (see attached jpg)

 

[출처] forum.unity.com/threads/automatically-set-hindi-language.624973/

 

Automatically set Hindi language

As you all know it's possible to use SystemLanguage to detect the default language of the device running the game. When my game opens, i use it to...

forum.unity.com

 

반응형
Posted by blueasa
, |

Problems that Thai is [?] In [Unity] iOS13

phenomenon

If when you try to multi-lingual in Unity Oke Select the default font asset referred to as "Arial", so you use Yoshinani the system font, but I did not have a problem until now, generating a phenomenon that garbled in iOS13 are you with.

Screenshot is iOS13.2.1 (iPhone8). In the middle of the screen [?] [?] [?] [?] And is in a place that is garbled applicable.
VIEW IMAGE

Investigation

Even Unity of the Issue have been reported, Armenian in addition to Thai, it seems to become garbled in Georgian.

For more details, it might be good to get a look at the people of Issue.

It summarizes the results of actually examined.

  • If you set the Thai fonts will be displayed without any problems.

    Screenshot is iOS13.2.1 (iPhone8). VIEW IMAGE
  • In iOS12.4.1 it will be as normally displays the Thai below.

    Screenshot is iOS12.4.1 (iPhoneXR). VIEW IMAGE
  • In Android10 it will be as normally displays the Thai below.
  • Unity version was also confirmed at 2018.3 and 2019.1, but it was the same result.

The method and the iOS language settings to use the system font to fall back a font to another tried such as the Thai, but it did not change.

temporary solution

Since it has published an app that was the Thai correspondence, it does not need to wait for the renovation of Unity.

Thinking of correspondence has the following procedure.

  1. Put the Thai font, eliminate garbled
  2. Raise Unity and is After the corresponding version

Since there is a free font Fortunately Thai, and the garbled solve with it.

Since a little thinner than the default font, it may not afford the alternative as long as there is a commitment.

I learned for the first time a license that GPL font exception. I did not know what I do a credit notation, it was for the time being added. If you have somebody who is familiar wait for information.

Font size was 480KB. I thought one more font size increases, but I have put in a not too nervous and if this much. But does not recommend because as far as possible towards the size of the app is small, I think good for the user.

Something like the following, we have set the font in the timing of switching to Thai.

text.font = Resources.Load<Font> ("Fonts/THSarabunNew/THSarabunNew");

It was also good as switched fallback, but because the provisional support of easy-to-understand on the code TODOhas been switched by the code this time on the grounds that I wanted to write a.

Summary

Because of what is in the Unity side, but have no idea what is in the iOS side, is a story that has survived for the time being in the provisional support.

We look forward to information If you know the other way.

reference

Unity Issue Tracker - [iOS 13.0] Some languages symbols are replaced with a [?] marks
https://issuetracker.unity3d.com/issues/ios-13-dot-0-all-thai-symbols-are-replaced-with-a-marks

Font - Unity manual
https://docs.unity3d.com/ja/2018.1/Manual/class-Font.html

[Unity] want to use a font that is installed on the OS in the Unity - Terra sur-blog
http://tsubakit1.hateblo.jp/entry/2018/05/30/234314

Public institutions of Thailand to issue "Thai font free" | Thailand favor
https://thaion.net/thai-font-sipa

Fxnt. Khxm »Fxnt Sarbrrn Prabprung Run Him" Sarabun New "
https://www.f0nt.com/release/th-sarabun-new/

GPL font exception - Wikipedia
Https://Ja.Wikipedia.Org/wiki/GPL font exception

 

 

[참조1] issuetracker.unity3d.com/issues/ios-13-dot-0-all-thai-symbols-are-replaced-with-a-marks

 

Unity IssueTracker - [iOS 13.0] Some languages symbols are replaced with a [?] marks

To reproduce: 1. Download attached "Thai Font Issue Example.zip" project and open in Unity 2. Build for iOS 3. Deploy the Xcode proj...

issuetracker.unity3d.com

 

[참조2] qiita.com/canecco/items/50b27ba214926e690ab0

 

【Unity】iOS13でタイ語が[?]になる問題 - Qiita

現象 Unityで多言語に対応しようとすると「Arial」というデフォルトのフォントアセットを選択しておけば、システムフォントをよしなに使ってくれるので今まで問題がなかったのですが、iOS13

qiita.com

 

[출처] titanwolf.org/Network/Articles/Article?AID=0f5127d9-dcac-4e95-8c1b-a97b6bc9a5c7#gsc.tab=0

 

Problems that Thai is [?] In [Unity] iOS13(Others-Community)

 

titanwolf.org

 

반응형
Posted by blueasa
, |

Unity 를 이용해 그림판 같은 기능을 구현하는 중에 겹치는 이미지의 테두리가 흰색으로 나타나는 현상이 발생 하였다.

 

 

위 화면은 Canvas 에 검정색 원 Image 여러개가 겹쳐 있고 이를 RenderTexture 를 통해 RawImage 로 출력하고 있는 예제 이다. 사용한 이미지는 아래와 같은 설정이 되어 있다.

 

 

Scene 화면을 통해 RawImage 의 테두리 부분을 확대해 보면 다음과 같이 투명하게 처리가 되고 있는 것이 보였다.

 

 

RenderTexture 로 그려주던 Canvas 를 메인으로 돌려보면 아래와 같이 의도 했던 대로 출력이 된다.

 

 

 

1. 이미지 테두리 부분의 픽셀이 기존 픽셀과 겹쳐지면서 혹은 덮어 쓰면서 해당 픽셀을 투명하게 바꾸고 있다.

2. RenderTexture 로 변환되 RawImage 로 출력하는 과정에서 테두리 부분이 투명해 지는 현상이 일어난다.

 

1. 이미지가 문제가 있다

2. RenderTexture 가 잘못 그려주고 있다

3. RawImage 가 잘못 출력하고 있다.

 

이미지에 육안으로 확인 되지 않는 투명한(?) 부분이 있다고 가정하고 이를 보정하는 것은 어떨까? 로 시작해 쉐이더를 추가한 Material 을 추가해 보았다.

그 결과 이미지에 Sprites/Default 쉐이더를 사용하는 Material 을 사용하니 간섭 현상이 사라졌다. Material 이 추가되지 않은 이미지의 기본 쉐이더는 UI/Default 쉐이더인데 Sprites/Default 쉐이더와의 차이가 이런 현상을 만드는 것 같다.

 

UI/Default 쉐이더 코드와 Sprite/Default 쉐이더 코드를 비교하며 테스트 했더니 다음과 같이 수정해 문제 해결이 가능했다.

- UI/Default 쉐이더의  Blend SrcAlpha OneMinusSrcAlpha 값을 Blend One OneMinusSrcAlpha 값으로 변경

Blend - 투명 오브젝트를 만드는데 사용합니다.

SrcAlpha - 스테이지 값을 소스 알파 값으로 곱합니다.

One - 1값입니다. 소스 또는 대상 컬러가 완전히 표시되도록 하려면 이 값을 사용합니다.

OneMinusSrcAlpha - 스테이지 값을 (1 - 소스 알파)로 곱합니다.

 

https://docs.unity3d.com/kr/current/Manual/SL-Blend.html

 

ShaderLab: 블렌딩 - Unity 매뉴얼

블렌딩은 투명 오브젝트를 만드는 데 사용됩니다.

docs.unity3d.com

 

정리하자면 소스 알파 값이란 새로 그려진 이미지의 알파 값이고 스테이지 값은 기존 화면에 그려져 있는 값인데 이둘을 곱하면 새로 그려진 이미지의 알파값을 따라가기 때문에 이를 1값으로 변경해 새로 그려진 이미지의 알파 값을 따라가지 않게 수정 함으로써 해결 됬다고 생각한다.

 

위와 같은 문제 때문이 었다면 RenderTexture 를 통하지 않고 직접 그리는 이미지에서도 해당 상황이 재현되야 하지 않을까? 하지만 직접 그리는 이미지에서는 해당 이슈가 발생하지 않는다. 

 

RenderTexture 설정이 잘못되어 출력이 잘못 되고 있는 것은 아닐까?

RenderTexture 의 Color Format 설정을 바꿔보니 다음 두 경우에 원했던 형태의 출력이 되는 것을 확인 하였다.

RGB565 - 모든 그래픽 카드를 지원하지 않는 16 bit 텍스쳐 포멧

RGB111110Float - 모든 그래픽 카드를 지원하지 않는 포멧

https://docs.unity3d.com/ScriptReference/RenderTextureFormat.html

 

Unity - Scripting API: RenderTextureFormat

You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho

docs.unity3d.com

보통의 경우 Default 값인 ARGB32 를 사용할 텐데 ... 이 방법은 아닌 것 같다.

 

RawImage 에서 출력 할 때 문제가 생기는 것은 아닐까?

https://forum.unity.com/threads/using-render-textures-on-a-ugui-image-panel-or-button.272332/

 

Using Render Textures on a uGUI Image, Panel or Button?

Hello! I'm trying to put my minimap into the uGUI system. Is it possible to get a Render Texture working with these? I've got my render texture...

forum.unity.com

관련 이슈로 토론한 흔적이 보인다. 여기서 찾은 방법은 UI/Default 쉐이더에서 알파 클립을 제거한 커스텀 쉐이더를 RawImage 에 붙여 해결한 것이다. 쉐이더 코드를 보면 강제로 알파 값을 1로 만들어 주는 역활을 하고 있다.

UI-Default-No-Alpha.shader
0.00MB

 

여지껏 시도해 봤던 방법 중에 커스텀 쉐이더를 RawImage 에 적용하는 방법이 제일 괜찮아 보여 일단은 이것으로 해결. 왜 저러는 건지에 대해서는 좀더 찾아봐야 될듯...



출처: https://ukprog.tistory.com/56 [Vader87]

 

[Unity3D] RenderTexture RawImage 출력 이슈

Unity 를 이용해 그림판 같은 기능을 구현하는 중에 겹치는 이미지의 테두리가 흰색으로 나타나는 현상이 발생 하였다. 위 화면은 Canvas 에 검정색 원 Image 여러개가 겹쳐 있고 이를 RenderTexture 를 ��

ukprog.tistory.com

 

반응형
Posted by blueasa
, |