forked from psygames/HotUnity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yinlong
committed
May 21, 2021
1 parent
a53ebc0
commit 5f817c2
Showing
6 changed files
with
92 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace HotUnity.Editor | ||
{ | ||
public static class HotFieldGUI | ||
{ | ||
public static Type hotScriptType; | ||
|
||
public static HotScriptAdapter.CacheInfo EditorDrawField(Type type, HotScriptAdapter.CacheInfo info) | ||
{ | ||
var title = Helper.ToTitle(info.fieldName); | ||
if (info.typeName == typeof(string).FullName) | ||
{ | ||
info.stringValue = EditorGUILayout.TextField(title, info.stringValue); | ||
} | ||
else if (info.typeName == typeof(Vector3).FullName) | ||
{ | ||
info.vector3Value = EditorGUILayout.Vector3Field(title, info.vector3Value); | ||
} | ||
else if (type.IsClass && typeof(Component).IsAssignableFrom(type)) | ||
{ | ||
info.componentValue = (Component)EditorGUILayout.ObjectField(title, info.componentValue, type); | ||
} | ||
else if (type.IsClass && hotScriptType.IsAssignableFrom(type)) | ||
{ | ||
var tempComp = (Component)EditorGUILayout.ObjectField(title, info.componentValue, typeof(HotScriptAdapter)); | ||
if (tempComp != null && tempComp is HotScriptAdapter | ||
&& ((HotScriptAdapter)tempComp).targetClass == type.FullName) | ||
{ | ||
info.componentValue = tempComp; | ||
} | ||
else | ||
{ | ||
info.componentValue = null; | ||
} | ||
} | ||
return info; | ||
} | ||
|
||
|
||
public static void RuntimeDrawField(FieldInfo fieldInfo, object obj) | ||
{ | ||
var title = Helper.ToTitle(fieldInfo.Name); | ||
if (fieldInfo.FieldType.FullName == typeof(string).FullName) | ||
{ | ||
var value = EditorGUILayout.TextField(title, $"{fieldInfo.GetValue(obj)}"); | ||
fieldInfo.SetValue(obj, value); | ||
} | ||
else if (fieldInfo.FieldType.FullName == typeof(Vector3).FullName) | ||
{ | ||
var value = EditorGUILayout.Vector3Field(title, (Vector3)fieldInfo.GetValue(obj)); | ||
fieldInfo.SetValue(obj, value); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters