Esempio n. 1
0
    public CursorSaveEntry JsonDeserialize(string fullPath)
    {
        if (fullPath != null)
        {
            string json = File.ReadAllText(fullPath, Encoding.ASCII);
            CursorSaveEntry returnEntry = null;

            try
            {
                returnEntry = (CursorSaveEntry)JsonUtility.FromJson(json, typeof(CursorSaveEntry));
            }
            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
    }
Esempio n. 2
0
    public CursorSaveEntry[] DeserializeAllCursorEntries()
    {
        List <string>
        names = Directory.GetFiles(folderPath).Where(x => !Path.GetExtension(x).Contains(".meta"))
                .ToList(); // i assume i get their names here?

        //for (int i = 0; i < names.Count; i++)
        //{
        //    if (names[i] != null)
        //    {
        //        if (names[i].Contains(".meta"))
        //        {
        //            names.Remove(names[i]);
        //        }
        //    }
        //}

        CursorSaveEntry[] saveEntries = new CursorSaveEntry[names.Count];

        for (int i = 0; i < names.Count; i++)
        {
            saveEntries[i] = JsonDeserialize(null, names[i]);
        }

        return(saveEntries);
    }
Esempio n. 3
0
    private void LoadCursor(CursorSaveEntry saveEntry) // Load them into saved stuff
    {
        CursorTextureEntry cursorTexture = textureEntries.Find(x => x.GetTextureName == saveEntry.textureName);

        if (cursorTexture == null)
        {
            Debug.LogError("Can not find texture associated with save entry, texture name: " + saveEntry.textureName);
        }
        else
        {
            Input_CursorNameInput(saveEntry.cursorName);

            curSelectedTexture = cursorTexture.GetTexture;

            Sprite loadedCursorSprite = Sprite.Create(cursorTexture.GetTexture,
                                                      new Rect(0f, 0f, curSelectedTexture.width, curSelectedTexture.height), new Vector2(0.5f, 0.5f),
                                                      pixelsPerUnit);

            // cursorColorPicker.color is throwing an error
            // how f****n fun
            cursorColorPicker.color = saveEntry.cursorColor;
            cursorPreview.sprite    = loadedCursorSprite;

            OnClick_PreviewCursor();

            NewCursorEntry loadedCursor = CreateCursor(false); // Change this to a create method instead?
            loadedCursor.SetSaveState(SaveState.Saved);
            loadedCursor.SavedAsFileName = saveEntry.cursorName;
            loadedCursor.isSaveEntry     = false; // THIS IS THE NORMAL F*****G CURSOR

            #region Creating cursorEntry for savedList, perhaps add an overload for CreateCursor instead?

            NewCursorEntry savedCursor = Instantiate(loadedCursor, savedCursorListContent);
            savedCursor.SetCursorPreferences(loadedCursor);
            savedCursor.SetSaveState(SaveState.Saved);
            savedCursor.isSaveEntry = true; // THIS IS THE F*****G SAVED CURSOR

            Button loadedEntryButton = savedCursor.GetComponent <Button>();
            loadedEntryButton.onClick.AddListener(() => OnClick_SelectCursor(savedCursor));

            #endregion

            if (!savedCursors.Contains(savedCursor))
            {
                savedCursors.Add(savedCursor);
            }
        }
    }
Esempio n. 4
0
    public void JsonSerialize(NewCursorEntry entry) // perhaps rename to savetofile or smth since it doesn't just serialize it but
    {                                               // saves it completely? maybe factorize the method too?
        // Check if it has a previous file name, if it does rename that file to the new name
        string fileName     = entry.GetCursorName;
        string saveFileName = entry.SavedAsFileName == null ? "" : entry.SavedAsFileName;
        string newFileName  = entry.GetCursorName == null ? "" : entry.GetCursorName;

        if (entry.SavedAsFileName != "")
        {
            if (entry.SavedAsFileName != entry.GetCursorName)
            {
                // if the file name isnt the same as the cursor name we have to
                // rename the file to the new cursor name

                // argumentNullException ???
                string oldFilePath = Path.Combine(folderPath, saveFileName); // this returns a null exception
                // because savedAsFileName is empty
                // WHY DOES THIS THROW AN EXCEPTION LOL
                string newFilePath = Path.Combine(folderPath, newFileName);

                if (File.Exists(oldFilePath)) // if it exists rename it, otherwise who cares since
                {                             // it'll just be created again
                    File.Move(oldFilePath, newFilePath);
                }
            }
        }

        CursorSaveEntry saveEntry = new CursorSaveEntry(entry);
        string          json      = JsonUtility.ToJson(saveEntry);
        string          filePath  = Path.Combine(folderPath, entry.GetCursorName);

        if (File.Exists(filePath))
        {
            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
    }
Esempio n. 5
0
    private void LoadCursorSave(CursorSaveEntry saveEntry) // Load it into save only
    {
        CursorTextureEntry cursorTexture = textureEntries.Find(x => x.GetTextureName == saveEntry.textureName);

        if (cursorTexture == null)
        {
            Debug.LogError("Can not find texture associated with save entry, texture name: " + saveEntry.textureName);
        }
        else
        {
            Input_CursorNameInput(saveEntry.cursorName);

            curSelectedTexture = cursorTexture.GetTexture;

            Sprite loadedCursorSprite = Sprite.Create(cursorTexture.GetTexture,
                                                      new Rect(0f, 0f, curSelectedTexture.width, curSelectedTexture.height), new Vector2(0.5f, 0.5f),
                                                      pixelsPerUnit);

            // cursorColorPicker.color is throwing an error
            // how f****n fun
            cursorColorPicker.color = saveEntry.cursorColor;
            cursorPreview.sprite    = loadedCursorSprite;

            OnClick_PreviewCursor(); // should work? no?

            NewCursorEntry savedCursor = CreateCursor(true);
            savedCursor.transform.SetParent(savedCursorListContent);
            savedCursor.SetCursorPreferences(savedCursor);
            savedCursor.SetSaveState(SaveState.Saved);
            savedCursor.SavedAsFileName = saveEntry.cursorName;
            savedCursor.isSaveEntry     = true; // THIS IS THE F*****G SAVED CURSOR

            Button loadedEntryButton = savedCursor.GetComponent <Button>();
            loadedEntryButton.onClick.AddListener(() => OnClick_SelectCursor(savedCursor));

            if (!savedCursors.Contains(savedCursor)) // do this beforef
            {
                savedCursors.Add(savedCursor);
            }
        }
    }
Esempio n. 6
0
    private void Update()
    {
        // unless the person is writing
        // Debug.Log(EventSystem.current.currentSelectedGameObject?.GetComponent<InputField>());
        // design a deselect method for eachtime the mouse is pressed unless its over a specific button
        // that works with either saving or selection

        bool       isReceivingUiInput = false;
        GameObject curSelectedUiObj   = EventSystem.current.currentSelectedGameObject;

        if (curSelectedUiObj != null) // should def work
        {
            if (curSelectedUiObj.GetComponent <InputField>())
            {
                isReceivingUiInput = true;
            }
            else
            {
                isReceivingUiInput = false;
            }
        }
        else
        {
            isReceivingUiInput = false;
        }

        if (isReceivingUiInput) // ignore keypresses, probably should do in movement too
        {
        }
        else // isnt receiving input
        {
            if (Keyboard.current.mKey.wasPressedThisFrame)
            {
                menuCanvas.gameObject.SetActive(!menuCanvas.gameObject.activeSelf);
            }

            if (Keyboard.current.escapeKey.wasPressedThisFrame)
            {
                ClearCursorSelectedEntries();
            }

            if (Keyboard.current.deleteKey.wasPressedThisFrame)
            {
                DeleteCursorEntry();
                //if (selectedCursorEntryList.Count > 0)
                //{
                //    selectedCursorEntryList.ForEach(x =>
                //    {
                //        if (x.GetSaveState == SaveState.EditedSinceLastSave || x.GetSaveState == SaveState.Saved)
                //        {
                //            if (File.Exists(folderPathName + x.GetCursorName))
                //            {
                //                File.Delete(folderPathName + x.GetCursorName);
                //            }
                //        }

                //        Destroy(x.gameObject);
                //    });
                //    selectedCursorEntryList.Clear();
                //}
            }

            if (Keyboard.current.leftCtrlKey.isPressed)
            {
                if (Keyboard.current.leftShiftKey.isPressed)
                {
                    if (Keyboard.current.sKey.wasPressedThisFrame)
                    {
                        if (selectedCursorEntryList.Count > 0) // actually would this work?
                        {
                            foreach (NewCursorEntry selectEntry in selectedCursorEntryList)
                            {
                                SaveCursorEntryToFile(selectEntry);
                            }
                            // occasion: select 4 files, change name to bob
                            // save files
                            // do they all become named bob?
                            // that would be a decent outcome
                            // would require name fix tho
                            // well technically no because it saves them to the file
                            // meanwhile save saves their preferences
                        }

                        if (curSelectedCursorEntry != null) // Saves last selected entry or loops?
                        {
                            SaveCursorEntryToFile(curSelectedCursorEntry);
                        }

                        ReloadSavedList();
                    }
                }
                else if (Keyboard.current.sKey.wasPressedThisFrame)
                {
                    // save preferences otherwise
                    if (selectedCursorEntryList.Count > 0)
                    {
                        foreach (NewCursorEntry selectedEntry in selectedCursorEntryList)
                        {
                            OnClick_SaveCursorPreferences();
                        }
                    }
                    else
                    {
                        if (curSelectedCursorEntry != null)
                        {
                            OnClick_SaveCursorPreferences();
                        }
                    }
                }
                // for saving
            }

            if (Keyboard.current.f11Key.wasPressedThisFrame)
            {
                CursorSaveEntry saveEntry = cursorSaveLoadUtility.JsonDeserialize(cursorToLoadName);
                LoadCursor(saveEntry);
            }
        }

        cursorPreview.color = cursorColorPicker.color;
    }
Esempio n. 7
0
    public CursorSaveEntry JsonDeserialize(string cursorName = null, string path = null) // THATS THE F****N CURSOR NAME RETARD
    {
        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);
                CursorSaveEntry returnEntry = null;

#if UNITY_EDITOR
                try
                {
#endif

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

#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)
        {
            string filePath = Path.Combine(folderPath + cursorName);

            if (File.Exists(filePath))
            {
                string          json        = File.ReadAllText(filePath, System.Text.Encoding.ASCII);
                CursorSaveEntry returnEntry = (CursorSaveEntry)JsonUtility.FromJson(json, typeof(CursorSaveEntry));
                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);
        }
    }