Пример #1
0
        protected bool OnGUIStandardButtons()
        {
            bool result = false;

            NavmeshBuild build = Context.Build;

            if (!build)
            {
                return(result);
            }

            bool guiEnabled = GUI.enabled;

            GUI.enabled = guiEnabled &&
                          mInputCompile == null &&
                          Context.TaskCount == 0 &&
                          !NavEditorUtil.SceneMismatch(build.BuildTarget.BuildInfo);

            if (GUILayout.Button("Recompile Input"))
            {
                mInputCompile = new MiniInputCompile(Context);

                if (mInputCompile.IsFinished)
                {
                    mInputCompile = null;
                }
            }

            GUI.enabled = guiEnabled &&
                          mInputCompile == null &&
                          Context.TaskCount == 0;

            if (GUILayout.Button("Reinitialize Builder"))
            {
                result = true;
                build.DiscardBuildData();
            }

            GUI.enabled = guiEnabled;

            return(result);
        }
Пример #2
0
        protected override void OnGUIMain()
        {
            NavmeshBuild build = Context.Build;

            if (!build)
            {
                return;
            }

            Rect statusArea = Context.MainArea;

            if (build.BuildState == NavmeshBuildState.Invalid)
            {
                return;
            }

            InputBuildInfo info;
            InputGeometry  geometry       = null;
            ConnectionSet  connections    = null;
            int            triCount       = 0;
            int            processorCount = 0;

            ViewOption viewFlags = 0;
            bool       hasData   = false;

            string topLabel;

            if (mCompiler != null)
            {
                if (mCompiler.IsFinished)
                {
                    if (mCompiler.HasData)
                    {
                        topLabel = "Input successfully compiled. (Needs to be accepted.)";
                    }
                    else
                    {
                        topLabel = "No input data produced.";
                    }
                }
                else
                {
                    topLabel = "Compiling";
                }

                info           = mCompiler.Info;
                geometry       = mCompiler.Geometry;
                connections    = mCompiler.Connections;
                triCount       = mCompiler.TriCount;
                processorCount = (mCompiler.Processors == null ? 0 : mCompiler.Processors.Length);

                if (geometry != null)
                {
                    hasData = true;
                }
            }
            else if (build.HasInputData)
            {
                topLabel = "Current Input";

                viewFlags = (ViewOption.Input | ViewOption.Grid);

                info           = build.InputInfo;
                geometry       = build.InputGeom;
                connections    = build.Connections;
                triCount       = geometry.TriCount;
                processorCount = build.NMGenProcessors.Count;

                hasData = true;
            }
            else
            {
                topLabel = "Input needs to be compiled.";
                info     = new InputBuildInfo();
            }

            DebugContext.SetViews(viewFlags);

            if (!hasData && triCount > 0)
            {
                GUI.Box(Context.MainArea
                        , string.Format("{0} {1:N0} triangles", topLabel, triCount)
                        , EditorUtil.HelpStyle);

                OnGUICompiler(statusArea);

                return;
            }

            GUILayout.BeginArea(statusArea, GUI.skin.box);

            string currScene = System.IO.Path.GetFileName(SceneManager.GetActiveScene().path);

            int idx = currScene.LastIndexOf(".");

            if (idx >= 0)
            {
                currScene = currScene.Substring(0, idx);
            }

            if (currScene.Length == 0)
            {
                currScene = "None";
            }

            GUILayout.BeginHorizontal();

            GUILayout.Label("Input scene:");

            GUILayout.Label(" Current: " + currScene);

            GUILayout.Label(" Last: "
                            + NavEditorUtil.SceneDisplayName(build.BuildTarget.BuildInfo));

            GUILayout.EndHorizontal();

            if (NavEditorUtil.SceneMismatch(build.BuildTarget.BuildInfo))
            {
                GUILayout.Box("Current scene does not match last input scene."
                              , EditorUtil.WarningStyle);
            }

            GUILayout.Space(MarginSize);

            GUILayout.Label(topLabel);

            if (hasData)
            {
                GUILayout.Space(ControlUtil.MarginSize * 3);

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical();

                GUILayout.Label("Geometry");

                GUILayout.Space(ControlUtil.MarginSize);

                GUILayout.Label(string.Format("Triangles: {0:N0}", triCount));

                GUILayout.Space(ControlUtil.MarginSize);

                GUILayout.Label("Min Bounds: " + Vector3Util.ToString(geometry.BoundsMin));

                GUILayout.Label("Max Bounds: " + Vector3Util.ToString(geometry.BoundsMax));

                GUILayout.Space(ControlUtil.MarginSize);

                UnityEngine.Vector3 diff = (geometry.BoundsMax - geometry.BoundsMin).ToUnityVector3();
                GUILayout.Label(string.Format("WxHxD: {0:f3} x {1:f3} x {2:f3}"
                                              , diff.x, diff.y, diff.z));

                GUILayout.Space(ControlUtil.MarginSize * 2);

                // Note: The build press interprets zero root objects as a global search.

                GUILayout.Space(ControlUtil.MarginSize);
                GUILayout.Label("Components");
                GUILayout.Space(ControlUtil.MarginSize);

                GUILayout.Label("Pre-filter: " + info.compCountPre);
                GUILayout.Label("Post-filter: " + info.compCountPost);

                GUILayout.EndVertical();

                GUILayout.BeginVertical();

                GUILayout.Label("Modifiers");

                GUILayout.Space(ControlUtil.MarginSize);

                GUILayout.Label("Component loaders: " + info.loaderCount);
                GUILayout.Label("Component filters: " + info.filterCount);
                GUILayout.Label("Area assignment: " + info.areaModifierCount);
                GUILayout.Label("Component compilers: " + info.compilerCount);
                GUILayout.Label("Input post-processors: " + info.postCount);
                GUILayout.Label("NMGen processors: " + processorCount);
                GUILayout.Label("Off-Mesh connections: " + connections.Count);

                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
            }

            GUILayout.EndArea();

            OnGUICompiler(statusArea);
        }
