Example #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var objectProp = property.FindPropertyRelative("editorSceneObject");

            EditorGUI.BeginChangeCheck();
            UnityEditor.EditorGUI.ObjectField(position, objectProp, typeof(SceneAsset), label);
            if (EditorGUI.EndChangeCheck())
            {
                var toPath = AssetDatabase.GetAssetPath(objectProp.objectReferenceValue);
                foreach (var target in property.serializedObject.targetObjects)
                {
                    var fromPath = AssetDatabase.GetAssetPath(target);
                    LinkedAssetTable.AddLink(fromPath, toPath, false);
                }
                LinkedAssetTable.SaveToDisk();
            }
        }
Example #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var boxRect  = EditorGUI.IndentedRect(new Rect(position.x - 2, position.y - 2, position.width + 2, LINE_HEIGHT + ERROR_LINE_HEIGHT + 4));
            var propRect = new Rect(position.x, position.y, position.width, LINE_HEIGHT);
            var helpRect = EditorGUI.IndentedRect(new Rect(propRect.x + 2, propRect.yMax + 2, propRect.width - 4, ERROR_LINE_HEIGHT - 4));

            var fieldType        = GetResourceIdType(property);
            var objectProp       = property.FindPropertyRelative("m_value");
            var resourcePathProp = property.FindPropertyRelative("m_resourcePath");

            var isError = (resourcePathProp.stringValue == "" && objectProp.objectReferenceValue != null);

            var prevColor = GUI.color;

            GUI.color = isError
                ? Color.red
                : Color.white;
            GUI.Box(boxRect, "");
            GUI.color = prevColor;

            EditorGUI.BeginChangeCheck();
            objectProp.objectReferenceValue = UnityEditor.EditorGUI.ObjectField(propRect, label, objectProp.objectReferenceValue, fieldType, false);
            if (EditorGUI.EndChangeCheck())
            {
                var toPath = AssetDatabase.GetAssetPath(objectProp.objectReferenceValue);
                foreach (var target in property.serializedObject.targetObjects)
                {
                    var fromPath = AssetDatabase.GetAssetPath(target);
                    LinkedAssetTable.AddLink(fromPath, toPath, false);
                }
                LinkedAssetTable.SaveToDisk();
            }

            if (isError)
            {
                UnityEditor.EditorGUI.HelpBox(helpRect, "This asset is not in a Resources folder!", MessageType.Error);
            }
            else
            {
                UnityEditor.EditorGUI.HelpBox(helpRect, string.Format("Resource path: \"{0}\"", resourcePathProp.stringValue), MessageType.Info);
            }
        }