Skip to content

Commit

Permalink
Merge pull request #29 from kimsama/feature/array-support
Browse files Browse the repository at this point in the history
Feature/array support
  • Loading branch information
kimsama authored Aug 22, 2016
2 parents de79b7a + ce11677 commit 26fb6a7
Show file tree
Hide file tree
Showing 65 changed files with 44,748 additions and 567 deletions.
95 changes: 95 additions & 0 deletions Assets/QuickSheet/Editor/BaseEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
///////////////////////////////////////////////////////////////////////////////
///
/// BaseEditor.cs
///
/// (c)2016 Kim, Hyoun Woo
///
///////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using UnityEditor;
using System.Collections;

namespace UnityQuickSheet
{
/// <summary>
/// Base class which draws properties of the created scriptableobject.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class BaseEditor<T> : Editor where T : ScriptableObject
{
protected SerializedObject targetObject;
protected SerializedProperty spreadsheetProp;
protected SerializedProperty worksheetProp;
protected SerializedProperty serializedData;

protected GUIStyle brown;
protected bool isGUISkinInitialized = false;

/// <summary>
/// Create SerialliedObject and initialize related SerializedProperty objects
/// which are needed to draw data on the Inspector view.
/// </summary>
public virtual void OnEnable()
{
T t = (T)target;
targetObject = new SerializedObject(t);

spreadsheetProp = targetObject.FindProperty("SheetName");
if (spreadsheetProp == null)
Debug.LogError("Failed to find 'SheetName' property.");

worksheetProp = targetObject.FindProperty("WorksheetName");
if (worksheetProp == null)
Debug.LogError("Failed to find 'WorksheetName' property.");

serializedData = targetObject.FindProperty("dataArray");
if (serializedData == null)
Debug.LogError("Failed to find 'dataArray' member field.");
}

/// <summary>
/// Create and initialize a new gui style which can be used for representing
/// each element of dataArray.
/// </summary>
protected void InitGUIStyle()
{
brown = new GUIStyle("box");
brown.normal.background = Resources.Load("brown", typeof(Texture2D)) as Texture2D;
brown.border = new RectOffset(4, 4, 4, 4);
brown.margin = new RectOffset(3, 3, 3, 3);
brown.padding = new RectOffset(4, 4, 4, 4);
}

/// <summary>
/// Draw serialized properties on the Inspector view.
/// </summary>
/// <param name="useGUIStyle"></param>
protected void DrawInspector(bool useGUIStyle = true)
{
// Draw 'spreadsheet' and 'worksheet' name.
EditorGUILayout.TextField(spreadsheetProp.name, spreadsheetProp.stringValue);
EditorGUILayout.TextField(worksheetProp.name, worksheetProp.stringValue);

// Draw properties of the data class.
if (useGUIStyle && !isGUISkinInitialized)
{
isGUISkinInitialized = true;
InitGUIStyle();
}

if (useGUIStyle)
GUIHelper.DrawSerializedProperty(serializedData, brown);
else
GUIHelper.DrawSerializedProperty(serializedData, brown);
}

///
/// Called when 'Update'(or 'Download' for google data) button is pressed.
/// It should be reimplemented in the derived class.
///
public virtual bool Load()
{
return false;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 17 additions & 33 deletions Assets/QuickSheet/Editor/BaseMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace UnityQuickSheet
{
/// <summary>
/// A class which represents column header on the worksheet.
/// </summary>
[System.Serializable]
public class ColumnHeader
{
Expand All @@ -25,78 +28,59 @@ public class ColumnHeader
public int OrderNO { get; set; }
}

/// <summary>
/// A class which stores various settings for a worksheet which is imported.
/// </summary>
public class BaseMachine : ScriptableObject
{
protected readonly static string ImportSettingFilename = "New Import Setting.asset";

[ExposeProperty]
[SerializeField]
private string templatePath = "QuickSheet/Templates";
public string TemplatePath
{
get { return templatePath; }
set { templatePath = value; }
}

/// <summary>
/// path the created ScriptableObject class file will be located.
/// </summary>
[SerializeField]
private string templatePath = "QuickSheet/Templates";

[ExposeProperty]
private string scriptFilePath;
public string RuntimeClassPath
{
get { return scriptFilePath; }
set { scriptFilePath = value; }
}

/// <summary>
/// path the created ScriptableObject class file will be located.
/// path the created editor script files will be located.
/// </summary>
[SerializeField]
private string scriptFilePath;

[ExposeProperty]
private string editorScriptFilePath;
public string EditorClassPath
{
get { return editorScriptFilePath; }
set { editorScriptFilePath = value; }
}

/// <summary>
/// path the created editor script files will be located.
/// </summary>
[SerializeField]
private string editorScriptFilePath;

//[ExposeProperty]
//public string DataFilePath
//{
// get { return dataFilePath; }
// set { dataFilePath = value; }
//}

/// <summary>
/// path the created asset file will be located.
/// </summary>
//[SerializeField]
//private string dataFilePath;

[ExposeProperty]
private string sheetName;
public string SpreadSheetName
{
get { return sheetName; }
set { sheetName = value; }
}

[SerializeField]
private string sheetName;

[ExposeProperty]
private string workSheetName;
public string WorkSheetName
{
get { return workSheetName; }
set { workSheetName = value; }
}

[SerializeField]
private string workSheetName;

[System.NonSerialized]
public bool onlyCreateDataClass = false;

Expand Down
91 changes: 55 additions & 36 deletions Assets/QuickSheet/Editor/BaseMachineEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,33 @@
namespace UnityQuickSheet
{
/// <summary>
///
/// A base class for a spreadsheet import setting.
/// </summary>
[CustomEditor(typeof(BaseMachine))]
public class BaseMachineEditor : Editor
{
protected BaseMachine machine;

protected readonly string NoTemplateString = "No Template File Found";
protected readonly string NoTemplateString = "No Template file is found";

protected GUIStyle headerStyle = null;

protected virtual void OnEnable()
{
// Nothing to do here.
}

public override void OnInspectorGUI()
{
if (headerStyle == null)
{
headerStyle = GUIHelper.MakeHeader();
}
}

/// <summary>
/// Do not call this in the derived class.
/// </summary>
protected virtual void Import(bool reimport = false)
{
Debug.LogWarning("!!! It should be implemented in the derived class !!!");
Expand Down Expand Up @@ -99,7 +117,7 @@ protected void CreateScriptableObjectClassScript(BaseMachine machine, ScriptPres
{
// write a script to the given folder.
writer = new StreamWriter(fullPath);
writer.Write(new NewScriptGenerator(sp).ToString());
writer.Write(new ScriptGenerator(sp).ToString());
}
catch (System.Exception e)
{
Expand Down Expand Up @@ -143,7 +161,7 @@ protected void CreateScriptableObjectEditorClassScript(BaseMachine machine, Scri
{
// write a script to the given folder.
writer = new StreamWriter(fullPath);
writer.Write(new NewScriptGenerator(sp).ToString());
writer.Write(new ScriptGenerator(sp).ToString());
}
catch (System.Exception e)
{
Expand Down Expand Up @@ -198,7 +216,7 @@ protected void CreateDataClassScript(BaseMachine machine, ScriptPrescription sp)
// write a script to the given folder.
using (var writer = new StreamWriter(fullPath))
{
writer.Write(new NewScriptGenerator(sp).ToString());
writer.Write(new ScriptGenerator(sp).ToString());
writer.Close();
}
}
Expand Down Expand Up @@ -281,49 +299,50 @@ protected string GetAbsoluteBuiltinTemplatePath()
return Path.Combine(EditorApplication.applicationContentsPath, machine.TemplatePath);
}

/// <summary>
/// Draw column headers on the Inspector view.
/// </summary>
protected void DrawHeaderSetting(BaseMachine m)
{
if (m.HasColumnHeader())
{
GUIStyle headerStyle = GUIHelper.MakeHeader();
GUILayout.Label("Type Settings:", headerStyle);

// Title
const int MEMBER_WIDTH = 100;
GUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.Label("Member", GUILayout.MinWidth(MEMBER_WIDTH));
GUILayout.FlexibleSpace();
string[] names = { "Type", "Array" };
int[] widths = { 55, 40 };
for (int i = 0; i < names.Length; i++)
using (new GUILayout.HorizontalScope(EditorStyles.toolbar))
{
GUILayout.Label(new GUIContent(names[i]), GUILayout.Width(widths[i]));
GUILayout.Label("Member", GUILayout.MinWidth(MEMBER_WIDTH));
GUILayout.FlexibleSpace();
string[] names = { "Type", "Array" };
int[] widths = { 55, 40 };
for (int i = 0; i < names.Length; i++)
{
GUILayout.Label(new GUIContent(names[i]), GUILayout.Width(widths[i]));
}
}
GUILayout.EndHorizontal();//EditorStyles.toolbar

//curretScroll = EditorGUILayout.BeginScrollView(curretScroll, false, false);
EditorGUILayout.BeginVertical("box");

//string lastCellName = string.Empty;
foreach (ColumnHeader header in m.ColumnHeaderList)
// Each cells
using (new EditorGUILayout.VerticalScope("box"))
{
GUILayout.BeginHorizontal();

// member field label
EditorGUILayout.LabelField(header.name, GUILayout.MinWidth(MEMBER_WIDTH));
GUILayout.FlexibleSpace();

// type enum popup
header.type = (CellType)EditorGUILayout.EnumPopup(header.type, GUILayout.Width(60));
GUILayout.Space(20);

// array toggle
header.isArray = EditorGUILayout.Toggle(header.isArray, GUILayout.Width(20));
GUILayout.Space(10);
GUILayout.EndHorizontal();
foreach (ColumnHeader header in m.ColumnHeaderList)
{
GUILayout.BeginHorizontal();

// show member field with label, read-only
EditorGUILayout.LabelField(header.name, GUILayout.MinWidth(MEMBER_WIDTH));
GUILayout.FlexibleSpace();

// specify type with enum-popup
header.type = (CellType)EditorGUILayout.EnumPopup(header.type, GUILayout.Width(60));
GUILayout.Space(20);

// array toggle
header.isArray = EditorGUILayout.Toggle(header.isArray, GUILayout.Width(20));
GUILayout.Space(10);
GUILayout.EndHorizontal();
}
}

EditorGUILayout.EndVertical(); //box
//EditorGUILayout.EndScrollView();
}
}
}
Expand Down
Loading

0 comments on commit 26fb6a7

Please sign in to comment.