Exemple #1
0
    /// <summary>
    /// 删除界面模型
    /// </summary>
    /// <param name="uInfo">界面模型信息</param>
    public static void DestroryUIModel(UIModelInfo uInfo, bool isCached = false)
    {
        //Debug.LogError("[Destroy] " + uInfo.strModelRes + " at " + Time.frameCount);
        if (mUIModels.Contains(uInfo))
        {
            mUIModels.Remove(uInfo);

            if (isCached && uInfo.oModel != null)
            {
                uInfo.oModel.transform.parent = null;
                // 这里创建并没有使用pool,回收也不应该使用。
                //ObjectManager.mSpawnPool.Despawn(uInfo.oModel.transform);
                MonoBehaviour.Destroy(uInfo.oModel);
            }
            if (uInfo.camera != null)
            {
                uInfo.camera.targetTexture = null;
                MonoBehaviour.Destroy(uInfo.camera.gameObject);
            }
            if (uInfo.oRoot != null)
            {
                MonoBehaviour.Destroy(uInfo.oRoot.gameObject);
            }
            if (uInfo.rtexture != null)
            {
                RenderTexture.ReleaseTemporary(uInfo.rtexture);
                uInfo.rtexture = null;
            }

            uInfo.oModel = null;
            uInfo        = null;
        }
    }
Exemple #2
0
    /// <summary>
    /// 切场景的时候 清除一下,确保模型没有残留
    /// </summary>
    public static void ClearModels()
    {
        if (mUIModels == null || mUIModels.Count < 1)
        {
            return;
        }

        for (int i = mUIModels.Count - 1; i >= 0; --i)
        {
            UIModelInfo uInfo = mUIModels[i];
            if (uInfo == null)
            {
                continue;
            }

            mUIModels.Remove(uInfo);

            if (uInfo.oModel != null)
            {
                uInfo.oModel.transform.parent = null;
                MonoBehaviour.Destroy(uInfo.oModel);
            }
            if (uInfo.camera != null)
            {
                uInfo.camera.targetTexture = null;
                MonoBehaviour.Destroy(uInfo.camera.gameObject);
            }
            if (uInfo.oRoot != null)
            {
                MonoBehaviour.Destroy(uInfo.oRoot.gameObject);
            }
            if (uInfo.rtexture != null)
            {
                RenderTexture.ReleaseTemporary(uInfo.rtexture);
                uInfo.rtexture = null;
            }

            uInfo.oModel = null;
            uInfo        = null;
        }
    }
Exemple #3
0
    /// <summary>
    /// 改变灯光效果
    /// </summary>
    /// <param name="uInfo"></param>
    /// <param name="fPosX"></param>
    /// <param name="fPosY"></param>
    /// <param name="fPosZ"></param>
    /// <param name="fIntensity"></param>
    public static void SetLight(UIModelInfo uInfo, bool bLight = true, float fIntensity = 1.75f, float fPosX = 0.0f, float fPosY = 8.8f, float fPosZ = -3.5f)
    {
        if (uInfo.oLight == null)
        {
            return;
        }

        if (bLight != uInfo.oLight.gameObject.activeSelf)
        {
            uInfo.oLight.gameObject.SetActive(bLight);
        }
        ///设置灯光位置
        Vector3 vTemp = Vector3.zero;

        vTemp.x = fPosX;
        vTemp.y = fPosY;
        vTemp.z = fPosZ;
        uInfo.oLight.gameObject.transform.localPosition = vTemp;

        ///设置灯光强度
        uInfo.oLight.intensity = fIntensity;
    }
Exemple #4
0
    /// <summary>
    /// 创建模型
    /// </summary>
    /// <param name="modelId"></param>
    /// <returns></returns>
    public static void CreateModel(string modelId, LoadHighUiModelComplete call)
    {
        if (string.IsNullOrEmpty(modelId))
        {
            return;
        }
        ClearModels();
        ResourceManager.Instance.LoadPrefab(modelId, (name, obj) =>
        {
            if (obj == null)
            {
                return;
            }

            UIModelInfo info = new UIModelInfo();
            miIndex          = (miIndex + 1) % 1000;

            int iLayerMask    = LayerMask.NameToLayer("UIModel");
            info.oModel       = obj;
            info.oModel.name  = modelId;
            GameObject goRoot = new GameObject(UtilTools.StringBuilder("goRoot", miIndex));
            if (goRoot != null)
            {
                goRoot.transform.parent     = UICamera.mainCamera.transform;
                goRoot.transform.localScale = Vector3.one;

                GameObject gocCamera = new GameObject(UtilTools.StringBuilder("Camera", miIndex));

                // 添加模型照射摄像机
                Camera cCamera                  = gocCamera.gameObject.AddComponent <Camera>();
                cCamera.transform.parent        = goRoot.transform;
                cCamera.transform.localPosition = UICamera.mainCamera.transform.localPosition;
                cCamera.transform.localRotation = UICamera.mainCamera.transform.localRotation;
                cCamera.transform.localScale    = UICamera.mainCamera.transform.localScale;
                cCamera.orthographic            = true;
                cCamera.orthographicSize        = 1;
                cCamera.nearClipPlane           = -10;
                cCamera.farClipPlane            = 10;
                cCamera.depth       = 1;
                cCamera.cullingMask = 1 << 8;

                ///设置模型相对摄像机位置
                info.oModel.transform.parent = goRoot.transform;
                Vector3 pos = Vector3.zero;
                pos         = new Vector3(0, -320, 0);
                info.oModel.transform.localPosition = pos;
                info.oModel.transform.localRotation = Quaternion.Euler(0.0f, 180.0f, 0.0f);
                info.oModel.transform.localScale    = new Vector3(3.8f, 3.8f, 3.8f);
                ///设置渲染贴图参数
                info.camera      = cCamera;
                info.oRoot       = goRoot;
                GameObject light = new GameObject("light");
                light.gameObject.AddComponent <Light>();
                light.transform.parent = goRoot.transform;
                light.gameObject.GetComponent <Light>().type = LightType.Directional;
                info.oLight   = light.gameObject.GetComponent <Light>();
                info.rtexture = RenderTexture.GetTemporary(1024, 1024, 16);
                info.rtexture.isPowerOfTwo = true;
                //info.rtexture.antiAliasing = 2;
                //info.rtexture.depth = 24;
                info.rtexture.filterMode = FilterMode.Bilinear;
                info.rtexture.wrapMode   = TextureWrapMode.Clamp;
                //info.rtexture.anisoLevel = 16;
                info.rtexture.MarkRestoreExpected();
                info.camera.targetTexture = info.rtexture;
                UtilTools.SetLayer(goRoot.gameObject, iLayerMask);
                mUIModels.Add(info);
                goRoot.transform.localPosition = Vector3.zero;
                if (call != null)
                {
                    call(info);
                }
            }
        });
    }