csharp 注销应用程序用户数据解析脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 注销应用程序用户数据解析脚本相关的知识,希望对你有一定的参考价值。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LitJson;

public class UserData
{
    public string username;
    public string userLang;
    public string characterIndex;
    public string today;
    public string playtime;
    public string questCount;
    public string[] quest;
    public bool[] questResult;
    public string[] completedQuest;
    public string[] failedQuest;
    public string registeredDate;
    public string favoriteGame;
    public GameData[] gameData;
}
public class GameData
{
    public string[] userGameDataString;
}

public class UserDataManager : MonoBehaviour
{
    [Header("References")]
    public AppManager _AppManager;
    [Space(12)]
    [Header("Settings")]
    public float typingSpeed = 0.125f;
    public float printDelay = 1.0f;
    public float printSpeed = 0.8f;
    [Space(16)]
    #region Global Variables
    [Header("Sounds")]
    public AudioSource successSound;
    public AudioSource failedSound;
    public AudioSource typingSound;
    [Space(12)]
    [Header("User Data Manager")]
    public GameObject endingCreditPanel;
    public Text username;
    public RectTransform slash;
    public Text date;
    public Text playtime;
    public Text[] questTitle = new Text[13];
    public GameObject[] ThankyouPanelMessage = new GameObject[2];
    #endregion
    #region Character Functions
    public int currentCharacterId;
    public GameObject[] characterModel = new GameObject[6];
    public GameObject currentCharacterModel = null;
    #endregion
    #region UserData
    private UserData currentUserData = null;
    private List<GameObject> newCompleted = new List<GameObject>();
    #endregion

    #region Debugging Functions
    public void FakeUserDataParser(int _fakeCharacterId, bool isKorean)
    {
        // Generate Fake Ending Credit
        username.text = "Jonghyeon";
        FixSlashPosition();
        date.text = "2019-07-08";
        playtime.text = "15:18 - 19:28(250m)";
        SetQuestNames();
        
        UserCharacterSelector(_fakeCharacterId);

        currentUserData = new UserData();
        currentUserData.quest = new string[13];
        currentUserData.questResult = new bool[13];
        currentUserData.completedQuest = new string[5];
        currentUserData.failedQuest = new string[8];

        // Parse Data into Data Object
        currentUserData.username = "Jonghyeon";
        if (isKorean)
            currentUserData.userLang="kr";
        else
            currentUserData.userLang="en";
        FixSlashPosition();
        currentUserData.characterIndex = _fakeCharacterId.ToString();
        currentUserData.today = "2019-07-08";
        currentUserData.playtime = "15:18 - 19:28(250m)";
        currentUserData.questResult[0] = true;
        currentUserData.questResult[1] = true;
        currentUserData.questResult[2] = false;
        currentUserData.questResult[3] = false;
        currentUserData.questResult[4] = false;
        currentUserData.questResult[5] = true;
        currentUserData.questResult[6] = false;
        currentUserData.questResult[7] = true;
        currentUserData.questResult[8] = false;
        currentUserData.questResult[9] = false;
        currentUserData.questResult[10] = false;
        currentUserData.questResult[11] = true;
        currentUserData.questResult[12] = false;


        int characterUserCharacterIndex = int.Parse(currentUserData.characterIndex);
        currentCharacterId = characterUserCharacterIndex;
        UserCharacterSelector(characterUserCharacterIndex);
        ThankyouPanelMessageLang(currentUserData.userLang);
    }

    #endregion

