/// <summary>
        /// 更新bundle名
        /// </summary>
        private void QuickUpdate()
        {
            StateObjectHolder obj = target as StateObjectHolder;

            for (int i = 0; i < obj.bundleList.Count; i++)
            {
                foreach (var item in obj.bundleList[i].itemList)
                {
                    var path   = AssetDatabase.GUIDToAssetPath(item.guid);
                    var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    if (prefab == null)
                    {
                        UnityEditor.EditorUtility.DisplayDialog("空对象", item.ID + "预制体为空", "确认");
                        continue;
                    }

                    string assetPath = UnityEditor.AssetDatabase.GetAssetPath(prefab);

                    UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath(assetPath);
                    item.assetName = prefab.name;

                    if (string.IsNullOrEmpty(item.assetName))
                    {
                        UnityEditor.EditorUtility.DisplayDialog("提示", "预制体" + item.assetName + "没有assetBundle标记", "确认");
                        return;
                    }
                    else
                    {
                        item.assetBundleName = importer.assetBundleName;
                    }
                }
            }
            EditorUtility.SetDirty(target);
        }
        /// <summary>
        /// 分类预览
        /// </summary>
        private void GroupPreview()
        {
            Dictionary <string, GameObject> parentDic = new Dictionary <string, GameObject>();

            StateObjectHolder obj = target as StateObjectHolder;

            foreach (var item in obj.prefabList)
            {
                if (!parentDic.ContainsKey(item.stateName))
                {
                    var parent = new GameObject(item.stateName);
                    parentDic.Add(item.stateName, parent);
                    created.Add(parent);
                }
                foreach (var pitem in item.itemList)
                {
                    if (pitem.prefab != null)
                    {
                        var pInstence = PrefabUtility.InstantiatePrefab(pitem.prefab);
                        (pInstence as GameObject).transform.SetParent(parentDic[item.stateName].transform);
                        created.Add(pInstence as GameObject);
                    }
                }
            }

            foreach (var item in obj.bundleList)
            {
                if (!parentDic.ContainsKey(item.stateName))
                {
                    var parent = new GameObject(item.stateName);
                    parentDic.Add(item.stateName, parent);
                    created.Add(parent);
                }
                foreach (var pitem in item.itemList)
                {
                    var path   = AssetDatabase.GUIDToAssetPath(pitem.guid);
                    var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    if (prefab != null)
                    {
                        var pInstence = PrefabUtility.InstantiatePrefab(prefab);
                        (pInstence as GameObject).transform.SetParent(parentDic[item.stateName].transform);
                        created.Add(pInstence as GameObject);
                    }
                }
            }
            EditorUtility.SetDirty(obj);
        }
        /// <summary>
        /// 去重复(需要判断 预制体/reset/position/rotation)
        /// 而不同的group之间则需要删除重复的对象,公用唯一的对象
        /// </summary>
        private void RemoveDouble()
        {
            StateObjectHolder obj = target as StateObjectHolder;

            for (int i = 0; i < obj.prefabList.Count; i++)
            {
                var item = obj.prefabList[i];
                compair : List <string> temp = new List <string>();
                for (int j = 0; j < item.itemList.Count; j++)
                {
                    var targetItem = item.itemList[j];
                    var ID         = targetItem.ID;

                    if (!temp.Contains(ID))
                    {
                        temp.Add(ID);
                    }
                    else
                    {
                        item.itemList.Remove(targetItem);
                        goto compair;
                    }
                }
            }
            for (int i = 0; i < obj.bundleList.Count; i++)
            {
                var item = obj.bundleList[i];
                compair : List <string> temp = new List <string>();
                for (int j = 0; j < item.itemList.Count; j++)
                {
                    var targetItem = item.itemList[j];
                    var ID         = targetItem.ID;

                    if (!temp.Contains(ID))
                    {
                        temp.Add(ID);
                    }
                    else
                    {
                        item.itemList.Remove(targetItem);
                        goto compair;
                    }
                }
            }
            EditorUtility.SetDirty(target);
        }
        private void SortAllBundles()
        {
            StateObjectHolder obj = target as StateObjectHolder;

            foreach (var item in obj.bundleList)
            {
                for (int i = 0; i < item.itemList.Count; i++)
                {
                    for (int j = i; j < item.itemList.Count - i - 1; j++)
                    {
                        var itemj  = item.itemList[j];
                        var itemj1 = item.itemList[j + 1];
                        if (string.Compare(itemj.assetName, itemj1.assetName) > 0)
                        {
                            var temp = itemj;
                            item.itemList[j]     = item.itemList[j + 1];
                            item.itemList[j + 1] = temp;
                        }
                    }
                }
            }

            foreach (var item in obj.prefabList)
            {
                for (int i = 0; i < item.itemList.Count; i++)
                {
                    for (int j = i; j < item.itemList.Count - i - 1; j++)
                    {
                        var itemj  = item.itemList[j];
                        var itemj1 = item.itemList[j + 1];

                        if (itemj.prefab != null && itemj1.prefab != null)
                        {
                            if (string.Compare(itemj.prefab.name, itemj1.prefab.name) > 0)
                            {
                                var temp = itemj;
                                item.itemList[j]     = item.itemList[j + 1];
                                item.itemList[j + 1] = temp;
                            }
                        }
                    }
                }
            }

            EditorUtility.SetDirty(obj);
        }
Esempio n. 5
0
 public StateChangeCtrl(StateObjectHolder hold)
 {
     this.hold = hold;
     itemLoadCtrl = new ItemLoadCtrl();
     catchStates = hold.GetNeedCatchStates();
 }