如果已经看过本章节: 目录传送门: 这是目录鸭~
1. 场景搭建:
首先我们去 AssetStore 逛淘宝~~~
我淘到的是这个资源, 其他好看的场景 (消耗不高的都行).
然后我们导入了这个资源后, 把资源根文件夹的名字改为 Select, 把 Demo 场景文件的名字改为 Selection, 我这样修改的 emmm...
然后打开那个 Demo 场景, 走到 LightningSetting 关闭雾效果 (这个消耗有点大, 关一下, 你开心也可以不关的~):
然后我们就在场景里移动 Main Camera 到你喜欢的好看的位置~
顺便创建个 Reflection Probe(反射效果的):
前面是没加的, 后面是加了的, 区别有点小, 仔细看右边的更漂亮诶~~~
然后我们在场景中创建空对象, 重新命名为你喜欢的名字, 用于展示英雄的角色坐标的定位, 我在里面放了个阿离并把相对坐标设置为零来测试站的位置是否准确 (我这里面还有个光照是因为脸部比较暗, 你可以自己调整光照的, 对~ 说的就是你 o(*^▽^*)o):
到此为止~ 我们的场景就搭建完毕了亲亲~
2. 英雄资源的打包相关 (重要!!!):
命名规则: 我们可以看到, 农药的 AssetBundle 命名结构是: 英雄 ID + 皮肤编号 (没有空格, 比如说阿离的 ID 是 199, 这个花间舞是第二个皮肤, 所以 ID 为 1992, 第一个默认皮肤不需要输入皮肤 ID 就 199 就好了)_英雄拼音_资源类型. assetbbundle.(下面可以看到廉颇 ID 是 105, 这个设定使得我们提资源十分方便~ 良心 TX~):
然后我们也打算用这种规则来命名~
下面部分含有代码~
创建几个新文件夹在根工程目录下, 路径是 ActorManager/Scripts, 然后再在里面创建一个 Csharp(即 C#), 名为 ActorManager:
- /*
- * 编辑者: Miku 酱
- * 版本: 1
- * 首次编写日期: 2019/09/15 13:53
- * 修改日期: 2019/09/15 13:53
- * 强行加一行~~~
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using LuoHao.AssetBundleManager;
- namespace LuoHao.Actor
- {
- public class ActorManager : MonoBehaviour
- {
- /// <summary>
- /// 角色信息文件的列表
- /// </summary>
- [TextArea]
- public List<string> actorFileList = new List<string>();
- /// <summary>
- /// 全部的角色信息
- /// </summary>
- public static Dictionary<int, ActorInfoData> allActor = new Dictionary<int, ActorInfoData>();
- private void Awake()
- {
- LoadAllActor();// 加载
- DontDestroyOnLoad(this.gameObject);// 切换场景不销毁这个物体
- // Debug.Log(allActor[100].actorName);// 测试
- }
- /// <summary>
- /// 加载角色信息
- /// </summary>
- public bool LoadAllActor()
- {
- for(int i = 0; i <actorFileList.Count; i++)
- {
- // 取得文件
- PackageForAssetBundle pfa= AssetBundleManager.AssetBundleManager.GetAssetBundle(actorFileList[i]);
- // 加载资源
- GameObject[] gms = pfa.GetAssetBundle().LoadAllAssets<GameObject>();
- ActorInfo[] ai = gms[0].GetComponents<ActorInfo>();
- if (ai.Length == 0)// 数组长度为 0 则返回错误
- {
- Debug.LogError("加载角色信息文件失败!\n 错误文件位置:"+actorFileList[i]);
- return false;
- }
- else
- {
- for (int i1 = 0; i1 <ai.Length; i1++)
- allActor.Add(ai[i1]._actorInfoData.actorID, ai[i1]._actorInfoData);
- // 信息载入字典....
- }
- pfa.UnLoadAssetBundle(true);// 卸载 ab 包
- }
- return true;
- }
- }
- /// <summary>
- /// 储存单个角色信息的类
- /// </summary>
- [System.Serializable]// 序列化, 注意要用 System 命名空间下面的
- public class ActorInfoData
- {
- /// <summary>
- /// 角色名字
- /// </summary>
- public string actorName = "英雄名字";
- /// <summary>
- /// 角色拼音
- /// </summary>
- public string actorPinYin = "PinYin";
- /// <summary>
- /// 角色 ID
- /// </summary>
- public int actorID = 100;
- /// <summary>
- /// 屏蔽英雄
- /// </summary>
- public bool banActor = false;
- /// <summary>
- /// 角色背景
- /// </summary>
- [TextArea]// 这个是文本框, 显示在编辑器的
- public string actorBG = "背景故事";
- /// <summary>
- /// 皮肤列表 (第一个就是原皮, 必填)
- /// </summary>
- public List<ActorSkin> actorSkins = new List<ActorSkin>();
- }
- /// <summary>
- /// 储存单个皮肤的
- /// </summary>
- [System.Serializable]// 序列化
- public class ActorSkin
- {
- /// <summary>
- /// 皮肤名字
- /// </summary>
- public string skinName = "皮肤名字";
- /// <summary>
- /// 皮肤展示模型资源路径
- /// </summary>
- [TextArea]// 这个是文本框, 显示在编辑器的
- public string skinShowModelPath = "皮肤展示模型资源路径";
- /// <summary>
- /// 皮肤对战模型资源路径
- /// </summary>
- [TextArea]// 这个是文本框, 显示在编辑器的
- public string skinBattleModelPath = "皮肤对战模型资源路径";
- /// <summary>
- /// 皮肤展示特效资源路径
- /// </summary>
- [TextArea]// 这个是文本框, 显示在编辑器的
- public string skinShowEffectPath = "皮肤展示特效资源";
- /// <summary>
- /// 皮肤对战特效资源路径
- /// </summary>
- [TextArea]// 这个是文本框, 显示在编辑器的
- public string skinBattleEffectPath = "皮肤对战特效资源";
- }
- }
脚本 ActorInfo(承载信息的载体):
- /*
- * 编辑者: Miku 酱
- * 版本: 1
- * 首次编写日期: 2019/09/15 13:53
- * 修改日期: 2019/09/15 13:53
- * 强行加一行~~~
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace LuoHao.Actor {
- public class ActorInfo : MonoBehaviour
- {
- [Header("角色信息")]
- public ActorInfoData _actorInfoData;
- }
- }
创建角色信息数据库:
来源: https://www.cnblogs.com/Miku-CEB-Bug/p/11522216.html