    #region User Data Parsing Functions
    public void UserDataParser(JSONObject userData)
    {
        Debug.Log(userData);
        Debug.Log("Got User Data");
        currentUserData = new UserData();
        currentUserData.quest = new string[userData["quests"].Count];
        currentUserData.questResult = new bool[userData["questResults"].Count];
        currentUserData.completedQuest = new string[userData["completedQuest"].Count];
        currentUserData.failedQuest = new string[userData["failedQuest"].Count];

        // Parse Data into Data Object
        currentUserData.username = userData["username"].str;
        currentUserData.userLang = userData["userLang"].str;
        FixSlashPosition();
        currentUserData.characterIndex = userData["characterId"].str;
        currentUserData.today = userData["today"].str;
        currentUserData.playtime = userData["playtime"].str;
        for (int i = 0; i < userData["quests"].Count; i++)
        {
            currentUserData.quest[i] = userData["quests"][i].str;
        }
        for (int i = 0; i < userData["questResults"].Count; i++)
        {
            currentUserData.questResult[i] = (bool)userData["questResults"][i].b;
        }
        for (int i = 0; i < userData["completedQuest"].Count; i++)
        {
            currentUserData.completedQuest[i] = userData["completedQuest"][i].str;
        }
        for (int i = 0; i < userData["failedQuest"].Count; i++)
        {
            currentUserData.failedQuest[i] = userData["failedQuest"][i].str;
        }

        int characterUserCharacterIndex = int.Parse(currentUserData.characterIndex);
        currentCharacterId = characterUserCharacterIndex;
        UserCharacterSelector(characterUserCharacterIndex);
        ThankyouPanelMessageLang(currentUserData.userLang);
    }
    public void ThankyouPanelMessageLang(string userLang)
    {
        if (userLang == "en")
        {
            ThankyouPanelMessage[0].SetActive(true);
            ThankyouPanelMessage[1].SetActive(false);
        }
        else
        {
            ThankyouPanelMessage[0].SetActive(false);
            ThankyouPanelMessage[1].SetActive(true);
        }

    }
    public void UserCharacterSelector(int _currentCharacterId)
    {
        Debug.Log("currentCharacter Id: " + _currentCharacterId);
        for (int i = 0; i < characterModel.Length; i++)
        {
            if (i == _currentCharacterId)
            {
                characterModel[i].SetActive(true);
            }
            else
            {
                characterModel[i].SetActive(false);
            }
        }
        currentCharacterModel = characterModel[_currentCharacterId];
        // Do Something with this gameObject.
    }
    public void EndingCreditManager()
    {

            Debug.Log(currentUserData.username + "," + currentUserData.today + "," + currentUserData.playtime);
            username.text = currentUserData.username;
            date.text = currentUserData.today;
            playtime.text = currentUserData.playtime;
            StartCoroutine(PrintQuests(printDelay, printSpeed));



    }
    #endregion
    #region Animation & Helpers
    public void SetQuestNames()
    {
        questTitle[0].text = "[Parallel Me]";
        questTitle[1].text = "[Campfire]";
        questTitle[2].text = "[Pop Tag!]";
        questTitle[3].text = "[The 3rd Supply Base]";
        questTitle[4].text = "[1,000,000/3sec]";
        questTitle[5].text = "[/Quiz Quiz]";
        questTitle[6].text = "[Lorna and Pann]";
        questTitle[7].text = "[Dimension Library]";
        questTitle[8].text = "[Hidden Track]";
        questTitle[9].text = "[Eye Tracking]";
        questTitle[10].text = "[Behind the Game]";
        questTitle[11].text = "[NPC]";
        questTitle[12].text = "[Hidden Message]";
    }
    public void FixSlashPosition()
    {
        float usernameWidth = username.preferredWidth;
        Vector3 slashPos = slash.anchoredPosition;
        slash.anchoredPosition = new Vector3(usernameWidth / 2 - usernameWidth - 30, slashPos.y, slashPos.z);
    }
    public IEnumerator PrintQuests(float _printDelay, float _printSpeed)
    {
        yield return new WaitForSeconds(_printDelay);
        for (int i = 0; i < currentUserData.questResult.Length; i++)
        {
            QuestResultAnim(i);
            yield return new WaitForSeconds(_printSpeed);
        }
        Debug.Log("Quest Printing Done");


    }
    public void QuestResultAnim(int _questIndex)
    {
        if (currentUserData.questResult[_questIndex])
        {
            StartCoroutine(TypeWriting(_questIndex, questTitle[_questIndex], " Completed", true));
        }
        else
        {
            StartCoroutine(TypeWriting(_questIndex, questTitle[_questIndex], " Failed", false));
        }
    }

