Exemplo n.º 1
0
    private void Awake()
    {
        if (!GetComponent <AudioSource>())
        {
            _audio = gameObject.AddComponent <AudioSource>();
        }

        _clips = DreamerUtil.GetScriptableObject <AudioClips>();
    }
        public static void InitByScriptableObject()
        {
            var prefabs = DreamerUtil.GetScriptableObject <GameObjectPoolPrefabs>();

            foreach (var item in prefabs.Prefabs)
            {
                var prefabType = item.prefabType.String2Enum <GameObjectPoolPrefabType>();
                if (!pools.ContainsKey(prefabType))
                {
                    pools.Add(prefabType, new GameObjectPool(item.prefab));
                }
            }
        }
        public static void AddGameObjectPoolPrefabType(List <GameObject> gameObjectLst)
        {
            var path = AssetDataBaseManager.GetScriptPath(DreamerToolConfig.GameObjectPrefabTypeName);

            if (path == "")
            {
                return;
            }

            using (StreamWriter sw = new StreamWriter(new FileStream(path, FileMode.Truncate)))
            {
                StringBuilder result = new StringBuilder();
                var           header = "public enum GameObjectPoolPrefabType\n{";
                result.Append(header);
                foreach (int v in Enum.GetValues(typeof(GameObjectPoolPrefabType)))
                {
                    result.Append("\n\t");
                    string strName = Enum.GetName(typeof(GameObjectPoolPrefabType), v);
                    var    gameObj = gameObjectLst.Find(gameObject => { return(gameObject.name == strName); });
                    if (gameObj != null)
                    {
                        gameObjectLst.Remove(gameObj);
                    }

                    result.Append(strName);
                    result.Append(",");
                }



                foreach (var gameObject in gameObjectLst)
                {
                    result.Append("\n\t");
                    result.Append(gameObject.name);
                    result.Append(",");
                }


                result.Append("\n}");
                sw.Write(result.ToString());
            }

            var prefabs = DreamerUtil.GetScriptableObject <GameObjectPoolPrefabs>();

            foreach (var gameObject in gameObjectLst)
            {
                prefabs.AddGameObject(new GameObjectPoolPrefab(gameObject.name, gameObject));
            }
        }
Exemplo n.º 4
0
    private static void AddToGameObjectPool()
    {
        var config        = DreamerUtil.GetScriptableObject <GameObjectPoolPrefabs>();
        var selectObjects = Selection.objects;
        List <GameObject> gameObjectList = new List <GameObject>();

        foreach (var selectedobject in selectObjects)
        {
            if (selectedobject is GameObject)
            {
                gameObjectList.Add(selectedobject as GameObject);
            }
            else
            {
                Debug.Log(selectedobject.name + "不是预制体");
            }
        }

        GameObjectPoolManager.AddGameObjectPoolPrefabType(gameObjectList);
    }