public override void Init() { //Log.Write("VR Init"); Script.UnhandledException += UnhandledException; // Catch errors and keep running unless fatal if (RigidBody == null) { if (!ObjectPrivate.TryGetFirstComponent(out RigidBody)) { // Since object scripts are initialized when the scene loads, no one will actually see this message. Log.Write("There is no RigidBodyComponent attached to this object."); //ScenePrivate.Chat.MessageAllUsers("There is no RigidBodyComponent attached to this object."); return; } else if (RigidBody.IsTriggerVolume()) { Log.Write("Collision Subscription: " + collisionSubscription); if (collisionSubscription == null) { collisionSubscription = RigidBody.Subscribe(CollisionEventType.AllCollisions, OnCollision, true); //Log.Write("Subscribed to Collision"); } } } }
protected override void InitObjective() { RigidBodyComponent triggerVolume; if (ObjectPrivate.TryGetFirstComponent <RigidBodyComponent>(out triggerVolume) && triggerVolume.IsTriggerVolume()) { if (!TriggerObjectives.Contains(triggerVolume)) { QLog(LogLevel.Info, "Adding scripted object as trigger volume."); TriggerObjectives.Insert(0, triggerVolume); } } TriggerObjectives = TriggerObjectives.Distinct().ToList(); TriggerHints = TriggerHints.Distinct().ToList(); int rbs = 0; for (int i = 0; i < TriggerObjectives.Count; ++i) { var trigger = TriggerObjectives[i]; RigidBodyComponent hint = null; int index = i; if (trigger != null && trigger.IsValid && trigger.IsTriggerVolume()) { ++rbs; QLog(LogLevel.Info, "Subscribing to collision " + trigger.Name + ", index " + index); Collectors[i] = new Dictionary <SessionId, CollectionState>(); trigger.Subscribe(CollisionEventType.Trigger, (data) => OnCollide(data, index)); if (TriggerHints.Count > i) { hint = TriggerHints[i]; } else if (TriggerHints.Count > 0) { hint = TriggerHints[0]; } if (hint != null && hint.IsValid && hint.IsTriggerVolume()) { QLog(LogLevel.Info, "Subscribing to hint " + hint.Name + ", index " + index); hint.Subscribe(CollisionEventType.Trigger, (data) => HintCollide(data, index)); } } } if (rbs == 0) { QLog(LogLevel.Error, "Must be attached to a trigger volume or have Trigger Volumes set in Extra Objectives."); return; } SubscribeToAll(EnableEvent, (ScriptEventData) => { ScriptEnabled = true; }); SubscribeToAll(DisableEvent, (ScriptEventData) => { ScriptEnabled = false; }); ScriptEnabled = StartEnabled; Timer.Create(300, 500, Cleanup); }
// Override Init to set up event handlers and start coroutines. public override void Init() { // Sensible default setting values if (OpenAngleDegrees == 0) { OpenAngleDegrees = 90; } if (Channel == 0) { Channel = 1000; } if (SecondsToOpen == 0) { SecondsToOpen = 1; } if (SecondsBeforeClose == 0) { SecondsBeforeClose = 5; } // Parse the pipe-delimited sensor names into a clean list if (SensorNames != null) { foreach (string Name in SensorNames.Split(',')) { if (Name.Trim() == "") { continue; } SensorNameList.Add(Name.Trim()); } } // Find the door we'll manipulate. if (DoorBody == null) { ObjectPrivate.TryGetFirstComponent(out DoorBody); } // Compute some basics OpenAngle = OpenAngleDegrees / Mathf.DegreesPerRadian; ClosedOrientation = DoorBody.GetOrientation(); HingeOffset = new Vector(HingeOffsetX, HingeOffsetY, 0, 0).Rotate(ref ClosedOrientation); ClosedPosition = DoorBody.GetPosition() + HingeOffset; // Only subscribe to collision events if the experience creator requested it if (OpenOnCollision) { DoorBody.Subscribe(CollisionEventType.CharacterContact, Collide); } // Only listen for chat if the experience creator wants outside sensors to trip this if (SensorNames != null) { ScenePrivate.Chat.Subscribe(Channel, null, ChatMessage); } // Start a continuous loop updating the door's position and orientation StartCoroutine(UpdateLoop); }
private void Subscribe(ScriptEventData sed) { if (Unsubscribes == null) { Unsubscribes = SubscribeToAll(LocalEvent, LocalTeleport); Unsubscribes += SubscribeToAll(RemoteEvent, RemoteTeleport); if (UseObjectForLocal || UseObjectForRemote) { try { RigidBodyComponent rigidBody = null; if (ObjectPrivate.TryGetFirstComponent(out rigidBody)) { CollisionEventType collisionEvent = rigidBody.IsTriggerVolume() ? CollisionEventType.Trigger : CollisionEventType.CharacterContact; if (UseObjectForRemote) { Unsubscribes += rigidBody.Subscribe(collisionEvent, (CollisionData data) => { AgentPrivate agent = ScenePrivate.FindAgent(data.HitComponentId.ObjectId); if (agent != null) { RemoteTeleport(agent.AgentInfo.SessionId); } }).Unsubscribe; } if (UseObjectForLocal) { Unsubscribes += rigidBody.Subscribe(collisionEvent, (CollisionData data) => { AgentPrivate agent = ScenePrivate.FindAgent(data.HitComponentId.ObjectId); if (agent != null) { LocalTeleport(agent.AgentInfo.SessionId); } }).Unsubscribe; } } } catch (NullReferenceException nre) { SimpleLog(LogLevel.Info, "NullReferenceException setting up collision events: " + nre.Message); } catch (Exception e) { SimpleLog(LogLevel.Error, "Exception setting up collision event user: " + e.Message); } } } }
public override void Init() { if (ObjectPrivate.TryGetFirstComponent(out RigidBody) && RigidBody.IsTriggerVolume()) { RigidBody.Subscribe(CollisionEventType.Trigger, OnTrigger); } else { Log.Write(LogLevel.Error, "Could not start " + GetType().Name + " because no trigger volume was found."); } }
public override void Init() { Log.Write("In TriggerMegaphone"); if (!ObjectPrivate.TryGetFirstComponent(out RigidBody)) { Log.Write(LogLevel.Error, "Could not start " + GetType().Name + " because no RigidBodyComponent was found."); return; } collisionSubscription = RigidBody.Subscribe(CollisionEventType.AllCollisions, OnCollision); }
public override void Init() { if (ObjectPrivate.TryGetFirstComponent(out RigidBody)) { RigidBody.Subscribe(CollisionEventType.RigidBodyContact, OnChop); } else { Log.Write(LogLevel.Error, "Choppable couldn't find a RigidBody component. That component is needed in order to detect when an avatar walks into them"); return; } }
public override void Init() { Script.UnhandledException += UnhandledException; // Catch errors and keep running unless fatal Log.Write("In TriggerPressed2"); if (ObjectPrivate.TryGetFirstComponent(out rigidBody)) { Log.Write("Calling OnCollide"); rigidBody.Subscribe(CollisionEventType.Trigger, OnCollide); } else { } }
public override void Init() { Script.UnhandledException += UnhandledException; // Catch errors and keep running unless fatal if (ObjectPrivate.TryGetFirstComponent(out rigidBody) && rigidBody.IsTriggerVolume()) { rigidBody.Subscribe(CollisionEventType.Trigger, OnCollide); } else { } }
protected override void SimpleInit() { if (!ObjectPrivate.TryGetFirstComponent(out RigidBody)) { Log.Write(LogLevel.Error, "Could not start " + GetType().Name + " because no RigidBodyComponent was found."); return; } SubscribeToAll(DisableEvent, (data) => { enabled = false; }); SubscribeToAll(EnableEvent, (data) => { enabled = true; }); enabled = StartEnabled; // Always subscribe to collisions to manage the agentsInTrigger list. // enabled will determine whether events are sent. if (collisionSubscription == null) { collisionSubscription = RigidBody.Subscribe(CollisionEventType.AllCollisions, OnCollision); } ScenePrivate.User.Subscribe(User.RemoveUser, (UserData data) => { foreach (var agent in agentsInTrigger.Where((kvp) => kvp.Value.SessionId == data.User)) { SimpleData sd = new SimpleData(this); sd.ObjectId = agent.Value.ObjectId; sd.AgentInfo = agent.Value; sd.SourceObjectId = ObjectPrivate.ObjectId; agentsInTrigger.Remove(agent.Key); if (enabled) { SendToAll(OnAgentExit, sd); ++userLoggedOut; if (agentsInTrigger.Count == 0) { SendToAll(OnLastAgentTriggerExit, sd); } } break; // should only ever be 1 or none. } }); agentsInTrigger = new Dictionary <ObjectId, AgentInfo>(); }
protected override void SimpleInit() { if (!ObjectPrivate.TryGetFirstComponent <RigidBodyComponent>(out triggerVolume) || !triggerVolume.IsTriggerVolume()) { Log.Write(LogLevel.Error, "QuestGiverTriggerVolume", "Must be attached to a trigger volume."); return; } base.SimpleInit(); triggerVolume.Subscribe(CollisionEventType.Trigger, OnCollide); SubscribeToAll(EnableEvent, (ScriptEventData) => { enabled = true; }); SubscribeToAll(DisableEvent, (ScriptEventData) => { enabled = false; }); enabled = StartEnabled; }
public override void Init() { if (ObjectPrivate.TryGetFirstComponent(out RigidBody)) { RigidBody.Subscribe(CollisionEventType.RigidBodyContact, OnCollision); RigidBody.SetMotionType(RigidBodyMotionType.MotionTypeDynamic); } else { Log.Write(LogLevel.Error, "Choppable couldn't find a RigidBody component. That component is needed in order to detect when an avatar walks into them"); return; } Pieces = ScenePrivate.FindReflective <INamedRigidThing>("Kitchen.Chopped").ToList <INamedRigidThing>(); Log.Write(LogLevel.Info, $"Found {Pieces.Count()} chopped bits"); Axe = ScenePrivate.FindReflective <IChopper>("Kitchen.Chopper").FirstOrDefault(); Log.Write(LogLevel.Info, $"Found Axe: {Axe.GetName()}"); }
public override void Init() { ScenePrivate.User.Subscribe(User.RemoveUser, UserLeft); // Collision events are related to the RigidBody component so we must find it. // See if this object has a RigidBodyComponent and grab the first one. if (ObjectPrivate.TryGetFirstComponent(out RigidBody)) { Relative_Loudness = (float)Loudness_dB - ZeroDBOffset; if (RigidBody.IsTriggerVolume()) { // Subscribe to TriggerVolume collisions on our rigid body: our callback (OnCollide) will get called // whenever a character or character vr hand collides with our trigger volume RigidBody.Subscribe(CollisionEventType.Trigger, OnCollide); } } else { // This will write to the region's log files. Only helpful to Linden developers. Log.Write("Couldn't find rigid body!"); } }
protected override void InitObjective() { MeshComponent localMesh; if (ObjectPrivate.TryGetFirstComponent <MeshComponent>(out localMesh)) { if (!InteractionObjectives.Contains(localMesh)) { InteractionObjectives.Insert(0, localMesh); } } InteractionObjectives = InteractionObjectives.Distinct().ToList(); InteractionHints = InteractionHints.Distinct().ToList(); int meshCount = 0; for (int i = 0; i < InteractionObjectives.Count; ++i) { int index = i; var mesh = InteractionObjectives[i]; if (mesh != null && mesh.IsValid) { ++meshCount; AddInteraction(mesh.ComponentId, index); Collectors[mesh.ComponentId] = new Dictionary <SessionId, CollectionState>(); RigidBodyComponent hint = null; if (InteractionHints.Count > i) { hint = InteractionHints[i]; } else if (InteractionHints.Count > 0) { hint = InteractionHints[0]; } if (hint != null && hint.IsValid && hint.IsTriggerVolume()) { hint.Subscribe(CollisionEventType.Trigger, (data) => HintCollide(data, index)); } if (HideInactive && mesh.IsScriptable) { mesh.SetIsVisible(false); } if (!mesh.IsScriptable && (HideInactive || HideCollected)) { SimpleLog(LogLevel.Error, "Mesh '" + mesh.Name + "' is not scriptable and will not be hidden."); } } } if (meshCount == 0) { QLog(LogLevel.Error, "Must be attached to a mesh or have valid meshes set in Extra Objectives."); return; } SubscribeToAll(EnableEvent, (ScriptEventData) => { enabled = true; }); SubscribeToAll(DisableEvent, (ScriptEventData) => { enabled = false; }); enabled = StartEnabled; Timer.Create(3, 73, Cleanup); }