예제 #1
0
    private void OnGUI()
    {
        GUISkin lastSkin = GUI.skin;

        GUI.skin = guiSkin;

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();

        if (GUI.Button(EditorGUILayout.GetControlRect(false),
                       new GUIContent("Reload", "Reload assets from source bundle"),
                       lastSkin.button))
        {
            AssetViewerDB.Load();
            guiSkin  = (GUISkin)Resources.Load("AssetViewer");
            GUI.skin = guiSkin;
        }

        searchText = EditorGUILayout.TextField(searchText);
        if (categoryNames?.Length > 0)
        {
            selectedCategoryIdx = EditorGUILayout.Popup(selectedCategoryIdx, categoryNames);
        }

        EditorGUILayout.EndHorizontal();

        GUI.Box(actualCanvas, "", "scrollview");

        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

        Rect scrollRect = new Rect(scrollPosition.x, scrollPosition.y, position.width, position.height);

        EditorGUILayout.BeginHorizontal();

        Rect lastRect = new Rect(0, 0, ITEM_WIDTH, ITEM_HEIGHT);

        int hCount    = -1;
        int hCountMax = Mathf.FloorToInt(scrollRect.width / ITEM_WIDTH);

        foreach (var loadedAsset in AssetViewerDB.LoadedAssets)
        {
            var asset     = loadedAsset.Asset;
            var assetName = loadedAsset.AssetName;

            // Name filter
            if (!string.IsNullOrWhiteSpace(searchText) && !asset.name.ToLower().Contains(searchText.ToLower()))
            {
                continue;
            }

            // Category filter
            if (selectedCategoryIdx > 0 && loadedAsset.AssetCategory != categoryNames[selectedCategoryIdx])
            {
                continue;
            }

            bool isVirtual = false;

            if (++hCount == hCountMax)
            {
                EditorGUILayout.EndHorizontal();
                lastRect.y += ITEM_HEIGHT;
                lastRect.x  = 0;
                isVirtual   = !scrollRect.Overlaps(lastRect);
                if (isVirtual)
                {
                    GUILayout.Space(ITEM_HEIGHT);
                }
                EditorGUILayout.BeginHorizontal();
                hCount = 0;
            }
            else
            {
                lastRect.x += ITEM_HEIGHT;
                isVirtual   = !scrollRect.Overlaps(lastRect);
                if (isVirtual)
                {
                    GUILayout.Space(ITEM_WIDTH);
                }
            }

            if (isVirtual)
            {
                continue;
            }

            Texture2D t = GetThumbnail(asset);

            GUILayout.Box(new GUIContent(asset.name, t, assetName), GUILayout.Height(80), GUILayout.Width(100));

            HandleAssetEvents(asset, assetName);
        }

        if (hCount != hCountMax)
        {
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndScrollView();
        GUI.skin = lastSkin;
    }
예제 #2
0
    private void OnGUI()
    {
        string modName = typeof(ModEntryPoint).Assembly.GetName().Name;

        GUILayout.Label("Build Settings", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Mod Name", modName);
        if (GUILayout.Button("Change"))
        {
            var obj = AssetDatabase.LoadAssetAtPath <Object>("Assets/Scripts/MyMod.asmdef");
            Selection.activeObject = obj;
            EditorGUIUtility.PingObject(obj);
        }
        EditorGUILayout.EndHorizontal();

        clearLogs        = GUILayout.Toggle(clearLogs, "Clear Logs");
        buildAssetBundle = GUILayout.Toggle(buildAssetBundle, "Build Asset Bundle");

        if (GUILayout.Button("BUILD"))
        {
            if (modName.Length > 0)
            {
                if (Directory.Exists(PATH_BUILD_BUNDLE))
                {
                    Directory.Delete(PATH_BUILD_BUNDLE, true);
                }

                if (Directory.Exists(PATH_BUILD_BUNDLE))
                {
                    throw new System.Exception("Temp/ModBuild exist");
                }

                if (!UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                {
                    return;
                }

                UnityEditor.SceneManagement.EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.EmptyScene, UnityEditor.SceneManagement.NewSceneMode.Single);
                RenderSettings.fog = true; // force enable fog

                Directory.CreateDirectory(PATH_BUILD_BUNDLE);

                //HACK for unique id
                AssetImporter.GetAtPath("Assets/Resources").SetAssetBundleNameAndVariant(modName + "_resources", "");
                AssetDatabase.Refresh();

                if (buildAssetBundle)
                {
                    BuildPipeline.BuildAssetBundles(PATH_BUILD_BUNDLE, BuildAssetBundleOptions.None /*BuildAssetBundleOptions.DisableWriteTypeTree*/, BuildTarget.StandaloneWindows64);
                }

                if (clearLogs)
                {
                    ClearLogConsole();
                }

                //copy dll
                string modsFolder = Application.persistentDataPath + "/../../AtomTeam/Atom/Mods";

                if (!Directory.Exists(modsFolder))
                {
                    Directory.CreateDirectory(modsFolder);
                }

                Copy("Library/ScriptAssemblies/" + modName + ".dll", modsFolder + "/" + modName + ".dll");
                Copy("Library/ScriptAssemblies/" + modName + ".pdb", modsFolder + "/" + modName + ".pdb");

                //copy res
                string modResFolder = modsFolder;

                string dataAsset = Application.dataPath;
                int    index     = dataAsset.ToLower().IndexOf(PATH_TO_ASSETS);
                dataAsset = dataAsset.Remove(index, PATH_TO_ASSETS.Length);

                var resPath = dataAsset + "/Temp/ModBuild/" + modName + "_resources";
                if (File.Exists(resPath))
                {
                    Copy(resPath, modResFolder + "/" + modName + "_resources");
                }
                Copy("Library/ScriptAssemblies/" + modName + ".dll", "Temp/ModBuild/" + modName + ".dll");
                Copy("Library/ScriptAssemblies/" + modName + ".pdb", "Temp/ModBuild/" + modName + ".pdb");


                EditorUtility.RevealInFinder(modsFolder + "/" + modName + ".dll");

                AssetViewerDB.Load();
            }
        }

        GUILayout.Space(50);

        GUILayout.Label("Publish Settings", EditorStyles.boldLabel);

        if (steam.IsSign())
        {
            EditorGUILayout.LabelField("App Id", steam.GetAppId().ToString());

            if (_modIndex < 0)
            {
                for (int i = 0; i != _modList.Count; ++i)
                {
                    if (GUILayout.Button("Open Mod Item(" + _modList[i].m_rgchTitle + ")"))
                    {
                        _modIndex = i;
                    }
                }

                if (GUILayout.Button("Create New Mod Item"))
                {
                    SteamAPICall_t handle = SteamUGC.CreateItem(SteamUtils.GetAppID(), EWorkshopFileType.k_EWorkshopFileTypeCommunity);
                    OnCreateItemResultCallResult.Set(handle);
                }
            }
            else
            {
                SteamUGCDetails_t details = _modList[_modIndex]; //copy temp
                EditorGUILayout.LabelField("Mod Id", details.m_nPublishedFileId.ToString());
                details.m_rgchTitle       = EditorGUILayout.TextField("Title", details.m_rgchTitle);
                details.m_rgchDescription = EditorGUILayout.TextField("Description", details.m_rgchDescription);
                details.m_eVisibility     = (ERemoteStoragePublishedFileVisibility)EditorGUILayout.EnumPopup(details.m_eVisibility);
                _modList[_modIndex]       = details; //assign

                if (GUILayout.Button("Upload details"))
                {
                    var handle = SteamUGC.StartItemUpdate(SteamUtils.GetAppID(), details.m_nPublishedFileId);
                    SteamUGC.SetItemTitle(handle, details.m_rgchTitle);
                    SteamUGC.SetItemDescription(handle, details.m_rgchDescription);
                    SteamUGC.SetItemVisibility(handle, details.m_eVisibility);
                    SteamAPICall_t callHandle = SteamUGC.SubmitItemUpdate(handle, "");
                    OnSubmitItemUpdateResultCallResult.Set(callHandle);
                }

                GUILayout.Space(20);

                EditorGUILayout.HelpBox("Select and upload preview image to Steam", MessageType.Info);

                if (GUILayout.Button("Upload preview image"))
                {
                    var handle = SteamUGC.StartItemUpdate(SteamUtils.GetAppID(), details.m_nPublishedFileId);
                    SteamUGC.SetItemPreview(handle, EditorUtility.OpenFilePanel("Preview mod image", "", "png"));
                    SteamAPICall_t callHandle = SteamUGC.SubmitItemUpdate(handle, "");
                    OnSubmitItemUpdateResultCallResult.Set(callHandle);
                }

                GUILayout.Space(20);

                EditorGUILayout.HelpBox("Upload pre built mod content to Steam", MessageType.Info);

                if (GUILayout.Button("Upload content"))
                {
                    var handle = SteamUGC.StartItemUpdate(SteamUtils.GetAppID(), details.m_nPublishedFileId);

                    string dataAsset = Application.dataPath;
                    int    index     = dataAsset.ToLower().IndexOf(PATH_TO_ASSETS);
                    dataAsset = dataAsset.Remove(index, PATH_TO_ASSETS.Length);

                    string modsFolder = dataAsset + "/" + PATH_BUILD_BUNDLE;

                    SteamUGC.SetItemContent(handle, modsFolder);
                    SteamAPICall_t callHandle = SteamUGC.SubmitItemUpdate(handle, "");
                    OnSubmitItemUpdateResultCallResult.Set(callHandle);
                }
            }
        }
        else
        {
            EditorGUILayout.HelpBox("Attach to Steam account", MessageType.Warning);

            if (GUILayout.Button("Attach"))
            {
                RequestInfo();
            }
        }
    }
예제 #3
0
    private void OnGUI()
    {
        GUISkin lastSkin = GUI.skin;

        if (guiSkin != null)
        {
            GUI.skin = guiSkin;
        }

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();


        if (gamedir.Length > 0)
        {
            if (GUILayout.Button(
                    new GUIContent("[X]", "Clear path"),
                    lastSkin.button, GUILayout.Width(30)))
            {
                if (EditorUtility.DisplayDialog("Clear current path to the StreamingAssets", "Are you sure you want clear current path to the StreamingAssets? ", "Yes", "Cancel"))
                {
                    gamedir = "";
                    PlayerPrefs.SetString("GAME_CONTENT_DIR", gamedir);
                }
            }

            EditorGUILayout.LabelField("Path to StreamingAssets", gamedir);
        }
        else
        {
            EditorGUILayout.LabelField("Path to StreamingAssets", gamedir);

            if (GUILayout.Button(
                    new GUIContent("...", "Setup game path to StreamingAssets"),
                    lastSkin.button))
            {
                gamedir = EditorUtility.OpenFolderPanel("StreamingAssets path", gamedir, "");
                PlayerPrefs.SetString("GAME_CONTENT_DIR", gamedir);

                AssetViewerDB.Load();
                guiSkin  = (GUISkin)Resources.Load("AssetViewer");
                GUI.skin = guiSkin;
            }
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();

        if (GUI.Button(EditorGUILayout.GetControlRect(false),
                       new GUIContent("Reload", "Reload assets from source bundle"),
                       lastSkin.button))
        {
            AssetViewerDB.Load();
            guiSkin  = (GUISkin)Resources.Load("AssetViewer");
            GUI.skin = guiSkin;
        }

        searchText = EditorGUILayout.TextField(searchText);

        if (categoryNames?.Length > 0)
        {
            selectedCategoryIdx = EditorGUILayout.Popup(selectedCategoryIdx, categoryNames);
        }

        EditorGUILayout.EndHorizontal();

        GUI.Box(actualCanvas, "", "scrollview");

        scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

        Rect scrollRect = new Rect(scrollPosition.x, scrollPosition.y, position.width, position.height);

        EditorGUILayout.BeginHorizontal();

        Rect lastRect = new Rect(0, 0, ITEM_WIDTH, ITEM_HEIGHT);

        int hCount    = -1;
        int hCountMax = Mathf.FloorToInt(scrollRect.width / ITEM_WIDTH);

        foreach (var loadedAsset in AssetViewerDB.LoadedAssets)
        {
            var asset = loadedAsset.Asset;

            if (asset == null)
            {
                continue;
            }
            var assetName = loadedAsset.AssetName;

            // Name filter
            if (!string.IsNullOrWhiteSpace(searchText) && !asset.name.ToLower().Contains(searchText.ToLower()))
            {
                continue;
            }

            // Category filter
            if (selectedCategoryIdx > 0 && loadedAsset.AssetCategory != categoryNames[selectedCategoryIdx])
            {
                continue;
            }

            bool isVirtual = false;

            if (++hCount == hCountMax)
            {
                EditorGUILayout.EndHorizontal();
                lastRect.y += ITEM_HEIGHT;
                lastRect.x  = 0;
                isVirtual   = !scrollRect.Overlaps(lastRect);
                if (isVirtual)
                {
                    GUILayout.Space(ITEM_HEIGHT);
                }
                EditorGUILayout.BeginHorizontal();
                hCount = 0;
            }
            else
            {
                lastRect.x += ITEM_HEIGHT;
                isVirtual   = !scrollRect.Overlaps(lastRect);
                if (isVirtual)
                {
                    GUILayout.Space(ITEM_WIDTH);
                }
            }

            if (isVirtual)
            {
                continue;
            }

            Texture2D t = GetThumbnail(asset);

            GUILayout.Box(new GUIContent(asset.name, t, assetName), GUILayout.Height(80), GUILayout.Width(100));

            HandleAssetEvents(asset, assetName);
        }

        if (hCount != hCountMax)
        {
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndScrollView();
        GUI.skin = lastSkin;
    }