Exemplo n.º 1
0
 public static void PreviewFolder(/* string label, */ string path, Action presetAction = null)
 {
     ScopeHorizontal.Begin(EditorStyles.helpBox);
     GUILayout.Label(path);
     GUILayout.FlexibleSpace();
     if (presetAction != null)
     {
         if (IconButton(EditorIcon.preset_context))
         {
             presetAction.Invoke();
         }
     }
     ScopeDisable.Begin(!path.IsExistsDirectory());
     if (IconButton(EditorIcon.icons_processed_folderempty_icon_asset))
     {
         ShellUtils.OpenDirectory(path);
     }
     ScopeDisable.End();
     ScopeHorizontal.End();
 }
Exemplo n.º 2
0
        public static string FileFiled(string label, string file, string[] filters, params GUILayoutOption[] options)
        {
            if (!label.IsEmpty())
            {
                EditorGUILayout.LabelField(label /*, EditorStyles.boldLabel*/);
            }
            var backgroundColor = GUI.backgroundColor;

            if (!file.IsEmpty() && !file.IsExistsFile())
            {
                GUI.backgroundColor = HEditorStyles.helpBoxInvalidColor;
            }
            ScopeHorizontal.Begin(EditorStyles.helpBox);
            var rect    = GUILayoutUtility.GetRect(GUIContent.none, HEditorStyles.folderField, options);
            var newfile = HEditorGUI.FileFiled(rect, GUIContent.none, file, filters);

            ScopeHorizontal.End();

            GUI.backgroundColor = backgroundColor;

            return(newfile);
        }
Exemplo n.º 3
0
        void _Draw(SerializedProperty it, ref bool fold)
        {
            Type type  = null;
            var  field = ScriptAttributeUtility.GetFieldInfoFromProperty(it, ref type);
            var  attrs = ScriptAttributeUtility.GetFieldAttributes(field);

            //Debug.Log(it.displayName);

            if (GetHas(attrs, typeof(GroupAttribute)))
            {
                if (!_foldLists.ContainsKey(it.displayName))
                {
                    _foldLists.Add(it.displayName, true);
                }


                var atb  = Get <GroupAttribute>(attrs);
                var rect = GUILayoutUtility.GetRect(EditorHelper.TempContent(it.displayName), EditorStyles.helpBox);
                if (Event.current.type == EventType.Repaint)
                {
                    var rect2 = rect;
                    rect2.x     -= 16;
                    rect2.width += 16;
                    EditorStyles.helpBox.Draw(rect2, false, false, false, false);
                }
                var sss = "";
                if (atb.prefix)
                {
                    sss = "Group - ";
                }
                sss += atb.name;
                _foldLists[it.displayName] = EditorGUI.Foldout(rect, _foldLists[it.displayName], sss, true);

                fold = _foldLists[it.displayName];
                //EditorGUILayout.LabelField( it.displayName );
                //if( _foldLists[ it.displayName ] ) {
                //	EditorGUILayout.PropertyField( it, true );
                //}
                //if( fold  ) {
                //	EditorGUI.indentLevel++;
                //}
                //else {
                //	EditorGUI.indentLevel--;
                //}
            }
            if (fold == false)
            {
                return;
            }
#if false
            if (it.isArray && type != typeof(string))
            {
                HReorderableList lst = null;
                _reorderableLists.TryGetValue(it.displayName, out lst);
                if (lst == null)
                {
                    lst = HReorderableList.CreateInstance(serializedObject, it.name);
                    _reorderableLists.Add(it.displayName, lst);
                }
                //EditorGUILayout.LabelField( it.displayName );
                lst.DoLayoutList();
            }
            //else if( it.propertyType == SerializedPropertyType.Vector3 ) {
            //}
            else
#endif
            //if( GetHas( attrs, typeof( PropertyAttribute ) ) {
            //	var hander = UnityScriptAttributeUtility.GetHandler( it );
            //	hander.MethodInvoke<bool>( "OnGUI", new object[] { } );
            //}
            //OnGUI( Rect position, SerializedProperty property, GUIContent label, bool includeChildren )
#if UNITY_2019_3_OR_NEWER
            if (it.propertyType == SerializedPropertyType.ManagedReference)
            {
                DrawSerializeReference(it);
            }
            else
#endif
            if (it.propertyType == SerializedPropertyType.ObjectReference && !GetHas(attrs, typeof(PropertyAttribute)))
            {
                if (it.objectReferenceValue == null)
                {
                    //EditorGUILayout.PropertyField( it, true );
                    //Debug.Log( it.GetTypeReflection().Name );
                    //if( it.GetTypeReflection() == typeof( Sprite ) ) {
                    //	it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue,typeof( Sprite), false );
                    //}
                    //else {
                    //	EditorGUILayout.PropertyField( it, true );
                    //}
                    ScopeHorizontal.Begin();
                    it.objectReferenceValue = EditorGUILayout.ObjectField(it.displayName, it.objectReferenceValue, type, true);
                    if (HEditorGUILayout.IconButton(EditorIcon.plus, 3))
                    {
                        var so   = CreateInstance(type);
                        var path = $"Assets/New {type.Name}.asset".GenerateUniqueAssetPath();
                        AssetDatabase.CreateAsset(so, path);
                        AssetDatabase.Refresh();
                        it.objectReferenceValue = so;
                    }
                    ScopeHorizontal.End();
                    //it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, it.GetTypeReflection(), true );
                    //it.objectReferenceValue=EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, it.GetTypeReflection(), true, GUILayout.Height() );
                }
                else if (it.objectReferenceValue.GetType() == typeof(Animator))
                {
                    HEditorGUI.PropertyField(it,
                                             EditorIcon.unityeditor_animationwindow, () => { EditorWindowUtils.Find(UnityTypes.UnityEditor_AnimationWindow); },
                                             EditorIcon.unityeditor_graphs_animatorcontrollertool, () => { EditorWindowUtils.Find(UnityTypes.UnityEditor_Graphs_AnimatorControllerTool); });
                }
                else if (it.objectReferenceValue.GetType().IsSubclassOf(typeof(ScriptableObject)))
                {
                    Editor ed = null;
                    if (_editorLists == null)
                    {
                        return;
                    }
                    _editorLists.TryGetValue(it.displayName, out ed);
                    if (ed == null)
                    {
                        ed = Editor.CreateEditor(it.objectReferenceValue);
                        _editorLists.Add(it.displayName, ed);
                    }

                    var h = EditorStyles.objectField.CalcHeight(GUIContent.none, 10);
                    EditorGUILayout.PropertyField(it, EditorHelper.TempContent("  "), true);
                    var r = GUILayoutUtility.GetLastRect();
                    r.y           = r.yMax - h;
                    r.height      = h;
                    it.isExpanded = EditorGUI.Foldout(r, it.isExpanded, EditorHelper.TempContent(it.displayName), true);
                    if (it.isExpanded)
                    {
                        try {
                            EditorGUI.indentLevel++;
                            EditorGUIUtility.hierarchyMode = false;
                            ScopeVertical.Begin(/*EditorStyles.helpBox*/);
                            ed.OnInspectorGUI();
                            //GUILayout.FlexibleSpace();
                            ScopeVertical.End();
                            EditorGUIUtility.hierarchyMode = true;
                            EditorGUI.indentLevel--;
                        }
                        catch (Exception e) {
                            Debug.LogException(e);
                        }
                    }
                }
                else
                {
                    //HGUIScope.Horizontal(_);
                    //void _() {
                    //it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, type, true );
                    EditorGUILayout.PropertyField(it, EditorHelper.TempContent(L10n.Tr(it.displayName)), true);
                    //	GUILayout.Button("aaaa");
                    //}
                }
            }
            else
            {
                //Debug.Log( type .Name);
                EditorGUILayout.PropertyField(it, EditorHelper.TempContent(L10n.Tr(it.displayName)), true);
            }
        }
