コード例 #1
0
 private string GetLuaLibStr(string path)
 {
     if (path != null)
     {
         return(CapsResInfoEditor.GetAssetNormPath(path));
     }
     return(null);
 }
コード例 #2
0
        public static string[] GetDependencies(string asset)
        {
            List <string>       deps        = new List <string>();
            LinkedList <string> parsingList = new LinkedList <string>();
            HashSet <string>    parsingSet  = new HashSet <string>();

            if (!string.IsNullOrEmpty(asset) && !CapsResInfoEditor.IsAssetScript(asset))
            {
                parsingSet.Add(asset);
                parsingList.AddLast(asset);
                var node = parsingList.First;
                while (node != null)
                {
                    var cur = node.Value;
                    try
                    {
                        var directdeps = AssetDatabase.GetDependencies(cur, false);
                        if (directdeps != null)
                        {
                            for (int i = 0; i < directdeps.Length; ++i)
                            {
                                var dep = directdeps[i];
                                if (!CapsResInfoEditor.IsAssetScript(dep))
                                {
                                    if (parsingSet.Add(dep))
                                    {
                                        parsingList.AddLast(dep);
                                        deps.Add(dep);
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                    node = node.Next;
                }
            }
            return(deps.ToArray());
        }
コード例 #3
0
        public static IEnumerator GenerateBuildWorkAsync(Dictionary <string, CapsResBuildWork> result, IList <string> assets, IEditorWorkProgressShower winprog, IList <IResBuilderEx> runOnceExBuilder)
        {
            var logger = new EditorWorkProgressLogger()
            {
                Shower = winprog
            };

            logger.Log("(Start) Generate Build Work.");
            if (winprog != null && AsyncWorkTimer.Check())
            {
                yield return(null);
            }

            if (result == null)
            {
                logger.Log("(Error) You have to provide container to retrive the result.");
                yield break;
            }
            result.Clear();

            if (assets == null)
            {
                logger.Log("(Option) Get All Assets.");
                assets = AssetDatabase.GetAllAssetPaths();
                if (winprog != null && AsyncWorkTimer.Check())
                {
                    yield return(null);
                }
            }

            if (assets != null)
            {
                List <IResBuilderEx> allExBuilders = new List <IResBuilderEx>(ResBuilderEx);
                if (runOnceExBuilder != null)
                {
                    allExBuilders.AddRange(runOnceExBuilder);
                }

                Dictionary <string, Dictionary <string, List <string> > >  mod2build = new Dictionary <string, Dictionary <string, List <string> > >();
                Dictionary <string, Dictionary <string, CapsResManifest> > mod2mani  = new Dictionary <string, Dictionary <string, CapsResManifest> >();
                for (int i = 0; i < assets.Count; ++i)
                {
                    if (winprog != null && AsyncWorkTimer.Check())
                    {
                        yield return(null);
                    }
                    var asset = assets[i];
                    logger.Log(asset);

                    if (string.IsNullOrEmpty(asset))
                    {
                        logger.Log("Empty Path.");
                        continue;
                    }
                    if (System.IO.Directory.Exists(asset))
                    {
                        logger.Log("Folder.");
                        continue;
                    }
                    if (CapsResInfoEditor.IsAssetScript(asset))
                    {
                        logger.Log("Script.");
                        continue;
                    }

                    string mod       = null;
                    string opmod     = null;
                    string dist      = null;
                    string norm      = asset;
                    bool   inPackage = false;
                    if (asset.StartsWith("Assets/Mods/") || (inPackage = asset.StartsWith("Packages/")))
                    {
                        string sub;
                        if (inPackage)
                        {
                            sub = asset.Substring("Packages/".Length);
                        }
                        else
                        {
                            sub = asset.Substring("Assets/Mods/".Length);
                        }
                        var index = sub.IndexOf('/');
                        if (index < 0)
                        {
                            logger.Log("Cannot Parse Module.");
                            continue;
                        }
                        mod = sub.Substring(0, index);
                        if (inPackage)
                        {
                            mod = CapsModEditor.GetPackageModName(mod);
                        }
                        if (string.IsNullOrEmpty(mod))
                        {
                            logger.Log("Empty Module.");
                            continue;
                        }
                        sub = sub.Substring(index + 1);
                        if (!sub.StartsWith("CapsRes/"))
                        {
                            logger.Log("Should Ignore This Asset.");
                            continue;
                        }
                        var  moddesc       = ResManager.GetDistributeDesc(mod);
                        bool isMainPackage = inPackage && !CapsModEditor.ShouldTreatPackageAsMod(CapsModEditor.GetPackageName(mod));
                        if (moddesc == null || moddesc.InMain || isMainPackage)
                        {
                            mod = "";
                            if (moddesc != null && moddesc.IsOptional && !isMainPackage)
                            {
                                opmod = moddesc.Mod;
                            }
                        }

                        sub  = sub.Substring("CapsRes/".Length);
                        norm = sub;
                        if (sub.StartsWith("dist/"))
                        {
                            sub   = sub.Substring("dist/".Length);
                            index = sub.IndexOf('/');
                            if (index > 0)
                            {
                                dist = sub.Substring(0, index);
                                norm = sub.Substring(index + 1);
                            }
                        }
                    }
                    else
                    {
                        if (asset.StartsWith("Assets/CapsRes/"))
                        {
                            mod = "";
                            var sub = asset.Substring("Assets/CapsRes/".Length);
                            norm = sub;
                            if (sub.StartsWith("dist/"))
                            {
                                sub = sub.Substring("dist/".Length);
                                var index = sub.IndexOf('/');
                                if (index > 0)
                                {
                                    dist = sub.Substring(0, index);
                                    norm = sub.Substring(index + 1);
                                }
                            }
                        }
                        else
                        {
                            logger.Log("Should Ignore This Asset.");
                            continue;
                        }
                    }

                    if (string.IsNullOrEmpty(norm))
                    {
                        logger.Log("Normallized Path Empty.");
                        continue;
                    }
                    mod  = mod ?? "";
                    dist = dist ?? "";
                    logger.Log("Mod " + mod + "; Dist " + dist + "; Norm " + norm);

                    Dictionary <string, List <string> > builds;
                    if (!mod2build.TryGetValue(mod, out builds))
                    {
                        builds         = new Dictionary <string, List <string> >();
                        mod2build[mod] = builds;
                    }

                    Dictionary <string, CapsResManifest> manis;
                    if (!mod2mani.TryGetValue(opmod ?? mod, out manis))
                    {
                        manis = new Dictionary <string, CapsResManifest>();
                        mod2mani[opmod ?? mod] = manis;
                    }
                    CapsResManifest mani;
                    if (!manis.TryGetValue(dist, out mani))
                    {
                        mani       = new CapsResManifest();
                        mani.MFlag = opmod ?? mod;
                        mani.DFlag = dist;
                        if (opmod != null)
                        {
                            mani.InMain = true;
                        }
                        manis[dist] = mani;
                    }

                    string bundle          = null;
                    bool   shouldWriteBRef = false;
                    for (int j = 0; j < allExBuilders.Count; ++j)
                    {
                        bundle = allExBuilders[j].FormatBundleName(asset, opmod ?? mod, dist, norm);
                        if (bundle != null)
                        {
                            break;
                        }
                    }
                    if (bundle == null)
                    {
                        bundle = FormatBundleName(asset, opmod ?? mod, dist, norm);
                    }
                    else
                    {
                        shouldWriteBRef = true;
                    }

                    List <string> build;
                    if (!builds.TryGetValue(bundle, out build))
                    {
                        build          = new List <string>();
                        builds[bundle] = build;
                    }
                    build.Add(asset);

                    var node = mani.AddOrGetItem(asset);
                    for (int j = 0; j < allExBuilders.Count; ++j)
                    {
                        if (allExBuilders[j].CreateItem(node))
                        {
                            break;
                        }
                    }
                    if (node.Item == null)
                    {
                        var item = new CapsResManifestItem(node);
                        if (asset.EndsWith(".prefab"))
                        {
                            item.Type = (int)CapsResManifestItemType.Prefab;
                        }
                        else if (asset.EndsWith(".unity"))
                        {
                            item.Type = (int)CapsResManifestItemType.Scene;
                        }
                        else
                        {
                            item.Type = (int)CapsResManifestItemType.Normal;
                        }
                        if (shouldWriteBRef)
                        {
                            item.BRef = bundle;
                        }
                        node.Item = item;
                    }
                    for (int j = 0; j < allExBuilders.Count; ++j)
                    {
                        allExBuilders[j].ModifyItem(node.Item);
                    }
                }

                if (winprog != null && AsyncWorkTimer.Check())
                {
                    yield return(null);
                }
                logger.Log("(Phase) Combine the final result.");

                foreach (var kvpbuild in mod2build)
                {
                    var mod               = kvpbuild.Key;
                    var builds            = kvpbuild.Value;
                    CapsResBuildWork work = new CapsResBuildWork();
                    if (mod == "")
                    {
                        List <CapsResManifest> manis = new List <CapsResManifest>(mod2mani[mod].Values);
                        foreach (var kvpmm in mod2mani)
                        {
                            if (!mod2build.ContainsKey(kvpmm.Key))
                            {
                                manis.AddRange(kvpmm.Value.Values);
                            }
                        }
                        work.Manifests = manis.ToArray();
                    }
                    else
                    {
                        work.Manifests = mod2mani[mod].Values.ToArray();
                    }

                    work.ABs = new AssetBundleBuild[builds.Count];
                    int index = 0;
                    foreach (var kvpbundle in builds)
                    {
                        var bundleName         = kvpbundle.Key;
                        var bundleAssets       = kvpbundle.Value;
                        AssetBundleBuild build = new AssetBundleBuild();
                        build.assetBundleName = kvpbundle.Key;
                        build.assetNames      = kvpbundle.Value.ToArray();
                        for (int j = 0; j < allExBuilders.Count; ++j)
                        {
                            allExBuilders[j].GenerateBuildWork(bundleName, bundleAssets, ref build, work, index);
                        }
                        work.ABs[index++] = build;
                    }

                    result[mod] = work;
                }
            }

            logger.Log("(Done) Generate Build Work.");
        }
コード例 #4
0
        private void ShowTypeSelWinFor(int index)
        {
            if (index >= 0 && index < rawindices.Count)
            {
                var kvp = rawindices[index];
                var val = kvp.Value;
                if ((val is Object || index == newindex2) && val != null || val == null && specifiedTypes[index] == typeof(Object))
                {
                    GenericMenu menu = new GenericMenu();

                    if (rawindices != null && index >= 0 && index < rawindices.Count)
                    {
                        if (val is GameObject || val is Component)
                        {
                            System.Action <Object> addMenuItem = (obj) =>
                            {
                                var type = obj.GetType();
                                menu.AddItem(new GUIContent(type.Name), object.Equals(val, obj), (selcomp) =>
                                {
                                    if (!object.Equals(val, selcomp))
                                    {
                                        EditField(index, kvp.Key, selcomp);
                                    }
                                }, obj);
                            };

                            var go = val is GameObject ? val as GameObject : ((Component)val).gameObject;
                            addMenuItem(go);

                            HashSet <Type> compTypes = new HashSet <Type>();
                            foreach (var comp in go.GetComponents <Component>())
                            {
                                var comptype = comp.GetType();
                                var attrs    = comptype.GetCustomAttributes(typeof(DataDictionaryComponentTypeAttribute), true);
                                if (attrs != null && attrs.Length > 0)
                                {
                                    var attr = attrs[0] as DataDictionaryComponentTypeAttribute;
                                    if (attr != null)
                                    {
                                        if (attr.Type == DataDictionaryComponentTypeAttribute.DataDictionaryComponentType.Main)
                                        {
                                            addMenuItem(comp);
                                            compTypes.Add(comptype);
                                        }
                                        else if (attr.Type == DataDictionaryComponentTypeAttribute.DataDictionaryComponentType.Sub)
                                        {
                                            compTypes.Add(comptype);
                                        }
                                    }
                                }
                            }

                            var transcomp = go.GetComponent <Transform>();
                            if (transcomp != null)
                            {
                                compTypes.Add(transcomp.GetType());
                                addMenuItem(transcomp);
                            }

                            bool sepAdded = false;
                            foreach (var comp in go.GetComponents <Component>())
                            {
                                var comptype = comp.GetType();
                                if (!compTypes.Contains(comptype))
                                {
                                    if (!sepAdded)
                                    {
                                        menu.AddSeparator("");
                                        sepAdded = true;
                                    }
                                    addMenuItem(comp);
                                }
                            }

                            if (index != newindex2)
                            {
                                menu.AddSeparator("");
                            }
                        }
                        if (index != newindex2)
                        {
                            menu.AddItem(new GUIContent("Plain"), false, () =>
                            {
                                string path = null;
                                if (val is Object && ((Object)val) != null)
                                {
                                    try
                                    {
                                        path = AssetDatabase.GetAssetPath(val as Object);
                                    }
                                    catch (Exception e)
                                    {
                                        Debug.LogException(e);
                                    }
                                }
                                if (!string.IsNullOrEmpty(path))
                                {
                                    path = CapsResInfoEditor.GetAssetNormPath(path);
                                }
                                specifiedTypes[index] = null;
                                EditField(index, kvp.Key, path);
                            });
                        }
                    }

                    menu.ShowAsContext();
                }
                else if (!(val is Object && ((Object)val) == null) && !(index == newindex2 && val == null))
                {
                    GenericMenu menu = new GenericMenu();
                    if (rawindices != null && index >= 0 && index < rawindices.Count)
                    {
                        var KeepStringType = specifiedTypes[index] == typeof(string);

                        System.Action <string> addMenuItem = (name) =>
                        {
                            string valstr = val == null ? "null" : val.ToString();
                            if (val is string && (string.IsNullOrEmpty(valstr) || name != "Auto"))
                            {
                                valstr = "\"" + valstr + "\"";
                            }

                            var title = name + " (" + valstr + ")";
                            menu.AddItem(new GUIContent(title), KeepStringType != (name == "Auto"), (x) =>
                            {
                                var oldType    = specifiedTypes[index];
                                object newType = null;
                                if (name != "Auto")
                                {
                                    newType = typeof(string);
                                }
                                specifiedTypes[index] = newType;
                                if (oldType != newType)
                                {
                                    EditField(index, kvp.Key, val);
                                }
                            }, name);
                        };

                        addMenuItem("Auto");
                        addMenuItem("String");
                        if (index != newindex1)
                        {
                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Object"), false, () =>
                            {
                                specifiedTypes[index] = typeof(Object);
                                object oldval;
                                oldDict.TryGetValue(kvp.Key, out oldval);
                                Object newval = null;
                                if (oldval is string)
                                {
                                    var path = oldval as string;
                                    {
                                        var real = CapsResInfoEditor.FindDistributeAsset(path);
                                        if (real != null)
                                        {
                                            try
                                            {
                                                var obj = AssetDatabase.LoadMainAssetAtPath(real);
                                                if (obj != null)
                                                {
                                                    newval = obj;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                Debug.LogException(e);
                                            }
                                        }
                                    }
                                    if (newval == null && !path.Contains('/'))
                                    {
                                        path     = path.Replace('.', '/');
                                        path     = "CapsSpt/" + path + ".lua";
                                        var real = ResManager.EditorResLoader.CheckDistributePath(path);
                                        if (real != null)
                                        {
                                            try
                                            {
                                                var obj = AssetDatabase.LoadMainAssetAtPath(real);
                                                if (obj != null)
                                                {
                                                    newval = obj;
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                Debug.LogException(e);
                                            }
                                        }
                                    }
                                }
                                EditField(index, kvp.Key, newval);
                            });
                        }
                        {
                            object oldval;
                            if (index == newindex1)
                            {
                                oldval = val;
                            }
                            else
                            {
                                oldDict.TryGetValue(kvp.Key, out oldval);
                            }
                            if (oldval is string)
                            {
                                var strval = oldval as string;
                                menu.AddSeparator("");
                                menu.AddItem(new GUIContent("Find Asset"), false, () =>
                                {
                                    var real = CapsResInfoEditor.FindDistributeAsset(strval);
                                    if (real != null)
                                    {
                                        try
                                        {
                                            var obj = AssetDatabase.LoadMainAssetAtPath(real);
                                            if (obj != null)
                                            {
                                                EditorGUIUtility.PingObject(obj);
                                                return;
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            Debug.LogException(e);
                                        }
                                    }
                                });
                                menu.AddItem(new GUIContent("Find Script"), false, () =>
                                {
                                    var path = strval.Replace('.', '/');
                                    path     = "CapsSpt/" + path + ".lua";
                                    var real = ResManager.EditorResLoader.CheckDistributePath(path);
                                    if (real != null)
                                    {
                                        try
                                        {
                                            var obj = AssetDatabase.LoadMainAssetAtPath(real);
                                            if (obj != null)
                                            {
                                                EditorGUIUtility.PingObject(obj);
                                                return;
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            Debug.LogException(e);
                                        }
                                    }
                                });
                            }
                        }
                    }
                    menu.ShowAsContext();
                }
                else if ((val is Object && ((Object)val) == null) || (val == null && specifiedTypes[index] == typeof(Object)))
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Auto"), true, () => { });
                    menu.AddItem(new GUIContent("Plain"), false, () =>
                    {
                        specifiedTypes[index] = null;
                        EditField(index, kvp.Key, null);
                    });
                    menu.ShowAsContext();
                }
            }
        }
コード例 #5
0
        public override void OnInspectorGUI()
        {
            bool prefabChanged = false;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Sync Data"))
            {
                //stubButtonClicked = true;
                Target.SyncDynamicChildStubs();
            }
            if (GUILayout.Button("Merge Stub"))
            {
                prefabChanged = Target.MergeDynamicChildStubs();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Re-create Stub"))
            {
                prefabChanged = Target.CreateDynamicChildStubs();
            }
            EditorGUILayout.EndHorizontal();
            if (prefabChanged)
            {
                PrefabStageExtensions.TrySavePrefabStage();
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(Target.gameObject.scene);
            }

            soTarget.Update();
            EditorGUILayout.PropertyField(spSource, new GUIContent("Source"));
            if (oldSource != spSource.stringValue)
            {
                oldSource = spSource.stringValue ?? "";
                oldPrefab = null;
                var path = ResManager.EditorResLoader.CheckDistributePath("CapsRes/" + oldSource, true);
                if (path != null)
                {
                    oldPrefab = AssetDatabase.LoadMainAssetAtPath(path);
                    if (!justEnabled)
                    {
                        Target.MergeStubFromPrefab(oldPrefab as GameObject);
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(Target.gameObject.scene);
                    }
                }
            }
            justEnabled = false;
            Object oldObj = oldPrefab;
            var    newObj = EditorGUILayout.ObjectField("Prefab", oldObj, typeof(GameObject), false);

            if (newObj != oldObj)
            {
                string newNorm = null;
                if (newObj != null)
                {
                    var newPath = AssetDatabase.GetAssetPath(newObj);
                    newNorm = CapsResInfoEditor.GetAssetNormPath(newPath);
                }
                newNorm = newNorm ?? "";
                spSource.stringValue = newNorm;
                oldPrefab            = newObj;
                oldSource            = newNorm;
            }
            EditorGUILayout.PropertyField(spEvent, new GUIContent("On Dynamic Child Loaded"));
            soTarget.ApplyModifiedProperties();
        }