Esempio n. 1
0
        public static void LoadAsync(string name, CollisionFile file, Transform destParent, bool forceConvex, System.Action onFinish)
        {
            // load collision file asyncly, and when it's ready just call the other function

            if (file != null)
            {
                // collision file already loaded
                // just call other function

                Utilities.F.RunExceptionSafe(() => Load(file, destParent, forceConvex));
                onFinish();
                return;
            }

            // load collision file asyncly
            CollisionFile.FromNameAsync(name, (cf) => {
                // loading finished
                // call other function
                if (cf != null)
                {
                    Utilities.F.RunExceptionSafe(() => Load(cf, destParent, forceConvex));
                }
                onFinish();
            });
        }
Esempio n. 2
0
        private static void Load(string name, CollisionFile file, Transform destParent, bool forceConvex)
        {
            CollisionModel col;

            if (_sLoaded.ContainsKey(name))
            {
                col = _sLoaded[name];
                if (col == null)
                {
                    return;
                }

                col.Spawn(destParent, forceConvex);
                return;
            }

            file = file ?? CollisionFile.FromName(name);
            if (file == null || (file.Flags & Flags.NotEmpty) != Flags.NotEmpty)
            {
                _sLoaded.Add(name, null);
                return;
            }

            col = new CollisionModel(file);
            _sLoaded.Add(name, col);

            col.Spawn(destParent, forceConvex);
        }
Esempio n. 3
0
        private CollisionModel(CollisionFile file)
        {
            Profiler.BeginSample("CollisionModel()");

            if (_sTemplateParent == null)
            {
                _sTemplateParent = new GameObject("Collision Templates");
                _sTemplateParent.SetActive(false);
            }

            _template = new GameObject(file.Name);
            _template.transform.SetParent(_sTemplateParent.transform);

            _flagGroups = new Dictionary <SurfaceFlags, Transform>();

            foreach (var box in file.Boxes)
            {
                Add <BoxCollider>(box.Surface, x =>
                {
                    var min = Convert(box.Min);
                    var max = Convert(box.Max);

                    x.center = (min + max) * .5f;
                    x.size   = (max - min);
                });
            }

            foreach (var sphere in file.Spheres)
            {
                Add <SphereCollider>(sphere.Surface, x =>
                {
                    x.center = Convert(sphere.Center);
                    x.radius = sphere.Radius;
                });
            }

            if (file.FaceGroups.Length > 0)
            {
                foreach (var group in file.FaceGroups)
                {
                    Add <MeshCollider>(file.Faces[group.StartFace].Surface, x =>
                    {
                        x.sharedMesh = Convert(group, file.Faces, file.Vertices);
                    });
                }
            }
            else if (file.Faces.Length > 0)
            {
                Add <MeshCollider>(file.Faces[0].Surface, x =>
                {
                    x.sharedMesh = Convert(file.Faces, file.Faces.Length, file.Vertices, file.Vertices.Length);
                });
            }

            // TODO: MeshCollider


            Profiler.EndSample();
        }
Esempio n. 4
0
        /// <summary>
        /// Initialize all the meshes<para/>
        /// Инициализация всех моделей
        /// </summary>
        public static void Init()
        {
            // Initialize collections
            // Создание коллекций
            Collisions      = new Dictionary <int, CollisionFile.Group>();
            NamedCollisions = new Dictionary <string, CollisionFile.Group>();

            // Looping through associated files
            // Проход через ассоциированные файлы
            foreach (string file in FileManager.CollisionFiles)
            {
                string ffile = PathManager.GetAbsolute(file);
                if (File.Exists(ffile))
                {
                    CollisionFile cf = new CollisionFile(ffile);
                    foreach (CollisionFile.Group g in cf.Collisions)
                    {
                        bool addToIndexed = false;
                        if (g.ID < ObjectManager.Definitions.Length)
                        {
                            if (ObjectManager.Definitions[g.ID] != null)
                            {
                                if (ObjectManager.Definitions[g.ID].ModelName == g.Name)
                                {
                                    addToIndexed = true;
                                }
                            }
                        }

                        // Add mesh to indexed list or model-oriented
                        // Добавление меша либо в список
                        if (addToIndexed)
                        {
                            if (!Collisions.ContainsKey(g.ID))
                            {
                                Collisions.Add(g.ID, g);
                            }
                        }
                        else
                        {
                            if (!NamedCollisions.ContainsKey(g.Name))
                            {
                                NamedCollisions.Add(g.Name, g);
                            }
                        }
                    }
                }
                else
                {
                    Dev.Console.Log("[CollisionManager] Unable to locate collision archive: " + file);
                }
            }
        }
