Better user guidance for working with AtomVariables (#70)

* #69 added custom editor for Variable Types, to guide the usage flow and reduce errors.

* allows unlocking of initialvalue in playmode

* adjustments to Variable Inspector

* Generator now works with all kinds of setups. just select the Packages folder when calling RegenerateAll.
Used this to regenerate the CustomEditors

* supports now structs

* Added RaiseButtons in VariableEditor. #72
Adding simple logging helper on listeners, for fast debugging.

* Call `serializedObject.Update();` before `OnInspectorGUI` in the editor script in order to update old value when changing value.
Show children for PropertyFields for initial and old value.
Some minor refactoring - renaming variables
Clean up in `RegenereateAllAtoms`
Use `OnEnable` instead of `OnAfterDeserialize` when setting inital value for variable. `OnAfterDeserialize` was causing major issues with the custom editor, eg. it did run when focusing a Variable and showing the inspector, basically making it worthless to change or even inspect the Variable at runtime. `OnEnable` is only called ones when the ScriptableObject is loaded in runtime, which is what we really want. This has been tested running in the editor and in builds.
Add missing editors scripts `TouchUserInputVariableEditor`and `SceneFieldVariableEditor`
This commit is contained in:
Oliver Biwer 2019-11-14 12:59:11 +01:00 committed by Adam Ramberg
parent 1c8964e30f
commit 1dd2baeaec
39 changed files with 557 additions and 22 deletions

View File

@ -0,0 +1,100 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Custom editor for Variables. Provides a better user workflow and indicates when which variables can be edited
/// </summary>
public abstract class AtomVariableEditor : UnityEditor.Editor
{
private bool _lockedInitialValue = true;
public override void OnInspectorGUI()
{
serializedObject.Update();
bool valueWasUpdated = false;
EditorGUILayout.PropertyField(serializedObject.FindProperty("_developerDescription"));
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(_lockedInitialValue && EditorApplication.isPlayingOrWillChangePlaymode);
EditorGUILayout.PropertyField(serializedObject.FindProperty("_initialValue"), true);
EditorGUI.EndDisabledGroup();
if (EditorApplication.isPlaying)
{
_lockedInitialValue = GUILayout.Toggle(_lockedInitialValue, "", new GUIStyle("IN LockButton") { fixedHeight = 16, margin = new RectOffset(0, 2, 4, 0) });
}
EditorGUILayout.EndHorizontal();
using (new EditorGUI.DisabledGroupScope(!EditorApplication.isPlaying))
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(serializedObject.FindProperty("_value"), true);
if (EditorGUI.EndChangeCheck() && target is AtomBaseVariable atomTarget)
{
try
{
var value = serializedObject.FindProperty("_value").GetPropertyValue();
atomTarget.BaseValue = value;
}
catch (InvalidOperationException)
{
var value = serializedObject.FindProperty("_value").GetGenericPropertyValue(atomTarget.BaseValue);
atomTarget.BaseValue = value;
}
valueWasUpdated = true;
}
}
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("_oldValue"), true);
EditorGUI.EndDisabledGroup();
const int raiseButtonWidth = 52;
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("Changed"));
var changed = serializedObject.FindProperty("Changed").objectReferenceValue;
if (changed != null && changed is AtomEvent evt && target is AtomBaseVariable atomTarget)
{
GUILayout.Space(2);
if (GUILayout.Button("Raise", GUILayout.Width(raiseButtonWidth), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
evt.GetType().GetMethod("Raise", BindingFlags.Public | BindingFlags.Instance)?.Invoke(evt, new[] { atomTarget.BaseValue });
}
}
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("ChangedWithHistory"));
var changedWithHistory = serializedObject.FindProperty("ChangedWithHistory").objectReferenceValue;
if (changedWithHistory != null && changedWithHistory is AtomEvent evt && target is AtomBaseVariable atomTarget)
{
object oldValue = serializedObject.FindProperty("_oldValue").GetGenericPropertyValue(atomTarget.BaseValue);
GUILayout.Space(2);
if (GUILayout.Button("Raise", GUILayout.Width(raiseButtonWidth), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
{
if (GUILayout.Button("Raise", GUILayout.Width(raiseButtonWidth), GUILayout.Height(EditorGUIUtility.singleLineHeight)))
evt.GetType().GetMethod("Raise", BindingFlags.Public | BindingFlags.Instance)
?.Invoke(evt, new[] { atomTarget.BaseValue, oldValue });
}
}
}
if (!valueWasUpdated)
{
serializedObject.ApplyModifiedProperties();
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9550aecb04364b7b873f85e76b88469b
timeCreated: 1572385612

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 449b5bf4598748b2a749ccc30919253d
timeCreated: 1572382898

View File

@ -0,0 +1,13 @@
// generated file
using UnityEditor;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `bool`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(BoolVariable))]
public sealed class BoolVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 591afae35a04c7669ab974a2ef017f08
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
// generated file
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `Collider2D`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(Collider2DVariable))]
public sealed class Collider2DVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79d1363917a8b79e59c947e879fd026f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
// generated file
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `Collider`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(ColliderVariable))]
public sealed class ColliderVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dca45529bc4f1e31dbcd30eb20574e42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
// generated file
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `Color`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(ColorVariable))]
public sealed class ColorVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da1dfcdd1e4bb7c4083418e51b207481
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,13 @@
// generated file
using UnityEditor;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `float`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(FloatVariable))]
public sealed class FloatVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 408568d3dc768ca10a1ce180fc4b5559
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
// generated file
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `GameObject`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(GameObjectVariable))]
public sealed class GameObjectVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6f4259686c554cf8ad2611239f658be5
timeCreated: 1572554806

