コード例 #1
0
    public PEERbotPalette LoadJSONPalette(PEERbotPalette palette, string path)
    {
        //Try to load the CSV first
        string encodedString = "";

        try{
            StreamReader reader = new StreamReader(path);
            encodedString = reader.ReadToEnd();//.ToLower();
            reader.Close();
        } catch (Exception e) {
            Debug.LogWarning("Failed to load JSON: " + path); return(palette);
        }

        //overwrite the palette if it exists
        PEERbotPaletteData paletteData = JsonUtility.FromJson <PEERbotPaletteData>(encodedString);

        palette.title = paletteData.title;

        //Create new buttons from newPalette template
        foreach (PEERbotButtonData buttonData in paletteData.buttons)
        {
            PEERbotButton buttonClone = pc.newButton();
            buttonClone.data = JsonUtility.FromJson <PEERbotButtonDataFull>(JsonUtility.ToJson(buttonData));
            pc.selectButton(buttonClone);
        }

        //Select the newly creatde palette
        pc.selectPalette(palette);
        //If successfully loaded, set the new path
        setHomePath(getPalettePathFolder(path));
        //Return the result
        return(palette);
    }
コード例 #2
0
ファイル: PEERbotButton.cs プロジェクト: sbeleidy/PEERbots
 public void setButtonToTemplate(PEERbotButton template)
 {
     if (template == null)
     {
         Debug.LogWarning("Template is null! Cannot set button."); return;
     }
     JsonUtility.FromJsonOverwrite(JsonUtility.ToJson(template), this);
 }
コード例 #3
0
 public void sendMessage(PEERbotButton button)
 {
     if (button == null)
     {
         Debug.LogWarning("Button is null! Cannot send button."); return;
     }
     sendMessage(button.data);
 }
コード例 #4
0
 public void deleteButton(PEERbotButton button)
 {
     if (button == null)
     {
         Debug.LogWarning("No button selected! Cannot delete button."); return;
     }
     //No button selected.
     currentPalette.buttons.Remove(button);
     Destroy(button.gameObject);
     button = null;
     //saveloader.SaveCurrentCSVPalette(); //Quick save
 }
コード例 #5
0
    public void copyButton()
    {
        if (currentButton == null)
        {
            Debug.LogWarning("No button selected! Cannot copy button."); return;
        }
        PEERbotButton prevButton = currentButton;
        PEERbotButton button     = newButton();

        button.setButtonToTemplate(prevButton);
        selectButton(button);
        //saveloader.SaveCurrentCSVPalette(); //Quick save
    }
コード例 #6
0
    public void selectButton(PEERbotButton button)
    {
        //Save a copy of the current button
        revertButton.setButtonToTemplate(button);

        //Show/hide outlines
        if (currentButton != null)
        {
            currentButton.gameObject.transform.Find("SelectedOutline").gameObject.SetActive(false);
        }
        if (button != null)
        {
            button.gameObject.transform.Find("SelectedOutline").gameObject.SetActive(true);
        }

        currentButton = button;
        editorUI.setUItoButton(button);
    }
コード例 #7
0
    public PEERbotButton newButton()
    {
        //Game Object Vars
        GameObject newButtonObject = Instantiate(buttonCopy, Vector3.zero, Quaternion.identity);

        newButtonObject.transform.SetParent(buttonCopy.transform.parent, true);
        newButtonObject.transform.localScale = new Vector3(1, 1, 1);
        newButtonObject.name = "Button" + (int)Random.Range(0, 1000);
        newButtonObject.SetActive(true);
        //Button vars
        PEERbotButton newButton = newButtonObject.GetComponent <PEERbotButton>();

        if (newButton == null)
        {
            Debug.LogError("Button script on ButtonCopy not found. PaletteCopy must have Palette script attached!"); return(null);
        }
        //Create a random button title
        //newButton.data.title = newButtonObject.name;
        //Add New Button to current palettes
        currentPalette.buttons.Add(newButton);
        selectButton(newButton);
        return(newButton);
    }
