コード例 #1
0
    private void StartExplosion(Vector3 contactPoint, Vector3 normal, GameObject otherNBodyGO)
    {
        if (!prefabOk)
        {
            Debug.LogError("prefab not ok");
            return;
        }
        NBody nbody = otherNBodyGO.GetComponent <NBody>();

        if (nbody == null)
        {
            Debug.LogError("Parent of collider does not have NBody - explosion aborted. " + otherNBodyGO.name);
            return;
        }
        // instantiate the prefab and set it's position to that of the current object
        GameObject explosionGO = Instantiate(explosionPrefab) as GameObject;

        explosionGO.transform.localPosition = Vector3.zero;
        explosionGO.transform.position      = transform.parent.position;
        // find out the velocity of this NBody and provide to dust init routine. (This becomes the CM velocity)
        // Tell engine to ignore this body
        ExplosionFromNBody explosionFromNBody = explosionGO.GetComponent <ExplosionFromNBody>();

        explosionFromNBody.Init(nbody, contactPoint);

        // Activate dust (this will inactivate the sphere model, so it will be hidden)
        // MUST remove the exploding FIRST or it's mass will accelerate the particles
        GravityEngine.instance.InactivateBody(transform.parent.gameObject);
        explosionGO.SetActive(true);
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        GUI.changed = false;

        ExplosionFromNBody efn = (ExplosionFromNBody)target;
        float explosionSize    = 10f;
        float soften           = 1f;
        float coneWidth        = 30f;
        float velocitySpread   = 0;

        explosionSize  = EditorGUILayout.FloatField(new GUIContent("Explosion Size", esizeTip), efn.explosionSize);
        coneWidth      = EditorGUILayout.FloatField(new GUIContent("Cone Width (deg.)", coneTip), efn.coneWidth);
        velocitySpread = EditorGUILayout.FloatField(new GUIContent("Velocity Spread", velTip), efn.velocitySpread);
        soften         = EditorGUILayout.FloatField(new GUIContent("Velocity Adjust", softenTip), efn.soften);

        if (GUI.changed)
        {
            Undo.RecordObject(efn, "ExplosionFromNBody Change");
            efn.explosionSize  = explosionSize;
            efn.coneWidth      = coneWidth;
            efn.soften         = soften;
            efn.velocitySpread = velocitySpread;
            EditorUtility.SetDirty(efn);
        }
    }