コード例 #1
0
    private void OnWorkshopAssetLoaded(SoundEffect sfx, Util.Maybe <string> result)
    {
        if (result.IsEmpty())
        {
            Debug.LogErrorFormat("Failed to load SFX {0} ({1}) from steam workshop {2}: {3}",
                                 sfx.id, sfx.name, sfx.content.steamWorkshopId, result.GetErrorMessage() ?? "(no error message)");
            // TODO: Retry? Warn user?
            return;
        }
        string directory   = result.Value;
        string wavFilePath = Path.Combine(directory, "audio.wav");
        string oggFilePath = Path.Combine(directory, "audio.ogg");

        if (File.Exists(wavFilePath))
        {
            StartCoroutine(LoadAudioClip(sfx, wavFilePath, AudioType.WAV));
        }
        else if (File.Exists(oggFilePath))
        {
            StartCoroutine(LoadAudioClip(sfx, oggFilePath, AudioType.OGGVORBIS));
        }
        else
        {
            Debug.LogError($"Could not find WAV or OGG file inside {directory}");
        }
    }
コード例 #2
0
    public Util.Maybe <TReturn> CallBehaviorUseMethod <TArgs, TReturn>(string useId, string actorId, string methodName, TArgs args)
    {
        using (Util.Profile("CallBehaviorUseMethod"))
        {
            var request = new CallBehaviorUseMethodRequest <TArgs>
            {
                actorId    = actorId,
                useId      = useId,
                methodName = methodName,
                args       = args
            };

            Util.Maybe <CallBehaviorUseMethodResponse <TReturn> > response =
                voosEngine.CommunicateWithAgent <CallBehaviorUseMethodRequest <TArgs>, CallBehaviorUseMethodResponse <TReturn> >(request);

            if (response.IsEmpty())
            {
                return(Util.Maybe <TReturn> .CreateEmpty());
            }
            else
            {
                return(Util.Maybe <TReturn> .CreateWith(response.Get().returnValue));
            }
        }
    }
コード例 #3
0
 void GetWorkshopHandler(Util.Maybe <WorkshopItem> maybeItem, System.Action <Util.Maybe <string> > onComplete, System.Action <float> onProgress, System.Action <WorkshopItem> handleItem)
 {
     if (maybeItem.IsEmpty())
     {
         onComplete(Util.Maybe <string> .CreateError(maybeItem.GetErrorMessage()));
     }
     else
     {
         var item = maybeItem.Value;
         if (!item.IsInstalled)
         {
             // The only way we know how to install something is to subscribe to it..
             SteamWorkshopMain.Instance.Subscribe(item, args =>
             {
                 handleItem?.Invoke(item);
                 StartCoroutine(DownloadRoutine(item, onComplete, onProgress));
             });
         }
         else
         {
             Debug.Assert(item.InstalledLocalFolder != null, $"Workshop item was IsInstalled but LocalFolder was null?");
             onComplete(Util.Maybe <string> .CreateWith(maybeItem.Value.InstalledLocalFolder));
         }
     }
 }
コード例 #4
0
 private void FetchCardStatus()
 {
     lastCardStatus = new RuntimeCardStatus();
     if (IsAssignmentValid())
     {
         Util.Maybe <RuntimeCardStatus> maybeStatus = this.assignment.GetAssignedBehavior().
                                                      CallScriptFunction <int, RuntimeCardStatus>("getCardStatus", 0);
         if (!maybeStatus.IsEmpty())
         {
             lastCardStatus = maybeStatus.Get();
         }
     }
     else
     {
         lastCardStatus = new RuntimeCardStatus();
     }
     // Fill in with defaults for nulls or empty strings:
     lastCardStatus.title       = string.IsNullOrEmpty(lastCardStatus.title) ? card.GetTitle() : lastCardStatus.title;
     lastCardStatus.description = string.IsNullOrEmpty(lastCardStatus.description) ? card.GetDescription() : lastCardStatus.description;
     lastCardStatus.debugText   = string.IsNullOrEmpty(lastCardStatus.debugText) ? "(No debug text)" : lastCardStatus.debugText;
     // For the error message, if there is a legacy getCardErrorMessage function in the card, use it:
     if (string.IsNullOrEmpty(lastCardStatus.errorMessage))
     {
         lastCardStatus.errorMessage = GetCardErrorMessage_LEGACY() ?? "";
     }
 }
