Skip to content
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

- Reactivate Generator function in Unity 2018.4. #106

Merged
merged 12 commits into from
Feb 19, 2020
22 changes: 18 additions & 4 deletions Packages/Core/Editor/Drawers/VariableDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
return;
}

label = EditorGUI.BeginProperty(position, label, property);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but need you to revert these changes before I merge this PR (the complete file).

position = EditorGUI.PrefixLabel(position, label);

var inner = new SerializedObject(property.objectReferenceValue);
var valueProp = inner.FindProperty("_value");
var width = GetPreviewSpace(valueProp.type) + (property.depth == 0 ? EditorGUIUtility.labelWidth : 0);
var restRect = IMGUIUtils.SnipRectH(position, width, out position, 6f);
base.OnGUI(position, property, GUIContent.none);
var width = GetPreviewSpace(valueProp.type);
Rect previewRect = new Rect(position);
previewRect.width = GetPreviewSpace(valueProp.type);
position.xMin = previewRect.xMax;

int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;

EditorGUI.BeginDisabledGroup(true);
EditorGUI.PropertyField(restRect, valueProp, label, false);
EditorGUI.PropertyField(previewRect, valueProp, GUIContent.none, false);
EditorGUI.EndDisabledGroup();

position.x = position.x + 6f;
position.width = position.width - 6f;
base.OnGUI(position, property, GUIContent.none);

EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}

private float GetPreviewSpace(string type)
Expand Down
5 changes: 3 additions & 2 deletions Packages/Core/Editor/Generator/Generator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_2019_1_OR_NEWER
#if UNITY_2018_4_OR_NEWER
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -56,8 +56,9 @@ public void Generate(string type, string baseWritePath, bool isEquatable, List<A

// Recursively search for template files. TODO: Is there a better way to find and load templates?
var templateSearchPath = Runtime.IsUnityAtomsRepo ?
Directory.GetParent(baseWritePath).FullName : // "Packages"
Directory.GetParent(Runtime.UnityAtomsCorePath).FullName : // "Packages"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if you do it like this instead:
Directory.GetParent(Application.dataPath).Parent.FullName
In my mind it's better if we can compute the path at runtime instead of relying on constants.

Directory.GetParent(Application.dataPath).FullName;

var templatePaths = Directory.GetFiles(templateSearchPath, "UA_Template*.txt", SearchOption.AllDirectories);
var templateConditions = new List<string>();
if (isEquatable) { templateConditions.Add("EQUATABLE"); }
Expand Down
13 changes: 11 additions & 2 deletions Packages/Core/Editor/Generator/GeneratorEditor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#if UNITY_2019_1_OR_NEWER
#if UNITY_2018_4_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
#if UNITY_2019_1_OR_NEWER
using UnityEngine.UIElements;
#elif UNITY_2018_4_OR_NEWER
using UnityEditor.Experimental.UIElements;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;
#endif

namespace UnityAtoms.Editor
{
Expand Down Expand Up @@ -148,8 +154,11 @@ private void OnEnable()
AtomTypes.FUNCTION_X2
};
generator = generator == null ? new Generator() : generator;

#if UNITY_2019_1_OR_NEWER
var root = this.rootVisualElement;
#elif UNITY_2018_4_OR_NEWER
var root = this.GetRootVisualContainer();
#endif
var pathRow = new VisualElement() { style = { flexDirection = FlexDirection.Row } };
pathRow.Add(new Label() { text = "Relative Write Path", style = { width = 180, marginRight = 8 } });
var textfield = new TextField() { value = _writePath, style = { flexGrow = 1 } };
Expand Down
2 changes: 1 addition & 1 deletion Packages/Core/Editor/Generator/RegenerateAllAtoms.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_2019_1_OR_NEWER
#if UNITY_2018_4_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
Expand Down
9 changes: 9 additions & 0 deletions Packages/Core/Runtime/Utils/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@ public static bool IsUnityAtomsRepo
{
get => System.Environment.CurrentDirectory.Contains("unity-atoms/Examples");
}

/// <summary>
/// Returns the path to Unity Atoms Core.
/// Mainly used to search for Templates.
/// </summary>
public static string UnityAtomsCorePath
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove constant. See my first comment.

{
get => "../Packages/Core";
}
}
}