Example #1
0
        private void CreateEditor()
        {
            if (m_editor != null)
            {
                Destroy(m_editor);
            }

            if (Editor.Selection.activeObject == null)
            {
                return;
            }

            UnityObject[] selectedObjects = Editor.Selection.objects.Where(o => o != null).ToArray();
            if (selectedObjects.Length != 1)
            {
                return;
            }

            Type objType = selectedObjects[0].GetType();

            for (int i = 1; i < selectedObjects.Length; ++i)
            {
                if (objType != selectedObjects[i].GetType())
                {
                    return;
                }
            }

            GameObject editorPrefab;

#if !UNITY_WEBGL && PROC_MATERIAL
            if (objType == typeof(Material) || objType == typeof(ProceduralMaterial))
#else
            if (objType == typeof(Material))
#endif

            {
                Material mat = selectedObjects[0] as Material;
                if (mat.shader == null)
                {
                    return;
                }

                editorPrefab = EditorsMap.GetMaterialEditor(mat.shader);
            }
            else
            {
                if (!EditorsMap.IsObjectEditorEnabled(objType))
                {
                    return;
                }
                editorPrefab = EditorsMap.GetObjectEditor(objType);
            }

            if (editorPrefab != null)
            {
                m_editor = Instantiate(editorPrefab);
                m_editor.transform.SetParent(Panel, false);
            }
        }
Example #2
0
        private void Init()
        {
            m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapPrefabName);
            if (m_map == null)
            {
                m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapTemplateName);
            }
            EditorsMap editorsMap = new EditorsMap();

            Assembly[] allAssemblies;
            Type[]     types;
            GetUOAssembliesAndTypes(out allAssemblies, out types);

            Assembly[] unityAssemblies = allAssemblies.Where(a => a != null && a.FullName != null && a.FullName.Contains("UnityEngine")).ToArray();
            Assembly[] otherAssemblies = allAssemblies.Where(a => a != null && a.FullName != null && !a.FullName.Contains("UnityEngine")).ToArray();

            m_objectEditorDescriptors = new[] { typeof(GameObject) }
            .Where(t => t.IsPublic && !t.IsGenericType)
            .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray();
            m_propertyEditorDescriptors = new[] { typeof(object), typeof(UnityEngine.Object), typeof(bool), typeof(Enum), typeof(List <>), typeof(Array), typeof(string), typeof(int), typeof(float), typeof(Range), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(Quaternion), typeof(Color), typeof(Bounds) }
            .Where(t => t.IsPublic)
            .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsPropertyEditorEnabled(t), m_map != null ? editorsMap.GetPropertyEditor(t, true) : null, true)).ToArray();
            m_stdComponentEditorDescriptors = unityAssemblies.SelectMany(a => a.GetTypes())
                                              .Where(t => typeof(Component).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType)
                                              .OrderBy(t => (t == typeof(Component)) ? string.Empty : t.Name)
                                              .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray();
            m_scriptEditorDescriptors = otherAssemblies.SelectMany(a => a.GetTypes())
                                        .Where(t => typeof(MonoBehaviour).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType)
                                        .OrderBy(t => t.FullName)
                                        .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray();

            List <Material> materials = new List <Material>();

            string[] assets = AssetDatabase.GetAllAssetPaths();
            foreach (string asset in assets)
            {
                if (!asset.EndsWith(".mat"))
                {
                    continue;
                }
                Material material = AssetDatabase.LoadAssetAtPath <Material>(asset);

                if (material == null ||
                    (material.hideFlags & HideFlags.DontSaveInBuild) != 0 ||
                    material.shader == null ||
                    (material.shader.hideFlags & HideFlags.DontSaveInBuild) != 0)
                {
                    continue;
                }
                materials.Add(material);
            }
            MaterialEditorDescriptor[] defaultDescriptors  = new[] { new MaterialEditorDescriptor(null, m_map != null && m_map.IsDefaultMaterialEditorEnabled, m_map != null ? m_map.DefaultMaterialEditor : null) };
            MaterialEditorDescriptor[] materialDescriptors = materials.Where(m => m.shader != null && !m.shader.name.StartsWith("Hidden/"))
                                                             .Select(m => m.shader).Distinct()
                                                             .OrderBy(s => s.name.StartsWith("Standard") ? string.Empty : s.name)
                                                             .Select(s => new MaterialEditorDescriptor(s, m_map != null && editorsMap.IsMaterialEditorEnabled(s), m_map != null ? editorsMap.GetMaterialEditor(s, true) : null)).ToArray();

            m_materialDescriptors = defaultDescriptors.Union(materialDescriptors).ToArray();
        }
Example #3
0
        protected override void InitOverride(object target, MemberInfo memberInfo, string label = null)
        {
            Type elementType = null;

            if (memberInfo is PropertyInfo)
            {
                elementType = ((PropertyInfo)memberInfo).PropertyType.GetElementType();
                if (elementType == null)
                {
                    if (((PropertyInfo)memberInfo).PropertyType.IsGenericType)
                    {
                        elementType = ((PropertyInfo)memberInfo).PropertyType.GetGenericArguments()[0];
                    }
                }
            }
            else if (memberInfo is FieldInfo)
            {
                elementType = ((FieldInfo)memberInfo).FieldType.GetElementType();
                if (elementType == null)
                {
                    if (((FieldInfo)memberInfo).FieldType.IsGenericType)
                    {
                        elementType = ((FieldInfo)memberInfo).FieldType.GetGenericArguments()[0];
                    }
                }
            }



            if (elementType != null)
            {
                GameObject editor = EditorsMap.GetPropertyEditor(elementType);
                if (EditorsMap.IsPropertyEditorEnabled(elementType))
                {
                    m_editorPrefab = editor.GetComponent <PropertyEditor>();
                }

                if (m_editorPrefab == null)
                {
                    Debug.LogWarning("Editor for " + memberInfo.Name + " not found");
                    Destroy(gameObject);
                }

                base.InitOverride(target, memberInfo, label);
            }
            else
            {
                if (elementType == null)
                {
                    Debug.LogWarning("Editor for " + memberInfo.Name + " not found");
                    Destroy(gameObject);
                }
            }

            if (StartExpanded)
            {
                Expander.isOn = GetValue().Count < 8;
            }
        }
Example #4
0
        private void Awake()
        {
            if (m_instance != null)
            {
                Debug.LogWarning("Another instance of RuntimeEditor exists");
            }
            m_instance = this;

            m_projectManager = Dependencies.ProjectManager;
            if (m_projectManager == null)
            {
                Debug.LogWarning("ProjectManager not found");
            }

            if (m_projectManager != null)
            {
                m_projectManager.IgnoreTypes(
                    typeof(SpriteGizmo),
                    typeof(AudioReverbZoneGizmo),
                    typeof(AudioSourceGizmo),
                    typeof(BoxColliderGizmo),
                    typeof(CapsuleColliderGizmo),
                    typeof(SphereColliderGizmo),
                    typeof(LightGizmo),
                    typeof(DirectionalLightGizmo),
                    typeof(PointLightGizmo),
                    typeof(SpotlightGizmo),
                    typeof(SkinnedMeshRendererGizmo));

                m_projectManager.SceneLoaded  += OnSceneLoaded;
                m_projectManager.SceneCreated += OnSceneCreated;
            }

            RuntimeEditorApplication.IsOpenedChanged       += OnIsOpenedChanged;
            RuntimeEditorApplication.PlaymodeStateChanging += OnPlaymodeStateChanging;

            ExposeToEditor[] editorObjects = ExposeToEditor.FindAll(ExposeToEditorObjectType.Undefined, false).Select(go => go.GetComponent <ExposeToEditor>()).ToArray();
            for (int i = 0; i < editorObjects.Length; ++i)
            {
                editorObjects[i].ObjectType = ExposeToEditorObjectType.EditorMode;
                editorObjects[i].Init();
            }

            ExposeToEditor.Awaked  += OnObjectAwaked;
            ExposeToEditor.Started += OnObjectStarted;
            RuntimeEditorApplication.SceneCameras = SceneCameras;

            PrepareCameras();
            RuntimeEditorApplication.SceneCameras[0].gameObject.SetActive(true);
            for (int i = 1; i < RuntimeEditorApplication.SceneCameras.Length; ++i)
            {
                RuntimeEditorApplication.SceneCameras[i].gameObject.SetActive(false);
            }

            EditorsMap.LoadMap();
        }
Example #5
0
        private void OnDestroy()
        {
            if (m_instance == this)
            {
                m_instance = null;
                RuntimeEditorApplication.Reset();
                EditorsMap.Reset();
            }

            Unsubscribe();
        }
        private PropertyEditor InstantiateEditor(PropertyInfo propertyInfo)
        {
            PropertyEditor editor = null;

            if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
            {
                GameObject prefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                if (prefab != null)
                {
                    editor = Instantiate(prefab).GetComponent <PropertyEditor>();
                    editor.transform.SetParent(EditorsPanel, false);
                }
            }

            return(editor);
        }
        private void CreateElementEditor(MemberInfo memberInfo, Type type)
        {
            if (!EditorsMap.IsPropertyEditorEnabled(type))
            {
                return;
            }
            GameObject editorPrefab = EditorsMap.GetPropertyEditor(type);

            if (editorPrefab == null)
            {
                return;
            }
            PropertyEditor editor = Instantiate(editorPrefab).GetComponent <PropertyEditor>();

            if (editor == null)
            {
                return;
            }

            CustomTypeFieldAccessor accessor = null;

            if (ChildDescriptors == null)
            {
                accessor = new CustomTypeFieldAccessor(this, memberInfo, memberInfo.Name);
            }
            else
            {
                PropertyDescriptor childPropertyDescriptor;
                if (ChildDescriptors.TryGetValue(memberInfo, out childPropertyDescriptor))
                {
                    accessor = new CustomTypeFieldAccessor(
                        this,
                        childPropertyDescriptor.MemberInfo, childPropertyDescriptor.Label);
                }
            }
            if (accessor != null)
            {
                editor.transform.SetParent(Panel, false);
                editor.Init(accessor, accessor.GetType().GetProperty("Value"), accessor.Name, OnValueChanging, OnValueChanged, null, false);
            }
        }
        private EditorDescriptor GetScriptEditorDescriptor(Type t, EditorsMap editorsMap)
        {
            bool       isPropertyEditorType = typeof(PropertyEditor).IsAssignableFrom(t);
            bool       isEditorEnabled      = false;
            GameObject editor = null;

            if (m_map != null)
            {
                if (isPropertyEditorType)
                {
                    isEditorEnabled = editorsMap.IsPropertyEditorEnabled(t, true);
                    editor          = editorsMap.GetPropertyEditor(t, true);
                }
                else
                {
                    isEditorEnabled = editorsMap.IsObjectEditorEnabled(t);
                    editor          = editorsMap.GetObjectEditor(t, true);
                }
            }
            return(new EditorDescriptor(t, isEditorEnabled, editor, isPropertyEditorType));
        }
Example #9
0
        private PropertyEditor InstantiatePropertyEditor(PropertyDescriptor descriptor)
        {
            if (descriptor.MemberInfo == null)
            {
                Debug.LogError("desciptor.MemberInfo is null");
                return(null);
            }

            if (descriptor.MemberType == null)
            {
                Debug.LogError("descriptor.MemberType is null");
                return(null);
            }

            GameObject editorGo = EditorsMap.GetPropertyEditor(descriptor.MemberType);

            if (editorGo == null)
            {
                return(null);
            }

            if (!EditorsMap.IsPropertyEditorEnabled(descriptor.MemberType))
            {
                return(null);
            }
            PropertyEditor editor = editorGo.GetComponent <PropertyEditor>();

            if (editor == null)
            {
                Debug.LogErrorFormat("editor {0} is not PropertyEditor", editorGo);
                return(null);
            }
            PropertyEditor instance = Instantiate(editor);

            instance.transform.SetParent(EditorsPanel, false);
            return(instance);
        }
        private void Start()
        {
            m_editor = IOC.Resolve <IRTE>();

            GameObject          go               = m_editor.Selection.activeGameObject;
            ExposeToEditor      exposeToEditor   = go.GetComponent <ExposeToEditor>();
            HierarchyItem       hierarchyItem    = go.GetComponent <HierarchyItem>();
            HashSet <Component> ignoreComponents = new HashSet <Component>();

            if (exposeToEditor != null)
            {
                if (exposeToEditor.Colliders != null)
                {
                    for (int i = 0; i < exposeToEditor.Colliders.Length; ++i)
                    {
                        Collider collider = exposeToEditor.Colliders[i];
                        if (!ignoreComponents.Contains(collider))
                        {
                            ignoreComponents.Add(collider);
                        }
                    }
                }

                ignoreComponents.Add(exposeToEditor);
            }

            if (hierarchyItem != null)
            {
                ignoreComponents.Add(hierarchyItem);
            }

            InputName.text        = go.name;
            TogEnableDisable.isOn = go.activeSelf;

            InputName.onEndEdit.AddListener(OnEndEditName);
            TogEnableDisable.onValueChanged.AddListener(OnEnableDisable);
            Component[] components = go.GetComponents <Component>();
            for (int i = 0; i < components.Length; ++i)
            {
                Component component = components[i];
                if (component == null)
                {
                    continue;
                }

                if (ignoreComponents.Contains(component))
                {
                    continue;
                }

                if ((component.hideFlags & HideFlags.HideInInspector) != 0)
                {
                    continue;
                }

                if (EditorsMap.IsObjectEditorEnabled(component.GetType()))
                {
                    GameObject editorPrefab = EditorsMap.GetObjectEditor(component.GetType());
                    if (editorPrefab != null)
                    {
                        ComponentEditor componentEditorPrefab = editorPrefab.GetComponent <ComponentEditor>();
                        if (componentEditorPrefab != null)
                        {
                            ComponentEditor editor = Instantiate(componentEditorPrefab);
                            editor.EndEditCallback = () =>
                            {
                                m_editor.IsDirty = true;
                            };
                            editor.transform.SetParent(ComponentsPanel, false);
                            editor.Component = component;
                        }
                        else
                        {
                            Debug.LogErrorFormat("editor prefab {0} does not have ComponentEditor script", editorPrefab.name);
                        }
                    }
                }
            }
        }
        public void BuildEditor()
        {
            foreach (Transform t in EditorsPanel)
            {
                Destroy(t.gameObject);
            }

            IMaterialDescriptor selector;

            if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector))
            {
                selector = new MaterialDescriptor();
            }


            object converter = selector.CreateConverter(this);

            MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter);
            if (descriptors == null)
            {
                Destroy(gameObject);
                return;
            }

            for (int i = 0; i < descriptors.Length; ++i)
            {
                MaterialPropertyDescriptor descriptor = descriptors[i];
                PropertyEditor             editor     = null;
                object       target       = descriptor.Target;
                PropertyInfo propertyInfo = descriptor.PropertyInfo;
#if !UNITY_WEBGL && PROC_MATERIAL
                if (descriptor.ProceduralDescription == null)
#endif
                {
                    RTShaderPropertyType propertyType = descriptor.Type;

                    switch (propertyType)
                    {
                    case RTShaderPropertyType.Range:
                        if (RangeEditor != null)
                        {
                            RangeEditor range = Instantiate(RangeEditor);
                            range.transform.SetParent(EditorsPanel, false);

                            var rangeLimits = descriptor.Limits;
                            range.Min = rangeLimits.Min;
                            range.Max = rangeLimits.Max;
                            editor    = range;
                        }
                        break;

                    default:
                        if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                        {
                            GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                            GameObject instance     = Instantiate(editorPrefab);
                            instance.transform.SetParent(EditorsPanel, false);

                            if (instance != null)
                            {
                                editor = instance.GetComponent <PropertyEditor>();
                            }
                        }
                        break;
                    }
                }
#if !UNITY_WEBGL && PROC_MATERIAL
                else
                {
                    ProcPropertyDescription input = descriptor.ProceduralDescription;
                    if (input.hasRange)
                    {
                        if (input.type == ProcPropertyType.Float)
                        {
                            if (RangeEditor != null)
                            {
                                RangeEditor range = Instantiate(RangeEditor);
                                range.transform.SetParent(EditorsPanel, false);
                                range.Min = input.minimum;
                                range.Max = input.maximum;
                                //TODO implement step on range editor // = input.step
                                editor = range;
                            }
                        }
                        else
                        {
                            //TODO: Implement range on vector editors

                            if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                            {
                                GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                                GameObject instance     = Instantiate(editorPrefab);
                                instance.transform.SetParent(EditorsPanel, false);

                                if (instance != null)
                                {
                                    editor = instance.GetComponent <PropertyEditor>();
                                }
                            }
                        }
                    }
                    else
                    {
                        //if(input.type == ProceduralPropertyType.Enum)
                        //TODO: Implement enum from string array editor. //input.enumOptions

                        if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType))
                        {
                            GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType);
                            GameObject instance     = Instantiate(editorPrefab);
                            instance.transform.SetParent(EditorsPanel, false);

                            if (instance != null)
                            {
                                editor = instance.GetComponent <PropertyEditor>();
                            }
                        }
                    }
                }
#endif

                if (editor == null)
                {
                    continue;
                }

                editor.Init(target, propertyInfo, descriptor.Label, null, descriptor.ValueChangedCallback, () =>
                {
                    RuntimeEditorApplication.SaveSelectedObjects();
                });
            }
        }