コード例 #5
0
 private void OnFinishSelectionForWorkshop(IEnumerable <string> result, Util.Maybe <ulong> workshopId)
 {
     if (result.Count() == 0)
     {
         return;
     }
     uploadDialog.Open(result, workshopId);
 }
コード例 #6
0
 public void Open(IEnumerable <string> pack, Util.Maybe <ulong> workshopId)
 {
     Open(workshopId);
     this.pack = pack;
     if (!workshopId.IsEmpty())
     {
         BehaviorSystem.SavedCardPack existingPack = behaviorSystem.GetCardPack(workshopId.Get());
         nameField.text = existingPack.workshopName;
         descField.text = existingPack.workshopDesc;
     }
 }
コード例 #7
0
    void OnUploadComplete(string name, Util.Maybe <ulong> maybeId, string id)
    {
        if (maybeId.IsEmpty())
        {
            popups.Show("Error uploading file to Steam Workshop:\n" + maybeId.GetErrorMessage(), "OK", () => { });
            DestroyImportFeedback(id);
            return;
        }

        terrainManager.AddCustomStyle(maybeId.Value, () => DestroyImportFeedback(id));
    }
コード例 #8
0
 protected void Open(Util.Maybe <ulong> workshopId)
 {
     this.workshopId = workshopId;
     nameField.text  = "";
     descField.text  = "";
     nameRequiredText.gameObject.SetActive(false);
     descRequiredText.gameObject.SetActive(false);
     finishedMessage.gameObject.SetActive(false);
     visitButton.gameObject.SetActive(false);
     uploadButton.gameObject.SetActive(true);
     gameObject.SetActive(true);
 }
コード例 #9
0
    void OnWorkshopUploadComplete(Util.Maybe <ulong> result)
    {
        pleaseWait.SetActive(false);
        if (result.IsEmpty())
        {
            // Error.
            popups.Show("Failed to upload image to Steam Workshop. " + result.GetErrorMessage(), "OK", () => { });
            return;
        }
        popups.Show("Image uploaded successfully.", "OK", () => { });
        LoadPreviewImage("sw:" + result.Get());
        ulong steamWorkshopId = result.Get();

        // Import image into the Image System and get its ID.
        currentImageId = imageSystem.ImportImageFromUrl("sw:" + steamWorkshopId);
    }
コード例 #10
0
 private void OnUploadComplete(string name, string desc, Util.Maybe <ulong> result)
 {
     uploadProgressGetter = null;
     if (result.GetErrorMessage() != null)
     {
         finishedMessage.text = result.GetErrorMessage();
     }
     else
     {
         string url = $"https://steamcommunity.com/sharedfiles/filedetails/?id={result.Get()}";
         finishedMessage.text = "Finished uploading! (Note: takes about 15 minutes to show up for other players)";
         visitButton.onClick.AddListener(() => Application.OpenURL(url));
         visitButton.gameObject.SetActive(true);
         OnUploadSuccess(result.Get());
     }
 }
コード例 #11
0
    void OnWorkshopFetchComplete(string url, Util.Maybe <string> workshopResult)
    {
        PendingRequest request;

        if (!pendingRequests.TryGetValue(url, out request))
        {
            // Definitely weird, but not fatal.
            Debug.LogError("Fetched workshop image has no corresponding request: " + url);
            return;
        }
        pendingRequests.Remove(url);
        if (workshopResult.IsEmpty())
        {
            // Failed.
            Debug.LogError("Failed to fetch image from Steam Workshop URL " + url +
                           ". Error: " + workshopResult.GetErrorMessage());
            SetColorsAndTexture(request.targetImages, Color.magenta);
            CallCallbacks(request.callbacks, url, false);
            return;
        }
        string directory   = workshopResult.Get();
        string pngFilePath = Path.Combine(directory, "image.png");
        string jpgFilePath = Path.Combine(directory, "image.jpg");
        string filePath    = File.Exists(pngFilePath) ? pngFilePath : File.Exists(jpgFilePath) ? jpgFilePath : null;

        if (filePath == null)
        {
            Debug.LogError("Steam workshop image has no image.png or image.jpg in it: " + url);
            SetColorsAndTexture(request.targetImages, Color.yellow);
            CallCallbacks(request.callbacks, url, false);
            return;
        }
        Texture2D tex = Util.ReadPngToTexture(filePath);

        if (tex == null)
        {
            Debug.LogError("Failed to convert steam workshop image to texture: " + url);
            SetColorsAndTexture(request.targetImages, Color.red);
            CallCallbacks(request.callbacks, url, false);
            return;
        }

        loadedTextures[url] = tex;
        SetColorsAndTexture(request.targetImages, Color.white, tex);
        CallCallbacks(request.callbacks, url, true);
    }