Пример #3
0
    /// <summary>
    /// Controls behavior of the inspector.
    /// </summary>
    public override void OnInspectorGUI()
    {
        NavmeshBuild targ = (NavmeshBuild)target;

        EditorGUIUtility.LookLikeControls(100);

        OnGUIState(targ);

        GUI.enabled = !targ.HasBuildData;

        EditorGUILayout.Separator();

        targ.BuildTarget = NavEditorUtil.OnGUINavmeshDataField("Bake Target", targ.BuildTarget);

        EditorGUILayout.Separator();

        NavmeshBuildType buildType = (NavmeshBuildType)
                                     EditorGUILayout.EnumPopup("Build Type", targ.BuildType);

        if (buildType != targ.BuildType)
        {
            targ.BuildType = buildType;
            if (buildType == NavmeshBuildType.Advanced)
            {
                BuildSelector.Instance.Select(targ);
            }
        }

        EditorGUILayout.Separator();

        TileBuildData tdata = targ.BuildData;

        GUI.enabled = (tdata == null && targ.TargetHasNavmesh);

        if (GUILayout.Button("Log Mesh State"))
        {
            Debug.Log(targ.BuildTarget.GetMeshReport());
        }

        GUI.enabled = true;

        switch (targ.BuildType)
        {
        case NavmeshBuildType.Standard:
            OnGUIStandard(targ);
            break;

        case NavmeshBuildType.Advanced:
            OnGUIAdvanced(targ);
            break;
        }

        EditorGUILayout.Separator();

        bool orig = mShowInputConfig;

        mShowInputConfig = EditorGUILayout.Foldout(mShowInputConfig, "Input Configuration");
        if (orig != mShowInputConfig)
        {
            EditorPrefs.SetBool(ShowInputKey, mShowInputConfig);
        }

        EditorGUIUtility.LookLikeControls();

        if (mShowInputConfig)
        {
            GUI.enabled = !targ.HasBuildData;

            EditorGUILayout.Separator();

            targ.AutoCleanGeometry = EditorGUILayout.Toggle("Auto-Clean", targ.AutoCleanGeometry);

            EditorGUILayout.Separator();

            ScriptableObject so  = (ScriptableObject)targ.SceneQuery;
            ScriptableObject nso = (ScriptableObject)EditorGUILayout.ObjectField(
                "Scene Query"
                , so
                , typeof(ScriptableObject)
                , false);

            if (nso != so)
            {
                if (!nso || nso is ISceneQuery)
                {
                    targ.SceneQuery = (ISceneQuery)nso;
                }
                else
                {
                    Debug.LogError(string.Format("{0} does not implement {1}."
                                                 , nso.name, typeof(ISceneQuery).Name));
                }
            }

            EditorGUILayout.Separator();

            if (OnGUIManageProcessorList(targ.inputProcessors))
            {
                targ.IsDirty = true;
            }

            GUI.enabled = true;
        }

        EditorGUILayout.Separator();

        if (targ.IsDirty)
        {
            EditorUtility.SetDirty(target);
            targ.IsDirty = false;
        }
    }
