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

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

        if (lwfName == null)
        {
            return;
        }

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

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

        ResourceCache.SharedInstance().UnloadLWFData(lwfName);
    }
示例#2
0
    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);
    }
示例#3
0
    void DrawButton(LWF.Button button, Factory factory)
    {
        Matrix4x4 savedMatrix = GUI.matrix;
        Color     savedColor  = GUI.color;

        factory.ConvertMatrix(ref matrix, button.matrix, 0, button.height);
        Factory.MultiplyMatrix(ref renderMatrix,
                               factory.gameObject.transform.localToWorldMatrix, matrix);
        Camera camera = factory.camera;

        Matrix4x4 m  = renderMatrix;
        Vector2   lt = GUIUtility.ScreenToGUIPoint(camera.WorldToScreenPoint(
                                                       m.MultiplyPoint(new Vector3(0, button.height))));
        Vector2 rt = GUIUtility.ScreenToGUIPoint(camera.WorldToScreenPoint(
                                                     m.MultiplyPoint(new Vector3(button.width, button.height))));
        Vector2 ld = GUIUtility.ScreenToGUIPoint(camera.WorldToScreenPoint(
                                                     m.MultiplyPoint(new Vector3(0, 0))));

        float dx = rt.x - lt.x;
        float dy = rt.y - lt.y;
        float w  = Mathf.Sqrt(dx * dx + dy * dy);

        dx = ld.x - lt.x;
        dy = ld.y - lt.y;
        float h     = Mathf.Sqrt(dx * dx + dy * dy);
        float angle =
            Mathf.Atan2(rt.x - lt.x, rt.y - lt.y) * Mathf.Rad2Deg - 90;

        lt.y = Screen.height - lt.y;
        GUIUtility.RotateAroundPivot(angle, lt);

        GUI.color = button == button.lwf.focus ?
                    LWFObjectInspector.focusButtonColor :
                    LWFObjectInspector.buttonColor;
        GUI.DrawTexture(new Rect(lt.x, lt.y, w, h), texture);

        GUI.matrix = savedMatrix;
        GUI.color  = savedColor;
    }
    void DrawButton(LWF.Button button, Factory factory)
    {
        Matrix4x4 savedMatrix = GUI.matrix;
        Color savedColor = GUI.color;

        factory.ConvertMatrix(ref matrix, button.matrix, 0, button.height);
        Factory.MultiplyMatrix(ref renderMatrix,
            factory.gameObject.transform.localToWorldMatrix, matrix);
        Camera camera = factory.camera;

        Matrix4x4 m = renderMatrix;
        Vector2 lt = GUIUtility.ScreenToGUIPoint(camera.WorldToScreenPoint(
            m.MultiplyPoint(new Vector3(0, button.height))));
        Vector2 rt = GUIUtility.ScreenToGUIPoint(camera.WorldToScreenPoint(
            m.MultiplyPoint(new Vector3(button.width, button.height))));
        Vector2 ld = GUIUtility.ScreenToGUIPoint(camera.WorldToScreenPoint(
            m.MultiplyPoint(new Vector3(0, 0))));

        float dx = rt.x - lt.x;
        float dy = rt.y - lt.y;
        float w = Mathf.Sqrt(dx * dx + dy * dy);
        dx = ld.x - lt.x;
        dy = ld.y - lt.y;
        float h = Mathf.Sqrt(dx * dx + dy * dy);
        float angle =
            Mathf.Atan2(rt.x - lt.x, rt.y - lt.y) * Mathf.Rad2Deg - 90;
        lt.y = Screen.height - lt.y;
        GUIUtility.RotateAroundPivot(angle, lt);

        GUI.color = button == button.lwf.focus ?
            LWFObjectInspector.focusButtonColor :
                LWFObjectInspector.buttonColor;
        GUI.DrawTexture(new Rect(lt.x, lt.y, w, h), texture);

        GUI.matrix = savedMatrix;
        GUI.color = savedColor;
    }
示例#5
0
    void OnGUI()
    {
        LWFObject[] lwfObjects =
            FindObjectsOfType(typeof(LWFObject)) as LWFObject[];
        if (lwfObjects == null)
        {
            return;
        }

        if (!texture)
        {
            texture = new Texture2D(1, 1);
            texture.SetPixel(0, 0, Color.white);
            texture.Apply();
        }

        Matrix4x4 savedMatrix = GUI.matrix;
        Color     savedColor  = GUI.color;

        foreach (LWFObject lwfObject in lwfObjects)
        {
            bool visibility;
            if (visibilities.TryGetValue(
                    lwfObject, out visibility) && !visibility)
            {
                continue;
            }

            LWF.LWF lwf = lwfObject.lwf;
            if (lwf == null)
            {
                continue;
            }

            lwf.Inspect((obj, hierarchy, depth, rOffset) => {
                if (obj.type != Type.BUTTON)
                {
                    return;
                }

                for (LWF.Object o = obj.parent; o != null; o = o.parent)
                {
                    LWF.Movie m = o as LWF.Movie;
                    if (m != null && !m.visible)
                    {
                        return;
                    }
                    if (visibilities.TryGetValue(
                            o, out visibility) && !visibility)
                    {
                        return;
                    }
                }

                Factory factory = lwf.rendererFactory as Factory;
                if (factory == null)
                {
                    return;
                }

                LWF.Button button = (LWF.Button)obj;
                DrawButton(button, factory);
            });
        }

        GUI.matrix = savedMatrix;
        GUI.color  = savedColor;
    }
示例#6
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);
    }
示例#7
0
文件: LWFObject.cs 项目: dipyalov/lwf
    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;
    }
示例#8
0
	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,
		bool useAdditionalColor = false,
		LWFDataCallback lwfDataCallback = null,
		LWFCallback lwfLoadCallback = null,
		LWFCallback lwfDestroyCallback = null,
		LWFDataLoader lwfDataLoader = null,
		TextureLoader textureLoader = null,
		TextureUnloader textureUnloader = null
#if LWF_USE_LUA
		, object luaState = null
#endif
		)
	{
		lwfName = path;
		callUpdate = autoUpdate;
		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;

		if (rendererFactoryConstructor != null) {
			RendererFactoryArguments arg = new RendererFactoryArguments(
				data, gameObject, zOffset, zRate, renderQueueOffset,
				useAdditionalColor, 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,
				useAdditionalColor, camera, texturePrefix, fontPrefix,
				textureLoader, textureUnloader);
		} else {
			factory = new LWF.DrawMeshRenderer.Factory(
				data, gameObject, zOffset, zRate, renderQueueOffset,
				useAdditionalColor, camera, texturePrefix, fontPrefix,
				textureLoader, textureUnloader);
		}

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

		OnLoad();

		return true;
	}
示例#9
0
	public virtual void OnDestroy()
	{
		isAlive = false;

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

		if (lwfName == null)
			return;

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

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

		ResourceCache.SharedInstance().UnloadLWFData(lwfName);
	}