示例#1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        GUI.changed = false;

        DustRing dustRing = (DustRing)target;

        float ringWidthPercent = 0;

        ringWidthPercent = EditorGUILayout.Slider(new GUIContent("Width (% radius)", rPercentTip), 100f * dustRing.ringWidthPercent, 0, 100) / 100f;
        if (GUI.changed)
        {
            Undo.RecordObject(dustRing, "DustRing Change");
            dustRing.ringWidthPercent = FixNaN.FixIfNaN(ringWidthPercent);
            EditorUtility.SetDirty(dustRing);
        }

        if (axisUpdated)
        {
            dustRing.ApplyScale(GravityEngine.Instance().GetLengthScale());
        }
    }
示例#2
0
    public override void OnInspectorGUI()
    {
        GUI.changed = false;

        NBody   nbody       = (NBody)target;
        float   mass        = 0f;
        float   size        = 0.1f;
        bool    autoSize    = true;
        Vector3 velocity    = Vector3.zero;
        Vector3 initialPos  = Vector3.zero;
        bool    rotateFrame = false;

        if (GravityEngine.Instance() == null)
        {
            EditorGUILayout.LabelField("Require a GravityEngine in the scene to", EditorStyles.boldLabel);
            EditorGUILayout.LabelField("display NBody component.", EditorStyles.boldLabel);
        }

        GravityScaler.Units units = GravityEngine.Instance().units;
        string mass_prompt        = string.Format("Mass ({0})", GravityScaler.MassUnits(units));

        mass = EditorGUILayout.DelayedFloatField(new GUIContent(mass_prompt, mTip), (float)nbody.mass);

        // If the velocity is controlled by an EllipseBase, or this NBody is the direct child of
        // BinaryPair or ThreeeBodySolution then don't allowit to be controlled.
        string controlledBy = null;

        if (nbody.transform.gameObject.GetComponent <OrbitEllipse>() != null)
        {
            controlledBy = "Initial position/Velocity is set by ellipse parameters.";
        }
        else if (nbody.transform.gameObject.GetComponent <OrbitHyper>() != null)
        {
            controlledBy = "Initial position/Velocity is set by hyperbola parameters.";
        }
        else if (nbody.transform.parent != null)
        {
            if (nbody.transform.parent.gameObject.GetComponent <BinaryPair>() != null)
            {
                controlledBy = "Initial position/Velocity is set by BinaryPair parent.";
            }
            else if (nbody.transform.parent.gameObject.GetComponent <ThreeBodySolution>() != null)
            {
                controlledBy = "Initial position/Velocity is set by ThreeBodySolution parent.";
            }
        }
        if (controlledBy == null)
        {
            switch (units)
            {
            case GravityScaler.Units.DIMENSIONLESS:
                EditorGUILayout.LabelField("Initial position set via transform");
                velocity   = EditorGUILayout.Vector3Field(new GUIContent("Velocity", velTip), nbody.vel);
                initialPos = nbody.transform.position;
                break;

            default:
                string prompt = string.Format("Initial Pos ({0})", GravityScaler.LengthUnits(units));
                initialPos = EditorGUILayout.Vector3Field(new GUIContent(prompt, iposTip), nbody.initialPos);

                prompt   = string.Format("Velocity ({0})", GravityScaler.VelocityUnits(units));
                velocity = EditorGUILayout.Vector3Field(new GUIContent(prompt, velTip), nbody.vel);
                break;
            }
        }
        else
        {
            EditorGUILayout.LabelField(controlledBy, EditorStyles.boldLabel);
            //EditorGUILayout.LabelField(string.Format("vel= {0:F2} {1:F2} {2:F2}", nbody.vel.x, nbody.vel.y, nbody.vel.z));
        }


        // particle capture size
        EditorGUIUtility.labelWidth = 200f;
        EditorGUIUtility.fieldWidth = 20f;
        rotateFrame = EditorGUILayout.Toggle(new GUIContent("Rotate frame in orbit", rotateTip), nbody.rotateFrame);
        autoSize    = EditorGUILayout.Toggle(new GUIContent("Automatic particle capture size", autoTip), nbody.automaticParticleCapture);
        EditorGUIUtility.labelWidth = 0;
        EditorGUIUtility.fieldWidth = 0;
        if (!autoSize)
        {
            EditorGUIUtility.labelWidth = 200f;
            EditorGUIUtility.fieldWidth = 40f;
            size = EditorGUILayout.FloatField(new GUIContent("Particle capture radius", sizeTip), (float)nbody.size);
            EditorGUIUtility.labelWidth = 0;
            EditorGUIUtility.fieldWidth = 0;
        }
        else
        {
            float detectedSize = nbody.CalculateSize();
            if (detectedSize < 0)
            {
                EditorGUILayout.LabelField("Did not detect a child with a MeshFilter.", EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Using size=" + size);
            }
            else
            {
                EditorGUILayout.LabelField("Particle Capture radius=" + detectedSize);
                size = detectedSize;
            }
        }
        if (mass < 0)
        {
            mass = 0;
        }

        if (nbody.transform.hasChanged)
        {
            // User has dragged the object and the transform has changed, need
            // to change the initial Pos to correspond to this position in the correct units
            if (units != GravityScaler.Units.DIMENSIONLESS)
            {
                initialPos = nbody.transform.position / GravityEngine.Instance().GetLengthScale();
            }
            nbody.initialPos           = initialPos;
            nbody.transform.hasChanged = false;
        }

        if (GUI.changed)
        {
            Undo.RecordObject(nbody, "NBody Change");
            nbody.mass        = FixNaN.FixIfNaN(mass);
            nbody.vel         = FixNaN.FixIfNaN(velocity);
            nbody.size        = size;
            nbody.rotateFrame = rotateFrame;
            nbody.automaticParticleCapture = autoSize;
            nbody.initialPos = initialPos;
            Debug.Log("new v=" + velocity);
            // must be after initialPos is updated
            nbody.ApplyScale(GravityEngine.Instance().GetLengthScale(),
                             GravityEngine.Instance().GetVelocityScale());
            EditorUtility.SetDirty(nbody);
        }
    }
示例#3
0
    public override void OnInspectorGUI()
    {
        Transform t            = (Transform)target;
        Vector3   position     = Vector3.zero;
        Vector3   scale        = Vector3.one;
        Vector3   eulerAngles  = Vector3.zero;
        bool      showPosition = false;

        // Only want to show Xform checkbox if there is a reason to supress normal view

        if ((t.gameObject.GetComponent <GravityEngine>() != null) ||
            (t.gameObject.GetComponent <BinaryPair>() != null) ||
            (t.gameObject.GetComponent <BinaryPair>() != null) ||
            (t.gameObject.GetComponent <EllipseBase>() != null) ||
            (t.gameObject.GetComponent <OrbitHyper>() != null) ||
            (t.gameObject.GetComponent <DustRing>() != null) ||
            (t.gameObject.GetComponentsInChildren <NBody>().Length > 0))
        {
            showXform = EditorGUILayout.Toggle(new GUIContent("Show Full transform", xformTip), showXform);
        }

        if (showXform)
        {
            // Replicate the standard transform inspector gui
            EditorGUI.indentLevel = 0;
            position    = EditorGUILayout.Vector3Field("Position", t.localPosition);
            eulerAngles = EditorGUILayout.Vector3Field("Rotation", t.localEulerAngles);
            scale       = EditorGUILayout.Vector3Field("Scale", t.localScale);
        }
        else if (t.gameObject.GetComponent <GravityEngine>() != null)
        {
            EditorGUILayout.LabelField("NbodyEngine scale handled by script controls below.");
        }
        else if (t.gameObject.GetComponent <BinaryPair>() != null)
        {
            position = EditorGUILayout.Vector3Field("Position", t.localPosition);
            EditorGUILayout.LabelField("Nbody scale set by NBodyEngine parameters.");
            EditorGUILayout.LabelField("(To scale binary adjust the orbit parameters a or p.)");
            EditorGUILayout.LabelField("Orientation controlled by orbit parameters.");
        }
        else if (t.parent != null && t.parent.gameObject.GetComponent <BinaryPair>() != null)
        {
            EditorGUILayout.LabelField("Position/orientation are handled by BinaryPair parameters in the parent.");
            EditorGUILayout.LabelField("(To scale e.g. sphere, add it as a child.)");
            showPosition = true;
        }
        else if (t.gameObject.GetComponent <EllipseBase>() != null)
        {
            EditorGUILayout.LabelField("Position/orientation are handled by Elliptical Orbit parameters below.");
            EditorGUILayout.LabelField("(To scale e.g. sphere, add it as a child.)");
            showPosition = true;
        }
        else if (t.gameObject.GetComponent <OrbitHyper>() != null)
        {
            EditorGUILayout.LabelField("Position/orientation are handled by OrbitHyper parameters below.");
            EditorGUILayout.LabelField("(To scale e.g. sphere, add it as a child.)");
            showPosition = true;
        }
        else if (t.gameObject.GetComponent <DustRing>() != null)
        {
            EditorGUILayout.LabelField("Position taken from parent.\nOrientation is handled by DustRing parameters below.");
            showPosition = true;
        }
        else if (t.gameObject.GetComponentsInChildren <NBody>().Length > 0)
        {
            // Why is this about children?
            if (GravityEngine.Instance().units == GravityScaler.Units.DIMENSIONLESS)
            {
                // ideally all units would be the same - this is to preserve bkwd compat.
                position = EditorGUILayout.Vector3Field("Position", t.localPosition);
            }
            else
            {
                EditorGUILayout.LabelField("Position is set from NBody initial position and");
                EditorGUILayout.LabelField("  GE units and length scale selection.");
                showPosition = true;
            }
            EditorGUILayout.LabelField("Nbody scale set by NBodyEngine parameters.");
            EditorGUILayout.LabelField("  (To scale e.g. sphere, add it as a child.)");
            EditorGUILayout.LabelField("Nbody orbital rotation controlled on a per orbit basis.");
        }
        else
        {
            // Replicate the standard transform inspector gui
            EditorGUI.indentLevel = 0;
            position    = EditorGUILayout.Vector3Field("Position", t.localPosition);
            eulerAngles = EditorGUILayout.Vector3Field("Rotation", t.localEulerAngles);
            scale       = EditorGUILayout.Vector3Field("Scale", t.localScale);
        }
        if (showPosition)
        {
            EditorGUILayout.LabelField(string.Format("position= {0:F2} {1:F2} {2:F2}", t.position.x, t.position.y, t.position.z));
            EditorGUILayout.LabelField(string.Format("scale= {0:F2} {1:F2} {2:F2}", t.localScale.x, t.localScale.y, t.localScale.z));
        }
        if (GUI.changed)
        {
            Undo.RecordObject(t, "Transform Change");
            t.localPosition    = FixNaN.FixIfNaN(position);
            t.localEulerAngles = FixNaN.FixIfNaN(eulerAngles);
            t.localScale       = FixNaN.FixIfNaN(scale);
        }
    }