Esempio n. 5
0
        private static void StepLoadCollision()
        {
            int numCollisionFiles = 0;

            foreach (var colFile in ArchiveManager.GetFileNamesWithExtension(".col"))
            {
                CollisionFile.Load(colFile);
                numCollisionFiles++;
            }

            Debug.Log("Number of collision files " + numCollisionFiles);
        }
Esempio n. 6
0
            public GeometryParts(string name, Clump clump, TextureDictionary[] txds)
            {
                Name = name;

                Geometry = clump.GeometryList.Geometry
                           .Select(x => new Geometry(x, Convert(x), txds))
                           .ToArray();

                Frames = clump.FrameList.Frames
                         .Select(x => Convert(x, clump.Atomics))
                         .ToArray();

                _collisions = clump.Collision;
            }
Esempio n. 7
0
        private void Awake()
        {
            if (HasLoaded)
            {
                return;
            }

            var archivePaths = Config.GetPaths("archive_paths");

            IArchive[] archives;
            using (Utilities.Profiler.Start("Archive load time")) {
                archives = archivePaths.Select(x =>
                                               File.Exists(x) ? (IArchive)ArchiveManager.LoadImageArchive(x)
                    : Directory.Exists(x) ? ArchiveManager.LoadLooseArchive(x)
                    : null).Where(x => x != null).ToArray();
            }

            using (Utilities.Profiler.Start("Collision load time")) {
                foreach (var archive in archives)
                {
                    foreach (var colFile in archive.GetFileNamesWithExtension(".col"))
                    {
                        CollisionFile.Load(colFile);
                    }
                }
            }

            using (Utilities.Profiler.Start("Item info load time")) {
                foreach (var path in Config.GetPaths("item_paths"))
                {
                    var ext = Path.GetExtension(path).ToLower();
                    switch (ext)
                    {
                    case ".dat":
                        Item.ReadLoadList(path); break;

                    case ".ide":
                        Item.ReadIde(path); break;

                    case ".ipl":
                        Item.ReadIpl(path); break;
                    }
                }
            }

            using (Utilities.Profiler.Start("Handling info load time")) {
                Handling.Load(Config.GetPath("handling_path"));
            }

            using (Utilities.Profiler.Start("Animation group info load time")) {
                foreach (var path in Config.GetPaths("anim_groups_paths"))
                {
                    AnimationGroup.Load(path);
                }
            }

            using (Utilities.Profiler.Start("Car color info load time")) {
                CarColors.Load(Config.GetPath("car_colors_path"));
            }

            HasLoaded = true;
        }
Esempio n. 8
0
 public static void Load(CollisionFile file, Transform destParent, bool forceConvex = false)
 {
     Load(file.Name, file, destParent, forceConvex);
 }
Esempio n. 9
0
 public CollisionModel(SectionHeader header, Stream stream)
     : base(header, stream)
 {
     Collision = CollisionFile.Load(stream);
 }
