예제 #1
0
        public Result <IObject> AddObject(IObject obj)
        {
            if (!_sceneObjects.ContainsKey(obj.InstanceGuid))
            {
                AddObjectEventArgs args = new AddObjectEventArgs(this, obj);
                EventManager <AddObjectEventArgs> manager
                    = new EventManager <AddObjectEventArgs>(AddObjectEvent, this, args);
                manager.OnSuccess = ev =>
                {
                    ev.AddObject.Scene = this;
                    return(_sceneObjects.TryAdd(ev.AddObject.InstanceGuid, ev.AddObject));
                };

                if (manager.Call())
                {
                    args.AddObject.OnInitialze();
                    if (args.AddObject is IDrawable)
                    {
                        _drawables.Add(args.AddObject.InstanceGuid, (IDrawable)args.AddObject);
                    }
                    return(Result <IObject> .Success(args.AddObject));
                }
                else
                {
                    return(Result <IObject> .Fail());
                }
            }

            return(Result <IObject> .Fail());
        }
예제 #2
0
        public Result <IObject> AddObject(IObject obj)
        {
            if (!_sceneObjects.ContainsKey(obj.InstanceGuid))
            {
                AddObjectEventArgs args = new AddObjectEventArgs(this, obj);
                EventManager <AddObjectEventArgs> manager
                          = new EventManager <AddObjectEventArgs>(AddObjectEvent, this, args);
                obj.Scene = this;
                _sceneObjects.TryAdd(obj.InstanceGuid, obj);

                manager.Call();
                args.AddObject.OnInitialze();
                if (args.AddObject is IComponentAttachable componentAttachable)
                {
                    foreach (IComponent component in componentAttachable.GetComponents().Value)
                    {
                        if (component is IDrawable drawable)
                        {
                            _drawables.Add(component.InstanceGuid, drawable);
                        }
                    }
                }

                return(Result <IObject> .Success(args.AddObject));
            }
            else
            {
                return(Result <IObject> .Fail());
            }
        }