コード例 #8
0
    ///*************************************************///
    ///***************BUTTON UI FUNCTIONS***************///
    ///*************************************************///

    //This is for all buttons
    public void setUItoButton(PEERbotButton button)
    {
        //Null button. Reset UI:
        if (button == null)  //Debug.Log("Deselected Button!");
        //Button
        {
            if (buttonTitle)
            {
                buttonTitle.text = "";
            }
            if (buttonColor)
            {
                buttonColor.value = 0;
            }
            //Speech
            if (speechField)
            {
                speechField.text = "";
            }
            if (rateSlider)
            {
                rateSlider.value = 1;
            }
            if (pitchSlider)
            {
                pitchSlider.value = 1;
            }
            if (volumeSlider)
            {
                volumeSlider.value = 1;
            }
            //Gaze
            if (gazeXSlider)
            {
                gazeXSlider.value = 0;
            }
            if (gazeYSlider)
            {
                gazeYSlider.value = 0;
            }
            //Emotion
            if (emotionDropdown)
            {
                emotionDropdown.value = 0;
            }
        }
        //Set UI to button:
        else   //Debug.Log("Selected Button!");
               //Speech
        {
            setSpeech(button.data.speech);
            setSpeechVolume(volumeSlider.value); //We don't want this to change when selecting a button
            setSpeechPitch(pitchSlider.value);   //We don't want this to change when selecting a button
            setSpeechRate(rateSlider.value);     //We don't want this to change when selecting a button
            //Gaze
            setGazeX(gazeXSlider.value);         //We don't want this to change when selecting a button
            setGazeY(gazeYSlider.value);         //We don't want this to change when selecting a button
            //Emotion
            setEmotion(button.data.emotion);
            //Goal/subgoal/proficiency
            setButtonGoal(button.data.goal);
            setButtonSubgoal(buttonGoal.value, button.data.subgoal);
            setButtonProficiency(button.data.proficiency);
            //Button (must happen last to not overwrite speech)
            setButtonTitle(button.data.title);
            setButtonColor(button.data.color);
        }
    }
コード例 #9
0
    public PEERbotPalette LoadCSVPaletteFromEncodedString(PEERbotPalette palette, string encodedString, string filename)
    {
        //Try to load the CSV first
        string[][] table;
        try{
            table = CsvParser2.Parse(encodedString);
        } catch (Exception e) {
            Debug.LogWarning("Failed to load malformed CSV: " + filename); return(palette);
        }
        //check and make sure there is content if parsed correctly
        if (table.Length == 0)
        {
            Debug.LogWarning("No rows, empty file: " + filename); return(palette);
        }
        else if (table[0].Length == 0)
        {
            Debug.LogWarning("No cols, empty file: " + filename); return(palette);
        }
        //Get rows/cols of table
        int rows = table.Length;
        int cols = table[0].Length;
        //Get a list of all the fields in the CSV
        List <string> fields = new List <string>();

        for (int j = 0; j < cols; j++)
        {
            //try to automap to known palette format(s) for backwards compatibility
            //Debug.Log("Before: " + table[0][j]);
            if (table[0][j] == "TITLE(text)")
            {
                table[0][j] = "title";
            }
            if (table[0][j] == "COLOR(0-7)")
            {
                table[0][j] = "color";
            }
            if (table[0][j] == "EMOTION(0-7)")
            {
                table[0][j] = "emotion";
            }
            if (table[0][j] == "SPEECH(text)")
            {
                table[0][j] = "speech";
            }
            if (table[0][j] == "RATE(0.0-3.0)")
            {
                table[0][j] = "rate";
            }
            if (table[0][j] == "PITCH(0.0-2.0)")
            {
                table[0][j] = "pitch";
            }
            if (table[0][j] == "GOAL(text)")
            {
                table[0][j] = "goal";
            }
            if (table[0][j] == "SUBGOAL(text)")
            {
                table[0][j] = "subgoal";
            }
            if (table[0][j] == "PROFICIENCY(text)")
            {
                table[0][j] = "proficiency";
            }
            //Debug.Log("After: " + table[0][j]);
            //Add to the list of fields
            fields.Add("\"" + table[0][j] + "\"");
        }
        //Load every button from every row in CSV
        for (int i = 1; i < rows; i++)
        {
            string json = "{ ";
            for (int j = 0; j < cols; j++)
            {
                json += fields[j] + ":" + "\"" + table[i][j] + "\"";
                json += (j != cols - 1) ? ", " : "}";
            }
            //Debug.Log(json);
            PEERbotButton newButton = pc.newButton();
            JsonUtility.FromJsonOverwrite(json, newButton.data);
            pc.selectButton(newButton);
        }
        //Fill the title and path
        palette.title = filename;
        //Select the newly created palette
        pc.selectPalette(palette);
        //Convert to JSON
        //SaveCurrentJSONPalette();
        //Return the result
        return(palette);
    }