コード例 #1
0
 public void SendCommand <TCommand, TRequest, TResponse>(IComponentWriter writer,
                                                         ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request,
                                                         EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout = null, CommandDelivery commandDelivery = CommandDelivery.RoundTrip)
     where TCommand : ICommandMetaclass, new()
 {
     SendCommandInternal(writer, PerformAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery);
 }
コード例 #2
0
 private void SelfIgnite(IComponentWriter writer)
 {
     if (flammable == null)
     {
         SpatialOS.Commands.SendCommand(writer, Flammable.Commands.Ignite.Descriptor, new Nothing(), gameObject.EntityId());
         return;
     }
     Ignite();
 }
コード例 #3
0
 public void SelfSetCanBeIgnited(IComponentWriter writer, bool canBeIgnited)
 {
     if (flammable == null)
     {
         SpatialOS.Commands.SendCommand(writer, Flammable.Commands.SetCanBeIgnited.Descriptor, new SetCanBeIgnitedRequest(canBeIgnited), gameObject.EntityId());
         return;
     }
     SetCanBeIgnited(canBeIgnited);
 }
コード例 #4
0
 public void SelfExtinguish(IComponentWriter writer, bool canBeIgnited)
 {
     if (flammable == null)
     {
         SpatialOS.Commands.SendCommand(writer, Flammable.Commands.Extinguish.Descriptor, new ExtinguishRequest(canBeIgnited), gameObject.EntityId());
         return;
     }
     Extinguish(canBeIgnited);
 }
コード例 #5
0
ファイル: FileManager.cs プロジェクト: JoHwanhee/FileSearcher
        public void Write(string saveDir, IComponentWriter writer = null)
        {
            if (writer == null)
            {
                writer = new ResultTextWriter();
            }

            writer?.Write(RootFolder, saveDir);
        }
