Beispiel #1
0
    public virtual void OnDestroy()
    {
        isAlive = false;

        if (lwfName == null)
        {
            return;
        }

        lwfDestroyCallbacks.ForEach(c => c(this));
        lwfDestroyCallbacks = null;

        if (lwf != null)
        {
            lwf.Destroy();
            lwf = null;
        }

        if (factory != null)
        {
            factory.Destruct();
            factory = null;
        }

        if (meshes != null)
        {
            meshes = null;
            ResourceCache.SharedInstance().DeleteRenderedMesh(lwfName);
        }

        ResourceCache.SharedInstance().UnloadLWFData(lwfName);
    }
Beispiel #2
0
	public virtual void OnDestroy()
	{
		isAlive = false;

		if (lwfName == null)
			return;

		lwfDestroyCallbacks.ForEach(c => c(this));
		lwfDestroyCallbacks = null;

		if (lwf != null) {
			lwf.Destroy();
			lwf = null;
		}

		if (factory != null) {
			factory.Destruct();
			factory = null;
		}

		if (meshes != null) {
			meshes = null;
			ResourceCache.SharedInstance().DeleteRenderedMesh(lwfName);
		}

		ResourceCache.SharedInstance().UnloadLWFData(lwfName);
	}
Beispiel #3
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);
    }
Beispiel #4
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;
    }
Beispiel #5
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);
    }
Beispiel #6
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,
		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, 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;
    }