Esempio n. 1
0
        //初始化,在作为组件被挂载时读取设置创建四叉树
        private void Awake()
        {
            QuadtreeSettingSingleton setting = Resources.Load <QuadtreeSettingSingleton>("QuadtreeWithSingletonSetting");

            //根据官方所说,Resources的最佳使用方法就是【别用它】,我个人也不喜欢这种把设置数据和游戏本体分到天涯海角的方法,所以我建议在设置完成后改成硬编码
            _quadtree = new QuadtreeDataSingleton <GameObject>(setting.top, setting.right, setting.bottom, setting.left, setting.maxLeafsNumber, setting.minSideLength);
        }
Esempio n. 2
0
        string GetSettingScriptFilePath()
        {
            QuadtreeSettingSingleton settingInstance = CreateInstance <QuadtreeSettingSingleton>();      //CreateInstance:创建一个继承了ScriptableObject的类的实例
            MonoScript settingScriptFile             = MonoScript.FromScriptableObject(settingInstance); //MonoScript.FromScriptableObject:根据ScriptableObject的实例获取到脚本文件
            string     fullPath   = AssetDatabase.GetAssetPath(settingScriptFile);                       //AssetDatabase.GetAssetPath:根据文件获取路径,包含了文件名
            string     folderPath = fullPath.Substring(0, fullPath.LastIndexOf("/") + 1);                //截取这个路径到最后一个斜线,这就是设置文件脚本所在的文件夹的路径

            return(folderPath);
        }
Esempio n. 3
0
        //获取设置文件
        QuadtreeSettingSingleton GetSettingObject(string settingObjectName)
        {
            QuadtreeSettingSingleton settingObject = LoadSetting(settingObjectName);

            if (settingObject != null)
            {
                return(settingObject);
            }
            return(CreatSettingObject(settingObjectName));
        }
Esempio n. 4
0
        QuadtreeSettingSingleton CreatSettingObject(string settingObjectName)
        {
            string settingScriptFilePath = GetSettingScriptFilePath();

            if (!AssetDatabase.IsValidFolder(settingScriptFilePath + "Resources")) //AssetDatabase.IsValidFolder:检测有没有这个路径表示的文件夹
            {
                CreatResourcesFolder(settingScriptFilePath);
            }

            QuadtreeSettingSingleton settingObject = CreateInstance <QuadtreeSettingSingleton>();

            AssetDatabase.CreateAsset(settingObject, settingScriptFilePath + "Resources/" + settingObjectName + ".asset"); //AssetDatabase.CreateAsset:创建资源文件

            return(settingObject);
        }