    public IEnumerator TypeWriting(int _questIndex, Text targetText, string textToAdd, bool isCompleted)
    {
        foreach (char c in textToAdd)
        {
            targetText.text += c;
            yield return new WaitForSeconds(typingSpeed);
        }
        ResultAnimEnd(_questIndex, isCompleted);

    }
    public void ResultAnimEnd(int _questIndex, bool isCompleted)
    {
        // Change Color & Play Sound.
        if (isCompleted)
        {
            GameObject newCompletedText = new GameObject("newCompleted");
            newCompleted.Add(newCompletedText);
            // newCompletedText.tag = "ResultText";
            RectTransform textOrigin = questTitle[_questIndex].gameObject.GetComponent<RectTransform>();
            newCompletedText.transform.SetParent(questTitle[_questIndex].gameObject.transform);
            newCompletedText.AddComponent<Text>();
            newCompletedText.GetComponent<Text>().text = "Completed";
            newCompletedText.GetComponent<Text>().font = questTitle[_questIndex].font;
            newCompletedText.GetComponent<Text>().fontSize = questTitle[_questIndex].fontSize;
            newCompletedText.GetComponent<RectTransform>().anchoredPosition = new Vector2(textOrigin.anchoredPosition.x, textOrigin.anchoredPosition.y);
            newCompletedText.GetComponent<RectTransform>().localPosition = new Vector3(0, 0, 0);
            newCompletedText.GetComponent<RectTransform>().eulerAngles = textOrigin.eulerAngles;
            newCompletedText.GetComponent<RectTransform>().sizeDelta = textOrigin.sizeDelta;
            newCompletedText.GetComponent<RectTransform>().localScale = textOrigin.localScale;
            newCompletedText.GetComponent<Text>().color = new Color32(32, 166, 220, 255);
            // newCompletedText.AddComponent<Shadow>();
            newCompletedText.AddComponent<Outline>().effectColor = new Color32(32, 166, 220, 255);
            newCompletedText.GetComponent<Outline>().effectDistance = new Vector2(0.1f, -0.1f);
            // newCompletedText.AddComponent<Shadow>().effectColor = new Color32(32, 166, 220, 255);
            float questResultTextWidth = questTitle[_questIndex].preferredWidth;
            newCompletedText.GetComponent<RectTransform>().anchoredPosition = new Vector2(questResultTextWidth / 2 - 8, newCompletedText.GetComponent<RectTransform>().anchoredPosition.y);

            successSound.Play(0);
        }
        else
        {
            questTitle[_questIndex].color = new Color32(255, 255, 255, 100);
            failedSound.Play(0);
        }

    }
    public void RecoverEndingCreditPanel()
    {
        Debug.Log(newCompleted.Count);
        foreach (GameObject completedText in newCompleted)
        {
            Destroy(completedText);
        }
        foreach(Text questText in questTitle){
            questText.color = new Color32(255, 255, 255, 255);
        }
        newCompleted.Clear();
        Debug.Log(newCompleted.Count);
        SetQuestNames();
    }
    #endregion


}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using SocketIO;
using UnityEngine.Video;
using System;
using SocketMessages;

public class SocketManager : MonoBehaviour
{

    #region Variables

    [Header("Socket")]
    public string serverIP;
    public string serverPort;
    public bool isConnected;
    [Space(8)]

    [Header("UI")]
    public GameObject connectionErrorPanel;
    public InputField inputIPAdress;
    public InputField inputPort;
    [Space(8)]

    [Header("Scripts Socket")]
    public SocketIOComponent socket;
    public SocketEmitMessageList socketEmitMessageList;
    SocketSettings socketSettings;

    [Header("Scripts Global")]
    [SerializeField] AppManager appManager;
    public UserDataManager _UserDataManager;

    #endregion


    #region Standard Function

    private void Awake()
    {
        // Load Socket settings
        LoadSettings();
    }

    public void Start()
    {

        // Return in debug mode
        if (appManager.debugServer) return;

        // Connection
        socket.gameObject.SetActive(true);
        socket.Connect();

        socket.On("open", TestOpen);
        socket.On("error", TestError);
        socket.On("close", TestClose);
        socket.On("unity-reload", ReloadApp);
        socket.On("unity-quit", QuitApp);

        socket.On("logout-tagging", ManageAppStarter);
        socket.On("printing-done", PrintingDone);

    }

    public void Update()
    {
        if (appManager.debugServer) return;

        // Display Error setting Pannel to configure IP adress of nodejs server
        if (isConnected && connectionErrorPanel.activeSelf)
        {
            connectionErrorPanel.SetActive(false);
            connectionErrorPanel.transform.GetChild(4).gameObject.SetActive(true);
        }
        else if (!isConnected && !connectionErrorPanel.activeSelf)
        {
            connectionErrorPanel.SetActive(true);
            inputIPAdress.placeholder.GetComponent<Text>().text = serverIP;
            inputPort.placeholder.GetComponent<Text>().text = serverPort;
            StartCoroutine(DisableBlocker(0.2f));
        }
    }

    #endregion
    #region Logout Experience
    public void StartPrinting()
    {
        if (appManager.debugServer) return;
        Debug.Log("Send printing signal");
        socket.Emit("print-receipt");
    }


