Skip to content

Commit 1937ea8

Browse files
author
Cippo
committed
testing testing branch aren't stable
1 parent 21ff366 commit 1937ea8

File tree

5 files changed

+260
-6
lines changed

5 files changed

+260
-6
lines changed

InterfaceReference/Examples/Examples.unity

Lines changed: 150 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@ NavMeshSettings:
113113
debug:
114114
m_Flags: 0
115115
m_NavMeshData: {fileID: 0}
116+
--- !u!1 &122467412
117+
GameObject:
118+
m_ObjectHideFlags: 0
119+
m_CorrespondingSourceObject: {fileID: 0}
120+
m_PrefabInternal: {fileID: 0}
121+
serializedVersion: 6
122+
m_Component:
123+
- component: {fileID: 122467413}
124+
m_Layer: 0
125+
m_Name: '--------------------------'
126+
m_TagString: Untagged
127+
m_Icon: {fileID: 0}
128+
m_NavMeshLayer: 0
129+
m_StaticEditorFlags: 0
130+
m_IsActive: 1
131+
--- !u!4 &122467413
132+
Transform:
133+
m_ObjectHideFlags: 0
134+
m_CorrespondingSourceObject: {fileID: 0}
135+
m_PrefabInternal: {fileID: 0}
136+
m_GameObject: {fileID: 122467412}
137+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
138+
m_LocalPosition: {x: 0, y: 0, z: 0}
139+
m_LocalScale: {x: 1, y: 1, z: 1}
140+
m_Children: []
141+
m_Father: {fileID: 0}
142+
m_RootOrder: 9
143+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
116144
--- !u!1 &257792216
117145
GameObject:
118146
m_ObjectHideFlags: 0
@@ -364,8 +392,8 @@ MonoBehaviour:
364392
- FavParams: 0
365393
FavString: []
366394
list:
367-
- {fileID: 1308923934}
368-
ActiveGameObject: {fileID: 1308923934}
395+
- {fileID: 1968288553}
396+
ActiveGameObject: {fileID: 1968288553}
369397
GUIDsList: []
370398
GUIDsActiveGameObject:
371399
PATHsList: []
@@ -376,8 +404,8 @@ MonoBehaviour:
376404
- FavParams: 0
377405
FavString: []
378406
list:
379-
- {fileID: 358149321}
380-
ActiveGameObject: {fileID: 358149321}
407+
- {fileID: 122467412}
408+
ActiveGameObject: {fileID: 122467412}
381409
GUIDsList: []
382410
GUIDsActiveGameObject:
383411
PATHsList: []
@@ -388,8 +416,8 @@ MonoBehaviour:
388416
- FavParams: 0
389417
FavString: []
390418
list:
391-
- {fileID: 908261137}
392-
ActiveGameObject: {fileID: 908261137}
419+
- {fileID: 1824733537}
420+
ActiveGameObject: {fileID: 1824733537}
393421
GUIDsList: []
394422
GUIDsActiveGameObject:
395423
PATHsList: []
@@ -409,6 +437,54 @@ MonoBehaviour:
409437
InstanceID: 0
410438
wasInit: 0
411439
CashedBool: 0
440+
- FavParams: 0
441+
FavString: []
442+
list:
443+
- {fileID: 506120582}
444+
ActiveGameObject: {fileID: 506120582}
445+
GUIDsList: []
446+
GUIDsActiveGameObject:
447+
PATHsList: []
448+
PATHsActiveGameObject:
449+
InstanceID: 0
450+
wasInit: 0
451+
CashedBool: 0
452+
- FavParams: 0
453+
FavString: []
454+
list:
455+
- {fileID: 1308923934}
456+
ActiveGameObject: {fileID: 1308923934}
457+
GUIDsList: []
458+
GUIDsActiveGameObject:
459+
PATHsList: []
460+
PATHsActiveGameObject:
461+
InstanceID: 0
462+
wasInit: 0
463+
CashedBool: 0
464+
- FavParams: 0
465+
FavString: []
466+
list:
467+
- {fileID: 358149321}
468+
ActiveGameObject: {fileID: 358149321}
469+
GUIDsList: []
470+
GUIDsActiveGameObject:
471+
PATHsList: []
472+
PATHsActiveGameObject:
473+
InstanceID: 0
474+
wasInit: 0
475+
CashedBool: 0
476+
- FavParams: 0
477+
FavString: []
478+
list:
479+
- {fileID: 908261137}
480+
ActiveGameObject: {fileID: 908261137}
481+
GUIDsList: []
482+
GUIDsActiveGameObject:
483+
PATHsList: []
484+
PATHsActiveGameObject:
485+
InstanceID: 0
486+
wasInit: 0
487+
CashedBool: 0
412488
Hash4: []
413489
Hash5: []
414490
Hash5_Fix2_0: []
@@ -492,3 +568,71 @@ MonoBehaviour:
492568
m_Script: {fileID: 11500000, guid: ccd30b2131b8f914f8d4673f35bc40a7, type: 3}
493569
m_Name:
494570
m_EditorClassIdentifier:
571+
--- !u!1 &1824733537
572+
GameObject:
573+
m_ObjectHideFlags: 0
574+
m_CorrespondingSourceObject: {fileID: 0}
575+
m_PrefabInternal: {fileID: 0}
576+
serializedVersion: 6
577+
m_Component:
578+
- component: {fileID: 1824733538}
579+
m_Layer: 0
580+
m_Name: '--------------------------'
581+
m_TagString: Untagged
582+
m_Icon: {fileID: 0}
583+
m_NavMeshLayer: 0
584+
m_StaticEditorFlags: 0
585+
m_IsActive: 1
586+
--- !u!4 &1824733538
587+
Transform:
588+
m_ObjectHideFlags: 0
589+
m_CorrespondingSourceObject: {fileID: 0}
590+
m_PrefabInternal: {fileID: 0}
591+
m_GameObject: {fileID: 1824733537}
592+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
593+
m_LocalPosition: {x: 0, y: 0, z: 0}
594+
m_LocalScale: {x: 1, y: 1, z: 1}
595+
m_Children: []
596+
m_Father: {fileID: 0}
597+
m_RootOrder: 7
598+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
599+
--- !u!1 &1968288553
600+
GameObject:
601+
m_ObjectHideFlags: 0
602+
m_CorrespondingSourceObject: {fileID: 0}
603+
m_PrefabInternal: {fileID: 0}
604+
serializedVersion: 6
605+
m_Component:
606+
- component: {fileID: 1968288555}
607+
- component: {fileID: 1968288554}
608+
m_Layer: 0
609+
m_Name: Component with Exposed Reference
610+
m_TagString: Untagged
611+
m_Icon: {fileID: 0}
612+
m_NavMeshLayer: 0
613+
m_StaticEditorFlags: 0
614+
m_IsActive: 1
615+
--- !u!114 &1968288554
616+
MonoBehaviour:
617+
m_ObjectHideFlags: 0
618+
m_CorrespondingSourceObject: {fileID: 0}
619+
m_PrefabInternal: {fileID: 0}
620+
m_GameObject: {fileID: 1968288553}
621+
m_Enabled: 1
622+
m_EditorHideFlags: 0
623+
m_Script: {fileID: 11500000, guid: 5d7b9862a7a50ed478a95fe23ae1a3c7, type: 3}
624+
m_Name:
625+
m_EditorClassIdentifier:
626+
--- !u!4 &1968288555
627+
Transform:
628+
m_ObjectHideFlags: 0
629+
m_CorrespondingSourceObject: {fileID: 0}
630+
m_PrefabInternal: {fileID: 0}
631+
m_GameObject: {fileID: 1968288553}
632+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
633+
m_LocalPosition: {x: 0, y: 0, z: 0}
634+
m_LocalScale: {x: 1, y: 1, z: 1}
635+
m_Children: []
636+
m_Father: {fileID: 0}
637+
m_RootOrder: 8
638+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Author: Alessandro Salani (Cippman)
3+
*/
4+
5+
using System;
6+
using CippSharp.Interfaces;
7+
using UnityEditor;
8+
using UnityEngine;
9+
using Object = UnityEngine.Object;
10+
11+
namespace CippSharp.Interfaces
12+
{
13+
public class ExposeAttribute : Attribute
14+
{
15+
ExposedReference<>
16+
}
17+
}
18+
19+
20+
#if UNITY_EDITOR
21+
namespace CippSharpEditor.Interfaces
22+
{
23+
/// <summary>
24+
/// Custom drawer of TypeFilterAttribute.
25+
/// </summary>
26+
[CustomPropertyDrawer(typeof(ExposeAttribute))]
27+
public class ExposeAttributeDrawer : PropertyDrawer
28+
{
29+
private object target = null;
30+
private readonly Object nullObject = null;
31+
private Object TargetObject
32+
{
33+
get { return target != null ? (Object)target : nullObject; }
34+
set { target = value; }
35+
}
36+
37+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
38+
{
39+
return EditorGUI.GetPropertyHeight(property, label, property.isExpanded && property.hasChildren);
40+
}
41+
42+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
43+
{
44+
ExposeAttribute exposeAttribute = attribute as ExposeAttribute;
45+
Type fieldType = fieldInfo.FieldType;
46+
if (property.propertyType == SerializedPropertyType.Generic && fieldType.IsInterface)
47+
{
48+
if (exposeAttribute != null)
49+
{
50+
target = fieldInfo.GetValue(property.serializedObject.targetObject);
51+
if (target == null)
52+
{
53+
TargetObject = EditorGUI.ObjectField(position, TargetObject, typeof(Object), true);
54+
fieldInfo.SetValue(property.serializedObject.targetObject, TargetObject);
55+
}
56+
else if (target is Object)
57+
{
58+
TargetObject = EditorGUI.ObjectField(position, TargetObject, typeof(Object), true);
59+
fieldInfo.SetValue(property.serializedObject.targetObject, TargetObject);
60+
}
61+
else
62+
{
63+
//Not implemented for interfaces that aren't also of type Object.
64+
}
65+
}
66+
else
67+
{
68+
Debug.LogError("Failed to assign the attribute.");
69+
}
70+
}
71+
else
72+
{
73+
Debug.LogWarning("Expose Attribute supports only Interface Reference fields.");
74+
}
75+
}
76+
}
77+
}
78+
#endif
79+

InterfaceReference/Scripts/Attributes/Expose.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using UnityEngine;
2+
3+
namespace CippSharp.Interfaces.Examples
4+
{
5+
public class ExposedInterfaceReference : MonoBehaviour
6+
{
7+
[SerializeField, Expose] public ICustomInterfaceExample customInterfaceExample = null;
8+
}
9+
}

InterfaceReference/Scripts/Examples/ExposedInterfaceReference.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)