Esempio n. 10
0
        static void StaticUpdate()
        {
            if (HasLoaded)
            {
                return;
            }

            switch (loadingStatus)
            {
            case 0:
                Debug.Log("Started loading GTA.");
                archivePaths = Config.GetPaths("archive_paths");
                break;

            case 1:
                using (Utilities.Profiler.Start("Archive load time")) {
                    List <IArchive> listArchives = new List <IArchive> ();
                    foreach (var path in archivePaths)
                    {
                        if (File.Exists(path))
                        {
                            listArchives.Add(ArchiveManager.LoadImageArchive(path));
                        }
                        else if (Directory.Exists(path))
                        {
                            listArchives.Add(ArchiveManager.LoadLooseArchive(path));
                        }
                        else
                        {
                            Debug.Log("Archive not found: " + path);
                        }
                    }
                    archives = listArchives.FindAll(a => a != null).ToArray();
                }
                break;

            case 2:
                using (Utilities.Profiler.Start("Collision load time")) {
                    int numCollisionFiles = 0;
                    foreach (var archive in archives)
                    {
                        foreach (var colFile in archive.GetFileNamesWithExtension(".col"))
                        {
                            CollisionFile.Load(colFile);
                            numCollisionFiles++;
                        }
                    }
                    Debug.Log("Number of collision files " + numCollisionFiles);
                }
                break;

            case 3:
                using (Utilities.Profiler.Start("Item info load time")) {
                    foreach (var path in Config.GetPaths("item_paths"))
                    {
                        var ext = Path.GetExtension(path).ToLower();
                        switch (ext)
                        {
                        case ".dat":
                            Item.ReadLoadList(path);
                            break;

                        case ".ide":
                            Item.ReadIde(path);
                            break;

                        case ".ipl":
                            Item.ReadIpl(path);
                            break;
                        }
                    }
                }
                break;

            case 4:
                using (Utilities.Profiler.Start("Handling info load time")) {
                    Handling.Load(Config.GetPath("handling_path"));
                }
                break;

            case 5:
                using (Utilities.Profiler.Start("Animation group info load time")) {
                    foreach (var path in Config.GetPaths("anim_groups_paths"))
                    {
                        AnimationGroup.Load(path);
                    }
                }
                break;

            case 6:
                using (Utilities.Profiler.Start("Car color info load time")) {
                    CarColors.Load(Config.GetPath("car_colors_path"));
                }
                break;

            case 7:
                using (Utilities.Profiler.Start("special texture load time")) {
                    MiniMap.loadTextures();

                    // Load mouse cursor texture
                    Texture2D mouse    = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse").Texture;
                    Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);
                    for (int x = 0; x < mouse.width; x++)
                    {
                        for (int y = 0; y < mouse.height; y++)
                        {
                            mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
                        }
                    }
                    mouseFix.Apply();
                    Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);
                }
                HasLoaded = true;
                Debug.Log("GTA loading finished.");
                break;
            }

            loadingStatus++;
        }
Esempio n. 11
0
        static void StaticUpdate()
        {
                        #if UNITY_EDITOR
            if (!EditorApplication.isPlaying && !HasLoaded)
            {
                // display loading progress in editor
            }
                        #endif

            if (HasLoaded)
            {
                return;
            }


            switch (loadingStatus)
            {
            case 0:

                Debug.Log("Started loading GTA.");

                archivePaths = Config.GetPaths("archive_paths");

                break;

            case 1:

                using (Utilities.Profiler.Start("Archive load time")) {
                    List <IArchive> listArchives = new List <IArchive> ();
                    foreach (var path in archivePaths)
                    {
                        if (File.Exists(path))
                        {
                            listArchives.Add(ArchiveManager.LoadImageArchive(path));
                        }
                        else if (Directory.Exists(path))
                        {
                            listArchives.Add(ArchiveManager.LoadLooseArchive(path));
                        }
                        else
                        {
                            Debug.Log("Archive not found: " + path);
                        }
                    }
                    archives = listArchives.FindAll(a => a != null).ToArray();
                }

                break;

            case 2:

                using (Utilities.Profiler.Start("Collision load time")) {
                    int numCollisionFiles = 0;
                    foreach (var archive in archives)
                    {
                        foreach (var colFile in archive.GetFileNamesWithExtension(".col"))
                        {
                            CollisionFile.Load(colFile);
                            numCollisionFiles++;
                        }
                    }
                    Debug.Log("Number of collision files " + numCollisionFiles);
                }

                break;

            case 3:

                using (Utilities.Profiler.Start("Item info load time")) {
                    foreach (var path in Config.GetPaths("item_paths"))
                    {
                        var ext = Path.GetExtension(path).ToLower();
                        switch (ext)
                        {
                        case ".dat":
                            Item.ReadLoadList(path);
                            break;

                        case ".ide":
                            Item.ReadIde(path);
                            break;

                        case ".ipl":
                            Item.ReadIpl(path);
                            break;
                        }
                    }
                }

                break;

            case 4:

                using (Utilities.Profiler.Start("Handling info load time")) {
                    Handling.Load(Config.GetPath("handling_path"));
                }

                break;

            case 5:

                using (Utilities.Profiler.Start("Animation group info load time")) {
                    foreach (var path in Config.GetPaths("anim_groups_paths"))
                    {
                        AnimationGroup.Load(path);
                    }
                }

                break;

            case 6:

                using (Utilities.Profiler.Start("Car color info load time")) {
                    CarColors.Load(Config.GetPath("car_colors_path"));
                }

                HasLoaded = true;

                Debug.Log("GTA loading finished.");

                break;
            }

            loadingStatus++;
        }