Initial commit: Unity WordConnect project
This commit is contained in:
9
Assets/TutorialInfo/Scripts/Editor.meta
Normal file
9
Assets/TutorialInfo/Scripts/Editor.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ad9b87dffba344c89909c6d1b1c17e1
|
||||
folderAsset: yes
|
||||
timeCreated: 1475593892
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
184
Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs
Normal file
184
Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs
Normal file
@ -0,0 +1,184 @@
|
||||
// // ©2015 - 2022 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
//
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using BlockPuzzleGameToolkit.TutorialInfo.Scripts;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.TutorialInfo.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(Readme))]
|
||||
[InitializeOnLoad]
|
||||
public class ReadmeEditor : UnityEditor.Editor
|
||||
{
|
||||
private static readonly string kShowedReadmeSessionStateName = "ReadmeEditor.showedReadme";
|
||||
|
||||
private static readonly float kSpace = 16f;
|
||||
|
||||
static ReadmeEditor()
|
||||
{
|
||||
EditorApplication.delayCall += SelectReadmeAutomatically;
|
||||
}
|
||||
|
||||
private static void SelectReadmeAutomatically()
|
||||
{
|
||||
if (!SessionState.GetBool(kShowedReadmeSessionStateName, false))
|
||||
{
|
||||
var readme = SelectReadme();
|
||||
SessionState.SetBool(kShowedReadmeSessionStateName, true);
|
||||
|
||||
if (readme && !readme.loadedLayout)
|
||||
{
|
||||
LoadLayout();
|
||||
readme.loadedLayout = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadLayout()
|
||||
{
|
||||
var assembly = typeof(EditorApplication).Assembly;
|
||||
var windowLayoutType = assembly.GetType("UnityEditor.WindowLayout", true);
|
||||
var method = windowLayoutType.GetMethod("LoadWindowLayout", BindingFlags.Public | BindingFlags.Static);
|
||||
method.Invoke(null, new object[] { Path.Combine(Application.dataPath, "TutorialInfo/Layout.wlt"), false });
|
||||
}
|
||||
|
||||
[MenuItem("WordConnect/Documentation/ReadMe")]
|
||||
private static Readme SelectReadme()
|
||||
{
|
||||
var ids = AssetDatabase.FindAssets("Readme t:Readme");
|
||||
if (ids.Length == 1)
|
||||
{
|
||||
var readmeObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(ids[0]));
|
||||
|
||||
Selection.objects = new[] { readmeObject };
|
||||
|
||||
return (Readme)readmeObject;
|
||||
}
|
||||
|
||||
Debug.Log("Couldn't find a readme");
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnHeaderGUI()
|
||||
{
|
||||
var readme = (Readme)target;
|
||||
Init();
|
||||
|
||||
var iconWidth = Mathf.Min(EditorGUIUtility.currentViewWidth / 3f - 20f, 128f);
|
||||
|
||||
GUILayout.BeginHorizontal("In BigTitle");
|
||||
{
|
||||
GUILayout.Label(readme.icon, GUILayout.Width(iconWidth), GUILayout.Height(iconWidth));
|
||||
GUILayout.Label(readme.title, TitleStyle);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var readme = (Readme)target;
|
||||
Init();
|
||||
|
||||
foreach (var section in readme.sections)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(section.heading))
|
||||
{
|
||||
GUILayout.Label(section.heading, HeadingStyle);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(section.text))
|
||||
{
|
||||
GUILayout.Label(section.text, BodyStyle);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(section.linkText))
|
||||
{
|
||||
if (LinkLabel(new GUIContent(section.linkText)))
|
||||
{
|
||||
Application.OpenURL(section.url);
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(kSpace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool m_Initialized;
|
||||
|
||||
private GUIStyle LinkStyle => m_LinkStyle;
|
||||
|
||||
[SerializeField]
|
||||
private GUIStyle m_LinkStyle;
|
||||
|
||||
private GUIStyle TitleStyle => m_TitleStyle;
|
||||
|
||||
[SerializeField]
|
||||
private GUIStyle m_TitleStyle;
|
||||
|
||||
private GUIStyle HeadingStyle => m_HeadingStyle;
|
||||
|
||||
[SerializeField]
|
||||
private GUIStyle m_HeadingStyle;
|
||||
|
||||
private GUIStyle BodyStyle => m_BodyStyle;
|
||||
|
||||
[SerializeField]
|
||||
private GUIStyle m_BodyStyle;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (m_Initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_BodyStyle = new GUIStyle(EditorStyles.label);
|
||||
m_BodyStyle.wordWrap = true;
|
||||
m_BodyStyle.fontSize = 14;
|
||||
|
||||
m_TitleStyle = new GUIStyle(m_BodyStyle);
|
||||
m_TitleStyle.fontSize = 26;
|
||||
|
||||
m_HeadingStyle = new GUIStyle(m_BodyStyle);
|
||||
m_HeadingStyle.fontSize = 18;
|
||||
|
||||
m_LinkStyle = new GUIStyle(m_BodyStyle);
|
||||
m_LinkStyle.wordWrap = false;
|
||||
// Match selection color which works nicely for both light and dark skins
|
||||
m_LinkStyle.normal.textColor = new Color(0x00 / 255f, 0x78 / 255f, 0xDA / 255f, 1f);
|
||||
m_LinkStyle.stretchWidth = false;
|
||||
|
||||
m_Initialized = true;
|
||||
}
|
||||
|
||||
private bool LinkLabel(GUIContent label, params GUILayoutOption[] options)
|
||||
{
|
||||
var position = GUILayoutUtility.GetRect(label, LinkStyle, options);
|
||||
|
||||
Handles.BeginGUI();
|
||||
Handles.color = LinkStyle.normal.textColor;
|
||||
Handles.DrawLine(new Vector3(position.xMin, position.yMax), new Vector3(position.xMax, position.yMax));
|
||||
Handles.color = Color.white;
|
||||
Handles.EndGUI();
|
||||
|
||||
EditorGUIUtility.AddCursorRect(position, MouseCursor.Link);
|
||||
|
||||
return GUI.Button(position, label, LinkStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs.meta
Normal file
12
Assets/TutorialInfo/Scripts/Editor/ReadmeEditor.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 476cc7d7cd9874016adc216baab94a0a
|
||||
timeCreated: 1484146680
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/TutorialInfo/Scripts/Readme.cs
Normal file
32
Assets/TutorialInfo/Scripts/Readme.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
//
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BlockPuzzleGameToolkit.TutorialInfo.Scripts
|
||||
{
|
||||
public class Readme : ScriptableObject
|
||||
{
|
||||
public Texture2D icon;
|
||||
public string title;
|
||||
public Section[] sections;
|
||||
public bool loadedLayout;
|
||||
|
||||
[Serializable]
|
||||
public class Section
|
||||
{
|
||||
public string heading, text, linkText, url;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/TutorialInfo/Scripts/Readme.cs.meta
Normal file
12
Assets/TutorialInfo/Scripts/Readme.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcf7219bab7fe46a1ad266029b2fee19
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- icon: {fileID: 2800000, guid: d4743ba2e2a59f946b2125c074582ce7, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a186f8a87ca4f4d3aa864638ad5dfb65, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user