Exemplo n.º 1
0
    private void SaveActor()
    {
        editMain.AddDebugMessage("Saving " + actor.GetDisplayName());
        Texture2D thumbnail = snapshotCamera.SnapshotActor(actor);

        if (sceneActorLibrary.Exists(actor.GetDisplayName()))
        {
            // TODO: Confirm overwrite?
        }
        sceneActorLibrary.Put(actor.GetDisplayName(), actor, thumbnail);
#if UNITY_EDITOR
        // Ctrl + Alt + click also copies the actor to clipboard for easy (and hacky) exporting.
        if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
        {
            GUIUtility.systemCopyBuffer = sceneActorLibrary.ExportToJson(actor, thumbnail);
            editMain.AddDebugMessage("Also saved TO CLIPBOARD as prefab (DEBUG)");
        }
#endif

        Sprite _sprite = Sprite.Create(thumbnail, new Rect(0, 0, thumbnail.width, thumbnail.height), new Vector2(.5f, .5f), 100);
        Instantiate(snapshotPopupPrefab, editMain.GetMainRect()).GetComponent <Popup>().Setup(_sprite, POPUP_DURATION);

        // TODO: put this back
        // creationLibrary.OnSaveActorPrefab(prefab);
    }
Exemplo n.º 2
0
    protected override void DoImport(WorkshopItem item)
    {
        Dictionary <string, SavedActorPrefab> prefabs = SceneActorLibrary.ReadPrefabsFromDir(item.InstalledLocalFolder, item);
        bool containsOverrides = false;

        foreach (var entry in prefabs)
        {
            if (sceneActorLibrary.Exists(entry.Key))
            {
                containsOverrides = true;
            }
        }
        if (containsOverrides)
        {
            popups.ShowThreeButtons(
                "This actor already exists in your library.",
                "Overwrite", () =>
            {
                sceneActorLibrary.PutPrefabs(prefabs, true);
                popups.Show(
                    $"{item.Name} was successfully imported. Check your custom actors!",
                    "Ok"
                    );
            },
                "Duplicate", () =>
            {
                sceneActorLibrary.PutPrefabs(prefabs);
                popups.Show(
                    $"{item.Name} was successfully imported. Check your custom actors!",
                    "Ok"
                    );
            },
                "Cancel", () => { });
        }
        else
        {
            sceneActorLibrary.PutPrefabs(prefabs);
            popups.Show(
                $"{item.Name} was successfully imported. Check your custom actors!",
                "Ok"
                );
        }
    }
