mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-16 21:08:28 +00:00
create inspector for LightSource
This commit is contained in:
parent
f87eb89c63
commit
0a3d2a53dc
4 changed files with 87 additions and 0 deletions
40
Assets/Scripts/Editor/EditorUtils.cs
Normal file
40
Assets/Scripts/Editor/EditorUtils.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SanAndreasUnity.Editor
|
||||
{
|
||||
public static class EditorUtils
|
||||
{
|
||||
|
||||
public static void DrawAllFieldsInInspector(object objectToDraw)
|
||||
{
|
||||
var fieldInfos = objectToDraw
|
||||
.GetType()
|
||||
.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
|
||||
foreach (var fieldInfo in fieldInfos)
|
||||
{
|
||||
var type = fieldInfo.FieldType;
|
||||
var value = fieldInfo.GetValue(objectToDraw);
|
||||
string labelText = $"{fieldInfo.Name}: ";
|
||||
|
||||
if (type.IsAssignableFrom(typeof(Component)))
|
||||
{
|
||||
EditorGUILayout.ObjectField(labelText, value as Component, type, true);
|
||||
}
|
||||
else if (type.IsEnum)
|
||||
{
|
||||
if (type.GetCustomAttribute<System.FlagsAttribute>() != null)
|
||||
EditorGUILayout.EnumFlagsField(labelText, value as System.Enum);
|
||||
else
|
||||
EditorGUILayout.EnumPopup(labelText, value as System.Enum);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField($"{labelText} {value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Editor/EditorUtils.cs.meta
Normal file
11
Assets/Scripts/Editor/EditorUtils.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64e4f6e8ec6a92a438502d2b48181ef8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Scripts/Editor/LightSourceInspector.cs
Normal file
25
Assets/Scripts/Editor/LightSourceInspector.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using SanAndreasUnity.Behaviours.World;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SanAndreasUnity.Editor
|
||||
{
|
||||
[CustomEditor(typeof(LightSource))]
|
||||
public class LightSourceInspector : UnityEditor.Editor
|
||||
{
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.DrawDefaultInspector ();
|
||||
|
||||
GUILayout.Space (10);
|
||||
GUILayout.Label("Light info:");
|
||||
GUILayout.Space (10);
|
||||
|
||||
var lightSource = (LightSource) this.target;
|
||||
|
||||
EditorUtils.DrawAllFieldsInInspector(lightSource.LightInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Editor/LightSourceInspector.cs.meta
Normal file
11
Assets/Scripts/Editor/LightSourceInspector.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2273f1726cfab940b38885d7f7ccf2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Reference in a new issue