demo多场景运行切换工具

curvy插件中的,很好用

这里写图片描述

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using FluffyUnderware.DevTools.Extensions;
using System.Collections.Generic;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class SceneSwitcher : MonoBehaviour {

    
    bool mChkAdditive;
    Vector2 sv = Vector2.zero;
    Rect mDropdownRect;
    string[] mItems;
    bool mShow;

#if UNITY_EDITOR
    void Start ()
    {
        
    }
#endif

    int CurrentLevel
    {
        get
        {
#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
            return Application.loadedLevel;
#else
            return UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex;
#endif
        }
        set
        {
            if (CurrentLevel != value)
            {
#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
                if (mChkAdditive)
                    Application.LoadLevelAdditive(value);
                else
                    Application.LoadLevel(value);
#else
                if (mChkAdditive)
                    UnityEngine.SceneManagement.SceneManager.LoadScene(value, UnityEngine.SceneManagement.LoadSceneMode.Additive);
                else
                    UnityEngine.SceneManagement.SceneManager.LoadScene(value,UnityEngine.SceneManagement.LoadSceneMode.Single);
#endif
            }
        }
    }

    void getScenes()
    {
        var items = new List<string>();
#if UNITY_EDITOR
        foreach (var lvl in EditorBuildSettings.scenes)
        {
            if (lvl.enabled)
            {
                var path = lvl.path.Split('/');
                items.Add(path[path.Length - 1].TrimEnd(".unity"));
            }
        }
#endif
        mItems = items.ToArray();
    }


    void onSelect(object index)
    {
        CurrentLevel = (int)index;
    }

    void OnGUI()
    {
        if (mItems == null)
        {
            mDropdownRect = new Rect(Screen.width - 200, 0, 295, 300);
            getScenes();
        }
        
        if (mItems.Length == 0 || CurrentLevel<0)
        {
            GUI.Label(new Rect(Screen.width-480, mDropdownRect.y, 460, 40),"Add scenes to the build settings to enable the scene switcher!");
        }
        else {
            mChkAdditive=GUI.Toggle(new Rect(mDropdownRect.x - 200, mDropdownRect.y, 80, 20), mChkAdditive, "Additive");
            if (GUI.Button(new Rect((mDropdownRect.x - 100), mDropdownRect.y, mDropdownRect.width, 25), ""))
            {
                if (!mShow)
                {
                    mShow = true;
                }
                else
                {
                    mShow = false;
                }
            }

            if (mShow)
            {
                sv = GUI.BeginScrollView(new Rect((mDropdownRect.x - 100), (mDropdownRect.y + 25), mDropdownRect.width, mDropdownRect.height), sv, new Rect(0, 0, mDropdownRect.width, Mathf.Max(mDropdownRect.height, (mItems.Length * 25))));

                GUI.Box(new Rect(0, 0, mDropdownRect.width, Mathf.Max(mDropdownRect.height, (mItems.Length * 25))), "");

                for (int index = 0; index < mItems.Length; index++)
                {

                    if (GUI.Button(new Rect(0, (index * 25), mDropdownRect.height, 25), ""))
                    {
                        mShow = false;
                        CurrentLevel = index;
                    }

                    GUI.Label(new Rect(5, (index * 25), mDropdownRect.height, 25), mItems[index]);

                }

                GUI.EndScrollView();
            }
            else if (CurrentLevel>=0 && CurrentLevel<mItems.Length)
            {
                GUI.Label(new Rect((mDropdownRect.x - 95), mDropdownRect.y, 300, 25), mItems[CurrentLevel]);
            }
        }

    }


}

#Editor模式下可以不添加场景实现场景切换

    private void Start()
    {
        StartCoroutine(LoadSceneCoroutine("Assets/Arts/px_scene/enginetest/role/ModelPlayer.unity"));
    }


    private IEnumerator LoadSceneCoroutine(string strResourcePath)
    {
        //ResourceManager.Instance.SetSwitchingLevel(true);

        //var async = UnityEditor.EditorApplication.LoadLevelAsyncInPlayMode(strResourcePath);
        //yield return async;
        yield return null;
        OpenUI();
    }
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android多字体切换Demo是一个用来展示如何在Android应用中动态切换字体的示例项目。 首先,我们需要在项目的assets文件夹下创建一个fonts文件夹,用于存放我们要使用的字体文件。可以在网上下载一些免费的字体文件,常见的格式有ttf和otf。 然后,在需要使用不同字体的TextView或其他控件中,我们可以通过以下代码来切换字体: 1. 首先,通过Typeface类加载字体文件: Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/字体文件名.ttf"); 2. 然后,通过setTypeface()方法将加载的字体应用到控件中: textView.setTypeface(typeface); 以上代码中,getAssets()方法用于获取到应用的AssetManager对象,createFromAsset()方法通过AssetManager和字体文件的路径来加载字体文件。 通过上述方法,我们可以在应用中自由切换不同的字体。可以在应用的设置中提供字体选择的选项,然后根据用户选择的字体名称来加载不同的字体文件。 值得注意的是,如果要在整个应用中实现字体切换,可以将以上代码放置在一个BaseActivity或者CustomTextView中,然后在所有的Activity中继承BaseActivity或者使用CustomTextView来替代默认的TextView控件。 总之,通过上述的操作,我们可以很容易地实现Android应用中的多字体切换功能。这对于一些特定的应用场景,例如书籍阅读、设计类应用等,可以提升用户体验和界面美观度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值