Exemplo n.º 3
0
    public override void Setup(SidebarManager _sidebarManager)
    {
        base.Setup(_sidebarManager);
        Util.FindIfNotSet(this, ref editMain);
        Util.FindIfNotSet(this, ref userMain);
        Util.FindIfNotSet(this, ref assetSearch);
        Util.FindIfNotSet(this, ref sceneActorLibrary);
        Util.FindIfNotSet(this, ref popups);

        ShouldShowInternalResult = (result) => { return(false); };
        lastResult = assetSearch.GetBuiltInSearchResult("Forest/Slime");

        creationLibraryUI.searchInput.onEndEdit.AddListener(OnInputFieldEnd);
        creationLibraryUI.clearSearchButton.onClick.AddListener(ClearSearch);
        sceneActorLibrary.onActorPut    += OnActorPut;
        sceneActorLibrary.onActorDelete += OnActorDelete;

        assetSearch.AddPrefabsProcessor((searchResult) => OnResult(searchResult, true));


        List <Util.Tuple <string, Texture2D> > allCategories = new List <Util.Tuple <string, Texture2D> >();

        allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_ALL, allCategoryIcon));
        foreach (CategoryButton category in dynamicCategories)
        {
            allCategories.Add(new Util.Tuple <string, Texture2D>(category.displayName, category.icon));
        }
        allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_DECORATIONS, decorationCategoryIcon));
        allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_CUSTOM, savedCategoryIcon));

        //NO_POLY_TOOLKIT_INTERNAL_CHECK
        if (!PolyToolkitInternal.PtSettings.Instance.authConfig.apiKey.Contains("INSERT YOUR"))
        {
            allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_POLY, polyCategoryIcon));
        }
        if (GisSearchManager.APIkey != "PUT YOUR KEY HERE")
        {
            allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_GIS, gisCategoryIcon));
        }

        allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_PARTICLES, particlesCategoryIcon));
        allCategories.Add(new Util.Tuple <string, Texture2D>(CATEGORY_SOUNDS, soundsCategoryIcon));

        foreach (Util.Tuple <string, Texture2D> categoryTuple in allCategories)
        {
            string           category       = categoryTuple.first;
            Texture2D        texture        = categoryTuple.second;
            TextIconButtonUI categoryButton = Instantiate(
                creationLibraryUI.categoryButtonPrefab, creationLibraryUI.categoriesList.transform);
            categoryButton.text.text   = category;
            categoryButton.icon.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
            categoryButton.button.onClick.AddListener(() =>
            {
                selectedCategory = category;
                UpdateAll();
            });
            if (category == CATEGORY_CHALLENGE)
            {
                categoryButton.medallion.gameObject.SetActive(true);
            }
            categoryButton.gameObject.SetActive(true);
        }

        creationLibraryUI.inCategoryBackButton.onClick.AddListener(() =>
        {
            selectedCategory = null;
            ClearSearch(); //includes update all
            // UpdateAll();
        });

        particleLibrary.Setup();
        particleLibrary.onParticleEffectSelected += OnParticleEffectSelected;
        soundLibrary.onSoundSelected             += OnSoundEffectSelected;
        soundLibrary.Setup();

        creationLibraryUI.inCategoryLink.onClick.AddListener(() =>
        {
            Application.OpenURL(challengeCategoryUrl);
        });

#if USE_STEAMWORKS
        actorPrefabUploadDialog = Instantiate(actorPrefabUploadDialogPrefab);
        actorPrefabUploadDialog.Setup();
        actorPrefabWorkshopMenu = Instantiate(actorPrefabWorkshopMenuPrefab);
        actorPrefabWorkshopMenu.Setup();
#endif

        creationLibraryUI.exportDropdownMenu.onOptionClicked += (value) =>
        {
            SquareImageButtonUI exportResult = selectedResult;
            Debug.Assert(selectedResult != null);
            ActorPrefab prefab = exportResult.GetSearchResult().actorPrefab;
            Debug.Assert(sceneActorLibrary.Exists(prefab?.GetId()));

            if (value == EXPORT_TO_DISK)
            {
                ExportToDisk(prefab);
            }
#if USE_STEAMWORKS
            else if (value == UPDATE_WORKSHOP_PREFAB)
            {
                ulong?id = GetWorkshopIdForActor(prefab);
                actorPrefabUploadDialog.Open(prefab, Util.Maybe <ulong> .CreateWith(id.Value));
            }
            else
            {
                actorPrefabUploadDialog.Open(prefab, Util.Maybe <ulong> .CreateEmpty());
            }
#endif
        };

#if USE_STEAMWORKS
        creationLibraryUI.importDropdownMenu.SetOptions(new List <string>()
        {
            IMPORT_FROM_DISK, IMPORT_FROM_WORKSHOP
        });
#else
        creationLibraryUI.importCustomButton.onClick.AddListener(ImportFromDisk);
#endif

        creationLibraryUI.importDropdownMenu.onOptionClicked += (value) =>
        {
            if (value == IMPORT_FROM_DISK)
            {
                ImportFromDisk();
            }
            else
            {
                actorPrefabWorkshopMenu.Open();
            }
        };

        pfxActorTemplate = assetSearch.GetBuiltInSearchResult("Empty");
        sfxActorTemplate = assetSearch.GetBuiltInSearchResult("Sound");
    }