是StrangeIoC课程30课时的最后的步骤,按照所有的操作进行,但最后创建的gameobjectpool.asset不能编辑
老师的项目:
我的项目:
有关创建Asset的脚本目录:
这里是有关创建Asset的所有代码
Framework/Editor/PoolManagerEditor.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
static class PoolManagerEditor {
[MenuItem("Manager/Create GameObjectPoolConfig")]
static void CreateGameObjectPoolList(){
GameObjectPoolList poolList = ScriptableObject.CreateInstance<GameObjectPoolList> ();
string path = "Assets/Framework/Resources/gameobjectpool.asset";//相对路径
AssetDatabase.CreateAsset (poolList, path);
AssetDatabase.SaveAssets ();
}
}
Framework/Scripts/GameObjectPool.cs:
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;
/// <summary>
/// 资源池
/// </summary>
[SerializeField]//序列化
public class GameObjectPool {
public string name;
public GameObject prefab;
public int maxAmount;
[NonSerialized]
private List<GameObject> goList = new List<GameObject>();
}
Framework/Scripts/GameObjectPoolList.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 管理所有对象池的类
/// </summary>
public class GameObjectPoolList : ScriptableObject{
//继承自ScriptableObject 表示把类GameObjectPoolList 变成可以自定义资源配置的文件
public List<GameObjectPool> poolList;
}