예제 #1
0
    public static Texture LoadTexture(string path)
    {
        FileMetadata metadata;

        try
        {
            metadata = GetTextureMetadata(path);
        }
        catch (System.Exception)
        {
            return(null);
        }

        var position = metadata.Offset;

        reader.BaseStream.Position = position;
        var texture = DDSImporter.ReadFile(reader);

        texture.name = path;
        return(texture);
    }
예제 #2
0
    System.Collections.IEnumerator LoadCoroutine()
    {
        // Verify that the directory exists and grab its files.
        string        directoryPath = FAGameComponent.Instance.MakeAbsolutePath("/units/" + _unitID);
        DirectoryInfo directory     = new DirectoryInfo(directoryPath);

        if (!directory.Exists)
        {
            Debug.LogError(directoryPath + " does not exist.");
            yield break;
        }
        IEnumerable <FileInfo> directoryFiles = directory.GetFiles();

        // Load the BP, so we know what mesh, animations, and textures to load and what shaders to load.
        FileInfo blueprintFile = directoryFiles.FirstOrDefault(x => x.Name.EndsWith("_unit.bp", StringComparison.CurrentCultureIgnoreCase));

        if (blueprintFile == null || !blueprintFile.Exists)
        {
            Debug.LogError(directoryPath + " does not contain a unit blueprint.");
            yield break;
        }
        BPImporter.Load(gameObject, blueprintFile);
        _blueprint = GetComponent <BPComponent>();
        yield return(null);

        // Save the BP to test the BP exporter.
        FileInfo blueprintFileExport = new FileInfo(directoryPath + "/exportTest.bp");

        BPExporter.Save(_blueprint, blueprintFileExport);
        yield return(null);

        // Get the LOD0 files.
        LODFiles lod0 = GetLODFiles(0, directoryFiles);

        if (lod0.mesh == null)
        {
            Debug.LogError(directoryPath + " does not contain an LOD0.scm file.");
            yield break;
        }

        // Load the mesh.
        SCMImporter.Load(gameObject, lod0.mesh);

        // Apply the blueprint's scale.
        LuaValue scaleVal = _blueprint.Get("Display.UniformScale");
        float    scale    = (scaleVal == null || scaleVal.LVT != LuaValueType.LVT_Float) ? 1.0f : scaleVal.FloatValue;

        transform.root.localScale = new Vector3(scale, scale, scale);
        yield return(null);

        // Iteratively load the DDS files.
        for (DDSImporter.LoadStages i = DDSImporter.LoadStages.Init; i < DDSImporter.LoadStages.Count; ++i)
        {
            bool success = DDSImporter.LoadStage(i, gameObject, lod0);
            yield return(null);

            if (!success)
            {
                break;
            }
        }

        // Load the SCAs referenced in the blueprint.
        List <FileInfo> scaFiles = GetSCAFiles();

        foreach (FileInfo scaFile in scaFiles)
        {
            SCAImporter.Load(gameObject, scaFile);
            yield return(null);
        }
        Animation animComponent = gameObject.GetComponentInParent <Animation>();

        /*if (animComponent.GetClipCount() > 0)
         * {
         *      Debug.Log("Playing animation " + scaFiles[0].Name);
         *      animComponent.clip = animComponent.GetClip(scaFiles[0].Name);
         *      animComponent.Play(scaFiles[0].Name);
         * }*/
    }