View File

@ -0,0 +1,13 @@
// generated file
using UnityEditor;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `int`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(IntVariable))]
public sealed class IntVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6af9f7558a5a454e90bbbf6ce1bd0541
timeCreated: 1572382924

View File

@ -0,0 +1,13 @@
// generated file
using UnityEditor;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `string`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(StringVariable))]
public sealed class StringVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 404d7547d21b4d1e958ac16e0a520749
timeCreated: 1572555412

View File

@ -0,0 +1,14 @@
// generated file
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `Vector2`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(Vector2Variable))]
public sealed class Vector2VariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 48b84618397a4b52bb2eb830fa5b65cf
timeCreated: 1572554754

View File

@ -0,0 +1,14 @@
// generated file
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
/// <summary>
/// Variable Inspector of type `Vector3`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(Vector3Variable))]
public sealed class Vector3VariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 78cf4391bcff8cedb879fa62b9b040e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,68 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace UnityAtoms.Editor
{
internal static class SerializedPropertyExtensions
{
public static T GetGenericPropertyValue<T>(this SerializedProperty property, T managedObjectOut)
{
object box = managedObjectOut;
var type = managedObjectOut.GetType();
foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
{
try
{
field.SetValue(box, property.FindPropertyRelative(field.Name).GetPropertyValue());
}
catch (InvalidOperationException)
{
}
}
return (T)box;
}
public static object GetPropertyValue(this SerializedProperty property)
{
if (property == null) throw new ArgumentNullException(nameof(property));
switch(property.propertyType)
{
case SerializedPropertyType.ObjectReference: return property.objectReferenceValue;
case SerializedPropertyType.ArraySize: return property.arraySize;
case SerializedPropertyType.Integer: return property.intValue;
case SerializedPropertyType.Boolean: return property.boolValue;
case SerializedPropertyType.Float: return property.floatValue;
case SerializedPropertyType.String: return property.stringValue;
case SerializedPropertyType.Color: return property.colorValue;
case SerializedPropertyType.LayerMask: return (LayerMask)property.intValue;
case SerializedPropertyType.Enum: return property.enumValueIndex;
case SerializedPropertyType.Vector2: return property.vector2Value;
case SerializedPropertyType.Vector3: return property.vector3Value;
case SerializedPropertyType.Vector4: return property.vector4Value;
case SerializedPropertyType.Vector2Int: return property.vector2IntValue;
case SerializedPropertyType.Vector3Int: return property.vector3IntValue;
case SerializedPropertyType.Quaternion: return property.quaternionValue;
case SerializedPropertyType.Rect: return property.rectValue;
case SerializedPropertyType.RectInt: return property.rectIntValue;
case SerializedPropertyType.BoundsInt: return property.boundsIntValue;
case SerializedPropertyType.Bounds: return property.boundsValue;
case SerializedPropertyType.Character: return (char)property.intValue;
case SerializedPropertyType.AnimationCurve: return property.animationCurveValue;
case SerializedPropertyType.FixedBufferSize: return property.fixedBufferSize;
case SerializedPropertyType.ExposedReference: return property.exposedReferenceValue;
case SerializedPropertyType.Generic:
throw new InvalidOperationException($"Cant handle {property.propertyType} types. for property {property.name}");
case SerializedPropertyType.Gradient:
throw new InvalidOperationException($"Cant handle {property.propertyType} types. for property {property.name}");
default:
throw new NotImplementedException();
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e83ef081eed545368e5c684a50bab8f4
timeCreated: 1572386030

View File

@ -56,7 +56,7 @@ namespace UnityAtoms.Editor
// Recursively search for template files. TODO: Is there a better way to find and load templates?
var templateSearchPath = Runtime.IsUnityAtomsRepo ?
Directory.GetParent(Directory.GetParent(Application.dataPath).FullName).FullName :
Directory.GetParent(baseWritePath).FullName : // "Packages"
Directory.GetParent(Application.dataPath).FullName;
var templatePaths = Directory.GetFiles(templateSearchPath, "UA_Template*.txt", SearchOption.AllDirectories);
var templateConditions = new List<string>();

View File

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
@ -44,6 +45,27 @@ namespace UnityAtoms.Editor
Debug.LogWarning("This is currently only available working in the Unity Atoms project...");
}
string path = EditorUtility.OpenFolderPanel("Select the 'Packages' folder (containing Core)", ".", "");
if (string.IsNullOrEmpty(path))
{
Debug.LogWarning("Empty path. Abort.");
return;
}
// make path relative:
path = new Uri(Application.dataPath).MakeRelativeUri(new Uri(path)).ToString();
var i = EditorUtility.DisplayDialogComplex("Regenerate Atoms",
$"Do you want to regenerate all Atoms and write them to '{path}'?\n",
"Yes, I know what I'm doing!", "Cancel", "");
if (i == 1)
{
Debug.LogWarning("Cancelled generating Atoms.");
return;
}
Runtime.IsUnityAtomsRepo = i == 0;
List<AtomType> ALL_ATOM_TYPES = new List<AtomType>()
{
AtomTypes.ACTION,
@ -61,20 +83,22 @@ namespace UnityAtoms.Editor
AtomTypes.VARIABLE
};
var itemsToRegenerate = new List<RegenerateItem>()
{
new RegenerateItem(type: "bool", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Collider2D", baseWritePath: "../Packages/Core", isEquatable: false, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Collider", baseWritePath: "../Packages/Core", isEquatable: false, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Color", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "float", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "GameObject", baseWritePath: "../Packages/Core", isEquatable: false, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "int", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "string", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Vector2", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Vector3", baseWritePath: "../Packages/Core", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "TouchUserInput", baseWritePath: "../Packages/Mobile", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.Mobile", subUnityAtomsNamespace: "Mobile"),
new RegenerateItem(type: "SceneField", baseWritePath: "../Packages/SceneMgmt", isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.SceneMgmt", subUnityAtomsNamespace: "SceneMgmt"),
new RegenerateItem(type: "bool", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Collider2D", baseWritePath: Path.Combine(path, "Core"), isEquatable: false, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Collider", baseWritePath: Path.Combine(path, "Core"), isEquatable: false, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Color", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "float", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "GameObject", baseWritePath: Path.Combine(path, "Core"), isEquatable: false, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "int", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "string", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Vector2", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "Vector3", baseWritePath: Path.Combine(path, "Core"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityEngine", subUnityAtomsNamespace: ""),
new RegenerateItem(type: "TouchUserInput", baseWritePath: Path.Combine(path, "Mobile"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.Mobile", subUnityAtomsNamespace: "Mobile"),
new RegenerateItem(type: "SceneField", baseWritePath: Path.Combine(path, "SceneMgmt"), isEquatable: true, atomTypesToGenerate: ALL_ATOM_TYPES, typeNamespace: "UnityAtoms.SceneMgmt", subUnityAtomsNamespace: "SceneMgmt"),
};
var generator = new Generator();

View File

@ -0,0 +1,23 @@
// generated file
using UnityEditor;
<%IF TYPE_HAS_NAMESPACE%>
using {TYPE_NAMESPACE};
<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
using UnityAtoms.Editor;
<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Variable Inspector of type `{TYPE}`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof({TYPE_NAME}Variable))]
public sealed class {TYPE_NAME}VariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 88c6cd99584540a0b9996d60416193d3
timeCreated: 1572554920

View File

@ -67,6 +67,14 @@ namespace UnityAtoms
_actionResponses[i].Do(item);
}
}
/// <summary>
/// Helper to regiser as listener callback
/// </summary>
public void DebugLog(T item)
{
Debug.Log(item.ToString());
}
}
/// <summary>
@ -134,5 +142,13 @@ namespace UnityAtoms
_actionResponses[i].Do(first, second);
}
}
/// <summary>
/// Helper to regiser as listener callback
/// </summary>
public void DebugLog(T1 item1, T2 item2)
{
Debug.Log(item1.ToString() + " <- " + item2);
}
}
}

