public void SetOffset(string key, Vector3 offset)
 {
     if (this.Attachments.ContainsKey(key))
     {
         GameObjectAttachment gameObjectAttachment = this.Attachments[key];
         gameObjectAttachment.Offset = offset;
         this.UpdateAttachment(key);
     }
 }
        public void AttachGameObject(string key, GameObject obj, Vector3 offset, bool pinToFloor, bool pinToCenterOfMass)
        {
            if (this.Attachments == null)
            {
                this.Attachments = new Dictionary <string, GameObjectAttachment>();
            }
            else if (this.Attachments.ContainsKey(key))
            {
                return;
            }
            GameObjectAttachment gameObjectAttachment = new GameObjectAttachment();

            gameObjectAttachment.Key = key;
            gameObjectAttachment.AttachedGameObject = obj;
            gameObjectAttachment.Offset             = offset;
            gameObjectAttachment.FloorPin           = pinToFloor;
            gameObjectAttachment.CenterOfMassPin    = pinToCenterOfMass;
            this.Attachments.Add(key, gameObjectAttachment);
            this.UpdateAttachment(key);
        }
        public void UpdateAttachment(string key)
        {
            GameObjectAttachment gameObjectAttachment = this.Attachments[key];

            if (gameObjectAttachment == null || gameObjectAttachment.AttachedGameObject == null || gameObjectAttachment.AttachedGameObject.transform == null)
            {
                return;
            }
            Vector3 vector = gameObjectAttachment.Offset;

            if (gameObjectAttachment.CenterOfMassPin && this.centerOfMassTransform != null)
            {
                vector += this.centerOfMassTransform.position;
            }
            else if (this.MainTransform != null)
            {
                vector += this.MainTransform.position;
            }
            if (gameObjectAttachment.FloorPin)
            {
                vector.y = gameObjectAttachment.Offset.y;
            }
            gameObjectAttachment.AttachedGameObject.transform.position = vector;
        }