コード例 #6
0
        public IComponentWriter GetComponentWriter(Type type)
        {
            if (type.IsSubclassOf(typeof(MonoBehaviour)))
            {
                MonoBehaviourWriter wr = new MonoBehaviourWriter();
                wr.filter = new Filter()
                {
                    filterType = wr.defaultFilterType
                };
                // This is set because we at the moment are exporting scripts in a different manner.
                wr.options = "noExport";
                return(wr);
            }

            string result = type.FullName;

            foreach (ComponentMap map in ComponentWriters)
            {
                try
                {
                    if (map.Type == result)
                    {
                        Type             tp     = Type.GetType(map.To);
                        IComponentWriter writer = (IComponentWriter)Activator.CreateInstance(tp);
                        if (writer is IFilteredComponentWriter)
                        {
                            if (map.FilterType == Filter.FilterType.None)
                            {
                                (writer as IFilteredComponentWriter).filter = new Filter()
                                {
                                    filterType = (writer as IFilteredComponentWriter).defaultFilterType
                                };
                            }
                            else
                            {
                                (writer as IFilteredComponentWriter).filter = new Filter()
                                {
                                    filterType = map.FilterType, items = map.FilterItems.Split(',')
                                };
                            }
                        }
                        if (writer is IOptionComponentWriter)
                        {
                            (writer as IOptionComponentWriter).options = map.Options ?? String.Empty;
                        }

                        return(writer);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log("Could create writer using map from " + map.Type + " to " + map.To + ". " + ex.Message);
                }
            }
            return(null);
        }
コード例 #7
0
        public void WeWillGetAnInstanceOfTheWriterIfItIsConfigured()
        {
            resolver.ComponentWriters.Add(new ComponentMap()
            {
                Type = "System.String", To = typeof(TestComponentWriter).AssemblyQualifiedName
            });
            IComponentWriter writer = resolver.GetComponentWriter("Hello".GetType());

            Assert.That(writer, Is.Not.Null);
            Assert.That(writer, Is.InstanceOf <TestComponentWriter>());
        }
コード例 #8
0
        private void CreateEntityInternal(IComponentWriter writer, bool requireAuthority, Worker.Entity template,
                                          CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
        {
            Action sendAction = () =>
            {
                var requestId = componentCommander.CreateEntityInternal(template, callback, timeout);
                TrackRequest(writer, requestId);
            };

            SendGenericCommand(writer, requireAuthority, callback, sendAction);
        }
コード例 #9
0
        private void SendQueryInternal(IComponentWriter writer, bool requireAuthority, EntityQuery query,
                                       CommandCallback <EntityQueryResult> callback, TimeSpan?timeout = null)
        {
            Action sendAction = () =>
            {
                var requestId = componentCommander.SendQueryInternal(query, callback, timeout);
                TrackRequest(writer, requestId);
            };

            SendGenericCommand(writer, requireAuthority, callback, sendAction);
        }
コード例 #10
0
        private void ReserveEntityIdsInternal(IComponentWriter writer, bool requireAuthority, CommandCallback <ReserveEntityIdsResult> callback,
                                              uint numberOfEntityIds, TimeSpan?timeout = null)
        {
            Action sendAction = () =>
            {
                var requestId = componentCommander.ReserveEntityIdsInternal(callback, numberOfEntityIds, timeout);
                TrackRequest(writer, requestId);
            };

            SendGenericCommand(writer, requireAuthority, callback, sendAction);
        }
コード例 #11
0
        private void SendGenericCommand <TResponse>(IComponentWriter writer, bool requireAuthority, CommandCallback <TResponse> callback,
                                                    Action sendAction)
        {
            var callbackWrapper = new CommandCallbackWrapper <TResponse>(callback);

            if (requireAuthority && (writer == null || communicator.GetAuthority(writer.EntityId, writer.ComponentId) == Authority.NotAuthoritative))
            {
                // This needs to be deferred, so that all callbacks are registered
                // before they are actually called.
                communicator.Defer(() => callbackWrapper.TriggerWithAuthorityError());
                return;
            }

            sendAction();
        }
コード例 #12
0
        private void SendCommandInternal <TCommand, TRequest, TResponse>(IComponentWriter writer, bool requireAuthority,
                                                                         ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request,
                                                                         EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout, CommandDelivery commandDelivery)
            where TCommand : ICommandMetaclass, new()
        {
            Action sendAction = () =>
            {
                var rawRequest = commandDescriptor.CreateRequest(request);
                Func <ICommandResponse <TCommand>, TResponse> extractResponse =
                    rawResponse => ExtractResponse(commandDescriptor, rawResponse);
                var requestId = componentCommander.SendCommandInternal(entityId, rawRequest, extractResponse, callback, timeout, commandDelivery);
                TrackRequest(writer, requestId);
            };

            SendGenericCommand(writer, requireAuthority, callback, sendAction);
        }
コード例 #13
0
        private void TrackRequest(IComponentWriter writer, Option <uint> requestId)
        {
            if (writer == null || !requestId.HasValue)
            {
                return;
            }

            var            component = new EntityComponentId(writer.EntityId, writer.ComponentId);
            HashSet <uint> requestIds;

            if (!componentToRequestIds.TryGetValue(component, out requestIds))
            {
                requestIds = new HashSet <uint> {
                    requestId.Value
                };
                componentToRequestIds.Add(component, requestIds);
            }
            else
            {
                requestIds.Add(requestId.Value);
            }
        }
コード例 #14
0
 public ICommandResponseHandler <ReserveEntityIdResult> ReserveEntityId(IComponentWriter writer, TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <ReserveEntityIdResult> .Wrap(callback => ReserveEntityId(writer, callback, timeout)));
 }
コード例 #15
0
 public ICommandResponseHandler <EntityQueryResult> SendQuery(IComponentWriter writer, EntityQuery query, TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <EntityQueryResult> .Wrap(callback => SendQuery(writer, query, callback, timeout)));
 }
コード例 #16
0
 public ICommandResponseHandler <DeleteEntityResult> DeleteEntity(IComponentWriter writer, EntityId entityId, TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <DeleteEntityResult> .Wrap(callback => DeleteEntity(writer, entityId, callback, timeout)));
 }
コード例 #17
0
 public ICommandResponseHandler <CreateEntityResult> CreateEntity(IComponentWriter writer, Worker.Entity template,
                                                                  TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <CreateEntityResult> .Wrap(callback => CreateEntity(writer, template, callback, timeout)));
 }
コード例 #18
0
 public ICommandResponseHandler <ReserveEntityIdsResult> ReserveEntityIds(IComponentWriter writer, uint numberOfEntityIds, TimeSpan?timeout = null)
 {
     return(CommandResponseHandler <ReserveEntityIdsResult> .Wrap(callback => ReserveEntityIds(writer, callback, numberOfEntityIds, timeout)));
 }
コード例 #19
0
        public void WeWillGetNullIfAWriterIsNotConfigured()
        {
            IComponentWriter writer = resolver.GetComponentWriter("Hello".GetType());

            Assert.That(writer, Is.Null);
        }
