public override void OnInspectorGUI()
    {
        GUI.changed = false;
        BinaryPair bPair    = (BinaryPair)target;
        Vector3    velocity = Vector3.zero;

        GravityScaler.Units units = GravityEngine.Instance().units;
        string prompt             = string.Format("Velocity ({0})", GravityScaler.VelocityUnits(units));

        velocity = EditorGUILayout.Vector3Field(new GUIContent(prompt, "velocity of binary center of mass"), bPair.velocity);


        if (GUI.changed)
        {
            Undo.RecordObject(bPair, "EllipseBase Change");
            bPair.velocity = velocity;
            EditorUtility.SetDirty(bPair);
        }
        base.OnInspectorGUI();

        if (axisUpdated)
        {
            bPair.ApplyScale(GravityEngine.Instance().GetLengthScale());
        }
    }
    public override void OnInspectorGUI()
    {
        GUI.changed = false;

        GravityParticles nbp              = (GravityParticles)target;
        Vector3          initialV         = nbp.initialVelocity;
        bool             addNBodyVelocity = nbp.addNBodyVelocity;

        IGravityParticlesInit particlesInit = nbp.GetComponent <IGravityParticlesInit>();

        GravityScaler.Units units = GravityEngine.Instance().units;
        string prompt             = string.Format("Initial Vel. ({0})", GravityScaler.VelocityUnits(units));

        if (particlesInit == null)
        {
            EditorGUILayout.LabelField("No init script", EditorStyles.boldLabel);
            bool hasNBody = false;
            if (nbp.GetComponent <NBody>() != null)
            {
                hasNBody = true;
            }
            else if (nbp.transform.parent != null && nbp.transform.parent.gameObject.GetComponent <NBody>() != null)
            {
                hasNBody = true;
            }
            if (hasNBody)
            {
                addNBodyVelocity = EditorGUILayout.Toggle(new GUIContent("Use velocity from NBody", velTip), nbp.addNBodyVelocity);
                if (addNBodyVelocity)
                {
                    EditorGUILayout.LabelField("Initial Velocity: (from NBody)", EditorStyles.boldLabel);
                }
                else
                {
                    initialV = EditorGUILayout.Vector3Field(new GUIContent(prompt, iTip), nbp.initialVelocity);
                }
            }
            else
            {
                initialV = EditorGUILayout.Vector3Field(new GUIContent(prompt, iTip), nbp.initialVelocity);
            }
        }
        else
        {
            EditorGUILayout.LabelField("Initalize with: " + particlesInit.GetType().ToString(), EditorStyles.boldLabel);
        }

        if (GUI.changed)
        {
            Undo.RecordObject(nbp, "GravityParticles Change");
            nbp.initialVelocity  = initialV;
            nbp.addNBodyVelocity = addNBodyVelocity;
            EditorUtility.SetDirty(nbp);
        }
    }
    public override void OnInspectorGUI()
    {
        GUI.changed = false;

        NBodyCollision nbc        = (NBodyCollision)target;
        GameObject     explodePF  = nbc.explosionPrefab;
        int            precedence = nbc.collisionPrecedence;
        float          explodeOrBounceVelocity = nbc.explodeOrBounceVelocity;
        float          bounceFactor            = 1f;
        string         layer = null;

        float oldWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = 200;

        NBodyCollision.CollisionType type = NBodyCollision.CollisionType.ABSORB_IMMEDIATE;

        type       = (NBodyCollision.CollisionType)EditorGUILayout.EnumPopup(new GUIContent("Collision Type", collTip), nbc.collisionType);
        precedence = EditorGUILayout.IntField(new GUIContent("Collision Precedence", cTip), nbc.collisionPrecedence);

        layer = EditorGUILayout.TextField(new GUIContent("Collision Layer (Optional)", layerTip), nbc.collisionLayer);

        if (type == NBodyCollision.CollisionType.EXPLODE)
        {
            explodePF = (GameObject)EditorGUILayout.ObjectField(
                new GUIContent("Explosion Prefab", "Particle System with NBodyParticles"), explodePF, typeof(GameObject), true);
        }
        else if (type == NBodyCollision.CollisionType.BOUNCE)
        {
            EditorGUIUtility.labelWidth = oldWidth;
            bounceFactor = EditorGUILayout.Slider(new GUIContent("Bounce", bTip), nbc.bounceFactor, 0f, 1f);
        }
        else if (type == NBodyCollision.CollisionType.EXPLODE_OR_BOUNCE)
        {
            explodePF = (GameObject)EditorGUILayout.ObjectField(
                new GUIContent("Explosion Prefab", "Particle System with NBodyParticles"), explodePF, typeof(GameObject), true);
            bounceFactor = EditorGUILayout.Slider(new GUIContent("Bounce", bTip), nbc.bounceFactor, 0f, 1f);
            GravityScaler.Units units = GravityEngine.Instance().units;
            EditorGUIUtility.labelWidth = oldWidth;
            string prompt = string.Format("Relative Velocity to Explode ({0})", GravityScaler.VelocityUnits(units));
            explodeOrBounceVelocity = EditorGUILayout.FloatField(new GUIContent(prompt, dTip), nbc.explodeOrBounceVelocity);
        }
        if (GUI.changed)
        {
            Undo.RecordObject(nbc, "NBodyCollision Change");
            nbc.explosionPrefab         = explodePF;
            nbc.collisionType           = type;
            nbc.bounceFactor            = bounceFactor;
            nbc.explodeOrBounceVelocity = explodeOrBounceVelocity;
            nbc.collisionPrecedence     = precedence;
            nbc.collisionLayer          = layer;
            EditorUtility.SetDirty(nbc);
        }
    }
Exemple #4
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);
        }
    }