void OnDestroy() { if (Instance == this) { Instance = null; } }
void Awake() { if (Instance != null) { Destroy(this); throw new InvalidOperationException("A Converter component has already been instantiated"); } Instance = this; }
public static GameObject ToNative(this SpeckleCore.SpecklePolyline specklePolyline) { GameObject go = SpecklePrefabs.InstantiateLine(); go.GetComponent <UnitySpeckleObjectData>().Id = specklePolyline._id; go.GetComponent <UnitySpeckleObjectData>().SpeckleObject = specklePolyline; Vector3[] pts = Util.SpecklePointsToUnityPoints(specklePolyline.Value); go.GetComponent <LineRenderer>().positionCount = pts.Length; go.GetComponent <LineRenderer>().SetPositions(pts); return(go); }
public static GameObject ToNative(this SpeckleCore.SpecklePoint specklePoint) { GameObject go = SpecklePrefabs.InstantiatePoint(); go.GetComponent <UnitySpeckleObjectData>().Id = specklePoint._id; go.GetComponent <UnitySpeckleObjectData>().SpeckleObject = specklePoint; Vector3 unityPoint = Util.SpecklePointsToUnityPoints(specklePoint.Value)[0]; Vector3[] pts = new Vector3[] { unityPoint, unityPoint }; go.GetComponent <LineRenderer>().positionCount = pts.Length; go.GetComponent <LineRenderer>().SetPositions(pts); return(go); }
public static GameObject ToNative(this SpeckleCore.SpeckleMesh speckleMesh) { GameObject go = SpecklePrefabs.InstantiateMesh(); go.GetComponent <UnitySpeckleObjectData>().Id = speckleMesh._id; go.GetComponent <UnitySpeckleObjectData>().SpeckleObject = speckleMesh; Mesh unityMesh = go.GetComponent <MeshFilter>().mesh; unityMesh.vertices = Util.SpecklePointsToUnityPoints(speckleMesh.Vertices); unityMesh.triangles = Util.SpeckleFacesToUnityTriangles(speckleMesh.Faces); unityMesh.RecalculateNormals(); unityMesh.RecalculateTangents(); MeshCollider mc = go.AddComponent <MeshCollider>(); mc.sharedMesh = unityMesh; return(go); }