public void CreateExplosion(Vector3 position)
    {
        _audioSource.Play();

        FloatingObject smoke_clone = _smokePool.GetObject() as FloatingObject;

        smoke_clone.transform.position = position;
        StartCoroutine(smoke_clone.ReturnToPool(_smoke.GetComponent <ParticleSystem>().duration * 2));

        FloatingObject explosion_clone = _explosionPool.GetObject() as FloatingObject;

        explosion_clone.transform.position = position;
        StartCoroutine(explosion_clone.ReturnToPool(_sparkDuration));
    }
Beispiel #2
0
    private void Start()
    {
        _ballsPool = new ObjectsPool(1, _ball);

        Hoop.Goal += delegate(){
            Vector2 NewBallPosition = new Vector2(Random.Range(-15, 15), Random.Range(-10, 18));

            while (NewBallPosition == OldBallPosition)
            {
                NewBallPosition = new Vector2(Random.Range(-15, 15), Random.Range(-10, 18));
            }

            _ball.ReturnToPool();
            _ball = _ballsPool.GetObject();
            _ball.GetComponent <BallBehaviour>().SetBall(NewBallPosition);
            OldBallPosition = NewBallPosition;
        };
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        FloatingObject fo = (FloatingObject)target;

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.BeginVertical();

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Physics", EditorStyles.boldLabel);

        EditorGUILayout.PropertyField(targetRigidbody,
                                      new GUIContent("Target Rigidbody", "Rigidbody on which the forces will be applied. Must be self or parent object's rigidbody"));
        EditorGUILayout.PropertyField(materialDensity,
                                      new GUIContent("Material Density",
                                                     "Density of the material object is made of. Anything higher than fluid density will sink. Check manual for proper use. Set to 0 to ignore."));
        EditorGUILayout.PropertyField(fluidDensity,
                                      new GUIContent("Fluid Density",
                                                     "Density of the fluid this object is in. Higher density will make object tent to float more easily. Affects only buoyancy. Check 'Dynamic Force Factor' for dynamic forces"));
        EditorGUILayout.PropertyField(dynamicForceFactor,
                                      new GUIContent("Dynamic Force Factor",
                                                     "Forces acting upon the object based on it's velocity."));

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Dummy Mesh", EditorStyles.boldLabel);

        EditorGUILayout.PropertyField(doConvexifyMesh, new GUIContent("Convexify Mesh",
                                                                      "Generate a convex mesh. This must be used if the mesh is not closed (missing one of its surfaces, e.g. only bottom of the hull has triangles)."));
        EditorGUILayout.PropertyField(doSimplifyMesh, new GUIContent("Simplify Mesh",
                                                                     "Generate a simplified mesh. 15-30 triangles is recommended for simple objects, and up to 100 for ships and similar and more complex objects. Simulation is O(n) where n is number of triangles."));
        if (fo.DoSimplifyMesh)
        {
            EditorGUILayout.PropertyField(simplificationRatio);
        }

        EditorGUILayout.Space();

        if (fo.TargetRigidbody == null)
        {
            fo.TargetRigidbody = fo.GetComponent <Rigidbody>();
        }

        if (!fo.PreviewDummyMesh || fo.OriginalMesh == null)
        {
            if (fo.GetComponent <MeshFilter>() != null)
            {
                fo.OriginalMesh = fo.GetComponent <MeshFilter>().sharedMesh;
            }
        }

        // Check if dummy mesh set
        if (fo.DummyMesh == null)
        {
            fo.DummyMesh = fo.originalMesh;
        }

        string buttonText = fo.PreviewDummyMesh ? "End Preview" : "Preview";

        if (GUILayout.Button(buttonText))
        {
            foreach (FloatingObject t in targets)
            {
                // Preview dummy mesh button
                t.PreviewDummyMesh = !t.PreviewDummyMesh;

                if (t.PreviewDummyMesh)
                {
                    t.GetComponent <MeshFilter>().mesh = t.DummyMesh;
                }
                else
                {
                    t.GetComponent <MeshFilter>().mesh = t.OriginalMesh;
                }
            }
        }


        if (fo.MaterialDensity != prevMaterialDensity)
        {
            fo.MeshVolume   = fo.VolumeOfMesh(fo.DummyMesh);
            fo.MaterialMass = fo.MeshVolume * fo.MaterialDensity;
        }

        if (GUILayout.Button("Update Dummy Mesh"))
        {
            foreach (FloatingObject t in targets)
            {
                // Update dummy mesh button
                if (t.OriginalMesh == null)
                {
                    t.OriginalMesh = t.GetComponent <MeshFilter>().sharedMesh;
                }
                t.DummyMesh = t.ManipulateMesh(t.OriginalMesh);
            }
        }

        // Tri count
        if (fo.DummyMesh != null && fo.OriginalMesh != null)
        {
            EditorGUILayout.LabelField("Original: " + (fo.OriginalMesh.triangles.Length / 3) + " -> Dummy: " + (fo.DummyMesh.triangles.Length / 3) + " triangles");
        }

        if (showAdvanced = EditorGUILayout.Foldout(showAdvanced, "Additional Options"))
        {
            EditorGUILayout.PropertyField(debug);
            EditorGUILayout.PropertyField(reuseForces);
            EditorGUILayout.PropertyField(reusePositionTreshold);
            EditorGUILayout.PropertyField(reuseAngleTreshold);
        }


        if (fo.GetComponent <Rigidbody>() != null && fo.DummyMesh != null)
        {
            if (fo.TargetRigidbody == fo.GetComponent <Rigidbody>())
            {
                if (fo.MaterialDensity > 0)
                {
                    fo.TargetRigidbody.mass = fo.MaterialMass;
                }
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.EndVertical();

        prevMaterialDensity = fo.MaterialDensity;

        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(fo);
        }

        serializedObject.ApplyModifiedProperties();
    }