Esempio n. 1
0
        public static bool Draw(Rect r, SerializedProperty prop, System.Type type, string path = null, bool ignoreIdentation = true)
        {
            var createdNewSO = false;
            var obj          = prop.objectReferenceValue;

            if (obj == null)
            {
                var iconSize = 16;
                var create   = GUI.Button(new Rect(r.x, r.y + (r.height - iconSize) / 2, iconSize, iconSize), IconCache.Get("match").Texture, new GUIStyle());
                if (create)
                {
                    var target = prop.serializedObject.targetObject;
                    if (prop.serializedObject.targetObject is MonoBehaviour)
                    {
                        target = MonoScript.FromMonoBehaviour((MonoBehaviour)prop.serializedObject.targetObject);
                    }
                    var selectedAssetPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(target));

                    var go = ScriptableObjectUtils.CreateSequential(selectedAssetPath + "\\" + prop.ToFileName(), type);
                    prop.objectReferenceValue = go;
                    prop.serializedObject.ApplyModifiedProperties();
                    createdNewSO = true;
                }
                r = r.CutLeft(iconSize + 2);
            }

            if (ignoreIdentation)
            {
                EditorGuiIndentManager.New(0);
            }
            var newObj = EditorGUI.ObjectField(r, obj, type, false);

            if (ignoreIdentation)
            {
                EditorGuiIndentManager.Revert();
            }
            if (newObj != obj)
            {
                prop.objectReferenceValue = newObj;
                prop.serializedObject.ApplyModifiedProperties();
            }

            return(createdNewSO);
        }
Esempio n. 2
0
        public static bool Draw <T>(Rect r, SerializedProperty prop, string newFolderPath) where T : ScriptableObject
        {
            var createdNewSO = false;
            var obj          = prop.objectReferenceValue;

            if (obj == null)
            {
                var iconSize = 16;
                var create   = GUI.Button(new Rect(r.x, r.y + (r.height - iconSize) / 2, iconSize, iconSize), IconCache.Get("match").Texture, new GUIStyle());
                if (create)
                {
                    var go = ScriptableObjectUtils.CreateSequential <T>(newFolderPath + prop.ToFileName());
                    prop.objectReferenceValue = go;
                    prop.serializedObject.ApplyModifiedProperties();
                    createdNewSO = true;
                }
                r = r.CutLeft(iconSize + 2);
            }

            Draw <T>(r, prop, false);
            return(createdNewSO);
        }
Esempio n. 3
0
        public static bool Layout <T>(SerializedProperty prop, string newFolderPath, params GUILayoutOption[] options) where T : ScriptableObject
        {
            var createdNewSO = false;
            var obj          = prop.objectReferenceValue;

            GUILayout.BeginHorizontal();
            if (obj == null)
            {
                var icon   = IconCache.Get("match").Texture;
                var slh    = EditorGUIUtility.singleLineHeight;
                var create = GUILayout.Button(icon, new GUIStyle(), GUILayout.Width((icon.width / icon.height) * slh), GUILayout.Height(slh));
                if (create)
                {
                    var go = ScriptableObjectUtils.CreateSequential <T>(newFolderPath + prop.ToFileName());
                    prop.objectReferenceValue = go;
                    prop.serializedObject.ApplyModifiedProperties();
                    createdNewSO = true;
                }
            }

            Layout <T>(prop, false, options);
            GUILayout.EndHorizontal();
            return(createdNewSO);
        }