Ejemplo n.º 1
0
        private void DoCheckPosTargets()
        {
            if (m_targets.Count > 0)
            {
                bool at_target = false;
                List<ScriptPosTarget> atTargets = new List<ScriptPosTarget>(MAX_TARGETS);
                lock (m_targetsLock)
                {
                    foreach (ScriptPosTarget target in m_targets)
                    {
                        if (Util.GetDistanceTo(target.TargetPos, m_rootPart.GroupPosition) <= target.Tolerance)
                        {
                            at_target = true;
                            // trigger at_target
                            if (m_scriptListens_atTarget)
                            {
                                ScriptPosTarget att = new ScriptPosTarget();
                                att.TargetPos = target.TargetPos;
                                att.Tolerance = target.Tolerance;
                                att.Handle = target.Handle;
                                atTargets.Add(att);
                            }
                        }
                    }
                }

                if (atTargets.Count > 0)
                {
                    uint[] localids = new uint[0];
                    lock (m_parts)
                    {
                        localids = new uint[m_parts.Count];
                        int cntr = 0;
                        foreach (SceneObjectPart part in m_parts.Values)
                        {
                            localids[cntr] = part.LocalId;
                            cntr++;
                        }
                    }

                    for (int ctr = 0; ctr < localids.Length; ctr++)
                    {
                        foreach (ScriptPosTarget att in atTargets)
                        {
                            m_scene.EventManager.TriggerAtTargetEvent(
                                localids[ctr], att.Handle, att.TargetPos, m_rootPart.GroupPosition);
                        }
                    }

                    return;
                }

                if (m_scriptListens_notAtTarget && !at_target)
                {
                    //trigger not_at_target
                    uint[] localids = new uint[0];
                    lock (m_parts)
                    {
                        localids = new uint[m_parts.Count];
                        int cntr = 0;
                        foreach (SceneObjectPart part in m_parts.Values)
                        {
                            localids[cntr] = part.LocalId;
                            cntr++;
                        }
                    }

                    for (int ctr = 0; ctr < localids.Length; ctr++)
                    {
                        m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public int RegisterTargetWaypoint(Vector3 target, float tolerance)
 {
     ScriptPosTarget waypoint = new ScriptPosTarget();
     waypoint.TargetPos = target;
     waypoint.Tolerance = tolerance;
     int handle = (int)m_scene.AllocateLocalId();
     waypoint.Handle = handle;
     lock (m_targetsLock)
     {
         if (m_targets.Count >= MAX_TARGETS)
         {   // table full, remove the first one
             ScriptPosTarget discard = m_targets[0];
             m_scene.SceneGraph.UnregisterObjectWithTargets(discard.Handle);
             m_targets.RemoveAt(0);
         }
         m_targets.Add(waypoint);
     }
     m_scene.SceneGraph.RegisterObjectWithTargets(handle, this);
     return handle;
 }