Tanoda
pb_ComponentEditorResolver.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using System.Collections.Generic;
4using UnityEngine.Video;
5
6namespace GILES.Interface
7{
14 public static class pb_ComponentEditorResolver
15 {
19 readonly static Dictionary<Type, Type> builtInComponentEditors = new Dictionary<Type, Type>()
20 {
21 { typeof(Transform), typeof(pb_TransformEditor) },
22 { typeof(RectTransform), typeof(pb_TransformEditor) },
23 { typeof(MeshRenderer), typeof(pb_MeshRendererEditor) },
24 { typeof(Camera), typeof(pb_CameraEditor) },
25 { typeof(OffsetHolder), typeof(pb_OffsetHolderEditor) },
26 { typeof(VideoPlayer), typeof(pb_VideoPlayerEditor) },
27 { typeof(RenameObject), typeof(pb_RenameObjectEditor) },
28 { typeof(VisualOffset), typeof(pb_VisualOffsetEditor)}
29 };
30
34 public static pb_ComponentEditor GetEditor(Component component)
35 {
36 GameObject go = new GameObject();
37
38 Type editorType = null;
39
40 if( !builtInComponentEditors.TryGetValue(component.GetType(), out editorType) )
41 {
42 foreach(KeyValuePair<Type, Type> kvp in builtInComponentEditors)
43 {
44 if(kvp.Key.IsAssignableFrom(component.GetType()))
45 {
46 editorType = kvp.Value;
47 break;
48 }
49 }
50 }
51
52 go.name = component.name;
53 pb_ComponentEditor editor = (pb_ComponentEditor) go.AddComponent( editorType ?? typeof(pb_ComponentEditor) );
54 editor.SetComponent(component);
55
56 return editor;
57 }
58 }
59}
UnityEngine.Component Component