Пример #4
0
    private static void OnGUIState(NavmeshBuild build)
    {
        INavmeshData     btarget = build.BuildTarget;
        NavmeshBuildInfo binfo   = (btarget == null ? null : btarget.BuildInfo);

        EditorGUILayout.Separator();

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        if (build.BuildState == NavmeshBuildState.Invalid)
        {
            if (!(ScriptableObject)btarget)
            {
                sb.AppendLine("No build target.");
            }

            if (build.inputProcessors.Count == 0)
            {
                sb.AppendLine("No input processors.");
            }

            GUILayout.Label(sb.ToString().Trim()
                            , EditorUtil.ErrorStyle, GUILayout.ExpandWidth(true));

            return;
        }

        sb.AppendLine("Input Scene: " + NavEditorUtil.SceneDisplayName(binfo));

        if (build.SceneQuery == null)
        {
            sb.AppendLine("Search scope: Entire scene");
        }

        if (build.TargetHasNavmesh)
        {
            sb.AppendLine("Target has existing navmesh.");
        }
        else
        {
            sb.AppendLine("Target does not have a navmesh.");
        }

        if (build.BuildType == NavmeshBuildType.Advanced)
        {
            TileBuildData tdata = build.BuildData;
            sb.AppendLine("Build state: " + build.BuildState);
            sb.AppendLine("Active builds: "
                          + (tdata == null ? 0 : build.BuildData.GetActive()));
        }

        GUILayout.Label(sb.ToString().Trim()
                        , EditorUtil.HelpStyle
                        , GUILayout.ExpandWidth(true));


        if (NavEditorUtil.SceneMismatch(binfo))
        {
            GUILayout.Box("Current scene does not match last input scene."
                          , EditorUtil.WarningStyle
                          , GUILayout.ExpandWidth(true));
        }

        EditorGUILayout.Separator();

        GUI.enabled = (btarget != null);

        NavmeshSceneDraw.Instance.OnGUI(build.BuildTarget, "Show Mesh", true, true);

        GUI.enabled = true;

        return;
    }
