Exemplo n.º 1
0
    public CsCursorSaveEntry CsCursorJsonDeserialize(string fullPath)
    {
        if (fullPath != null)
        {
            string            json        = File.ReadAllText(fullPath, Encoding.ASCII);
            CsCursorSaveEntry returnEntry = null;

            try
            {
                returnEntry = (CsCursorSaveEntry)JsonUtility.FromJson(json, typeof(CsCursorSaveEntry));
            }
            catch (System.Exception e)
            {
#if UNITY_EDITOR
                Debug.LogWarning(e);
                Debug.Break();
#endif
            }

            if (returnEntry == null)
            {
#if UNITY_EDITOR
                Debug.Log("File exists: " + File.Exists(fullPath) + " Path: " + fullPath);
                Debug.Break();
#endif
            }

            return(returnEntry);
        }

        return(null); // the path was not passed
    }
    public void OnClick_ReloadProperties()
    {
        CsCursorSaveEntry entry =
            saveLoadUtility.CsCursorJsonDeserialize();

        if (entry == null)
        {
            Debug.LogWarning("Entry is: " + entry + ", save file probably doesn't exist?");
        }
        else
        {
            properties.LoadPropsFromSave(entry);
        }
    }
 public void LoadPropsFromSave(CsCursorSaveEntry saveEntry)
 {
     CursorName            = saveEntry.cursorName;
     CursorColorMultiplier = saveEntry.cursorColorMultiplier;
     CrossPivotRotation    = saveEntry.crossPivotRotation;
     LineColor             = saveEntry.lineColor;
     LineLength            = saveEntry.lineLength;
     LineWidth             = saveEntry.lineWidth;
     LineWidth             = saveEntry.lineDistanceFromCenter;
     LineLocalRotation     = saveEntry.lineLocalRotation;
     DotColor         = saveEntry.dotColor;
     Radius           = saveEntry.radius;
     DotLocalRotation = saveEntry.dotLocalRotation;
 }
Exemplo n.º 4
0
    public void CsCursorJsonSerialize(CsCustomCursorEntry entry)
    {
        CsCursorSaveEntry saveEntry = new CsCursorSaveEntry(entry);
        string            json      = JsonUtility.ToJson(saveEntry);
        string            filePath  = Path.Combine(csCursorFolderPath, entry.CursorName);

        if (File.Exists(csCursorFolderPath))
        {
            File.WriteAllText(filePath, json);
        }
        else
        {
            FileStream fileStream = File.Create(filePath);
            fileStream.Close();

            File.WriteAllText(filePath, json);
        }

#if UNITY_EDITOR
        UnityEditor.AssetDatabase.Refresh();
        Debug.Log(json + "\n------------------------------------------");
#endif
    }
Exemplo n.º 5
0
    public CsCursorSaveEntry CsCursorJsonDeserialize(string cursorName = null, string path = null)
    {
        if (path != null) // if a path is given e.g by the start load thing
        {
            if (File.Exists(path))
            {
                string            json        = File.ReadAllText(path, System.Text.Encoding.ASCII);
                CsCursorSaveEntry returnEntry = null;

#if UNITY_EDITOR
                try
                {
#endif

                returnEntry = (CsCursorSaveEntry)JsonUtility.FromJson(json, typeof(CsCursorSaveEntry));

#if UNITY_EDITOR
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
                Debug.Break();
            }

            if (returnEntry == null)
            {
                Debug.Log(cursorName + " | " + path + " | " + File.Exists(path));
                Debug.Break();
            }
#endif

                return(returnEntry);
            }
        }

        if (cursorName != null)
        {
            Debug.Log(cursorName);
            string filePath = Path.Combine(csCursorFolderPath, cursorName);

            if (File.Exists(filePath))
            {
                string            json        = File.ReadAllText(filePath, System.Text.Encoding.ASCII);
                CsCursorSaveEntry returnEntry =
                    (CsCursorSaveEntry)JsonUtility.FromJson(json, typeof(CsCursorSaveEntry));
                return(returnEntry);
            }
            else
            {
#if UNITY_EDITOR
                Debug.LogWarning("File with name: " + cursorName + "  does not exist. Perhaps save first?");
#endif
                return(null);
            }
        }
        else
        {
#if UNITY_EDITOR
            Debug.LogWarning("Cursor name is null, path: " + path + "\nReturning null...");
#endif
            return(null);
        }
    }