프로그래밍/유니티2020. 9. 7. 10:19

'프로그래밍 > 유니티' 카테고리의 다른 글

모뉴먼트벨리 구현  (0) 2020.04.07
패드 해상도 대응용 코드  (0) 2020.03.04
앱 실행될때 자동으로 호출  (0) 2020.01.13
Unirx 스트림 합성  (0) 2019.09.16
unirx invoke 같은 기능  (0) 2019.08.20
Posted by JinFluenza
프로그래밍/유니티2020. 4. 7. 21:14

'프로그래밍 > 유니티' 카테고리의 다른 글

스크린샷 + 쉐어링  (0) 2020.09.07
패드 해상도 대응용 코드  (0) 2020.03.04
앱 실행될때 자동으로 호출  (0) 2020.01.13
Unirx 스트림 합성  (0) 2019.09.16
unirx invoke 같은 기능  (0) 2019.08.20
Posted by JinFluenza
프로그래밍/유니티2020. 3. 4. 19:00

[RequireComponent(typeof(CanvasScaler))]
public class CanvasScalerSetter : MonoBehaviour
{
    private CanvasScaler scaler;

    private void Awake()
    {
        scaler = GetComponent();
        SetMatchSize();
    }

    private void SetMatchSize()
    {
        float referenceResolustion = scaler.referenceResolution.x / scaler.referenceResolution.y;

        float currentResolution = (float)Screen.width / (float)Screen.height;

        if (referenceResolustion >= currentResolution)
        {
            scaler.matchWidthOrHeight = 0;
        }
        else
        {
            scaler.matchWidthOrHeight = 1;
        }
    }
}

'프로그래밍 > 유니티' 카테고리의 다른 글

스크린샷 + 쉐어링  (0) 2020.09.07
모뉴먼트벨리 구현  (0) 2020.04.07
앱 실행될때 자동으로 호출  (0) 2020.01.13
Unirx 스트림 합성  (0) 2019.09.16
unirx invoke 같은 기능  (0) 2019.08.20
Posted by JinFluenza
프로그래밍/유니티2020. 1. 13. 14:32

        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]

'프로그래밍 > 유니티' 카테고리의 다른 글

모뉴먼트벨리 구현  (0) 2020.04.07
패드 해상도 대응용 코드  (0) 2020.03.04
Unirx 스트림 합성  (0) 2019.09.16
unirx invoke 같은 기능  (0) 2019.08.20
Jenzect projectContext 세팅  (0) 2019.08.14
Posted by JinFluenza
프로그래밍/유니티2019. 9. 16. 10:23

'프로그래밍 > 유니티' 카테고리의 다른 글

패드 해상도 대응용 코드  (0) 2020.03.04
앱 실행될때 자동으로 호출  (0) 2020.01.13
unirx invoke 같은 기능  (0) 2019.08.20
Jenzect projectContext 세팅  (0) 2019.08.14
unity 2d spriterenderer sort  (0) 2019.08.13
Posted by JinFluenza
프로그래밍/유니티2019. 8. 20. 17:27
Posted by JinFluenza
프로그래밍/유니티2019. 8. 14. 01:53

Global Bindings Using Project Context

This all works great for each individual scene, but what if you have dependencies that you wish to persist permanently across all scenes? In Zenject you can do this by adding installers to a ProjectContext object.

To do this, first you need to create a prefab for the ProjectContext, and then you can add installers to it. You can do this most easily by selecting the menu item Edit -> Zenject -> Create Project Context. You should then see a new asset in the folder Assets/Resources called 'ProjectContext'. Alternatively, you can right click somewhere in Projects tab and select Create -> Zenject -> ProjectContext.

If you click on this it will appear nearly identically to the inspector for SceneContext. The easiest way to configure this prefab is to temporarily add it to your scene, add Installers to it, then click "Apply" to save it back to the prefab before deleting it from your scene. In addition to installers, you can also add your own custom MonoBehaviour classes to the ProjectContext object directly.

Then, when you start any scene that contains a SceneContext, your ProjectContext object will always be initialized first. All the installers you add here will be executed and the bindings that you add within them will be available for use in all scenes within your project. The ProjectContext game object is set as DontDestroyOnLoad so it will not be destroyed when changing scenes.

Note also that this only occurs once. If you load another scene from the first scene, your ProjectContext will not be called again and the bindings that it added previously will persist into the new scene. You can declare ITickable / IInitializable/ IDisposable objects in your project context installers in the same way you do for your scene installers with the result being that IInitializable.Initialize is called only once across each play session and IDisposable.Dispose is only called once the application is fully stopped.

The reason that all the bindings you add to a global installer are available for any classes within each individual scene, is because the Container in each scene uses the ProjectContext Container as it's "parent". For more information on nested containers see here.

ProjectContext is a very convenient place to put objects that you want to persist across scenes. However, the fact that it's completely global to every scene can lead to some unintended behaviour. For example, this means that even if you write a simple test scene that uses Zenject, it will load the ProjectContext, which may not be what you want. To address these problems it is often better to use Scene Parenting instead, since that approach allows you to be selective in terms of which scenes inherit the same common bindings. See here for more details on that approach.

Note also that by default, any game objects that are instantiated inside ProjectContext will be parented underneath it by default. If you'd prefer that each newly instantiated object is instead placed at the root of the scene hierarchy (but still marked DontDestroyOnLoad) then you can change this by unchecking the flag 'Parent New Objects Under Context' in the inspector of ProjectContext.

 

 

+ 반드시 씬에 scenecontext가 하나라도 있어야 인스턴스가 생성됨.

+바인딩 예시 (MonoInstaller)

        Container.Bind().FromComponentInNewPrefab(soundManager).AsSingle().NonLazy();  ->프리팹 클론 한개 생성함.

 

'프로그래밍 > 유니티' 카테고리의 다른 글

Unirx 스트림 합성  (0) 2019.09.16
unirx invoke 같은 기능  (0) 2019.08.20
unity 2d spriterenderer sort  (0) 2019.08.13
에디터에서 시작할때 게임뷰 스케일 최소값으로 고정  (0) 2019.07.31
inspector attribute  (0) 2019.06.10
Posted by JinFluenza
프로그래밍/유니티2019. 8. 13. 15:00

'프로그래밍 > 유니티' 카테고리의 다른 글

unirx invoke 같은 기능  (0) 2019.08.20
Jenzect projectContext 세팅  (0) 2019.08.14
에디터에서 시작할때 게임뷰 스케일 최소값으로 고정  (0) 2019.07.31
inspector attribute  (0) 2019.06.10
리플렉션  (0) 2019.05.20
Posted by JinFluenza
프로그래밍/유니티2019. 7. 31. 23:57

'프로그래밍 > 유니티' 카테고리의 다른 글

Jenzect projectContext 세팅  (0) 2019.08.14
unity 2d spriterenderer sort  (0) 2019.08.13
inspector attribute  (0) 2019.06.10
리플렉션  (0) 2019.05.20
무한스크롤  (0) 2019.05.17
Posted by JinFluenza
프로그래밍/유니티2019. 6. 10. 13:59

'프로그래밍 > 유니티' 카테고리의 다른 글

unity 2d spriterenderer sort  (0) 2019.08.13
에디터에서 시작할때 게임뷰 스케일 최소값으로 고정  (0) 2019.07.31
리플렉션  (0) 2019.05.20
무한스크롤  (0) 2019.05.17
Itween for TextMeshProUGUI & UGUI  (0) 2019.05.02
Posted by JinFluenza