Пример #5
0
    /// <summary>
    /// Controls behavior of the inspector.
    /// </summary>
    public override void OnInspectorGUI()
    {
        NavManagerProvider targ = (NavManagerProvider)target;

        INavmeshData navmeshData = targ.NavmeshData;

        string msg = "";

        if (navmeshData == null || !navmeshData.HasNavmesh)
        {
            msg = "No navigation mesh.\n";
        }

        if (!targ.AvoidanceSet)
        {
            msg += "No avoidance set.\n";
        }

        if (!targ.AgentGroups)
        {
            msg += "No agent groups.\n";
        }

        if (msg.Length > 0)
        {
            GUILayout.Box(msg.Trim(), EditorUtil.ErrorStyle, GUILayout.ExpandWidth(true));
        }

        EditorGUILayout.Separator();

        bool bv = EditorGUILayout.Toggle("Show Mesh", targ.DebugEnabled);

        if (bv != targ.DebugEnabled)
        {
            if (bv)
            {
                // Turn off asset draw.
                org.critterai.nav.u3d.editor.NavmeshSceneDraw.Instance.Hide();
            }

            targ.DebugEnabled = bv;
        }

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Navigation Settings");

        EditorGUILayout.Separator();

        targ.NavmeshData = NavEditorUtil.OnGUINavmeshDataField("Navmesh Data", targ.NavmeshData);

        targ.AgentGroups = (AgentGroupSettings)EditorGUILayout.ObjectField(
            "Agent Groups", targ.AgentGroups, typeof(AgentGroupSettings), false);

        EditorGUILayout.Separator();

        targ.MaxQueryNodes       = EditorGUILayout.IntField("Max Query Nodes", targ.MaxQueryNodes);
        targ.MaxPathSize         = EditorGUILayout.IntField("Max Path Size", targ.MaxPathSize);
        targ.MaxStraightPathSize =
            EditorGUILayout.IntField("Max Straight Path", targ.MaxStraightPathSize);

        targ.MaxAgents = EditorGUILayout.IntField("Max Nav Agents", targ.MaxAgents);

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Crowd Settings");

        EditorGUILayout.Separator();

        targ.MaxCrowdAgents = EditorGUILayout.IntField("Max Crowd Agents", targ.MaxCrowdAgents);
        targ.MaxAgentRadius = EditorGUILayout.FloatField("Max Agent Radius", targ.MaxAgentRadius);

        EditorGUILayout.Separator();

        targ.AvoidanceSet = (CrowdAvoidanceSet)EditorGUILayout.ObjectField(
            "Avoidance Set", targ.AvoidanceSet, typeof(CrowdAvoidanceSet), false);

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Accuracy Settings");

        EditorGUILayout.Separator();

        targ.Extents     = EditorGUILayout.Vector3Field("Extents", targ.Extents);
        targ.WideExtents = EditorGUILayout.Vector3Field("Wide Extents", targ.WideExtents);

        EditorGUILayout.Separator();

        targ.RadiusAt        = EditorGUILayout.FloatField("Radius At", targ.RadiusAt);
        targ.RadiusNear      = EditorGUILayout.FloatField("Radius Near", targ.RadiusNear);
        targ.HeightTolerance = EditorGUILayout.FloatField("Height Tolerance", targ.HeightTolerance);

        EditorGUILayout.Separator();

        targ.TurnThreshold = EditorGUILayout.FloatField("Turn Threshold", targ.TurnThreshold);
        targ.AngleAt       = EditorGUILayout.FloatField("Angle At", targ.AngleAt);

        EditorGUILayout.Separator();

        EditorGUILayout.Separator();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Пример #6
0
    /// <summary>
    /// Controls behavior of the inspector.
    /// </summary>
    public override void OnInspectorGUI()
    {
        CAIBakedNavmesh targ = (CAIBakedNavmesh)target;

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Status", (targ.HasNavmesh ? "Has mesh" : "Empty"));
        EditorGUILayout.LabelField("Version", targ.Version.ToString());
        EditorGUILayout.LabelField("Input Scene", NavEditorUtil.SceneDisplayName(targ.BuildInfo));

        EditorGUILayout.Separator();

        NavmeshSceneDraw.Instance.OnGUI(targ, "Show Mesh", true, true);

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();

        GUI.enabled = targ.HasNavmesh;
        if (GUILayout.Button("Save"))
        {
            string filePath = EditorUtility.SaveFilePanel(
                "Save Navigation Mesh"
                , ""
                , targ.name
                , "navmesh");
            SaveMesh(targ, filePath);
        }
        GUI.enabled = true;

        if (GUILayout.Button("Load"))
        {
            string filePath = EditorUtility.OpenFilePanel(
                "Select Serialized Navmesh"
                , ""
                , "navmesh");
            if (LoadMesh(targ, filePath))
            {
                GUI.changed = true;
            }
        }

        EditorGUILayout.EndHorizontal();

        if (targ.HasNavmesh)
        {
            EditorGUILayout.Separator();

            if (GUILayout.Button("Log Mesh State"))
            {
                Debug.Log(targ.GetMeshReport());
            }
        }

        EditorGUILayout.Separator();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }