Ejemplo n.º 1
0
    /*
     * Loads path layout asset with the specified name from a resources folder.
     * */
    public void loadPathLayout(string layoutName)
    {
        pathLayoutAsset = layoutName;

        // Load data structure object (created by tool) from disk
        data = (RedirectionDataStructure)Resources.LoadAll(pathLayoutAsset)[0] as RedirectionDataStructure;
        if (data != null)
        {
            //Debug.Log("Label: " + data.jointPointA.getLabel());
            currentIntersection = data.intersections[0];
            currentJoint        = currentIntersection.getJoint();
        }
        else
        {
            Debug.Log("Data is null");
        }
    }
Ejemplo n.º 2
0
    /*
     * Load (or create if it does not exist) the data structure object.
     * Load all the gui specific variables saved to editorprefs.
     * */
    private void OnEnable()
    {
        data                  = (RedirectionDataStructure)AssetDatabase.LoadAssetAtPath(@"Assets/Resources/data.asset", typeof(RedirectionDataStructure));
        gain                  = EditorPrefs.GetFloat("gain", gain);
        sideLength            = EditorPrefs.GetFloat("sideLength", sideLength);
        safetyDistance        = EditorPrefs.GetFloat("safetyDistance", safetyDistance);
        walkingZoneRadius     = EditorPrefs.GetFloat("walkingRadius", walkingZoneRadius);
        intersectionIndex     = EditorPrefs.GetInt("intersectionIndex", intersectionIndex);
        curveIndex            = EditorPrefs.GetInt("curveIndex", curveIndex);
        joint                 = EditorPrefs.GetInt("joint", joint);
        showCurves            = EditorPrefs.GetBool("showCurves", showCurves);
        showJoints            = EditorPrefs.GetBool("showJoints", showJoints);
        showPaths             = EditorPrefs.GetBool("showPaths", showPaths);
        showIntersections     = EditorPrefs.GetBool("showIntersections", showIntersections);
        hideJointsGui         = EditorPrefs.GetBool("hideJointsGui", hideJointsGui);
        generateAutomatically = EditorPrefs.GetBool("generateAutomatically", generateAutomatically);

        if (data == null)
        {
            Debug.Log("Created new data resource");
            data = CreateInstance <RedirectionDataStructure>();
            if (!AssetDatabase.IsValidFolder("Assets/Resources"))
            {
                AssetDatabase.CreateFolder("Assets", "Resources");
            }
            AssetDatabase.CreateAsset(data, "Assets/Resources/data.asset");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            gain                  = 2;
            sideLength            = 4;
            safetyDistance        = 0.5f;
            walkingZoneRadius     = 0.25f;
            intersectionIndex     = 0;
            curveIndex            = 0;
            joint                 = 0;
            showCurves            = true;
            showJoints            = true;
            showPaths             = true;
            showIntersections     = true;
            hideJointsGui         = false;
            generateAutomatically = false;
        }
    }
