コード例 #1
0
ファイル: LWFObject.cs プロジェクト: kevbaker/lwf-demo
    public virtual bool Load(string path,
                             string texturePrefix            = "", string fontPrefix = "",
                             float zOffset                   = 0, float zRate        = 1, int renderQueueOffset = 0,
                             Camera camera                   = null, bool autoUpdate = true,
                             LWFDataCallback lwfDataCallback = null,
                             LWFLoadCallback lwfLoadCallback = null,
                             LWFDataLoader lwfDataLoader     = null,
                             TextureLoader textureLoader     = null,
                             TextureUnloader textureUnloader = null)
    {
        lwfName    = path;
        callUpdate = autoUpdate;
        if (camera == null)
        {
            camera = Camera.main;
        }

        if (lwfLoadCallback != null)
        {
            lwfLoadCallbacks.Add(lwfLoadCallback);
        }

        LWF.Data data =
            ResourceCache.SharedInstance().LoadLWFData(lwfName, lwfDataLoader);
        if (data == null || !data.Check())
        {
            return(false);
        }

        if (lwfDataCallback != null && !lwfDataCallback(data))
        {
            return(false);
        }

        if (rendererFactoryConstructor != null)
        {
            RendererFactoryArguments arg = new RendererFactoryArguments(
                data, gameObject, zOffset, zRate, renderQueueOffset, camera,
                texturePrefix, fontPrefix, textureLoader, textureUnloader);
            factory = rendererFactoryConstructor(arg);
        }
        else if (useCombinedMeshRenderer && data.textures.Length == 1)
        {
            factory = new LWF.CombinedMeshRenderer.Factory(
                data, gameObject, zOffset, zRate, renderQueueOffset, camera,
                texturePrefix, fontPrefix, textureLoader, textureUnloader);
        }
        else
        {
            factory = new LWF.DrawMeshRenderer.Factory(
                data, gameObject, zOffset, zRate, renderQueueOffset, camera,
                texturePrefix, fontPrefix, textureLoader, textureUnloader);
        }

        lwf = new LWF.LWF(data, factory);

        OnLoad();

        return(true);
    }