コード例 #20
0
 public void ReserveEntityId(IComponentWriter writer, CommandCallback <ReserveEntityIdResult> callback,
                             TimeSpan?timeout = null)
 {
     ReserveEntityIdInternal(writer, PerformAuthorityCheck, callback, timeout);
 }
コード例 #21
0
 public void DeleteEntity(IComponentWriter writer, EntityId entityId,
                          CommandCallback <DeleteEntityResult> callback, TimeSpan?timeout = null)
 {
     DeleteEntityInternal(writer, PerformAuthorityCheck, entityId, callback, timeout);
 }
コード例 #22
0
 public void CreateEntity(IComponentWriter writer, Worker.Entity template,
                          CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
 {
     CreateEntityInternal(writer, PerformAuthorityCheck, template, callback, timeout);
 }
コード例 #23
0
 public void ReserveEntityIds(IComponentWriter writer, CommandCallback <ReserveEntityIdsResult> callback,
                              uint numberOfEntityIds, TimeSpan?timeout = null)
 {
     ReserveEntityIdsInternal(writer, PerformAuthorityCheck, callback, numberOfEntityIds, timeout);
 }
コード例 #24
0
 public void SendQuery(IComponentWriter writer, EntityQuery query,
                       CommandCallback <EntityQueryResult> callback, TimeSpan?timeout = null)
 {
     SendQueryInternal(writer, PerformAuthorityCheck, query, callback, timeout);
 }
コード例 #25
0
 public ComponentsController(IComponentReader reader, IComponentWriter writer) : base(reader, writer)
 {
     _reader = reader ?? throw new ArgumentNullException(nameof(reader));
     _writer = writer ?? throw new ArgumentNullException(nameof(writer));
 }
コード例 #26
0
 /// <inheritdoc />
 public ICommandResponseHandler <TResponse> SendCommand <TCommand, TRequest, TResponse>(IComponentWriter writer, ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor,
                                                                                        TRequest request, EntityId entityId, TimeSpan?timeout, CommandDelivery commandDelivery = CommandDelivery.RoundTrip) where TCommand : ICommandMetaclass, new()
 {
     return(CommandResponseHandler <TResponse> .Wrap(callback => SendCommandInternal(writer, PerformAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery)));
 }
コード例 #27
0
ファイル: SceneWriter.cs プロジェクト: mikecrews/FFWD
        private bool WriteComponent(Component component, bool isPrefab)
        {
            if (resolver == null)
            {
                return(false);
            }
            if (component == null)
            {
                return(false);
            }
            if (component is Transform)
            {
                WriteTransform(component as Transform, isPrefab);
                return(true);
            }

            System.Type type = component.GetType();
            if (resolver.SkipComponent(component))
            {
                if (!componentsNotWritten.Contains(type.FullName))
                {
                    componentsNotWritten.Add(type.FullName);
                }
                return(false);
            }
            IComponentWriter componentWriter = resolver.GetComponentWriter(type);

            if (componentWriter != null)
            {
                writtenIds.Add(component.GetInstanceID());
                if (!isPrefab)
                {
                    writer.WriteStartElement("c");
                    writer.WriteAttributeString("Type", resolver.ResolveObjectType(component));
                }
                if (!writingResources && component.GetType().GetCustomAttributes(false).Any(att => att.GetType().Name == "FFWD_ExportAsResourceAttribute"))
                {
                    WriteInlineResource(component);
                    return(true);
                }
                writer.WriteElementString("id", component.GetInstanceID().ToString());
                if (isPrefab)
                {
                    writer.WriteElementString("isPrefab", ToString(true));
                }
                try
                {
                    componentWriter.Write(this, component);
                }
                catch (Exception ex)
                {
                    Debug.LogError(String.Format("Exception when writing {0} on {1} under {2} using writer {3} :\n{4}",
                                                 component.GetType(), component.name, component.transform.root.name, componentWriter.GetType(), ex.Message), component);
                }
                if (!isPrefab)
                {
                    writer.WriteEndElement();
                }
                return(true);
            }
            else
            {
                if (type == typeof(MeshCollider))
                {
                    Debug.Log("Unexported Mesh collider", component);
                }
                if (!componentsNotWritten.Contains(type.FullName))
                {
                    componentsNotWritten.Add(type.FullName);
                }
            }
            return(false);
        }