Built-in extra asset

private const string kStandardSpritePath = "UI/Skin/UISprite.psd";
private const string kBackgroundSpriteResourcePath = "UI/Skin/Background.psd";
private const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd";
private const string kKnobPath = "UI/Skin/Knob.psd";
private const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
Image image = buttonRoot.AddComponent<Image>();
image.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);

https://forum.unity.com/threads/accessing-ui-build-in-sprites-in-c.305075/

singleton class vs static class

static class 를 사용하려 하다 문득 singleton과의 차이점이 궁금하여 찾아보았다. 아래 4가지가 내가 여러 포스트에서 본 것을 정리해둔 것 같다.

  1. Singleton objects are stored in Heap, but static objects are stored in stack.
  2. We can clone (if the designer did not disallow it) the singleton object, but we can not clone the static class object .
  3. Singleton classes follow the OOP (object oriented principles), static classes do not.
  4. We can implement an interface with a Singleton class, but a class’s static methods (or e.g. a C# static class) cannot.

https://stackoverflow.com/questions/519520/difference-between-static-class-and-singleton-pattern

참고해볼 다른 포스트

https://postpiglet.netlify.app/posts/csharp-singletone-vs-staticclass/

Spherical coordinate system

구면 좌표계

다음의 3가지 요소를 이용하여 3차원 좌표를 결정할 수 있는 체계를 말한다.

3요소 : 반지름(radial distance), 극각(polar angle), 방위각(azimuthal angle)

구면 좌표계의 한 점 P (r, θ, φ) r= radius, θ=polar angle, φ=azimuthal angle 을 3차원 데카르트 공간좌표계로 변환하면 다음과 같다

P (x,y,z) = P(r, θ, φ)
x = r cosφ sinθ
y = r sinφ cosθ
z = r cosθ

https://en.wikipedia.org/wiki/Spherical_coordinate_system

https://github.com/mrdoob/three.js/blob/master/src/math/Spherical.js

three.js 구면좌표계 계산 클래스

C# 생성자와 필드 초기화

https://docs.microsoft.com/ko-kr/archive/blogs/ericlippert/why-do-initializers-run-in-the-opposite-order-as-constructors-part-two

생성자와 필드 초기화 순서가 궁금하여 다음과 같은 예제 코드를 작성했다. 위 링크의 포스트에 비슷한 예제가 있으니 궁금하면 한번 확인해보기 바란다.

class Apple
    {
        public Apple(string text)
        {
            Console.WriteLine(text);
        }
    }

    class Orange
    {
        Apple apple = new Apple("Orange apple");
        Apple apple1 = new Apple("Orange apple1");
        public Orange()
        {
            Console.WriteLine("Orange write");
        }
    }

    class Melon : Orange
    {
        Apple greenApple = new Apple("Melon apple");
        Apple blueApple = new Apple("Blue melon apple");
        public Melon()
        {
            Console.WriteLine("Melon write");
        }

        public void Shape() 
        {
            Console.WriteLine("melon is sphere");
        }
    }
 class Program
    {
        static void Main(string[] args)
        {
            new Melon();
        }
    }

결과는 다음과 같다.

초기화 리스트는 derived class -> base class 순으로 그리고 위에서 아래쪽으로 실행 되었다.

하지만 생성자는 base class -> derived class 로 호출되었다.