public void Set(UnassignedBehavior target, VoosEngine.BehaviorLogItem?error = null)
    {
        Clear();
        Debug.Assert(target.IsValid(), "Given target was not valid?");

        this.target = target;

        // Use draft code if it's there.
        liveCode = Util.IsNotNullNorEmpty(target.GetDraftCode()) ?
                   target.GetDraftCode().NormalizeLineEndings() :
                   target.GetCode().NormalizeLineEndings();

        lastCompiledCode = target.GetCode().NormalizeLineEndings();

        browser.SetCode(liveCode);

        // Restore scroll pos if this is the same as before
        if (scrollPosByUri.ContainsKey(target.GetBehaviorUri()))
        {
            browser.SetScrollTop(scrollPosByUri[target.GetBehaviorUri()]);
        }

        browser.SetReadOnly(target.IsBehaviorReadOnly());

        if (error.HasValue)
        {
            AddErrorToMonaco(error.Value.lineNum, error.Value.message);
        }
    }
 void UpdateScrollPosPolling()
 {
     if (waitingOnScrollPosPoll)
     {
         return;
     }
     else
     {
         waitingOnScrollPosPoll = true;
         browser.GetScrollTopAsync(value =>
         {
             waitingOnScrollPosPoll = false;
             if (!this.isActiveAndEnabled || this.target == null)
             {
                 return;
             }
             scrollPosByUri[target.GetBehaviorUri()] = (int)value;
         }, () =>
         {
             waitingOnScrollPosPoll = false;
         });
     }
 }
    public void Open(string openCardUri = null, VoosEngine.BehaviorLogItem?error = null)
    {
        gameObject.SetActive(true);

        resourceClaimer.Unclaim();
        isNewCard = false;

        this.error = null;
        // Which card are we editing ?
        if (openCardUri != null && behaviorSystem.IsBehaviorUriValid(openCardUri))
        {
            cardUri    = openCardUri;
            this.error = error;
        }
        else if (cardUri == null || !behaviorSystem.IsBehaviorUriValid(cardUri))
        {
            UnassignedBehavior newBehavior = behaviorSystem.CreateNewBehavior(
                CodeTemplates.MISC, BehaviorCards.GetMiscMetadataJson());
            cardUri   = newBehavior.GetBehaviorUri();
            isNewCard = true;
        }

        resourceClaimer.Claim(UnassignedBehavior.GetClaimResourceId(cardUri), OnClaimStatusChanged);
    }