Exemplo n.º 4
0
        /////////////////////////////////////////
        public void DrawItem()
        {
            if (currentItem == null)
            {
                return;
            }
            if (currentItem.folder)
            {
                return;
            }

            using (new GUILayoutScope(16, 4)) {
                ////////////////////////

                ScopeHorizontal.Begin();
                EditorGUILayout.LabelField("General", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                ScopeHorizontal.End();

                ScopeVertical.Begin(GUI.skin.box);
                ScopeChange.Begin();
                currentItem.m_json.autoReferenced = EditorGUILayout.Toggle("Auto Referenced", currentItem.m_json.autoReferenced);
                if (ScopeChange.End())
                {
                    currentItem.isDIRTY = true;
                }
                ScopeVertical.End();

                ////////////////////////

                ScopeHorizontal.Begin();
                EditorGUILayout.LabelField("Assembly Definition References", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                ScopeHorizontal.End();

                ////////////////////////

                Ref del = null;

                foreach (var e in currentItem.参照しているasmdefのリスト)
                {
                    using (new GUIBackgroundColorScope()) {
                        if (e.guid.IsEmpty())
                        {
                            if (e.バックアップされている)
                            {
                                GUI.backgroundColor = Color.yellow;
                            }
                            else
                            {
                                GUI.backgroundColor = Color.red;
                            }
                        }
                        ScopeHorizontal.Begin(EditorStyles.helpBox);
                        ScopeChange.Begin();
                        e.toggle = HEditorGUILayout.ToggleLeft(e.asmDefの名前, e.toggle);
                        if (ScopeChange.End())
                        {
                            currentItem.isDIRTY = true;
                        }
                        GUILayout.FlexibleSpace();
                        if (HEditorGUILayout.IconButton(EditorIcon.minus))
                        {
                            del = e;
                            currentItem.isDIRTY = true;
                        }

                        ScopeHorizontal.End();
                    }
                }
                if (del != null)
                {
                    currentItem.参照しているasmdefのリスト.Remove(del);
                }

                //ScopeHorizontal.Begin();
                //GUILayout.FlexibleSpace();
                //if( GUILayout.Button( "整形") ) {
                //	Debug.Log( currentItem.m_json.name );
                //	ShellUtils.Start( "dotnet-format", $"-v diag {currentItem.m_json.name}.csproj" );
                //	//ShellUtils.Start( "cmd.exe", "/k dir" );
                //	//System.Diagnostics.Process p = new System.Diagnostics.Process();
                //	//p.StartInfo.FileName = "cmd.exe";
                //	//p.StartInfo.Arguments = "/k dotnet-format -v diag com.unity.cinemachine.Editor.csproj";
                //	//p.SynchronizingObject = this;
                //	//p.StartInfo.UseShellExecute = true;
                //	//p.Exited += ( sender, e ) => {
                //	//	EditorApplication.delayCall += () => {
                //	//		exitHandler( sender, e );
                //	//	};
                //	//};
                //	//p.Start();
                //	//p.WaitForExit();
                //}
                //ScopeHorizontal.End();

                GUILayout.FlexibleSpace();
            }


            var dropRc = GUILayoutUtility.GetLastRect();

            DrawFileDragArea(dropRc, DD, DragAndDropVisualMode.Link);
            //HEditorGUI.DrawDebugRect( dropRc );
        }