// IntPtr bodyHandle) public void OnBodyAddedCallback(Body body) { // Create the game object bool isFinger = false; GameObject gameObject; Shape.ShapeType type = body.Shape.Type; if (type == Shape.ShapeType.Capsule) { float capsuleRadius = body.Shape.CapsuleRadius; float capsuleSegmentLength = body.Shape.CapsuleSegmentLength; gameObject = GameObject.Instantiate(Resources.Load(UnityUtil.ResourcesFolder + UnityUtil.FingerBoneTemplateName) as GameObject) as GameObject; // Adjust dimensions float capsuleHeight = capsuleRadius * 2f + capsuleSegmentLength; float yScale = capsuleHeight / 2f; float zxScale = capsuleRadius / 0.5f; gameObject.transform.localScale = new Vector3(zxScale, yScale, zxScale); gameObject.name = UnityUtil.FingerBoneName; LeapTransform t = new LeapTransform(); t = new LeapTransform(Native.AccessPropertyAsTransform(body, Native.Property.BodyTransform, Native.Mode.Get, t.ToNative())); gameObject.transform.position = t.Position; gameObject.transform.rotation = t.Rotation; gameObject.rigidbody.maxAngularVelocity = 100.0f; isFinger = true; fingerBoneCount++; } else { gameObject = GameObject.Instantiate(Resources.Load(UnityUtil.ResourcesFolder + UnityUtil.HandPalmTemplateName) as GameObject) as GameObject; gameObject.name = UnityUtil.HandPalmName; LeapTransform t = new LeapTransform(); t = new LeapTransform(Native.AccessPropertyAsTransform(body, Native.Property.BodyTransform, Native.Mode.Get, t.ToNative())); gameObject.transform.position = t.Position; gameObject.transform.rotation = t.Rotation; gameObject.rigidbody.maxAngularVelocity = 100.0f; latestHandPalmAdded = gameObject; fingerBoneCount = 0; } BodyMapper.Add(gameObject, body); GameObject container = isFinger && latestHandPalmAdded != null ? latestHandPalmAdded : GameObject.Find(UnityUtil.DynamicObjectContainerName) as GameObject; gameObject.transform.parent = container.transform; gameObject.layer = UnityUtil.LayerForHands; if (fingerBoneCount%3 == 0 && fingerBoneCount > 0) { gameObject.name = UnityUtil.FingerTipBoneName; if (fingerBoneCount == 3) { gameObject.name = UnityUtil.ThumbTipBoneName; } } if (fingerBoneCount == 15) { latestHandPalmAdded = null; fingerBoneCount = 0; if (UnityUtil.FilterHandCollisionPerColliderExplicitly) { DisableHandSelfCollisions(gameObject.transform.parent); } } }
public void OnBodyAddedCallback(Body body)// IntPtr bodyHandle) { // Create the game object bool isFinger = false; GameObject gameObject; Shape.ShapeType type = body.Shape.Type; if (type == Shape.ShapeType.Capsule) { float capsuleRadius = body.Shape.CapsuleRadius; float capsuleSegmentLength = body.Shape.CapsuleSegmentLength; gameObject = GameObject.Instantiate(Resources.Load(UnityUtil.ResourcesFolder + UnityUtil.FingerBoneTemplateName) as GameObject) as GameObject; // Adjust dimensions float capsuleHeight = capsuleRadius * 2f + capsuleSegmentLength; float yScale = capsuleHeight / 2f; float zxScale = capsuleRadius / 0.5f; gameObject.transform.localScale = new Vector3(zxScale, yScale, zxScale); gameObject.name = UnityUtil.FingerBoneName; LeapTransform t = new LeapTransform(); t = new LeapTransform(Native.AccessPropertyAsTransform(body, Native.Property.BodyTransform, Native.Mode.Get, t.ToNative())); gameObject.transform.position = t.Position; gameObject.transform.rotation = t.Rotation; gameObject.rigidbody.maxAngularVelocity = 100.0f; isFinger = true; fingerBoneCount++; } else { gameObject = GameObject.Instantiate(Resources.Load(UnityUtil.ResourcesFolder + UnityUtil.HandPalmTemplateName) as GameObject) as GameObject; gameObject.name = UnityUtil.HandPalmName; LeapTransform t = new LeapTransform(); t = new LeapTransform(Native.AccessPropertyAsTransform(body, Native.Property.BodyTransform, Native.Mode.Get, t.ToNative())); gameObject.transform.position = t.Position; gameObject.transform.rotation = t.Rotation; gameObject.rigidbody.maxAngularVelocity = 100.0f; latestHandPalmAdded = gameObject; fingerBoneCount = 0; } BodyMapper.Add(gameObject, body); GameObject container = isFinger && latestHandPalmAdded != null ? latestHandPalmAdded : GameObject.Find(UnityUtil.DynamicObjectContainerName) as GameObject; gameObject.transform.parent = container.transform; gameObject.layer = UnityUtil.LayerForHands; if (fingerBoneCount % 3 == 0 && fingerBoneCount > 0) { gameObject.name = UnityUtil.FingerTipBoneName; if (fingerBoneCount == 3) { gameObject.name = UnityUtil.ThumbTipBoneName; } } if (fingerBoneCount == 15) { latestHandPalmAdded = null; fingerBoneCount = 0; if (UnityUtil.FilterHandCollisionPerColliderExplicitly) { DisableHandSelfCollisions(gameObject.transform.parent); } } }
public void AddClickAnchor(LeapTransform t) { Native.AccessPropertyAsTransform(this, Native.Property.ShapeClickAnchors, Native.Mode.Add, t.ToNative()); }