Ejemplo n.º 3
0
    /*
     * Draws the gui of the editor window.
     * */
    void OnGUI()
    {
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Data Object", EditorStyles.boldLabel);
        GUI.enabled = false;
        data        = (RedirectionDataStructure)EditorGUILayout.ObjectField(data, typeof(object), false);
        GUI.enabled = true;

        EditorGUILayout.Space();
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("General", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical();
        bool oldShowCurves = showCurves;

        showCurves = EditorGUILayout.ToggleLeft("Show Curves", showCurves);
        if (oldShowCurves != showCurves)
        {
            SceneView.RepaintAll();
        }
        bool oldShowJoints = showJoints;

        showJoints = EditorGUILayout.ToggleLeft("Show JointPoints", showJoints);
        if (oldShowJoints != showJoints)
        {
            SceneView.RepaintAll();
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical();
        bool oldShowPaths = showPaths;

        showPaths = EditorGUILayout.ToggleLeft("Show Virtual Paths", showPaths);
        if (oldShowPaths != showPaths)
        {
            SceneView.RepaintAll();
        }
        bool oldShowIntersections = showIntersections;

        showIntersections = EditorGUILayout.ToggleLeft("Show Virtual Intersections", showIntersections);
        if (oldShowIntersections != showIntersections)
        {
            SceneView.RepaintAll();
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.HelpBox("Resetting means removing all joints, curves, intersections, and paths!", MessageType.Warning);

        if (GUILayout.Button("Reset all", GUILayout.Width(100)))
        {
            Debug.Log("Created new data resource");
            AssetDatabase.DeleteAsset("Assets/Resources/data.asset");
            data = CreateInstance <RedirectionDataStructure>();
            if (!AssetDatabase.IsValidFolder("Assets/Resources/"))
            {
                AssetDatabase.CreateFolder("Assets", "Resources");
            }
            AssetDatabase.CreateAsset(data, "Assets/Resources/data.asset");
            intersectionIndex = 0;
            curveIndex        = 0;
            hideJointsGui     = false;
            jointAPosition    = new Vector3(0.55f, 0, -1.25f);
            jointBPosition    = new Vector3(0.55f, 0, 1.25f);
            jointCPosition    = new Vector3(-1.615f, 0, 0);
            this.saveChanges();
            SceneView.RepaintAll();
        }

        if (hideJointsGui)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.Space();
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Jointpoints", EditorStyles.boldLabel);

        generateAutomatically = EditorGUILayout.ToggleLeft("Generate jointpoints automatically according to tracking space", generateAutomatically);
        if (!generateAutomatically)
        {
            GUI.enabled = false;
        }
        sideLength        = EditorGUILayout.FloatField("Side length", sideLength, GUILayout.Width(200));
        safetyDistance    = EditorGUILayout.FloatField("Safety distance", safetyDistance, GUILayout.Width(200));
        walkingZoneRadius = EditorGUILayout.FloatField("Walking zone radius (at joints)", walkingZoneRadius, GUILayout.Width(200));
        GUI.enabled       = true;

        if (generateAutomatically)
        {
            GUI.enabled = false;
        }
        jointAPosition = EditorGUILayout.Vector3Field("Joint A", jointAPosition);
        jointBPosition = EditorGUILayout.Vector3Field("Joint B", jointBPosition);
        jointCPosition = EditorGUILayout.Vector3Field("Joint C", jointCPosition);
        GUI.enabled    = true;

        if (hideJointsGui)
        {
            GUI.enabled = false;
        }
        if (GUILayout.Button("Create curves", GUILayout.Width(100)))
        {
            hideJointsGui = true;
            if (generateAutomatically)
            {
                calculateJointPositions(sideLength, safetyDistance);
                data.initJointsAndCurves(jointAPosition, jointBPosition, jointCPosition, walkingZoneRadius);
            }
            else
            {
                data.initJointsAndCurves(jointAPosition, jointBPosition, jointCPosition, walkingZoneRadius);
            }
            this.saveChanges();
        }
        GUI.enabled = true;

        if (!hideJointsGui)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.Space();
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Start Position", EditorStyles.boldLabel);
        EditorGUILayout.HelpBox("Choosing a new start joint, removes all existing intersections and paths!", MessageType.Warning);

        joint = EditorGUILayout.Popup("Start Joint", joint, new string[] { "A", "B", "C" }, GUILayout.Width(300));
        if (GUILayout.Button("Set start joint", GUILayout.Width(100)))
        {
            if (joint == 0)
            {
                data.setStartPosition(data.jointPointA);
            }
            if (joint == 1)
            {
                data.setStartPosition(data.jointPointB);
            }
            if (joint == 2)
            {
                data.setStartPosition(data.jointPointC);
            }
            intersectionIndex = 0;
            curveIndex        = 0;
            this.saveChanges();
        }

        if (intersectionIndex >= data.intersections.Count)
        {
            intersectionIndex = 0;
        }

        // Show path creation fields only when a start point was chosen
        if (data.intersections.Count > 0 && intersectionIndex < data.intersections.Count)
        {
            GUI.enabled = true;
        }
        else
        {
            GUI.enabled = false;
        }

        EditorGUILayout.Space();
        GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Virtual Paths", EditorStyles.boldLabel);

        EditorGUILayout.HelpBox("Active intersection is marked yellow in the scene view.", MessageType.Info);

        string[] intersectionOptions = new string[data.intersections.Count];
        int      i = 0;

        foreach (VirtualIntersection intersection in data.intersections)
        {
            intersectionOptions[i] = intersection.getLabel();
            i++;
        }
        int oldIntersectionIndex = intersectionIndex;

        intersectionIndex = EditorGUILayout.Popup("Intersection", intersectionIndex, intersectionOptions, GUILayout.Width(400));
        if (oldIntersectionIndex != intersectionIndex)
        {
            curveIndex = 0;
            SceneView.RepaintAll();
        }

        curveIndex = EditorGUILayout.Popup("Curve", curveIndex, calculateCurveOptions(intersectionIndex), GUILayout.Width(400));
        gain       = EditorGUILayout.FloatField("Gain", gain); // TODO: Limit this to detection thresholds!

        if (curveOptions.Length == 0 || curveOptions[curveIndex] == "")
        {
            GUI.enabled = false;
        }
        if (GUILayout.Button("Create Path", GUILayout.Width(100)))
        {
            data.createPathAndIntersection(data.intersections[intersectionIndex], this.getCurve(curveIndex, intersectionIndex), gain);
            curveIndex = 0;
            this.saveChanges();
            this.Repaint();
        }

        GUI.enabled = true;
        EditorGUILayout.EndScrollView();
    }