//newly received messages public Attachment(string fileName, string fileKey, byte[] thumbnailBytes, string contentType, AttachmentState attachmentState) { this.FileName = fileName; this.FileKey = fileKey; this.Thumbnail = thumbnailBytes; this.ContentType = contentType; this.FileState = attachmentState; }
public void Read(BinaryReader reader) { _fileKey = reader.ReadString(); _fileName = reader.ReadString(); _contentType = reader.ReadString(); int count = reader.ReadInt32(); if (count != 0) { _thumbnail = reader.ReadBytes(count); } else { _thumbnail = null; } _fileState = (AttachmentState)reader.ReadInt32(); }
internal Attachment(AttachmentState state) { this.State = state; }
public static Attachment ToAttachment(AttachmentState state) { return(new Attachment(state)); }
// // Determine target positions + rotations for body and attached part // void StartAttachingPart() { if (selectedChildJoint.attachmentType != AttachmentType.LevelAttachment) { parentStartRotation = selectedParentJoint.owner.getRootComponent().transform.rotation; parentTargetRotation = Quaternion.identity; parentStartPosition = selectedParentJoint.owner.getRootComponent().transform.position; parentTargetPosition = FindParentTargetPosition(); if (!CheckRoomToAttach()) { Abort(); return; } childStartPosition = selectedChildJoint.owner.transform.position; childStartRotation = selectedChildJoint.owner.transform.rotation; Vector3 parentChange = parentTargetPosition - parentStartPosition; Bone jointBone = player.skeleton.GetBoneForSlot(selectedParentJoint.slot); if (jointBone.LowerJoint) { jointBone = jointBone.LowerJoint; } childTargetPosition = Quaternion.Inverse(parentStartRotation) * (jointBone.transform.position - player.transform.position) + player.transform.position + parentChange; childTargetRotation = Quaternion.Inverse(parentStartRotation) * jointBone.GetBoneRotation(); state = AttachmentState.AttachingPart; // Disable movement during actual attachment... movementController.enabled = false; if (selectedChildJoint.owner.rigidbody2D) { Destroy(selectedChildJoint.owner.rigidbody2D); } if (selectedParentJoint.owner.getRootComponent().rigidbody2D) { Destroy(selectedParentJoint.owner.getRootComponent().rigidbody2D); } // TODO attachment speed proportional to distance / rotation? attachmentTime = 0.0f; } else { // it's a 'static' level object we are attaching to, it won't move (to us, at least) // so just attach player to it using a hinge joint.. if (selectedChildJoint.collider2D.attachedRigidbody) { // First, make a distance joint to pull body to attachment selectedParentJoint.AttachToLevelObject(selectedChildJoint); // TODO attachment speed proportional to distance / rotation? initialDistance = Vector2.Distance(selectedParentJoint.transform.position, selectedChildJoint.transform.position); attachmentTime = 0.0f; selectedParentJoint.SetAttachmentDistance(initialDistance); attachmentTime = 0.0f; state = AttachmentState.AttachingToLevelObject; } } }
// // Select joint on body to attach new part to / detach existing part // void SelectParent() { if (Input.GetKeyDown(KeyCode.F)) { // Abort to regular mode Abort(); return; } // Select the joint closest to the mouse pointer / direction Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); float closestDistance = float.MaxValue; AttachmentPoint closestJoint = null; foreach (var parentJoint in parentJoints) { float distance = Vector2.Distance(mousePosition.XY(), parentJoint.transform.position.XY()); if (distance < closestDistance) { closestJoint = parentJoint; closestDistance = distance; } } if (closestJoint) { attachmentText.enabled = true; attachmentText.color = Color.white; SetSelectedParent(closestJoint); if (selectedParentJoint.AttachedToLevelObject) { attachmentText.text = "DISCONNECT FROM "; attachmentText.text += selectedParentJoint.child.AttachmentName; attachmentText.color = Color.red; } else if (selectedParentJoint.child != null) { attachmentText.text = "DETACH "; attachmentText.text += selectedParentJoint.child.AttachmentName; attachmentText.text += " FROM "; attachmentText.text += selectedParentJoint.AttachmentName; attachmentText.color = Color.red; } else { attachmentText.text = "ATTACH TO "; attachmentText.text += selectedParentJoint.AttachmentName; attachmentText.text += "..."; } } else { attachmentText.enabled = false; } if (Input.GetMouseButtonDown(0)) { if (selectedParentJoint.AttachedToLevelObject) { selectedParentJoint.child.OnDetach(); selectedParentJoint.DetachFromLevelObject(); selectedParentJoint.childTransform = selectedParentJoint.transform; enabled = false; } else if (selectedParentJoint.child != null) { // If selected parent joint already has a child, detach it selectedParentJoint.child.OnDetach(); selectedParentJoint.owner.Unattach(selectedParentJoint, selectedParentJoint.child); selectedParentJoint.childTransform = selectedParentJoint.transform; state = AttachmentState.AttachingPart; enabled = false; } else { // Select a child to attach now state = AttachmentState.SelectChild; // Transition camera ... selectChildCamera.AcquireCamera(); attachmentShadowVisual.enabled = false; attachmentRangeVisual.enabled = true; attachmentRangeVisual.transform.localScale = Vector3.one * (2 * attachmentRange + 0.5f); // Show the range... AudioSource.PlayClipAtPoint(jointSelectedClip, transform.position); player.inputHints.ClearHints(); player.inputHints.AddHint("LMB", "Select Object To Attach"); player.inputHints.AddHint("F", "Exit Attachment Mode"); } } }
// // Select unattached child part to attach to body // void SelectChild() { GetUnattachedChildren(); if (Input.GetKeyDown(KeyCode.F)) { // Abort to regular mode Abort(); return; } // Select the joint closest to the mouse pointer / direction Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); float closestDistance = float.MaxValue; AttachmentPoint closestJoint = null; foreach (var child in childJoints) { float distance = Vector2.Distance(mousePosition.XY(), child.transform.position.XY()); if (distance < closestDistance) { closestJoint = child; closestDistance = distance; } } attachmentText.enabled = false; if (closestJoint) { SetSelectedChild(closestJoint); selectedParentJoint.childTransform = selectedChildJoint.transform; attachmentText.enabled = true; if (!CheckRoomToAttach()) { attachmentText.color = Color.red; attachmentText.text = "NO ROOM"; } else { attachmentText.color = Color.white; attachmentText.text = selectedChildJoint.AttachmentName; } } else { // remove lightning bolt thing selectedParentJoint.childTransform = selectedParentJoint.transform; SetSelectedChild(null); } if (Input.GetMouseButtonDown(0)) { if (selectedChildJoint != null) { AudioSource.PlayClipAtPoint(jointSelectedClip, transform.position); StartAttachingPart(); } else { // Nothing selected, abort Abort(); state = AttachmentState.AttachingPart; } } }
void OnEnable() { state = AttachmentState.SelectParent; attachedParts = player.allComponents; player.inputHints.ClearHints(); player.inputHints.AddHint("LMB", "Select Joint"); player.inputHints.AddHint("F", "Exit Attachment Mode"); parentJoints = new List<AttachmentPoint>(); foreach (var part in attachedParts) { parentJoints.AddRange(part.allJoints); } // Special case: we are hooked into a terminal, as just a head if (parentJoints.Count == 1) { AttachmentPoint parentJoint = parentJoints[0]; if (parentJoint && parentJoint.AttachedToLevelObject) { parentJoint.child.OnDetach(); parentJoint.DetachFromLevelObject(); parentJoint.childTransform = parentJoint.transform; enabled = false; return; } } // Transition camera to zoom on player selectParentCamera.AcquireCamera(); AudioSource.PlayClipAtPoint(onEnableClip, transform.position); attachmentShadowVisual.enabled = true; movementController.MouseAim = false; }
public Attachment(string fileName, byte[] thumbnailBytes, AttachmentState attachmentState) { this.FileName = fileName; this.Thumbnail = thumbnailBytes; this.FileState = attachmentState; }