Esempio n. 1
0
    public override void OnInspectorGUI()
    {
        GUI.enabled = true;

        if (!AssetDatabase.GetAssetPath(Selection.activeObject).EndsWith(".fs"))
        {
            DrawDefaultInspector();
        }
        else
        {
            EditorGUILayout.BeginHorizontal("box");
            GUIStyle boldtext = new GUIStyle();
            boldtext.fontStyle = FontStyle.Bold;
            EditorGUILayout.LabelField("Imported F# Script", boldtext);
            EditorGUILayout.EndHorizontal();

            var targetAssetPath = AssetDatabase.GetAssetPath(target);
            if (!Directory.Exists(targetAssetPath) && File.Exists(targetAssetPath))
            {
                var sr = File.OpenText(targetAssetPath);
                code = sr.ReadToEnd();
                sr.Close();

                GUIStyle myStyle = new GUIStyle();
                GUIStyle style   = EditorStyles.textField;
                myStyle.border            = style.border;
                myStyle.contentOffset     = style.contentOffset;
                myStyle.normal.background = style.normal.background;
                myStyle.padding           = style.padding;
                myStyle.wordWrap          = true;
                EditorGUILayout.LabelField(code, myStyle);
            }

            var rec = EditorGUILayout.BeginHorizontal();
            if (GUI.Button(new Rect(rec.width - 80, 25, 50, 15), "vs-sln", EditorStyles.miniButton))
            {
                var path     = AssetDatabase.GetAssetPath(Selection.activeObject);
                var basePath = FSharpProject.GetProjectRootPath();
                var fileName = PathUtilModule.GetAbsolutePath(basePath, path);
                UniFSharp.FSharpSolution.OpenExternalVisualStudio(SolutionType.FSharp, fileName);
            }

            if (GUI.Button(new Rect(rec.width - 145, 25, 60, 15), "mono-sln", EditorStyles.miniButton))
            {
                UniFSharp.FSharpSolution.OpenExternalMonoDevelop();
            }
            EditorGUILayout.EndHorizontal();
        }
    }
Esempio n. 2
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginVertical();
        (this.target as Transform).localRotation = Quaternion.Euler(EditorGUILayout.Vector3Field("Local Rotation", (this.target as Transform).localRotation.eulerAngles));
        (this.target as Transform).localPosition = EditorGUILayout.Vector3Field("Local Position", (this.target as Transform).localPosition);
        (this.target as Transform).localScale    = EditorGUILayout.Vector3Field("Local Scale", (this.target as Transform).localScale);
        EditorGUILayout.EndVertical();

        // F# Script Drag % Drop
        if (DragAndDrop.objectReferences.Length > 0 && AssetDatabase.GetAssetPath(DragAndDrop.objectReferences[0]).EndsWith(".fs"))
        {
            DragDropArea <UnityEngine.Object>(null, draggedObjects =>
            {
                var dropTarget = this.target as Transform;


                foreach (var draggedObject in draggedObjects)
                {
                    var outputPath = FSharpProject.GetNormalOutputAssemblyPath();
                    if (!Directory.Exists(outputPath))
                    {
                        EditorUtility.DisplayDialog("Warning", "F# Assembly is not found.\nPlease Build.", "OK");
                        break;
                    }


                    var notfound = true;
                    foreach (var dll in Directory.GetFiles(outputPath, "*.dll"))
                    {
                        var fileName = Path.GetFileName(dll);
                        if (fileName == "FSharp.Core.dll")
                        {
                            continue;
                        }

                        var assem = Assembly.LoadFrom(dll);
                        IEnumerable <Type> behaviors = null;
                        switch (UniFSharp.FSharpBuildToolsWindow.FSharpOption.assemblySearch)
                        {
                        case AssemblySearch.Simple:
                            var @namespace = GetNameSpace(AssetDatabase.GetAssetPath(draggedObject));
                            var typeName   = GetTypeName(AssetDatabase.GetAssetPath(draggedObject));
                            behaviors      = assem.GetTypes().Where(type => typeof(MonoBehaviour).IsAssignableFrom(type) && type.FullName == @namespace + typeName);
                            break;

                        case AssemblySearch.CompilerService:
                            var types = GetTypes(AssetDatabase.GetAssetPath(draggedObject));
                            behaviors = assem.GetTypes().Where(type => typeof(MonoBehaviour).IsAssignableFrom(type) && types.Contains(type.FullName));
                            break;

                        default:
                            break;
                        }

                        if (behaviors != null && behaviors.Any())
                        {
                            DragAndDrop.AcceptDrag();
                            foreach (var behavior in behaviors)
                            {
                                dropTarget.gameObject.AddComponent(behavior);
                                notfound = false;
                            }
                        }
                    }

                    if (notfound)
                    {
                        EditorUtility.DisplayDialog("Warning", "MonoBehaviour is not found in the F # assembly.", "OK");
                        return;
                    }
                }
            }, null, 50);
        }
    }