コード例 #12
0
    void OnSoundUploadComplete(string name, Util.Maybe <ulong> result, string id)
    {
        Util.Tuple <ProgressItemUI, WorkshopAssetSource.GetUploadProgress> tuple = importingListItems[id];
        importingListItems.Remove(id);
        Destroy(tuple.first.gameObject);

        if (result.IsEmpty())
        {
            popups.Show("Error uploading sound to Steam Workshop:\n" + result.GetErrorMessage(), "OK", () => { });
            return;
        }
        SoundEffect soundEffect = new SoundEffect(
            id, name, SoundEffectContent.NewWithSteamWorkshopId(result.Value));

        soundEffectSystem.PutSoundEffect(soundEffect);
        // TODO: maybe immediately open the just-created sound effect?
    }
コード例 #13
0
    public void Open(ActorPrefab actorPrefab, Util.Maybe <ulong> workshopId)
    {
        Open(workshopId);

        SceneActorLibrary.SavedActorPacks actorPacks = sceneActorLibrary.GetActorPacks();
        this.actorPrefab       = actorPrefab;
        thumbnailImage.texture = actorPrefab.GetThumbnail();

        if (!workshopId.IsEmpty())
        {
            SceneActorLibrary.SavedActorPack existingPack = sceneActorLibrary.GetActorPack(workshopId.Get());
            nameField.text = existingPack.workshopName;
            descField.text = existingPack.workshopDesc;
        }
        else
        {
            nameField.text = actorPrefab.GetLabel();
            descField.text = actorPrefab.GetDescription();
        }
    }
コード例 #14
0
    public string GetBehaviorPropertiesJson(string behaviorUri)
    {
        var request = new GetBehaviorPropertiesRequest();

        request.behaviorUri = behaviorUri;

        if (!SyncBehaviorIfNeeded(behaviorUri))
        {
            Util.LogError($"GetBehaviorPropertiesJson failed for {behaviorUri} because it did not compile.");
            return(null);
        }

        Util.Maybe <GetBehaviorPropertiesResponse> response = voosEngine.CommunicateWithAgent <GetBehaviorPropertiesRequest, GetBehaviorPropertiesResponse>(request);
        if (response.IsEmpty())
        {
            Util.LogError($"GetBehaviorPropertiesJson failed for behavior URI {behaviorUri}");
            return(null);
        }
        else
        {
            return(response.Get().propsJson);
        }
    }
コード例 #15
0
    // This syncs everything except the behavior sources
    void SyncDatabase()
    {
        if (currentBatchName != null)
        {
            // Wait for end of batch before sync'ing.
            return;
        }

        using (Util.Profile("SyncDatabase"))
        {
            UpdateRequest request = new UpdateRequest();
            request.jsonObject = db.Save();
            Util.Maybe <UpdateResponse> maybeResponse = voosEngine.CommunicateWithAgent <UpdateRequest, UpdateResponse>(request);
            if (maybeResponse.IsEmpty())
            {
                throw new System.Exception("Failed to sync behavior database. Cannot proceed.");
            }

            brainIdsHandlingCollisions.Clear();
            brainIdsHandlingCollisions.AddRange(maybeResponse.Value.brainsHandlingCollisions);
            onBrainsHandlingCollisionsChanged?.Invoke();
        }
    }
コード例 #16
0
 void StartSelection(System.Action <IEnumerable <string> > selectionFinishedCallback, Util.Maybe <ulong> workshopId)
 {
     BehaviorSystem.SavedCardPack pack = null;
     if (!workshopId.IsEmpty())
     {
         pack = behaviorSystem.GetCardPack(workshopId.Get());
     }
     this.selection = new Selection(selectionFinishedCallback);
     cardLibraryUI.selectionModePrompt.SetActive(true);
     foreach (GameObject containerObj in cardContainerObjects)
     {
         StartSelectionForContainerObj(containerObj, pack);
     }
 }