private IEnumerator DoFire()
        {
            fireData.startTime = Time.time;
            yield return(new WaitForSeconds(fireData.duration));

            ProjectileObject projectile = ProjectileFromPool();

            // rotate to the correct direction
            Vector3 eulerAngles = projectilePrefab.transform.eulerAngles;

            eulerAngles.y += playerTransform.eulerAngles.y;
            Quaternion rotation = Quaternion.identity;

            rotation.eulerAngles = eulerAngles;
            projectile.Fire(playerTransform.position + playerTransform.rotation * spawnPositionOffset, rotation, playerTransform.forward);
            GameManager.instance.OnPauseGame -= GamePaused;
        }
        private ProjectileObject ProjectileFromPool()
        {
            ProjectileObject obj = null;

            // keep a start index to prevent the constant pushing and popping from the list
            if (pool.Count > 0 && pool[poolIndex].IsActive() == false)
            {
                obj       = pool[poolIndex];
                poolIndex = (poolIndex + 1) % pool.Count;
                return(obj);
            }

            // No inactive objects, need to instantiate a new one
            obj = (GameObject.Instantiate(projectilePrefab.gameObject) as GameObject).GetComponent <ProjectileObject>();

            obj.Init();
            obj.SetStartParent(playerTransform);

            pool.Insert(poolIndex, obj);
            poolIndex = (poolIndex + 1) % pool.Count;

            return(obj);
        }
        public void OnGUI()
        {
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            GUILayout.Label("This wizard will assist in the creation of a new character.\nThe more frequently changed fields are listed and the\nunlisted fields will remain with their default value.\n" +
                            "All of these values can be changed at a later point in time.");
            GUILayout.Space(5);
            GUILayout.Label("Model", "BoldLabel");
            if (model == null) {
                GUI.color = Color.red;
            }
            model = EditorGUILayout.ObjectField("Character Model", model, typeof(GameObject), true) as GameObject;
            GUI.color = Color.white;

            GUILayout.Label("Player", "BoldLabel");
            horizontalSpeed = EditorGUILayout.FloatField("Horizontal Speed", horizontalSpeed);
            jumpHeight = EditorGUILayout.FloatField("Jump Height", jumpHeight);
            slideDuration = EditorGUILayout.FloatField("Slide Duration", slideDuration);
            attackType = (AttackType)EditorGUILayout.EnumPopup("Attack Type", attackType);
            if (attackType == AttackType.Fixed) {
                attackCloseDistance = EditorGUILayout.FloatField("Close Attack Distance", attackCloseDistance);
                attackFarDistance = EditorGUILayout.FloatField("Far Attack Distance", attackFarDistance);
            } else if (attackType == AttackType.Projectile) {
                projectileObject = EditorGUILayout.ObjectField("Projectile", projectileObject, typeof(ProjectileObject), true) as ProjectileObject;
            }
            autoTurn = EditorGUILayout.Toggle("Auto Turn?", autoTurn);
            autoJump = EditorGUILayout.Toggle("Auto Jump?", autoJump);

            DistanceValueListInspector.ShowLoopToggle(ref forwardSpeedList, DistanceValueType.Speed);
            if (forwardSpeedList == null || forwardSpeedList.Count() == 0) {
                GUI.color = Color.red;
            }
            DistanceValueListInspector.ShowDistanceValues(ref forwardSpeedList, DistanceValueType.Speed);
            GUI.color = Color.white;
            DistanceValueListInspector.ShowAddNewValue(ref forwardSpeedList, DistanceValueType.Speed);

            GUILayout.Space(5);
            GUILayout.Label("Particles", "BoldLabel");
            GUILayout.Label("Optionally specify a character to copy the particles from");
            particleSource = EditorGUILayout.ObjectField("Particles Source", particleSource, typeof(PlayerController), true) as PlayerController;

            GUILayout.Space(5);
            GUILayout.Label("Animations", "BoldLabel");
            useMecanim = EditorGUILayout.Toggle("Use Mecanim?", useMecanim);
            if (useMecanim) {
                runStateName = EditorGUILayout.TextField("Run State Name", runStateName);
                jumpStateName = EditorGUILayout.TextField("Jump State Name", jumpStateName);
                slideStateName = EditorGUILayout.TextField("Slide State Name", slideStateName);
                rightStrafeStateName = EditorGUILayout.TextField("Right Strafe State Name", rightStrafeStateName);
                leftStrafeStateName = EditorGUILayout.TextField("Left Strafe State Name", leftStrafeStateName);
                attackStateName = EditorGUILayout.TextField("Attack State Name", attackStateName);
                backwardDeathStateName = EditorGUILayout.TextField("Backward Death State Name", backwardDeathStateName);
                forwardDeathStateName = EditorGUILayout.TextField("Forward Death State Name", forwardDeathStateName);
                idleStateName = EditorGUILayout.TextField("Idle State Name", idleStateName);
            } else {
                runAnimationName = EditorGUILayout.TextField("Run Animation Name", runAnimationName);
                runJumpAnimationName = EditorGUILayout.TextField("Jump Animation Name", runJumpAnimationName);
                runSlideAnimationName = EditorGUILayout.TextField("Slide Animation Name", runSlideAnimationName);
                runRightStrafeAnimationName = EditorGUILayout.TextField("Right Strafe Animation Name", runRightStrafeAnimationName);
                runLeftStrafeAnimationName = EditorGUILayout.TextField("Left Strafe Animation Name", runLeftStrafeAnimationName);
                attackAnimationName = EditorGUILayout.TextField("Attack Animation Name", attackAnimationName);
                backwardDeathAnimationName = EditorGUILayout.TextField("Backward Death Animation Name", backwardDeathAnimationName);
                forwardDeathAnimationName = EditorGUILayout.TextField("Forward Death Animation Name", forwardDeathAnimationName);
                idleAnimationName = EditorGUILayout.TextField("Idle Animation Name", idleAnimationName);
            }

            if (model == null || forwardSpeedList == null || forwardSpeedList.Count() == 0) {
                GUI.enabled = false;
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Create") && GUI.enabled) {
                CreateCharacter();
            }
            GUI.enabled = true;

            GUILayout.EndScrollView();
        }
        public void OnGUI()
        {
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            GUILayout.Label("This wizard will assist in the creation of a new character.\nThe more frequently changed fields are listed and the\nunlisted fields will remain with their default value.\n" +
                            "All of these values can be changed at a later point in time.");
            GUILayout.Space(5);
            GUILayout.Label("Model", "BoldLabel");
            if (model == null)
            {
                GUI.color = Color.red;
            }
            model     = EditorGUILayout.ObjectField("Character Model", model, typeof(GameObject), true) as GameObject;
            GUI.color = Color.white;

            GUILayout.Label("Player", "BoldLabel");
            horizontalSpeed = EditorGUILayout.FloatField("Horizontal Speed", horizontalSpeed);
            jumpHeight      = EditorGUILayout.FloatField("Jump Height", jumpHeight);
            slideDuration   = EditorGUILayout.FloatField("Slide Duration", slideDuration);
            attackType      = (AttackType)EditorGUILayout.EnumPopup("Attack Type", attackType);
            if (attackType == AttackType.Fixed)
            {
                attackCloseDistance = EditorGUILayout.FloatField("Close Attack Distance", attackCloseDistance);
                attackFarDistance   = EditorGUILayout.FloatField("Far Attack Distance", attackFarDistance);
            }
            else if (attackType == AttackType.Projectile)
            {
                projectileObject = EditorGUILayout.ObjectField("Projectile", projectileObject, typeof(ProjectileObject), true) as ProjectileObject;
            }
            autoTurn = EditorGUILayout.Toggle("Auto Turn?", autoTurn);
            autoJump = EditorGUILayout.Toggle("Auto Jump?", autoJump);

            DistanceValueListInspector.ShowLoopToggle(ref forwardSpeedList, DistanceValueType.Speed);
            if (forwardSpeedList == null || forwardSpeedList.Count() == 0)
            {
                GUI.color = Color.red;
            }
            DistanceValueListInspector.ShowDistanceValues(ref forwardSpeedList, DistanceValueType.Speed);
            GUI.color = Color.white;
            DistanceValueListInspector.ShowAddNewValue(ref forwardSpeedList, DistanceValueType.Speed);

            GUILayout.Space(5);
            GUILayout.Label("Particles", "BoldLabel");
            GUILayout.Label("Optionally specify a character to copy the particles from");
            particleSource = EditorGUILayout.ObjectField("Particles Source", particleSource, typeof(PlayerController), true) as PlayerController;

            GUILayout.Space(5);
            GUILayout.Label("Animations", "BoldLabel");
            useMecanim = EditorGUILayout.Toggle("Use Mecanim?", useMecanim);
            if (useMecanim)
            {
                runStateName           = EditorGUILayout.TextField("Run State Name", runStateName);
                jumpStateName          = EditorGUILayout.TextField("Jump State Name", jumpStateName);
                slideStateName         = EditorGUILayout.TextField("Slide State Name", slideStateName);
                rightStrafeStateName   = EditorGUILayout.TextField("Right Strafe State Name", rightStrafeStateName);
                leftStrafeStateName    = EditorGUILayout.TextField("Left Strafe State Name", leftStrafeStateName);
                attackStateName        = EditorGUILayout.TextField("Attack State Name", attackStateName);
                backwardDeathStateName = EditorGUILayout.TextField("Backward Death State Name", backwardDeathStateName);
                forwardDeathStateName  = EditorGUILayout.TextField("Forward Death State Name", forwardDeathStateName);
                idleStateName          = EditorGUILayout.TextField("Idle State Name", idleStateName);
            }
            else
            {
                runAnimationName            = EditorGUILayout.TextField("Run Animation Name", runAnimationName);
                runJumpAnimationName        = EditorGUILayout.TextField("Jump Animation Name", runJumpAnimationName);
                runSlideAnimationName       = EditorGUILayout.TextField("Slide Animation Name", runSlideAnimationName);
                runRightStrafeAnimationName = EditorGUILayout.TextField("Right Strafe Animation Name", runRightStrafeAnimationName);
                runLeftStrafeAnimationName  = EditorGUILayout.TextField("Left Strafe Animation Name", runLeftStrafeAnimationName);
                attackAnimationName         = EditorGUILayout.TextField("Attack Animation Name", attackAnimationName);
                backwardDeathAnimationName  = EditorGUILayout.TextField("Backward Death Animation Name", backwardDeathAnimationName);
                forwardDeathAnimationName   = EditorGUILayout.TextField("Forward Death Animation Name", forwardDeathAnimationName);
                idleAnimationName           = EditorGUILayout.TextField("Idle Animation Name", idleAnimationName);
            }

            if (model == null || forwardSpeedList == null || forwardSpeedList.Count() == 0)
            {
                GUI.enabled = false;
            }
            GUILayout.Space(10);
            if (GUILayout.Button("Create") && GUI.enabled)
            {
                CreateCharacter();
            }
            GUI.enabled = true;

            GUILayout.EndScrollView();
        }