public static unsafe BlobAssetReference <Collider> Create( NativeArray <float> heights, int2 size, float3 scale, CollisionMethod collisionMethod, CollisionFilter filter, Material material ) { if (math.any(size < 2)) { throw new ArgumentOutOfRangeException("Tried to create TerrainCollider with size < 2"); } if (math.any(scale <= float3.zero)) { throw new ArgumentOutOfRangeException("Tried to create TerrainCollider with scale <= 0"); } // Allocate memory for the collider int totalSize = sizeof(TerrainCollider) + Terrain.CalculateDataSize(size); var collider = (TerrainCollider *)UnsafeUtility.Malloc(totalSize, 16, Allocator.Temp); // BlobAssetReference<T> does memcpy, so allocate memory first and then assign properly aligned values to result var blob = BlobAssetReference <Collider> .Create(collider, totalSize); UnsafeUtility.Free(collider, Allocator.Temp); collider = (TerrainCollider *)blob.GetUnsafePtr(); UnsafeUtility.MemClear(collider, totalSize); // Initialize the collider collider->m_Header.Type = ColliderType.Terrain; collider->m_Header.CollisionType = (collisionMethod == CollisionMethod.Triangles) ? CollisionType.Composite : CollisionType.Terrain; collider->m_Header.Version = 1; collider->m_Header.Magic = 0xff; collider->m_Header.Filter = filter; collider->Material = material; collider->MemorySize = totalSize; collider->Terrain.Init(size, scale, (float *)heights.GetUnsafePtr()); return(blob); }
public static unsafe BlobAssetReference <Collider> Create( NativeArray <sfloat> heights, int2 size, float3 scale, CollisionMethod collisionMethod, CollisionFilter filter, Material material ) { SafetyChecks.CheckInRangeAndThrow(size.x, new int2(2, int.MaxValue), nameof(size)); SafetyChecks.CheckInRangeAndThrow(size.y, new int2(2, int.MaxValue), nameof(size)); SafetyChecks.CheckFiniteAndPositiveAndThrow(scale, nameof(scale)); // Allocate memory for the collider int totalSize = sizeof(TerrainCollider) + Terrain.CalculateDataSize(size); var collider = (TerrainCollider *)UnsafeUtility.Malloc(totalSize, 16, Allocator.Temp); UnsafeUtility.MemClear(collider, totalSize); // Initialize the collider collider->m_Header.Type = ColliderType.Terrain; collider->m_Header.CollisionType = (collisionMethod == CollisionMethod.Triangles) ? CollisionType.Composite : CollisionType.Terrain; collider->m_Header.Version = 1; collider->m_Header.Magic = 0xff; collider->m_Header.Filter = filter; collider->Material = material; collider->MemorySize = totalSize; collider->Terrain.Init(size, scale, (sfloat *)heights.GetUnsafePtr()); var blob = BlobAssetReference <Collider> .Create(collider, totalSize); UnsafeUtility.Free(collider, Allocator.Temp); return(blob); }
public static unsafe BlobAssetReference <Collider> Create( int2 size, float3 scale, float *heights, CollisionMethod collisionMethod, CollisionFilter?filter = null, Material?material = null ) { var heightsArray = new NativeArray <float>(size.x * size.y, Allocator.Temp, NativeArrayOptions.UninitializedMemory); UnsafeUtility.MemCpy(heightsArray.GetUnsafePtr(), heights, heightsArray.Length * UnsafeUtility.SizeOf <float>()); return(Create(heightsArray, size, scale, collisionMethod, filter ?? CollisionFilter.Default, material ?? Material.Default)); }
protected bool CanOpenFile(AccessMode requestedMode, CollisionMethod requestedCollision, bool doesAlreadyExist) { if (requestedCollision == CollisionMethod.FailIfExists && doesAlreadyExist) { return(false); } if (requestedMode == AccessMode.ReadOnly && !doesAlreadyExist) { return(false); } return(true); }
public static BlobAssetReference <Collider> Create( NativeArray <float> heights, int2 size, float3 scale, CollisionMethod collisionMethod, CollisionFilter filter ) => Create(heights, size, scale, collisionMethod, filter, Material.Default);
private void SetCollisionMethod(CollisionMethod _collisionMethod) { collisionMethod = _collisionMethod; }
public abstract Task <Stream> OpenFileAsync(string path, AccessMode accessMode = AccessMode.ReadOnly, CollisionMethod collisionMethod = CollisionMethod.NormalOpen);
private DeviceMessage CreateCollisionDeviceMessage(CollisionMethod method, Int32 xThreshold, Int32 xSpeedThreshold, Int32 yThreshold, Int32 ySpeedThreshold, Int32 quietTime) { Byte[] numArray = new Byte[] { (Byte)method, (Byte)xThreshold, (Byte)xSpeedThreshold, (Byte)yThreshold, (Byte)ySpeedThreshold, (Byte)quietTime }; return(new DeviceMessage(2, 18, numArray, DeviceMessage.SopParameters.ResetTimeout)); }
public void SetCollisionStyle(CollisionMethod style) { collisionMethod = style; }
/// <summary> /// Sphero contains a powerful analysis function to filter accelerometer data in order to detect collisions. /// Because this is a great example of a high-level concept that humans excel and – but robots do not – a number of parameters control the behavior. /// When a collision is detected an asynchronous message is generated to the client . /// </summary> /// <param name="method">Detection method type to use</param> /// <param name="xThreshold">Threshold for the X (left/right) axe of Sphero. A value of 00h disables the contribution of that axis</param> /// <param name="xSpeed">Speed value for the X axe. This setting is ranged by the speed, then added to Xt to generate the final threshold value.</param> /// <param name="yThreshold">Threshold for the Y (front/back) axe of Sphero. A value of 00h disables the contribution of that axis</param> /// <param name="ySpeed">Speed value for the YX axe. This setting is ranged by the speed, then added to Yt to generate the final threshold value.</param> /// <param name="dead">Post-collision dead time to prevent retriggering; specified in 10ms increments.</param> public void ConfigureCollisionDetection(CollisionMethod method, byte xThreshold, byte xSpeed, byte yThreshold, byte ySpeed, byte dead) { CommandPacket command = new CommandPacket(0xFE, DeviceIDs.SPHERO, CommandIDs.Sphero.CONFIGURE_COLLISION_DETECTION, new byte[] { (byte)method, xThreshold, xSpeed, yThreshold, ySpeed, dead }); _connection.SendCommand(command); }
private DeviceMessage CreateCollisionDeviceMessage(CollisionMethod method, Int32 xThreshold, Int32 xSpeedThreshold, Int32 yThreshold, Int32 ySpeedThreshold, Int32 quietTime) { Byte[] numArray = new Byte[] { (Byte)method, (Byte)xThreshold, (Byte)xSpeedThreshold, (Byte)yThreshold, (Byte)ySpeedThreshold, (Byte)quietTime }; return new DeviceMessage(2, 18, numArray, DeviceMessage.SopParameters.ResetTimeout); }
public override async Task <Stream> OpenFileAsync(string path, AccessMode accessMode = AccessMode.ReadOnly, CollisionMethod collisionMethod = CollisionMethod.NormalOpen) { if (path == null) { throw new ArgumentNullException(nameof(path)); } await AwaitHelper.EnsureNotMainThread(); var fi = new FileInfo(path); // set some default enums FileMode mode = FileMode.Open; FileAccess access = FileAccess.Read; FileShare sharing = FileShare.Read; FileOptions opts = FileOptions.RandomAccess | FileOptions.Asynchronous; // parse the supplied options switch (accessMode) { case AccessMode.ReadWrite: mode = FileMode.OpenOrCreate; access = FileAccess.ReadWrite; break; case AccessMode.ReadWriteTemporary: mode = FileMode.OpenOrCreate; access = FileAccess.ReadWrite; opts |= FileOptions.DeleteOnClose; break; case AccessMode.ReadWriteExclusive: mode = FileMode.OpenOrCreate; access = FileAccess.ReadWrite; sharing = FileShare.None; break; } // check collision options if (fi.Exists) { if (collisionMethod == CollisionMethod.FailIfExists) { return(null); } else if (collisionMethod == CollisionMethod.RenameIfExists) { // append numbers until we find a unique one var fPath = fi.DirectoryName; var fName = Path.GetFileNameWithoutExtension(fi.Name); for (int num = 2; ; num++) { var name = Path.Combine(fPath, string.Format("{0}-{1}.{2}", fName, num, fi.Extension)); if (!File.Exists(name)) { path = name; // use this new name break; } } } else if (collisionMethod == CollisionMethod.OverwriteIfExists && accessMode != AccessMode.ReadOnly) { mode = FileMode.Create; } } // try creating the file stream try { return(new FileStream(path, mode, access, sharing, 16 * 1024, opts)); } catch (ArgumentException) { // bad file name } catch (NotSupportedException) { // something weird, like lpt1: } catch (FileNotFoundException) { // file doesn't exist for read } catch (IOException) { // stream broke } catch (UnauthorizedAccessException) { // not permitted } return(null); }