Skip to content

Updated the UnityProject #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assets/CustomNotes.dll
Binary file not shown.
231 changes: 145 additions & 86 deletions Assets/Editor/CompileNoteWindow.cs
Original file line number Diff line number Diff line change
@@ -1,135 +1,194 @@
using System.Collections;
using CustomNotes;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.IO;
using UnityEngine.UI;
using UnityEngine;

public class CompileNoteWindow : EditorWindow
{
private static IEnumerable<NoteDescriptor> notes = Enumerable.Empty<NoteDescriptor>();

// Current scroll position
private Vector2 scrollPosition = Vector2.zero;

private CustomNotes.NoteDescriptor[] notes;
[MenuItem("Window/Note Exporter")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(CompileNoteWindow), false, "Note Exporter");
GetWindow(typeof(CompileNoteWindow), false, "Note Exporter");
}
public Vector2 scrollPosition = Vector2.zero;

private void OnFocus()
{
notes = GameObject.FindObjectsOfType<CustomNotes.NoteDescriptor>();
}
void OnGUI()
private void OnGUI()
{
var window = EditorWindow.GetWindow(typeof(CompileNoteWindow), false, "Note Exporter");
GUILayout.Label("Notes", EditorStyles.boldLabel);
GUILayout.Space(20);

int ScrollSpace = (16+20)+ (16+17+17+20+20);
foreach (CustomNotes.NoteDescriptor note in notes)
// Editor scroll height
int scrollSpace = 50;
int extraSpace = 0;
foreach (NoteDescriptor note in notes)
{
if (note != null)
{

ScrollSpace += (16+17+17+20+20);

scrollSpace += CalculateAdditionScrollSpace(note, extraSpace);
extraSpace += 2;
}
}

// Scroll bar
EditorWindow window = GetWindow(typeof(CompileNoteWindow), false, "Note Exporter", false);
Rect rectPosition = new Rect(0, 0, EditorGUIUtility.currentViewWidth, window.position.size.y);
Rect rectViewPosition = new Rect(0, 0, EditorGUIUtility.currentViewWidth - 20, scrollSpace);
scrollPosition = GUI.BeginScrollView(rectPosition, scrollPosition, rectViewPosition, false, false);

float currentWindowWidth = EditorGUIUtility.currentViewWidth;
float windowWidthIncludingScrollbar = currentWindowWidth;
if (window.position.size.y >= ScrollSpace)
if (window.position.size.y >= scrollSpace)
{
windowWidthIncludingScrollbar += 30;
}
scrollPosition = GUI.BeginScrollView(new Rect(0, 0, EditorGUIUtility.currentViewWidth, window.position.size.y), scrollPosition, new Rect(0, 0, EditorGUIUtility.currentViewWidth-20, ScrollSpace),false,false);

//GUILayout.ScrollViewScope
GUILayout.Label("Notes", EditorStyles.boldLabel, GUILayout.Height(16));
GUILayout.Space(20);

foreach (CustomNotes.NoteDescriptor note in notes)
// Editor content
foreach (NoteDescriptor note in notes)
{
if (note != null)
bool isMissingAuthorName = string.IsNullOrWhiteSpace(note.AuthorName);
bool isMissingNoteName = string.IsNullOrWhiteSpace(note.NoteName);
bool isMissingNoteLeft = !note.transform.Find("NoteLeft");
bool isMissingNoteRight = !note.transform.Find("NoteRight");
bool isMissingNoteDotLeft = note.DisableBaseNoteArrows && !note.transform.Find("NoteDotLeft");
bool isMissingNoteDotRight = note.DisableBaseNoteArrows && !note.transform.Find("NoteDotRight");

// Object options
GUILayout.Label("GameObject: " + note.NoteName, EditorStyles.boldLabel, GUILayout.Height(16));
note.AuthorName = EditorGUILayout.TextField("Author name", note.AuthorName, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.NoteName = EditorGUILayout.TextField("Note name", note.NoteName, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.Description = EditorGUILayout.TextField("Note description", note.Description, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.DisableBaseNoteArrows = EditorGUILayout.Toggle("Disable Base Note Arrows", note.DisableBaseNoteArrows, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.UsesNoteColor = EditorGUILayout.Toggle("Uses Note Color", note.UsesNoteColor, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.NoteColorStrength = EditorGUILayout.FloatField("Note Color Strength", note.NoteColorStrength, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.Icon = (Texture2D)EditorGUILayout.ObjectField("Cover Image", note.Icon, typeof(Texture2D), false, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(75));

bool disableExportButton = false;
if (isMissingAuthorName || isMissingNoteName
|| isMissingNoteLeft || isMissingNoteRight
|| isMissingNoteDotLeft || isMissingNoteDotRight)
{
GUILayout.Label("GameObject : " + note.gameObject.name, EditorStyles.boldLabel, GUILayout.Height(16));
note.AuthorName = EditorGUILayout.TextField("Author name", note.AuthorName, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
note.NoteName = EditorGUILayout.TextField("Note name", note.NoteName, GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(17));
disableExportButton = true;
}

EditorGUI.BeginDisabledGroup(note.transform.Find("NoteLeft") == null || note.transform.Find("NoteRight") == null || (note.DisableBaseNoteArrows == true && (note.transform.Find("NoteDotLeft") == null || note.transform.Find("NoteDotRight") == null)));
if (GUILayout.Button("Export " + note.NoteName, GUILayout.Width(windowWidthIncludingScrollbar - 40),GUILayout.Height(20)))
EditorGUI.BeginDisabledGroup(disableExportButton);

if (GUILayout.Button($"Export {note.NoteName}", GUILayout.Width(windowWidthIncludingScrollbar - 40), GUILayout.Height(20)))
{
GameObject noteObject = note.gameObject;
if (noteObject != null && note != null)
{
GameObject noteObject = note.gameObject;
if (noteObject != null && note != null)
string path = EditorUtility.SaveFilePanel("Save note (bloq) file", "", $"{note.NoteName}.bloq", "bloq");

if (!string.IsNullOrWhiteSpace(path))
{
string path = EditorUtility.SaveFilePanel("Save note file", "", note.NoteName + ".bloq", "bloq");
Debug.Log(path == "");
string guid = $"{{{GUID.Generate()}}}";
string fileName = $"{Path.GetFileName(path)}_{guid}";
string folderPath = Path.GetDirectoryName(path);

if (path != "")
{
string fileName = Path.GetFileName(path);
string folderPath = Path.GetDirectoryName(path);

Selection.activeObject = noteObject;
EditorUtility.SetDirty(note);
EditorSceneManager.MarkSceneDirty(noteObject.scene);
EditorSceneManager.SaveScene(noteObject.scene);
PrefabUtility.CreatePrefab("Assets/_CustomNote.prefab", Selection.activeObject as GameObject);
AssetBundleBuild assetBundleBuild = default(AssetBundleBuild);
assetBundleBuild.assetNames = new string[] {
Selection.activeObject = noteObject;
EditorUtility.SetDirty(note);
EditorSceneManager.MarkSceneDirty(noteObject.scene);
EditorSceneManager.SaveScene(noteObject.scene);
PrefabUtility.CreatePrefab("Assets/_CustomNote.prefab", Selection.activeObject as GameObject);
AssetBundleBuild assetBundleBuild = default(AssetBundleBuild);
assetBundleBuild.assetNames = new string[] {
"Assets/_CustomNote.prefab"
};

assetBundleBuild.assetBundleName = fileName;
assetBundleBuild.assetBundleName = fileName;

BuildTargetGroup selectedBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
BuildTarget activeBuildTarget = EditorUserBuildSettings.activeBuildTarget;
BuildTargetGroup selectedBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
BuildTarget activeBuildTarget = EditorUserBuildSettings.activeBuildTarget;

BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { assetBundleBuild }, 0, EditorUserBuildSettings.activeBuildTarget);
EditorPrefs.SetString("currentBuildingAssetBundlePath", folderPath);
EditorUserBuildSettings.SwitchActiveBuildTarget(selectedBuildTargetGroup, activeBuildTarget);
AssetDatabase.DeleteAsset("Assets/_CustomNote.prefab");
if (File.Exists(path))
BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { assetBundleBuild }, 0, EditorUserBuildSettings.activeBuildTarget);
EditorPrefs.SetString("currentBuildingAssetBundlePath", folderPath);
EditorUserBuildSettings.SwitchActiveBuildTarget(selectedBuildTargetGroup, activeBuildTarget);
AssetDatabase.DeleteAsset("Assets/_CustomNote.prefab");

if (File.Exists(path))
{
bool isDirectory = (File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory;
if (!isDirectory)
{
File.Delete(path);
}
File.Move(Application.temporaryCachePath + "/" + fileName, path);
AssetDatabase.Refresh();
EditorUtility.DisplayDialog("Exportation Successful!", "Exportation Successful!", "OK");
}
else
{
EditorUtility.DisplayDialog("Exportation Failed!", "Path is invalid.", "OK");
}
}
else
{
EditorUtility.DisplayDialog("Exportation Failed!", "Note GameObject is missing.", "OK");
}
}
EditorGUI.EndDisabledGroup();

if (note.transform.Find("NoteLeft") == null)
{
GUILayout.Label("NoteLeft gameObject is missing", EditorStyles.boldLabel);
}
if (note.transform.Find("NoteRight") == null)
{
GUILayout.Label("NoteRight gameObject is missing", EditorStyles.boldLabel);
File.Move(Path.Combine(Application.temporaryCachePath, fileName), path);
AssetDatabase.Refresh();
EditorUtility.DisplayDialog("Export Successful!", "Export Successful!", "OK");
}
}
if (note.DisableBaseNoteArrows)
else
{
if (note.transform.Find("NoteDotLeft") == null)
{
GUILayout.Label("Disabling Base Game Note Arrows is enabled and NoteDotLeft gameObject is missing", EditorStyles.boldLabel);
}
if (note.transform.Find("NoteDotRight") == null)
{
GUILayout.Label("Disabling Base Game Note Arrows is enabled and NoteDotRight gameObject is missing", EditorStyles.boldLabel);
}
EditorUtility.DisplayDialog("Export Failed!", "GameObject is missing.", "OK");
}
GUILayout.Space(20);
}

EditorGUI.EndDisabledGroup();

if (isMissingNoteLeft)
GUILayout.Label("NoteLeft gameObject is missing", EditorStyles.boldLabel);

if (isMissingNoteRight)
GUILayout.Label("NoteRight gameObject is missing", EditorStyles.boldLabel);

if (isMissingNoteDotLeft)
GUILayout.Label("Disabling Base Game Note Arrows is enabled and NoteDotLeft gameObject is missing", EditorStyles.boldLabel);

if (isMissingNoteDotRight)
GUILayout.Label("Disabling Base Game Note Arrows is enabled and NoteDotRight gameObject is missing", EditorStyles.boldLabel);

if (isMissingAuthorName)
GUILayout.Label("Author name is empty", EditorStyles.boldLabel);

if (isMissingNoteName)
GUILayout.Label("Note name is empty", EditorStyles.boldLabel);

GUILayout.Space(20);
}

GUI.EndScrollView();
}

private void OnFocus()
{
notes = FindObjectsOfType<NoteDescriptor>();
}

private int CalculateAdditionScrollSpace(NoteDescriptor note, int extraSpace = 0)
{
int additionalSpace = 253 + extraSpace;
int labelHeight = 22;

if (string.IsNullOrEmpty(note.NoteName))
additionalSpace += labelHeight;

if (string.IsNullOrEmpty(note.AuthorName))
additionalSpace += labelHeight;

if (!note.transform.Find("NoteLeft"))
additionalSpace += labelHeight;

if (!note.transform.Find("NoteRight"))
additionalSpace += labelHeight;

if (note.DisableBaseNoteArrows)
{
if (!note.transform.Find("NoteDotLeft"))
additionalSpace += labelHeight;

if (!note.transform.Find("NoteDotRight"))
additionalSpace += labelHeight;
}

return additionalSpace;
}
}