Beispiel #1
0
 void AddNewCard(string category)
 {
     // Close();
     BehaviorCards.CardMetadata md = BehaviorCards.CardMetadata.DefaultCardMetadata;
     md.cardSystemCardData.categories = new string[] { category };
     string             metadataJson = JsonUtility.ToJson(md);
     UnassignedBehavior newBehavior  = behaviorSystem.CreateNewBehavior(
         BehaviorCards.GetDefaultCodeForCategory(category), metadataJson);
     // onCodeRequest(newBehavior.GetId());
 }
    private void ReloadCard(string path)
    {
        string metaPath = path + ".metaJson";

        if (!File.Exists(metaPath))
        {
            Complain($"Can't load card from {path} because there is no corresponding .metaJson file.");
            return;
        }
        string jsContents   = File.ReadAllText(path);
        string metaContents = File.ReadAllText(metaPath);

        BehaviorCards.CardMetadata cardMeta = JsonUtility.FromJson <BehaviorCards.CardMetadata>(metaContents);
        string providedId = cardMeta.cardSystemCardData.userProvidedId;

        if (!string.IsNullOrEmpty(cardMeta.cardSystemCardData.imageResourcePath) &&
            !cardMeta.cardSystemCardData.imageResourcePath.StartsWith("icon:") &&
            !cardMeta.cardSystemCardData.imageResourcePath.StartsWith("BuiltinAssets")
            )
        {
            Complain($"Error loading {path}: metaJson file has invalid format for imageResourcePath field.");
            return;
        }
        if (string.IsNullOrEmpty(providedId))
        {
            Complain($"Error loading {path}: metaJson file is missing userProvidedId field.");
            return;
        }
        providedId = providedId.ToLowerInvariant();
        if (!BehaviorSystem.IsGuid(providedId))
        {
            Complain($"Error loading {path}: userProvidedId must be a valid GUID (32 hex digits).");
            return;
        }
        Debug.Log($"Hot-loading card from {path} -> {providedId}");
        Behavior behavior = new Behavior
        {
            label        = "Hotloaded",
            javascript   = jsContents,
            metadataJson = metaContents
        };

        loadedCardGuids.Add(providedId);
        behaviorSystem.PutBehavior(providedId, behavior);
    }