Showing the changes to scripts/tutorials/entity_scripts (1 of 1 file). Show all
Unified · Split
| @@ -22,7 +22,7 @@ · 21 unmodified lines | ||
| 22 | 22 | this.entityID = entityID; |
| 23 | 23 | } |
| 24 | 24 | this.unload = function() { |
| 25 | − if (MyAvatar.getParentID() === this.entityID) { | |
| 25 | + if (MyAvatar.sessionUUID === this.getSeatUser()) { | |
| 26 | 26 | this.sitUp(this.entityID); |
| 27 | 27 | } |
| 28 | 28 | if (this.interval) { |
| @@ -32,11 +32,39 @@ · 3 unmodified lines | ||
| 32 | 32 | this.cleanupOverlay(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | + this.setSeatUser = function(user) { | |
| 36 | + var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData; | |
| 37 | + userData = JSON.parse(userData); | |
| 38 | + | |
| 39 | + if (user) { | |
| 40 | + userData.seat.user = user; | |
| 41 | + } else { | |
| 42 | + delete userData.seat.user; | |
| 43 | + } | |
| 44 | + | |
| 45 | + Entities.editEntity(this.entityID, { | |
| 46 | + userData: JSON.stringify(userData) | |
| 47 | + }); | |
| 48 | + } | |
| 49 | + this.getSeatUser = function() { | |
| 50 | + var properties = Entities.getEntityProperties(this.entityID, ["userData", "position"]); | |
| 51 | + var userData = JSON.parse(properties.userData); | |
| 52 | + | |
| 53 | + if (userData.seat.user && userData.seat.user !== MyAvatar.sessionUUID) { | |
| 54 | + var avatar = AvatarList.getAvatar(userData.seat.user); | |
| 55 | + if (avatar && Vec3.distance(avatar.position, properties.position) > RELEASE_DISTANCE) { | |
| 56 | + return null; | |
| 57 | + } | |
| 58 | + } | |
| 59 | + return userData.seat.user; | |
| 60 | + } | |
| 61 | + | |
| 35 | 62 | this.checkSeatForAvatar = function() { |
| 63 | + var seatUser = this.getSeatUser(); | |
| 36 | 64 | var avatarIdentifiers = AvatarList.getAvatarIdentifiers(); |
| 37 | 65 | for (var i in avatarIdentifiers) { |
| 38 | 66 | var avatar = AvatarList.getAvatar(avatarIdentifiers[i]); |
| 39 | − if (avatar && avatar.getParentID() === this.entityID) { | |
| 67 | + if (avatar && avatar.sessionUUID === seatUser) { | |
| 40 | 68 | return true; |
| 41 | 69 | } |
| 42 | 70 | } |
| @@ -53,7 +81,7 @@ · 10 unmodified lines | ||
| 53 | 81 | |
| 54 | 82 | var that = this; |
| 55 | 83 | Script.setTimeout(function() { |
| 56 | − MyAvatar.setParentID(that.entityID); | |
| 84 | + that.setSeatUser(MyAvatar.sessionUUID); | |
| 57 | 85 | MyAvatar.characterControllerEnabled = false; |
| 58 | 86 | MyAvatar.hmdLeanRecenterEnabled = false; |
| 59 | 87 | MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME); |
| @@ -62,7 +90,7 @@ · 2 unmodified lines | ||
| 62 | 90 | var index = MyAvatar.getJointIndex("Hips"); |
| 63 | 91 | MyAvatar.pinJoint(index, properties.position, properties.rotation); |
| 64 | 92 | |
| 65 | − that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(props) { | |
| 93 | + that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(properties) { | |
| 66 | 94 | return { headType: 0 }; |
| 67 | 95 | }, ["headType"]); |
| 68 | 96 | |
| @@ -82,7 +110,7 @@ · 13 unmodified lines | ||
| 82 | 110 | MyAvatar.restoreRoleAnimation(ROLE); |
| 83 | 111 | MyAvatar.characterControllerEnabled = true; |
| 84 | 112 | MyAvatar.hmdLeanRecenterEnabled = true; |
| 85 | − MyAvatar.setParentID(""); | |
| 113 | + this.setSeatUser(null); | |
| 86 | 114 | |
| 87 | 115 | var index = MyAvatar.getJointIndex("Hips"); |
| 88 | 116 | MyAvatar.clearPinOnJoint(index); |
| @@ -130,9 +158,9 @@ · 41 unmodified lines | ||
| 130 | 158 | x: textSize.width + 2 * textMargin, |
| 131 | 159 | y: textSize.height + 2 * textMargin |
| 132 | 160 | } |
| 133 | − var props = Entities.getEntityProperties(this.entityID, ["position", "registrationPoint", "dimensions"]); | |
| 134 | − var yOffset = (1.0 - props.registrationPoint.y) * props.dimensions.y + (overlayDimensions.y / 2.0); | |
| 135 | − var overlayPosition = Vec3.sum(props.position, { x: 0, y: yOffset, z: 0 }); | |
| 161 | + var properties = Entities.getEntityProperties(this.entityID, ["position", "registrationPoint", "dimensions"]); | |
| 162 | + var yOffset = (1.0 - properties.registrationPoint.y) * properties.dimensions.y + (overlayDimensions.y / 2.0); | |
| 163 | + var overlayPosition = Vec3.sum(properties.position, { x: 0, y: yOffset, z: 0 }); | |
| 136 | 164 | Overlays.editOverlay(this.overlay, { |
| 137 | 165 | position: overlayPosition, |
| 138 | 166 | dimensions: overlayDimensions |
| @@ -147,7 +175,7 @@ · 8 unmodified lines | ||
| 147 | 175 | |
| 148 | 176 | |
| 149 | 177 | this.update = function(dt) { |
| 150 | − if (MyAvatar.getParentID() === this.entityID) { | |
| 178 | + if (MyAvatar.sessionUUID === this.getSeatUser()) { | |
| 151 | 179 | var properties = Entities.getEntityProperties(this.entityID, ["position"]); |
| 152 | 180 | var avatarDistance = Vec3.distance(MyAvatar.position, properties.position); |
| 153 | 181 | var ikError = MyAvatar.getIKErrorOnLastSolve(); |
| @@ -179,13 +207,13 @@ · 25 unmodified lines | ||
| 179 | 207 | } |
| 180 | 208 | |
| 181 | 209 | this.canSitDesktop = function() { |
| 182 | − var props = Entities.getEntityProperties(this.entityID, ["position"]); | |
| 183 | − var distanceFromSeat = Vec3.distance(MyAvatar.position, props.position); | |
| 210 | + var properties = Entities.getEntityProperties(this.entityID, ["position"]); | |
| 211 | + var distanceFromSeat = Vec3.distance(MyAvatar.position, properties.position); | |
| 184 | 212 | return distanceFromSeat < DESKTOP_MAX_DISTANCE && !this.checkSeatForAvatar(); |
| 185 | 213 | } |
| 186 | 214 | |
| 187 | 215 | this.hoverEnterEntity = function(event) { |
| 188 | − if (isInEditMode() || (MyAvatar.getParentID() === this.entityID)) { | |
| 216 | + if (isInEditMode() || (MyAvatar.sessionUUID === this.getSeatUser())) { | |
| 189 | 217 | return; |
| 190 | 218 | } |
| 191 | 219 | |
| @@ -209,7 +237,7 @@ · 17 unmodified lines | ||
| 209 | 237 | } |
| 210 | 238 | |
| 211 | 239 | this.clickDownOnEntity = function () { |
| 212 | − if (isInEditMode() || (MyAvatar.getParentID() === this.entityID)) { | |
| 240 | + if (isInEditMode() || (MyAvatar.sessionUUID === this.getSeatUser())) { | |
| 213 | 241 | return; |
| 214 | 242 | } |
| 215 | 243 | if (this.canSitDesktop()) { |