View File

@ -18,10 +18,23 @@ namespace UnityAtoms
public const string LOG_PREFIX = "UnityAtoms :: ";
}
#if UNITY_EDITOR
private static bool? _isUnityAtomsRepo = false;
#endif
/// <summary>
/// Determine if we are working the Unity Atoms source library / repo or not.
/// </summary>
/// <returns>`true` if we are working in the Unity Atoms source library / repo, otherwise `false`.</returns>
public static bool IsUnityAtomsRepo { get => System.Environment.CurrentDirectory.Contains("unity-atoms/Examples"); }
public static bool IsUnityAtomsRepo
{
#if !UNITY_EDITOR
get => System.Environment.CurrentDirectory.Contains("unity-atoms/Examples");
#else
get => (_isUnityAtomsRepo = (_isUnityAtomsRepo ?? System.Environment.CurrentDirectory.Contains("unity-atoms/Examples"))).Value;
set => _isUnityAtomsRepo = value;
#endif
}
}
}

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace UnityAtoms
{
@ -12,8 +10,7 @@ namespace UnityAtoms
/// <typeparam name="E1">Event of type `AtomEvent&lt;T&gt;`.</typeparam>
/// <typeparam name="E2">Event of type `AtomEvent&lt;T, T&gt;`.</typeparam>
[EditorIcon("atom-icon-lush")]
public abstract class AtomVariable<T, E1, E2> : AtomBaseVariable<T>,
ISerializationCallbackReceiver
public abstract class AtomVariable<T, E1, E2> : AtomBaseVariable<T>
where E1 : AtomEvent<T>
where E2 : AtomEvent<T, T>
{
@ -58,6 +55,9 @@ namespace UnityAtoms
private void OnEnable()
{
_oldValue = _initialValue;
_value = _initialValue;
if (Changed == null) return;
Changed.Raise(Value);
}
@ -108,9 +108,6 @@ namespace UnityAtoms
return SetValue(variable.Value);
}
public void OnBeforeSerialize() { }
public void OnAfterDeserialize() { _value = _initialValue; }
#region Observable
/// <summary>

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1887292ce984d494298d0065a9fb003e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
// generated file
using UnityEditor;
using UnityAtoms.Mobile;
using UnityAtoms.Editor;
namespace UnityAtoms.Mobile.Editor
{
/// <summary>
/// Variable Inspector of type `TouchUserInput`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(TouchUserInputVariable))]
public sealed class TouchUserInputVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a72768c3752b1495b83355bdc144f619
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -81,7 +81,7 @@ namespace UnityAtoms.Mobile
/// <returns>`true` if equal, otherwise `false`.</returns>
public bool Equals(TouchUserInput other)
{
return this.InputState == other.InputState && this.InputWorldPos == other.InputWorldPos && this.InputWorldPosLastFrame == other.InputWorldPosLastFrame;
return this.InputState == other.InputState && this.InputWorldPos == other.InputWorldPos && this.InputWorldPosLastFrame == other.InputWorldPosLastFrame && this.InputPosLastDown == other.InputPosLastDown;
}
/// <summary>

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ffb58394f499b43dead7bda60d779f78
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
// generated file
using UnityEditor;
using UnityAtoms.SceneMgmt;
using UnityAtoms.Editor;
namespace UnityAtoms.SceneMgmt.Editor
{
/// <summary>
/// Variable Inspector of type `SceneField`. Inherits from `AtomVariableEditor`
/// </summary>
[CustomEditor(typeof(SceneFieldVariable))]
public sealed class SceneFieldVariableEditor : AtomVariableEditor
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aeacd70810e8c4835b06d4e4f6e34df9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: