コード例 #1
0
        public Result <IObject> RemoveObject(Guid hash)
        {
            if (_sceneObjects.TryGetValue(hash, out IObject obj))
            {
                RemoveObjectEventArgs args = new RemoveObjectEventArgs(this, obj);
                EventManager <RemoveObjectEventArgs> manager
                    = new EventManager <RemoveObjectEventArgs>(RemoveObjectEvent, this, args);
                _sceneObjects.TryRemove(hash, out obj);

                manager.Call();
                args.RemoveObject.OnDestroy();

                if (args.RemoveObject is IComponentAttachable componentAttachable)
                {
                    foreach (IComponent component in componentAttachable.GetComponents().Value)
                    {
                        if (component is IDrawable)
                        {
                            _drawables.Remove(component.InstanceGuid);
                        }
                    }
                }

                return(Result <IObject> .Success(args.RemoveObject));
            }
            else
            {
                return(Result <IObject> .Fail());
            }
        }
コード例 #2
0
ファイル: Scene.cs プロジェクト: JulianoCristian/EngineGL
        public Result <IObject> RemoveObject(Guid hash)
        {
            if (_sceneObjects.TryGetValue(hash, out IObject obj))
            {
                RemoveObjectEventArgs args = new RemoveObjectEventArgs(this, obj);
                EventManager <RemoveObjectEventArgs> manager
                    = new EventManager <RemoveObjectEventArgs>(RemoveObjectEvent, this, args);
                manager.OnSuccess = ev => _sceneObjects.TryRemove(hash, out obj);

                if (manager.Call())
                {
                    args.RemoveObject.OnDestroy();
                    _drawables.Remove(args.RemoveObject.InstanceGuid);
                    return(Result <IObject> .Success(args.RemoveObject));
                }
                else
                {
                    return(Result <IObject> .Fail());
                }
            }

            return(Result <IObject> .Fail());
        }