Last active
December 6, 2021 06:31
-
-
Save kyubuns/fe7b3bb9c6cbca88c4e9050bb336c903 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Sandbox : MonoBehaviour | |
{ | |
public void Start() | |
{ | |
普通はVector2も渡せちゃう(Vector3.one); | |
普通はVector2も渡せちゃう(Vector2.one); | |
絶対にVector3を渡してほしい(Vector3.one); | |
絶対にVector3を渡してほしい(Vector2.one); // ここはビルド通らない | |
} | |
public void 普通はVector2も渡せちゃう(Vector3 v) | |
{ | |
Debug.Log(v); | |
} | |
public void 絶対にVector3を渡してほしい(Vector3Only v) | |
{ | |
Debug.Log((Vector3) v); | |
} | |
public class Vector3Only | |
{ | |
private Vector3 _value; | |
public static implicit operator Vector3Only(Vector3 x) | |
{ | |
return new Vector3Only {_value = x}; | |
} | |
public static explicit operator Vector3(Vector3Only x) | |
{ | |
return x._value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment