public void ExportAssetbundle(Object[] selectionGameObjects)
        {
            if (selectionGameObjects == null || selectionGameObjects.Length == 0)
            {
                return;
            }
            AssetDatabase.SaveAssets();

            foreach (var v in _BuildTargetMap)
            {
                foreach (Object obj in selectionGameObjects)
                {
                    if (obj is GameObject || obj is Texture2D)
                    {
                        AssetDatabase.Refresh();
                        string locationPathName = RootPath + "/" + v.Value + "/" + obj.name + ".assetbundle";
                        HS_Directory.CreateDirectory(HS_Path.GetDirectoryName(locationPathName));
                        BuildPipeline.BuildAssetBundle(obj, null, locationPathName, BuildAssetBundleOptions.CollectDependencies, v.Key);
                    }
                    else
                    {
                        D.LogForce(obj.name + " 不是预制体");
                    }
                }
            }
            this.OpenFolder();
            EditorUtility.DisplayDialog("提示", "打包完成", "确认");
        }
Beispiel #2
0
        static public void BuildForWindows(HS_EditDefine.HS_ChannelDefine channelDefine)
        {
            LoadConfig();

            ChannelConfig channelConfig = S_AllChannelConfig[channelDefine.ToString()];
            //string channel = channelConfig.channel;
            string packerName = channelConfig.packerName;
            string rootPath   = S_RootPath;

            PlayerSettings.bundleIdentifier            = packerName;
            PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
            string path = rootPath + "/Client/Windows";

            HS_Directory.CreateDirectory(path);

            try
            {
                HS_Base.SystemDeleteFolder(path);
            }
            catch (System.Exception _e)
            {
                D.LogForce("Ignore: " + _e.ToString());
            }

            string lastDefineSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);

            if (!string.IsNullOrEmpty(channelConfig.defineSymbols))
            {
                PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, channelConfig.defineSymbols);
            }
            else
            {
                PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, "");
            }
            if (!string.IsNullOrEmpty(lastDefineSymbols))
            {
                PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, lastDefineSymbols);
            }

            path += "/" + packerName + ".exe";

            //FilterEditorDLL(FilterEditorDLLModel.Assets2Backups);
            //更新SVN并且拷贝到streamingAssets
            SVNUpdate(RuntimePlatform.WindowsPlayer);

            BuildPipeline.BuildPlayer(GetBuildScenes(), path, BuildTarget.StandaloneWindows64, BuildOptions.None);
            //FilterEditorDLL(FilterEditorDLLModel.Backups2Assets);
            RemoveSVNResources();
            AssetDatabase.Refresh();
            System.Diagnostics.Process.Start(HS_Path.GetDirectoryName(path));
        }
Beispiel #3
0
        public static void Init()
        {
            string root = Directory.GetCurrentDirectory();

            //代码目录
            HS_Directory.CreateDirectory(root + "/Assets/Script/Sprite");
            HS_Directory.CreateDirectory(root + "/Assets/Script/VLayer/Base");
            HS_Directory.CreateDirectory(root + "/Assets/Script/VLayer/View");

            //资源目录
            HS_Directory.CreateDirectory("Assets/SubAssets/Res/Prefabs/UI");

            AssetDatabase.Refresh();
        }
Beispiel #4
0
        public static void SVNUpdate(RuntimePlatform platform)
        {
            string platformAssets = HS_PlatformRes.Directory[platform];

            SVNSetiingWindows.Update();
            string streamingAssetsPath = Application.streamingAssetsPath;

            HS_Directory.CreateDirectory(streamingAssetsPath);

            s_CopyFolder.Clear();
            foreach (string p in SVNSetiingWindows.UpdatePaths)
            {
                string folderName     = HS_Path.GetCurrentFolder(p);
                string fullFolderName = streamingAssetsPath + @"/" + folderName;
                try
                {
                    HS_Base.SystemDeleteFolder(fullFolderName);
                }
                catch (System.Exception _e)
                {
                    D.LogForce("Ignore: " + _e.ToString());
                }
            }
            AssetDatabase.Refresh();

            foreach (string p in SVNSetiingWindows.UpdatePaths)
            {
                string dstPath = streamingAssetsPath + @"/";

                if (p.Contains("Assets"))
                {
                    if (!p.Contains(platformAssets))
                    {
                        continue;
                    }
                    dstPath += platformAssets;
                }
                else
                {
                    dstPath += HS_Path.GetCurrentFolder(p);
                }
                s_CopyFolder.Add(dstPath);
                HS_Base.SystemCopyDirectory(p, dstPath, new string[] { ".svn", ".bat", ".dll" });
            }
            AssetDatabase.Refresh();
            HS_GenerateMD5.GenerateMD5(streamingAssetsPath, "");
        }
Beispiel #5
0
        static public void Export(string prefabPath, string scriptPath, string cellPath, string baseClassName = "HS_ViewBase", Transform root = null)
        {
            if (root == null)
            {
                GameObject c = GameObject.Find("UI").gameObject;
                if (c == null)
                {
                    Debug.LogError("No UI Compent in Hierarchy.");
                    return;
                }
                root = c.transform;
            }
            if (scriptPath.IndexOf("Assets/") != 0 || prefabPath.IndexOf("Assets/") != 0)
            {
                Debug.LogError("Path alway start with \"Assets/\" .");
                return;
            }
            HS_Directory.CreateDirectory(prefabPath);
            for (int i = root.childCount - 1; i >= 0; --i)
            {
                Transform child = root.GetChild(i);
                if (child.gameObject.activeSelf && child.gameObject.CompareTag(VIEW_UI))
                {
                    string viewName = child.gameObject.name;
                    mObjectNameIds.Clear();
                    mObjectNames.Clear();
                    mPathDict.Clear();
                    mPropertyDict.Clear();
                    mPropertyNameDict.Clear();
                    mUIListViewList.Clear();

                    ParseCanvas(child, child, "");

                    for (int j = 0; j < mUIListViewList.Count; j++)
                    {
                        HS_ListViewBase listView = mUIListViewList[j].GetComponent <HS_ListViewBase>();
                        if (listView != null)
                        {
                            GameObject cellPrefab = listView.GetCellPrefab();
                            if (cellPrefab == null)
                            {
                                string cellName       = listView.GetCellPrefabName();
                                string cellPrefabPath = GetCellPathName(cellName, cellPath);
                                Debug.Log("load path:" + cellPrefabPath);
                                GameObject prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(cellPrefabPath, typeof(GameObject)) as GameObject;
                                cellPrefab = GameObject.Instantiate(prefab) as GameObject;
                                cellPrefab.transform.SetParent(listView.GetGridContent().transform);
                                cellPrefab.transform.localScale = Vector3.one;
                                cellPrefab.name = "CellPrefab";
                            }
                            if (cellPrefab == null)
                            {
                                Debug.LogError("No cell prefab:" + mUIListViewList[j].name);
                                break;
                            }
                            listView.SetCellPrefab(cellPrefab);
                            ParseCanvas(cellPrefab.transform, cellPrefab.transform, "");
                        }
                        else
                        {
                            mUIListViewList.RemoveAt(j--);
                        }
                    }

                    string newBaseClassName = GenerateViewBaseClass(child, prefabPath, scriptPath + "/Base", cellPath, baseClassName);

                    GenerateViewClass(scriptPath, viewName, newBaseClassName);
                }
            }

            Debug.Log("Export is completed");

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Beispiel #6
0
        static private string GenerateViewBaseClass(Transform panel, string prefabPath, string scriptPath, string cellPath, string baseClassName)
        {
            // generate script
            StringBuilder code      = new StringBuilder();
            string        className = "Base" + UpperFirstLetter(panel.name) + "View";

            code.AppendLine("using System;");
            code.AppendLine("using System.Collections;");
            code.AppendLine("using System.Collections.Generic;");
            code.AppendLine("using UnityEngine;");
            code.AppendLine("using HS.Base;");
            code.AppendLine("using HS.UI;");
            code.AppendLine("using HS.Manager;");

            code.AppendLine("");
            code.AppendLine("public class " + className + " : " + baseClassName);
            code.AppendLine("{");

            List <Property> properties;

            if (mPropertyDict.TryGetValue(panel, out properties))
            {
                for (int i = 0; i < properties.Count; i++)
                {
                    Property p = properties[i];
                    if (!p.isPrivate)
                    {
                        code.Append(TAB1).AppendLine(string.Format("protected {0} {1};", p.type, p.name));
                    }
                }
            }

            string viewPath = "";
            int    index    = prefabPath.LastIndexOf("/Resources");

            if (index > 0)
            {
                if (prefabPath[index + 10] == '/')
                {
                    viewPath = prefabPath.Substring(index + 11);
                }
            }
            code.Append(TAB1).AppendLine("");
            code.Append(TAB1).AppendLine("internal override GameObject GetViewPrefab()");
            code.Append(TAB1).AppendLine("{");
            code.Append(TAB2).AppendLine(string.Format("return HS_ResourceManager.LoadAsset<GameObject>(\"{0}\");", viewPath + (string.IsNullOrEmpty(viewPath) ? "" : "/") + panel.name));
            code.Append(TAB1).AppendLine("}");

            code.Append(TAB1).AppendLine("");
            code.Append(TAB1).AppendLine("protected override void OnCreated()");
            code.Append(TAB1).AppendLine("{");


            code.Append(TAB2).AppendLine("base.OnCreated();");

            code.Append(TAB1).AppendLine("");

            code.Append(TAB2).AppendLine("Transform transform = this.transform;");
            code.Append(TAB2).AppendLine("if (transform == HS_ViewManager.root.transform) return;");
            if (properties != null)
            {
                foreach (Property p in properties)
                {
                    code.Append(TAB2).AppendLine("");
                    System.Type type     = p.type;
                    string      propName = "this." + p.name;
                    if (p.isPrivate)
                    {
                        propName = p.name;
                        code.Append(TAB2).AppendLine(string.Format("{2} {0} = HS_Base.FindProperty<{2}>(transform, \"{1}\");", propName, p.path, type));
                    }
                    else
                    {
                        code.Append(TAB2).AppendLine(string.Format("{0} = HS_Base.FindProperty<{2}>(transform, \"{1}\");", propName, p.path, type));
                    }

                    if (type == typeof(Button))
                    {
                        code.Append(TAB2).AppendLine("this.RegisterButtonClickEvent (" + propName + ");");
                    }
                    else if (type == typeof(Slider))
                    {
                        code.Append(TAB2).AppendLine("this.RegisterSliderEvent (" + propName + ");");
                    }
                    else if (type == typeof(Toggle))
                    {
                        code.Append(TAB2).AppendLine("this.RegisterToggleEvent (" + propName + ");");
                    }
                    else if (type == typeof(Dropdown))
                    {
                        code.Append(TAB2).AppendLine("this.RegisterDropDownEvent (" + propName + ");");
                    }
                    else if (type == typeof(InputField))
                    {
                        code.Append(TAB2).AppendLine("this.RegisterInputFieldEvent (" + propName + ");");
                    }
                    else if (type == typeof(Text))
                    {
                        HS_LocalizationText localizationText = p.com.transform.GetComponent <HS_LocalizationText>();
                        if (localizationText != null && localizationText.languageKey != "")
                        {
                            //Localization.Format ();
                            code.Append(TAB2).AppendLine("LocalizationText " + p.name + "LocalizationText = " + p.name + ".transform.GetComponent<LocalizationText> ();");
                            code.Append(TAB2).AppendLine(propName + ".text = Localization.Format (" + p.name + "LocalizationText.languageKey);");
                        }
                        else
                        {
                            code.Append(TAB2).AppendLine(propName + ".text = \"" + Regex.Replace(((Text)p.com).text, "(\\\"|\\\\)", "\\$0") + "\";");
                        }
                    }
                    else if (type == typeof(HS_UIListView))
                    {
                        code.Append(TAB2).AppendLine(propName + ".onInit += OnListViewInit;");
                        code.Append(TAB2).AppendLine(propName + ".onCellCreated += OnCellCreated;");
                        if (type == typeof(HS_UIListView))
                        {
                            code.Append(TAB2).AppendLine(propName + ".onClick += OnListViewClick;");
                            code.Append(TAB2).AppendLine(propName + ".onSelected += OnListViewSelected;");
                            code.Append(TAB2).AppendLine(propName + ".onDeselected += OnListViewDeselected;");
                        }
                    }
                }
            }
            code.Append(TAB1).AppendLine("}");

            System.Action <Transform, string> generateCellClass = delegate(Transform cell, string name)
            {
                List <Property> props;
                if (!mPropertyDict.TryGetValue(cell, out props))
                {
                    props = new List <Property>();
                }
                code.Append(TAB2).AppendLine("public class " + name);
                code.Append(TAB2).AppendLine("{");
                foreach (Property p in props)
                {
                    if (!p.isPrivate)
                    {
                        code.Append(TAB3).AppendLine(string.Format("public {0} {1};", p.type, p.name));
                    }
                }
                code.Append(TAB2).AppendLine("}");
                code.Append(TAB2).AppendLine("");
            };
            System.Action <Transform, string, string, string> generateCellProperty = delegate(Transform cell, string cellClassName, string insName, string space)
            {
                List <Property> props;
                if (!mPropertyDict.TryGetValue(cell, out props))
                {
                    props = new List <Property>();
                }
                code.Append(space).AppendLine(cellClassName + " " + insName + " = new " + cellClassName + "();");
                foreach (Property p in props)
                {
                    if (p.isPrivate)
                    {
                        code.Append(space).AppendLine(string.Format("{2} {0} = HS_Base.FindProperty<{2}>(t, \"{1}\");", p.name, p.path, p.type));
                        if (p.type == typeof(Text))
                        {
                            code.Append(space).AppendLine(p.name + ".text = \"" + Regex.Replace(((Text)p.com).text, "(\\\"|\\\\)", "\\$0") + "\";");
                        }
                    }
                    else
                    {
                        code.Append(space).AppendLine(string.Format("{0}.{1} = HS_Base.FindProperty<{3}>(t, \"{2}\");", insName, p.name, p.path, p.type));
                    }
                }
            };

            foreach (Transform t in mUIListViewList)
            {
                HS_ListViewBase listView   = t.GetComponent <HS_ListViewBase>();
                GameObject      cellPrefab = listView.GetCellPrefab();
                if (cellPrefab == null)
                {
                    Debug.LogError("No cell prefab:" + t.name);
                    break;
                }

                string panelName      = mObjectNames[t];
                string panelClassName = "TV" + UpperFirstLetter(panelName);
                string cellStructName = "Cell";
                code.Append(TAB1).AppendLine("");
                code.Append(TAB1).AppendLine("#region " + panelName);
                code.Append(TAB1).AppendLine("protected static class " + panelClassName);
                code.Append(TAB1).AppendLine("{");

                mObjectNameIds.Clear();

                generateCellClass(cellPrefab.transform, "Cell");

                code.Append(TAB2).AppendLine("static public " + cellStructName + " Get(HS_UIListViewCell cell)");
                code.Append(TAB2).AppendLine("{");
                code.Append(TAB3).AppendLine("Transform t = cell.transform;");

                generateCellProperty(cellPrefab.transform, "Cell", "obj", TAB3);

                code.Append(TAB3).AppendLine("return obj;");
                code.Append(TAB2).AppendLine("}");

                code.Append(TAB1).AppendLine("}");
                code.Append(TAB1).AppendLine("#endregion");
            }

            code.AppendLine("}");

            WriteString(scriptPath + "/" + className + ".cs", code.ToString());

            foreach (Transform t in mUIListViewList)
            {
                HS_ListViewBase listView = t.GetComponent <HS_ListViewBase>();
                if (listView != null)
                {
                    string cellName = GetCellPrefabName(panel, t);
                    //Debug.Log("RecordCellPrefabName " + cellName);
                    listView.RecordCellPrefabName(cellName);
                    GameObject cell = listView.GetCellPrefab();
                    if (cell != null)
                    {
                        string cellPrefabPath = GetCellPathName(cellName, cellPath);
                        HS_Directory.CreateDirectory(cellPath);
                        PrefabUtility.CreatePrefab(cellPrefabPath, cell, ReplacePrefabOptions.ConnectToPrefab);
                    }

                    GameObject gridContent = listView.GetGridContent();
                    for (int i = gridContent.transform.childCount - 1; i >= 0; i--)
                    {
                        GameObject.DestroyImmediate(gridContent.transform.GetChild(i).gameObject);
                    }
                }
            }

            MakeDirs(prefabPath);
            PrefabUtility.CreatePrefab(prefabPath + "/" + panel.name + ".prefab", panel.gameObject, ReplacePrefabOptions.ConnectToPrefab);

            GameObject.DestroyImmediate(panel.gameObject);

            return(className);
        }
Beispiel #7
0
        public void ExportAssetbundle(Object[] selectionGameObjects)
        {
            if (selectionGameObjects == null || selectionGameObjects.Length == 0)
            {
                return;
            }
            foreach (var v in _BuildTargetMap)
            {
                foreach (Object obj in selectionGameObjects)
                {
                    AssetDatabase.Refresh();
                    string assetPath     = AssetDatabase.GetAssetPath(obj);
                    bool   isOpenSucceed = EditorApplication.OpenScene(assetPath);
                    if (isOpenSucceed)
                    {
                        Dictionary <string, GameObject> ignorePrefabDic = new Dictionary <string, GameObject>();
                        try
                        {
                            foreach (string ignoreObjName in IgnoreGameObject)
                            {
                                GameObject deleteObj = GameObject.Find(ignoreObjName);
                                if (deleteObj != null)
                                {
                                    GameObject prefab = PrefabUtility.GetPrefabParent(deleteObj) as GameObject;
                                    ignorePrefabDic.Add(deleteObj.name, prefab);
                                    GameObject.DestroyImmediate(deleteObj);
                                }
                            }
                        }
                        catch (System.Exception _e)
                        {
                            D.LogError(_e.ToString());
                        }

                        EditorApplication.SaveScene();

                        string locationPathName = RootPath + "/" + v.Value + "/" + obj.name + ".assetbundle";
                        HS_Directory.CreateDirectory(Path.GetDirectoryName(locationPathName));
                        string[] scenes = { assetPath };
                        AssetDatabase.Refresh();
                        string b = BuildPipeline.BuildPlayer(scenes, locationPathName, v.Key, BuildOptions.BuildAdditionalStreamedScenes);
                        Debug.Log("打包完成 => " + b);
                        AssetDatabase.Refresh();

                        try
                        {
                            foreach (var ignoreObj in ignorePrefabDic)
                            {
                                GameObject ins = PrefabUtility.InstantiatePrefab(ignoreObj.Value) as GameObject;
                                ins.name = ignoreObj.Key;
                            }
                        }
                        catch (System.Exception _e)
                        {
                            D.LogError(_e.ToString());
                        }


                        EditorApplication.SaveScene();
                    }
                }
            }
            this.OpenFolder();
            EditorUtility.DisplayDialog("提示", "打包完成", "确认");
        }