    public void EndOfExperience()
    {
        if (appManager.debugServer) Debug.Log("End of experience, but in server debug mode"); return;
        socket.Emit("end-of-experience");
    }
    #endregion


    #region Socket Settings Function

    public void UpdateServerAdress()
    {
        socket.url = "ws://" + serverIP + ":" + serverPort + "/socket.io/?EIO=4&transport=websocket";
    }

    public IEnumerator DisableBlocker(float _wait)
    {
        yield return new WaitForSeconds(_wait);
        if (connectionErrorPanel.activeSelf)
            connectionErrorPanel.transform.GetChild(4).gameObject.SetActive(false);
    }

    #endregion


    #region Node JS Common Function

    public void SendMessageToNode(string _message, string _contents)
    {
        //Debug.Log(_message);
        JSONObject jsonContents = new JSONObject(_contents);
        socket.Emit(_message, jsonContents);
    }

    public void TestOpen(SocketIOEvent e)
    {
        Debug.Log("Local NodeJS server connected");
        //Debug.Log("[SocketIO] Open received: " + e.name + " " + e.data);
        isConnected = true;
    }

    public void TestError(SocketIOEvent e)
    {
        Debug.Log("Local NodeJS server disconnected:error" + e);
        //Debug.Log("[SocketIO] Error received: " + e.name + " " + e.data);
        if (isConnected)
            isConnected = false;
    }

    public void TestClose(SocketIOEvent e)
    {
        Debug.Log("Local NodeJS server disconnected");
        //Debug.Log("[SocketIO] Close received: " + e.name + " " + e.data);
        isConnected = false;
    }

    public void ReloadApp(SocketIOEvent e)
    {
        //Debug Message and Data
        //Debug.Log("[SocketIO]Reload: " + e.name);
        StartCoroutine(appManager.ReloadScene());
    }

    public void QuitApp(SocketIOEvent e)
    {
        //Debug Message and Data
        //Debug.Log("[SocketIO]Quit: " + e.name);
        StartCoroutine(appManager.QuitScene());
    }

    public void ManageAppStarter(SocketIOEvent e)
    {
        if (e.data == null) return;
        if (e.data.GetField("userData") == null) return;
        
        JSONObject userData = e.data.GetField("userData");
        appManager.JoinTheApp();
        _UserDataManager.UserDataParser(userData);
    }

    public void PrintingDone(SocketIOEvent e)
    {
        Debug.Log("Printing Done, timing issue");
        // appManager.ThankyouForPlaying();
    }

    #endregion


    #region UI Socket Settings

    public void ChangeIpAdress(string _ip, string _port)
    {
        serverIP = _ip;
        serverPort = _port;
    }

    public void UpdateIpAdress(string _ip, string _port)
    {
        SaveServerSettings(_ip, _port);
        connectionErrorPanel.SetActive(false);
        UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex);
    }

    public void SaveSettingsButton()
    {
        string _newIp = inputIPAdress.text;
        if (_newIp == "")
            _newIp = inputIPAdress.placeholder.GetComponent<Text>().text;
        string _newPort = inputPort.text;
        if (_newPort == "")
            _newPort = inputPort.placeholder.GetComponent<Text>().text;
        UpdateIpAdress(_newIp, _newPort);
    }

    #endregion


    #region Player Prefabs 

    public void LoadSettings()
    {
        socketSettings = new SocketSettings();

        if (PlayerPrefs.HasKey("ipAdress") && PlayerPrefs.HasKey("port"))
            ChangeIpAdress(PlayerPrefs.GetString("ipAdress"), PlayerPrefs.GetString("port"));
        else
            UpdateIpAdress("127.0.0.1", "8888");

        UpdateServerAdress();

    }

    public void SaveServerSettings(string _newIp, string _newPort)
    {
        socketSettings.ipAdress = _newIp;
        PlayerPrefs.SetString("ipAdress", _newIp);
        socketSettings.port = _newPort;
        PlayerPrefs.SetString("port", _newPort);
    }

    #endregion

}

以上是关于csharp 注销应用程序用户数据解析脚本的主要内容,如果未能解决你的问题,请参考以下文章

如何在没有注销/登录的情况下将用户添加到组 - Bash 脚本

注销脚本上的语法错误?

csharp 注销ACS

joomla 自定义表单注销用户

llinux重启用户切换注销命令

删除用户注销 API 的 grafana cookie