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