Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Last active December 6, 2021 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyubuns/fe7b3bb9c6cbca88c4e9050bb336c903 to your computer and use it in GitHub Desktop.
Save kyubuns/fe7b3bb9c6cbca88c4e9050bb336c903 to your computer and use it in GitHub Desktop.
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