-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditorInternal; | ||
using UnityEditor; | ||
|
||
namespace ARCeye | ||
{ | ||
[CustomPropertyDrawer(typeof(Layer))] | ||
public class LayerDrawer : PropertyDrawer | ||
{ | ||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) | ||
{ | ||
return EditorGUI.GetPropertyHeight(property, label, true); | ||
} | ||
|
||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
float lineHeight = EditorGUIUtility.singleLineHeight + 2; | ||
|
||
EditorGUI.BeginProperty(position, label, property); | ||
|
||
var layerNameProp = property.FindPropertyRelative("layerName"); | ||
var linkToStageProp = property.FindPropertyRelative("linkToStage"); | ||
var stageNameProp = property.FindPropertyRelative("stageName"); | ||
var subLayerProp = property.FindPropertyRelative("subLayers"); | ||
|
||
string layerName = layerNameProp.stringValue; | ||
bool linkToStage = linkToStageProp.boolValue; | ||
|
||
EditorGUI.PrefixLabel(position, new GUIContent($"계층 - {layerName}")); | ||
position.y += lineHeight; | ||
|
||
{ | ||
EditorGUI.indentLevel++; | ||
|
||
float fullWidth = EditorGUIUtility.currentViewWidth - position.x - 10; | ||
|
||
Rect layerNameRect = new Rect(position.x, position.y, fullWidth, EditorGUIUtility.singleLineHeight); | ||
position.y += lineHeight; | ||
|
||
Rect linkToStageRect = new Rect(position.x, position.y, fullWidth, EditorGUIUtility.singleLineHeight); | ||
position.y += lineHeight; | ||
|
||
EditorGUI.PropertyField(layerNameRect, layerNameProp, new GUIContent("계층 이름")); | ||
EditorGUI.PropertyField(linkToStageRect, linkToStageProp, new GUIContent("스테이지 연결")); | ||
|
||
if(linkToStage) | ||
{ | ||
Rect stageNameRect = new Rect(position.x, position.y, fullWidth, EditorGUIUtility.singleLineHeight); | ||
position.y += lineHeight; | ||
|
||
EditorGUI.PropertyField(stageNameRect, stageNameProp, new GUIContent("스테이지 이름")); | ||
} | ||
else | ||
{ | ||
Rect subLayerRect = new Rect(position.x, position.y, fullWidth, EditorGUIUtility.singleLineHeight); | ||
position.y += lineHeight; | ||
|
||
EditorGUI.PropertyField(subLayerRect, subLayerProp, new GUIContent("하위 계층")); | ||
EditorUtility.SetDirty(subLayerProp.serializedObject.targetObject); | ||
} | ||
|
||
EditorGUI.indentLevel--; | ||
} | ||
|
||
subLayerProp.serializedObject.ApplyModifiedProperties(); | ||
property.serializedObject.ApplyModifiedProperties(); | ||
|
||
EditorGUI.EndProperty(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace ARCeye | ||
{ | ||
[CustomEditor(typeof(LayerInfoSetting))] | ||
public class LayerInfoSettingEditor : Editor | ||
{ | ||
private LayerInfoSetting m_LayerInfoSetting; | ||
|
||
private SerializedProperty m_LayerTreeProp; | ||
|
||
private Color m_OriginalContentColor; | ||
private Color m_OriginalBackgroundColor; | ||
|
||
|
||
const int kMAX_DEPTH = 7; | ||
|
||
void OnEnable() | ||
{ | ||
m_LayerInfoSetting = (LayerInfoSetting) target; | ||
m_LayerTreeProp = serializedObject.FindProperty("m_LayerTree"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
DrawLogo(); | ||
DrawAllLayers(); | ||
} | ||
|
||
private void DrawLogo() | ||
{ | ||
EditorGUILayout.Space(); | ||
|
||
GUIStyle style = new GUIStyle(); | ||
style.fixedHeight = 30; | ||
style.alignment = TextAnchor.MiddleCenter; | ||
|
||
GUILayout.Label(Resources.Load("Sprites/ARSDK-Logo") as Texture, style, GUILayout.ExpandWidth(true)); | ||
|
||
EditorGUILayout.Space(); | ||
} | ||
|
||
private void DrawAllLayers() | ||
{ | ||
SerializedLayerTree layerTree = m_LayerInfoSetting.layerTree; | ||
Layer layer = layerTree.Deserialize(); | ||
|
||
DrawLayer(layer, 0); | ||
|
||
layerTree.SerializeFromLayer(layer); | ||
|
||
EditorUtility.SetDirty(m_LayerTreeProp.serializedObject.targetObject); | ||
m_LayerTreeProp.serializedObject.ApplyModifiedProperties(); | ||
} | ||
|
||
private void DrawLayer(Layer layer, int depth) | ||
{ | ||
if(layer == null) return; | ||
if(depth == kMAX_DEPTH) return; | ||
|
||
m_OriginalContentColor = GUI.contentColor; | ||
m_OriginalBackgroundColor = GUI.backgroundColor; | ||
|
||
|
||
EditorGUI.indentLevel = depth; | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
|
||
// FoldOut 타이틀 바. | ||
DrawFoldOutLabel(layer, depth); | ||
|
||
// 새 계층 추가 버튼 | ||
DrawAddLayerButton(layer, depth); | ||
|
||
// 계층 삭제 버튼 | ||
DrawRemoveLayerButton(layer); | ||
|
||
EditorGUILayout.EndHorizontal(); | ||
|
||
|
||
// Foldout 컨텐츠. | ||
if(layer.foldout) | ||
{ | ||
DrawFoldOutContents(layer, depth); | ||
} | ||
} | ||
|
||
private void DrawFoldOutLabel(Layer layer, int depth) | ||
{ | ||
string foldoutLabel; | ||
|
||
if(layer.linkToStage) | ||
{ | ||
GUI.contentColor = Color.yellow; | ||
foldoutLabel = $"계층 {depth + 1} {layer.layerName} → {layer.stageName}"; | ||
} | ||
else | ||
{ | ||
foldoutLabel = $"계층 {depth + 1} {layer.layerName}"; | ||
} | ||
|
||
layer.foldout = EditorGUILayout.Foldout(layer.foldout, foldoutLabel); | ||
|
||
GUI.contentColor = m_OriginalContentColor; | ||
} | ||
|
||
private void DrawAddLayerButton(Layer layer, int depth) | ||
{ | ||
GUILayout.FlexibleSpace(); | ||
|
||
GUI.backgroundColor = Color.green; | ||
if(layer.foldout && !layer.linkToStage && layer.depth < 6) | ||
{ | ||
if(GUILayout.Button($"새 계층 {depth + 2} 추가")) { | ||
layer.subLayers.Add(new Layer(depth + 1)); | ||
} | ||
} | ||
GUI.backgroundColor = m_OriginalBackgroundColor; | ||
} | ||
|
||
private void DrawRemoveLayerButton(Layer layer) | ||
{ | ||
GUI.backgroundColor = Color.red; | ||
if(GUILayout.Button($"-")) | ||
{ | ||
layer.isRemoved = true; | ||
} | ||
GUI.backgroundColor = m_OriginalBackgroundColor; | ||
} | ||
|
||
private void DrawFoldOutContents(Layer layer, int depth) | ||
{ | ||
EditorGUI.indentLevel++; | ||
|
||
layer.layerName = EditorGUILayout.TextField("계층 이름", layer.layerName); | ||
layer.linkToStage = EditorGUILayout.Toggle("스테이지 연결", layer.linkToStage); | ||
|
||
if(layer.linkToStage) | ||
{ | ||
layer.stageName = EditorGUILayout.TextField("스테이지 이름", layer.stageName); | ||
} | ||
else | ||
{ | ||
List<Layer> subLayers = layer.subLayers; | ||
Layer removedLayer = null; | ||
foreach(var child in subLayers) | ||
{ | ||
if(child.data == null) continue; | ||
DrawLayer(child, depth + 1); | ||
|
||
if(child.isRemoved) { | ||
removedLayer = child; | ||
} | ||
} | ||
|
||
if(removedLayer != null) | ||
{ | ||
subLayers.Remove(removedLayer); | ||
} | ||
} | ||
|
||
EditorGUI.indentLevel--; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace ARCeye | ||
{ | ||
public class LayerInfoSettingGenerator | ||
{ | ||
[MenuItem("Assets/Create/ARCeye/LayerInfoSetting")] | ||
public static void CreateLayerInfoSetting() | ||
{ | ||
LayerInfoSetting asset = ScriptableObject.CreateInstance<LayerInfoSetting>(); | ||
|
||
AssetDatabase.CreateAsset(asset, "Assets/ARPG/Core/LayerInfoSetting.asset"); | ||
AssetDatabase.SaveAssets(); | ||
|
||
EditorUtility.FocusProjectWindow(); | ||
|
||
Selection.activeObject = asset; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!114 &11400000 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 0} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: f12a043366a0f44e6a4a4aea6a2e16df, type: 3} | ||
m_Name: LayerInfoSetting | ||
m_EditorClassIdentifier: | ||
m_LayerTree: | ||
layerList: | ||
- data: | ||
layerName: AMCOHERITZ | ||
linkToStage: 0 | ||
stageName: aa | ||
depth: 0 | ||
layerInfoCode: AMCOHERITZ | ||
foldout: 1 | ||
isRemoved: 0 | ||
childCount: 2 | ||
- data: | ||
layerName: GND | ||
linkToStage: 1 | ||
stageName: 1F | ||
depth: 1 | ||
layerInfoCode: AMCOHERITZ_GND | ||
foldout: 1 | ||
isRemoved: 0 | ||
childCount: 0 | ||
- data: | ||
layerName: 2F | ||
linkToStage: 1 | ||
stageName: 2F | ||
depth: 1 | ||
layerInfoCode: AMCOHERITZ_2F | ||
foldout: 1 | ||
isRemoved: 0 | ||
childCount: 1 | ||
- data: | ||
layerName: | ||
linkToStage: 0 | ||
stageName: | ||
depth: 2 | ||
layerInfoCode: | ||
foldout: 1 | ||
isRemoved: 0 | ||
childCount: 1 | ||
- data: | ||
layerName: | ||
linkToStage: 0 | ||
stageName: | ||
depth: 3 | ||
layerInfoCode: | ||
foldout: 1 | ||
isRemoved: 0 | ||
childCount: 0 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.