示例#1
0
 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();
     GUILayout.Space(16);
     GUI.enabled = Application.isPlaying;
     if (GUILayout.Button("Explode!"))
     {
         explosion.Explode();
     }
     GUI.enabled = true;
     if (explosion.sources.Length == 0)
     {
         EditorGUILayout.HelpBox(SOURCE_WARNING, MessageType.Warning);
     }
     if (GUILayout.Button("Duplicate Component"))
     {
         Handy.DuplicateComponent(explosion, explosion.gameObject);
     }
 }
示例#2
0
    public void Explode()
    {
        if (sources.Length == 0)
        {
            Debug.LogWarning(SOURCE_WARNING);
            return;
        }

        if (explodeDelay > 0)
        {
            var go = new GameObject();
            go.transform.position = transform.position;

            var copy = Handy.DuplicateComponent(this, go);
            copy.explodeDelay = 0f;

            Destroy(go, explodeDelay);

            return;
        }

        for (int index = 0; index < count; index++)
        {
            int  sourceIndex = mode == Mode.Random ? Random.Range(0, sources.Length) : index % sources.Length;
            Item source      = sources[sourceIndex];

            float angle = mode == Mode.Random ? Random.Range(0f, 360f) : (float)index / count * 360f;

            Item shard = Instantiate(source, transform.position, Quaternion.Euler(0f, 0f, angle));
            shard.gameObject.hideFlags = hideClonesInHierarchy ? HideFlags.HideInHierarchy : HideFlags.None;

            float vVariation     = mode == Mode.Random ? Random.Range(-velocityVariation, velocityVariation) : 0f;
            float shardVelocity  = velocity * (1f + vVariation);
            float shardVelocityX = shardVelocity * Mathf.Cos(angle * Mathf.Deg2Rad);
            float shardVelocityY = shardVelocity * Mathf.Sin(angle * Mathf.Deg2Rad);
            shard.velocity = new Vector3(shardVelocityX, shardVelocityY, 0f);

            float tVariation = mode == Mode.Random ? Random.Range(-timeMaxVariation, timeMaxVariation) : 0f;
            shard.timeMax = timeMax * (1f + tVariation);
        }
    }