Ejemplo n.º 1
0
        public void Import(Stream input, string path)
        {
            using (var reader = new BinaryReader(input))
            {
                try
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(Directory.GetParent(assetPath) + "/" + path));

                    LocatorArray locatorArray = null;

                    var locatorCount = reader.ReadUInt32();
                    var type         = (LocatorType)reader.ReadUInt32();

                    IUnityThreadCommand createLocatorArrayCommand = new CreateScriptableObject <LocatorArray>(path,
                                                                                                              (createdLocatorArray) => locatorArray = createdLocatorArray);

                    var waitHandle = dispatcher.DispatchCommand(createLocatorArrayCommand);
                    waitHandle.WaitOne();

                    locatorArray.Read(type, locatorCount, reader, hashManager);
                    dispatcher.DispatchCommand(new MarkAssetsAsDirtyAndSave(locatorArray)).WaitOne();
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public static Entity MakeEntity(FoxEntity foxData, Dictionary <string, Type> entityTypes, ConcurrentDictionary <string, FoxEntity> unimplementedTypeTable, IUnityThreadCommandDispatcher unityThreadDispatcher, IEntityReferenceResolver entityReferenceResolver)
        {
            // Get Entity type.
            Type entityType;

            if (!entityTypes.TryGetValue(foxData.ClassName, out entityType) && !unimplementedTypeTable.ContainsKey(foxData.ClassName))
            {
                Debug.LogWarning("Class '" + foxData.ClassName + "' not found in entityTypes.");
                unimplementedTypeTable.TryAdd(foxData.ClassName, foxData);
                return(null);
            }

            // Get new Entity instance.
            // We can't make new GameObjects outside the main thread, so dispatch a request for one to the Unity thread.
            Entity entityInstance = null;
            var    waitEvent      = unityThreadDispatcher.DispatchCommand(new CreateEntity(entityType,
                                                                                           newEntity => entityInstance = newEntity));

            // Wait for our command to be executed by the Unity thread.
            waitEvent.WaitOne();
            entityReferenceResolver.RegisterReference(foxData.Address, entityInstance);

            // Load properties.
            ImportEntityProperties(entityInstance, foxData, entityReferenceResolver);
            return(entityInstance);
        }
Ejemplo n.º 3
0
        public void Import(Stream input, string path)
        {
            var lookupTable = new FoxLookupTable(GlobalHashNameDictionary);
            var foxFile     = FoxFile.ReadFoxFile(input, lookupTable);

            IEntityReferenceResolver referenceResolver = new EntityReferenceResolver();

            Framework.Tpp.Classes.DataSet dataSet = null;

            // Load each Entity.
            ICollection <Entity> entities = new List <Entity>();

            foreach (var entry in foxFile.Entities)
            {
                var entity = EntityFactory.MakeEntity(entry, entityTypes, unimplementedTypeTable, commandDispatcher, referenceResolver);

                if (entity != null)
                {
                    entities.Add(entity);
                }

                if (!(entity is Framework.Tpp.Classes.DataSet))
                {
                    continue;
                }
                dataSet = entity as Framework.Tpp.Classes.DataSet;
                dataSet.SetPath(path);
            }

            // Call OnLoaded() on the new Entities.
            var autoResetEvent = commandDispatcher.DispatchCommand(new InitializeEntities(dataSet, entities));

            autoResetEvent.WaitOne();

            // Generate new Entity classes.
            foreach (var unimplementedType in unimplementedTypeTable)
            {
                Debug.Log("Generating C# class for type " + unimplementedType.Key);
                EntityClassGenerator.GenerateEntityClass(unimplementedType.Value);
            }
        }
Ejemplo n.º 4
0
        public void Import(Stream input, string path)
        {
            var prefabPath = Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + ".prefab";

            if (File.Exists(prefabPath))
            {
                return;
            }

            try
            {
                var reader = new Fmdl();
                reader.Read(input);

                Directory.CreateDirectory(Path.GetDirectoryName(Directory.GetParent(assetPath) + "/" + path));
                var createMeshCommand = new CreateMesh(() => reader.CreateAndSaveMesh(path));
                unityThreadDispacher.DispatchCommand(createMeshCommand);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError(e);
                throw;
            }
        }