Esempio n. 1
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);
    }
Esempio n. 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 (!string.IsNullOrEmpty(texturePrefix))
            {
                texturePrefix += "/";
            }
        }
        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;
    }