Exemplo n.º 1
0
        public override bool Remove(IObject obj, ScriptInstance instance = null)
        {
            if (!m_Objects.ContainsValue(obj))
            {
                return(false);
            }
            var    objgroup = obj as ObjectGroup;
            IAgent agent;

            if (objgroup != null)
            {
                foreach (ObjectPart objpart in objgroup.Values)
                {
                    Interlocked.Decrement(ref m_PrimitiveCount);
                    foreach (ObjectPartInventoryItem item in objpart.Inventory.Values)
                    {
                        ScriptInstance removeinstance = item.ScriptInstance;
                        if (removeinstance != instance)
                        {
                            removeinstance = item.RemoveScriptInstance;
                            if (removeinstance != null)
                            {
                                ScriptThreadPool.AbortScript(removeinstance);
                                removeinstance.Abort();
                                removeinstance.Remove();
                                ScriptLoader.Remove(item.AssetID, removeinstance);
                            }
                        }
                    }
                    m_Primitives.Remove(objpart.ID);
                    objpart.SendKillObject();
                    RemoveLocalID(objpart);
                }

                if (m_Objects.Remove(objgroup.ID))
                {
                    Interlocked.Decrement(ref m_ObjectCount);
                }
            }
            else if ((agent = obj as IAgent) != null)
            {
                foreach (IAgentListener aglistener in AgentListeners)
                {
                    try
                    {
                        aglistener.RemovedAgent(agent);
                    }
                    catch (Exception e)
                    {
                        m_Log.DebugFormat("Exception {0}\n{1}", e.Message, e.StackTrace);
                    }
                }

                if (agent.IsInScene(this))
                {
                    /* only detach if agent is at our scene */
                    agent.DetachAllAttachments();
                }
                m_Objects.Remove(agent.ID);
                if (m_Agents.Remove(agent.ID))
                {
                    Interlocked.Decrement(ref m_AgentCount);
                }
                agent.SendKillObject(ID);
                RemoveLocalID(agent);
            }
            else
            {
                agent.SendKillObject(ID);
                m_Objects.Remove(obj.ID);
                RemoveLocalID(obj);
            }

            return(true);
        }