GameFramework篇:新项目搭建GF框架需知

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_15020543/article/details/86314833

1.AB包相关配置

GF资源管理实属牛批,但要使用它,并不是全自动的,还是要配置一下

创建一个静态类,类名随意,注意里面至少要包含以下三个属性,后面的地址所指就是打AB包所必须的三个配置文件(这个地址可以自己更改,注意改变路径就行)

        [AssetBundleBuilderConfigPath] public static string AssetBundleBuilderConfig =
            Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleBuilder.xml");

        [AssetBundleEditorConfigPath] public static string AssetBundleEditorConfig =
            Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleEditor.xml");

        [AssetBundleCollectionConfigPath] public static string AssetBundleCollectionConfig =
            Utility.Path.GetCombinePath(Application.dataPath, "GameMain/Configs/AssetBundleCollection.xml");

其中除了AssetBundleEditor.xml,其余两个都可以在打包的时候自动升成。所以我们要指定目录创建AssetBundleEditor.xml文件,并在里面填入以下信息

其中SourceAssetRootPath是指定资源根目录位置的,自己注意视情况更改

<?xml version="1.0" encoding="UTF-8"?>
<UnityGameFramework>
    <AssetBundleEditor>
        <Settings>
            <SourceAssetRootPath>Assets/GameMain</SourceAssetRootPath>
            <SourceAssetSearchPaths>
                <SourceAssetSearchPath RelativePath=""/>
            </SourceAssetSearchPaths>
            <SourceAssetUnionTypeFilter>t:Scene t:Prefab t:Shader t:Model t:Material t:Texture t:AudioClip
                t:AnimationClip t:AnimatorController t:Font t:TextAsset t:ScriptableObject
            </SourceAssetUnionTypeFilter>
            <SourceAssetUnionLabelFilter>l:AssetBundleInclusive</SourceAssetUnionLabelFilter>
            <SourceAssetExceptTypeFilter>t:Script</SourceAssetExceptTypeFilter>
            <SourceAssetExceptLabelFilter>l:AssetBundleExclusive</SourceAssetExceptLabelFilter>
            <AssetSorter>Name</AssetSorter>
        </Settings>
    </AssetBundleEditor>
</UnityGameFramework>

2.UI模块相关

说实话我没想到使用UI模块会出那么多变故。。。我花了半天时间才找到问题所在。。。

首先要创建并设置一个默认Canvas,因为没有Canvas的支撑,UGUI无法正确显示

再搞一个UGuiGroupHelper

//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: [email protected]
// Data: 2019年1月11日 23:35:22
//------------------------------------------------------------

using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;

namespace GameMain.Scripts.UI
{
    public class UGuiGroupHelper : UIGroupHelperBase
    {
        public const int DepthFactor = 1000;

        private int m_Depth = 0;
        private Canvas m_CachedCanvas = null;

        /// <summary>
        /// 设置界面组深度。
        /// </summary>
        /// <param name="depth">界面组深度。</param>
        public override void SetDepth(int depth)
        {
            m_Depth = depth;
            m_CachedCanvas.overrideSorting = true;
            m_CachedCanvas.sortingOrder = DepthFactor * depth;
        }

        private void Awake()
        {
            m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
            gameObject.GetOrAddComponent<GraphicRaycaster>();
        }

        private void Start()
        {
            m_CachedCanvas.overrideSorting = true;
            m_CachedCanvas.sortingOrder = DepthFactor * m_Depth;

            RectTransform transform = GetComponent<RectTransform>();
            transform.anchorMin = Vector2.zero;
            transform.anchorMax = Vector2.one;
            transform.anchoredPosition = Vector2.zero;
            transform.sizeDelta = Vector2.zero;
        }
    }
}

按下图所示替换默认的辅助器

然后是UGuiForm

//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: [email protected]
// Data: 2019年1月11日 23:42:05
//------------------------------------------------------------

using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;

namespace GameMain.Scripts.UI
{
    public class UGuiForm:UIFormLogic
    {
        private Canvas m_CachedCanvas = null;

        public int OriginalDepth
        {
            get;
            private set;
        }

        protected override void OnInit(object userData)
        {
            base.OnInit(userData);

            m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
            m_CachedCanvas.overrideSorting = true;
            OriginalDepth = m_CachedCanvas.sortingOrder;

            RectTransform transform = GetComponent<RectTransform>();
            transform.anchorMin = Vector2.zero;
            transform.anchorMax = Vector2.one;
            transform.anchoredPosition = Vector2.zero;
            transform.sizeDelta = Vector2.zero;

            gameObject.GetOrAddComponent<GraphicRaycaster>();
        }

    }
}

每个UIForm都要继承这个类

至此,你做的UI效果,才是你想要的效果。。。

3.配表相关

保存的时候选择-文本文件(制表符分隔)

在Unity中应当能识别其数据

没有的话,就用文本文档打开,另存为UTF-8

4://TODO

猜你喜欢

转载自blog.csdn.net/qq_15020543/article/details/86314833