コード例 #2
0
    public virtual bool Load(string path,
                             string texturePrefix            = null, string fontPrefix = "",
                             float zOffset                   = 0, float zRate = 1, int renderQueueOffset = 0,
                             Camera renderCamera             = null, Camera inputCamera      = null,
                             bool autoUpdate                 = true, bool useAdditionalColor = false,
                             LWFDataCallback lwfDataCallback = null,
                             LWFCallback lwfLoadCallback     = null,
                             LWFCallback lwfDestroyCallback  = null,
                             LWFDataLoader lwfDataLoader     = null,
                             TextureLoader textureLoader     = null,
                             TextureUnloader textureUnloader = null,
                             string shaderName               = "LWF"
#if LWF_USE_LUA
                             , object luaState = null
#endif
                             )
    {
        callUpdate = autoUpdate;
        if (inputCamera == null)
        {
            inputCamera = Camera.main;
        }

        if (texturePrefix == null)
        {
            texturePrefix = Path.GetDirectoryName(path) + "/";
        }
        if (lwfLoadCallback != null)
        {
            lwfLoadCallbacks.Add(lwfLoadCallback);
        }
        if (lwfDestroyCallback != null)
        {
            lwfDestroyCallbacks.Add(lwfDestroyCallback);
        }

        ResourceCache cache = ResourceCache.SharedInstance();

        LWF.Data data = cache.LoadLWFData(path, lwfDataLoader);
        if (data == null || !data.Check())
        {
            return(false);
        }

        if (lwfDataCallback != null && !lwfDataCallback(data))
        {
            return(false);
        }

        RendererType rt = rendererType;

#if UNITY_EDITOR
        if (!Application.isPlaying && rt == RendererType.CombinedMeshRenderer)
        {
            rt = RendererType.DrawMeshRenderer;
        }
#endif
        if (rt == RendererType.CombinedMeshRenderer)
        {
            combinedMeshRendererfactory = new LWF.CombinedMeshRenderer.Factory(
                data, gameObject, zOffset, zRate, renderQueueOffset,
                mSortingLayerName, mSortingOrder, useAdditionalColor,
                renderCamera, inputCamera, texturePrefix, fontPrefix,
                textureLoader, textureUnloader, shaderName);
            factory = combinedMeshRendererfactory;
        }
        else if (rt == RendererType.DrawMeshRenderer)
        {
            factory = new LWF.DrawMeshRenderer.Factory(
                data, gameObject, zOffset, zRate, renderQueueOffset,
                mSortingLayerName, mSortingOrder, useAdditionalColor,
                renderCamera, inputCamera, texturePrefix, fontPrefix,
                textureLoader, textureUnloader, shaderName);
        }
        else           /*if (rt == RendererType.UIVertexRenderer)*/
        {
            factory = new LWF.UIVertexRenderer.Factory(
                data, gameObject, zOffset, zRate, renderQueueOffset,
                mSortingLayerName, mSortingOrder, useAdditionalColor,
                renderCamera, inputCamera, texturePrefix, fontPrefix,
                textureLoader, textureUnloader, shaderName);
        }

#if LWF_USE_LUA
        lwf = new LWF.LWF(data, factory, luaState);
#else
        lwf = new LWF.LWF(data, factory);
#endif

        lwf.lwfLoader = (childPath, childTexturePrefix) => {
            LWF.Data childData = cache.LoadLWFData(childPath, lwfDataLoader);
            if (childData == null || !childData.Check())
            {
                return(null);
            }

            if (lwfDataCallback != null && !lwfDataCallback(childData))
            {
                return(null);
            }

            if (childTexturePrefix == null)
            {
                childTexturePrefix = Path.GetDirectoryName(childPath) + "/";
            }

            LWF.UnityRenderer.Factory f;
            if (rt == RendererType.CombinedMeshRenderer)
            {
                f = new LWF.CombinedMeshRenderer.Factory(
                    childData, gameObject, factory.zOffset, factory.zRate,
                    factory.renderQueueOffset, mSortingLayerName, mSortingOrder,
                    factory.useAdditionalColor, factory.renderCamera,
                    factory.inputCamera, childTexturePrefix, factory.fontPrefix,
                    factory.textureLoader, factory.textureUnloader, shaderName, true);
            }
            else if (rt == RendererType.DrawMeshRenderer)
            {
                f = new LWF.DrawMeshRenderer.Factory(
                    childData, gameObject, factory.zOffset, factory.zRate,
                    factory.renderQueueOffset, mSortingLayerName, mSortingOrder,
                    factory.useAdditionalColor, factory.renderCamera,
                    factory.inputCamera, childTexturePrefix, factory.fontPrefix,
                    factory.textureLoader, factory.textureUnloader, shaderName);
            }
            else               /*if (rt == RendererType.UIVertexRenderer)*/
            {
                f = new LWF.UIVertexRenderer.Factory(
                    childData, gameObject, factory.zOffset, factory.zRate,
                    factory.renderQueueOffset, mSortingLayerName, mSortingOrder,
                    factory.useAdditionalColor, factory.renderCamera,
                    factory.inputCamera, childTexturePrefix, factory.fontPrefix,
                    factory.textureLoader, factory.textureUnloader, shaderName);
            }

#if LWF_USE_LUA
            LWF.LWF child = new LWF.LWF(childData, f, lwf.luaState);
#else
            LWF.LWF child = new LWF.LWF(childData, f);
#endif
            child.lwfLoader   = lwf.lwfLoader;
            child.lwfUnloader = () => {
                ResourceCache.SharedInstance().UnloadLWFData(childPath);
            };
            return(child);
        };
        lwf.lwfUnloader = () => {
            ResourceCache.SharedInstance().UnloadLWFData(path);
        };

        OnLoad();

        return(true);
    }
コード例 #3
0
    public virtual bool Load(string path,
                             string texturePrefix            = "", string fontPrefix = "",
                             float zOffset                   = 0, float zRate   = 1, int renderQueueOffset = 0,
                             int cachingFrames               = 0, Camera camera = null, bool autoPlay      = true,
                             bool useAdditionalColor         = false,
                             LWFDataCallback lwfDataCallback = null,
                             LWFCallback lwfLoadCallback     = null,
                             LWFCallback lwfDestroyCallback  = null,
                             LWFDataLoader lwfDataLoader     = null,
                             TextureLoader textureLoader     = null,
                             TextureUnloader textureUnloader = null)
    {
        lwfName = path;
        if (camera == null)
        {
            camera = Camera.main;
        }

        if (lwfLoadCallback != null)
        {
            lwfLoadCallbacks.Add(lwfLoadCallback);
        }
        if (lwfDestroyCallback != null)
        {
            lwfDestroyCallbacks.Add(lwfDestroyCallback);
        }

        LWF.Data data =
            ResourceCache.SharedInstance().LoadLWFData(lwfName, lwfDataLoader);
        if (data == null || !data.Check())
        {
            return(false);
        }

        if (lwfDataCallback != null && !lwfDataCallback(data))
        {
            return(false);
        }

        factory = new LWF.CombinedMeshRenderer.Factory(data, gameObject,
                                                       zOffset, zRate, renderQueueOffset, useAdditionalColor, camera,
                                                       texturePrefix, fontPrefix, textureLoader, textureUnloader);

        lwf = new LWF.LWF(data, factory);

        if (cachingFrames == 0)
        {
            foreach (LWF.Format.Movie m in data.movies)
            {
                if (cachingFrames < m.frames)
                {
                    cachingFrames = m.frames;
                }
            }
            if (cachingFrames == 0)
            {
                cachingFrames = 1;
            }
        }

        meshes = ResourceCache.SharedInstance().AddRenderedMesh(
            lwfName, cachingFrames);
        frameNo = 0;

        OnLoad();

        if (autoPlay)
        {
            Play();
        }

        return(true);
    }