Exemplo n.º 1
0
    /// <summary>
    /// removes the object, plays the death effect and schedules
    /// a respawn if enabled, otherwise destroys the object
    /// </summary>
    public virtual void Die()
    {
        if (!vp_Utility.IsActive(m_Transform.gameObject))
        {
            return;
        }

        if (m_EventHandler.Dead.Active)
        {
            return;
        }

        RemoveBulletHoles();

        DoRagdoll();

        m_EventHandler.Dead.Start();
        m_EventHandler.Animate.Send(m_AI.DamageHandlerDeathAnimState);
        m_GetHitEndTimer.Cancel();

        if (m_AI.DamageHandlerRagdoll != null)
        {
            vp_Utility.Activate(m_Transform.gameObject, false);
        }

        DeathSpawnObjects.RandomizeList();
        foreach (DeathSpawnObject o in DeathSpawnObjects)
        {
            if (o.Prefab != null)
            {
                if (Random.Range(0f, 1f) < o.Probability)
                {
                    Object.Instantiate(o.Prefab, m_Transform.position, m_Transform.rotation);
                    if (m_AI.DamageHandlerOnlySpawnOneObject)
                    {
                        break;
                    }
                }
            }
        }

        if (m_AI.DamageHandlerRespawns)
        {
            vp_Timer.In(Random.Range(m_AI.DamageHandlerRespawnTime.x, m_AI.DamageHandlerRespawnTime.y), Respawn);
        }
        else
        {
            if (m_EventHandler != null)
            {
                vp_AIManager.Unregister(m_EventHandler);
            }

            Object.Destroy(m_Transform.gameObject);
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Stop retreating and start roaming
 /// </summary>
 protected virtual void OnStop_Retreat()
 {
     m_RetreatTimer.Cancel();
     if (m_CurrentHealth <= m_AI.MovementRetreatHealthThreshold)
     {
         m_EventHandler.Idle.Start();
         vp_Timer.In(Random.Range(m_AI.MovementRoamingWaitTime.x, m_AI.MovementRoamingWaitTime.y + 1), delegate() {
             m_EventHandler.Roaming.TryStart();
         }, m_RoamingTimer);
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// stop timers if AI is told to stop
    /// </summary>
    protected virtual void OnStart_Stop()
    {
        object activity = m_EventHandler.Stop.Argument;

        m_MoveAgainTimer.Cancel();
        m_RoamingTimer.Cancel();
        m_WaitingForPathTimer.Cancel();
        if (activity != m_EventHandler.Retreat)
        {
            m_RetreatTimer.Cancel();
        }
    }
Exemplo n.º 4
0
    /// <summary>
    ///
    /// </summary>
    protected override void Update()
    {
        base.Update();

        // if have a target and swiveling is enabled
        if ((m_Target != null) && m_AngleBob.enabled)
        {
            m_AngleBob.enabled = false;
            vp_ResumeSwivelTimer.Cancel();
        }

        // if we have no target and swiveling is not enabled
        if ((m_Target == null) && !m_AngleBob.enabled && !vp_ResumeSwivelTimer.Active)
        {
            vp_Timer.In(WakeInterval * 2.0f, delegate()
            {
                m_AngleBob.enabled = true;
            }, vp_ResumeSwivelTimer);
        }

#if UNITY_EDITOR
        m_AngleBob.BobAmp.y  = SwivelAmp;
        m_AngleBob.BobRate.y = SwivelRate;
        m_AngleBob.YOffset   = SwivelOffset;
#endif

        SwivelRotation.y             = m_Transform.eulerAngles.y;
        Swivel.transform.eulerAngles = SwivelRotation;
    }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 public virtual void CancelTimers()
 {
     vp_Timer.CancelAll("EjectShell");
     m_DisableAttackStateTimer.Cancel();
     m_SetWeaponTimer.Cancel();
     m_SetWeaponRefreshTimer.Cancel();
 }
Exemplo n.º 6
0
 /// <summary>
 /// stops the stopwatch
 /// </summary>
 public void Stop()
 {
     m_Timer.Cancel();
     if (GetComponent <AudioSource>().isPlaying)
     {
         GetComponent <AudioSource>().Stop();
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// call this when the hero cuts the correct wire in the
 /// nick of time!
 /// </summary>
 void CancelBomb()
 {
     GetComponent <AudioSource>().Stop();
     DigitalPosition = m_StartPosition;
     m_Timer.Cancel();
     m_TimeBombNumberAlpha = 1.0f;
     m_NumberBlinkTimer.Cancel();
     m_ExplosionDelayTimer.Cancel();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Repeat call.
 /// </summary>
 /// <param name="delaySeconds">Delay(seconds).</param>
 /// <param name="repeatTimes">Repeat times, set <c>1</c> for no repeat .</param>
 /// <param name="callBack">Call back.</param>
 public static vp_Timer.Handle RepeatCall(float delaySeconds, int repeatTimes, Action callback)
 {
     vp_Timer.Handle handle = new vp_Timer.Handle();
     vp_Timer.In(delaySeconds, () => {
         handle.Cancel();
         callback();
     }, 1, handle);
     return(handle);
 }
Exemplo n.º 9
0
    /// <summary>
    /// reset to initial state
    /// </summary>
    protected virtual void OnMessage_Reset(Vector3 newSpawnPosition)
    {
        m_AI.AStarCanSearch    = false;
        m_TargetReached        = false;
        m_CanSearchAgain       = true;
        waitingForRepath       = false;
        m_LastRepath           = -9999;
        m_CurrentWaypointIndex = 0;

        m_RepeatTrySearchPathTimer.Cancel();
        m_ShouldRepath = true;
    }
Exemplo n.º 10
0
 private static void Schedule(float time, vp_Timer.Callback func, vp_Timer.ArgCallback argFunc, object args, vp_Timer.Handle timerHandle, int iterations, float interval)
 {
     if (func == null && argFunc == null)
     {
         Debug.LogError("Error: (vp_Timer) Aborted event because function is null.");
         return;
     }
     if (vp_Timer.m_MainObject == null)
     {
         vp_Timer.m_MainObject = new GameObject("Timers");
         vp_Timer.m_MainObject.AddComponent <vp_Timer>();
         UnityEngine.Object.DontDestroyOnLoad(vp_Timer.m_MainObject);
     }
     time                = Mathf.Max(0f, time);
     iterations          = Mathf.Max(0, iterations);
     interval            = ((interval != -1f) ? Mathf.Max(0f, interval) : time);
     vp_Timer.m_NewEvent = null;
     if (vp_Timer.m_Pool.Count > 0)
     {
         vp_Timer.m_NewEvent = vp_Timer.m_Pool[0];
         vp_Timer.m_Pool.Remove(vp_Timer.m_NewEvent);
     }
     else
     {
         vp_Timer.m_NewEvent = new vp_Timer.Event();
     }
     vp_Timer.m_EventCount++;
     vp_Timer.m_NewEvent.Id = vp_Timer.m_EventCount;
     if (func != null)
     {
         vp_Timer.m_NewEvent.Function = func;
     }
     else if (argFunc != null)
     {
         vp_Timer.m_NewEvent.ArgFunction = argFunc;
         vp_Timer.m_NewEvent.Arguments   = args;
     }
     vp_Timer.m_NewEvent.StartTime  = Time.time;
     vp_Timer.m_NewEvent.DueTime    = Time.time + time;
     vp_Timer.m_NewEvent.Iterations = iterations;
     vp_Timer.m_NewEvent.Interval   = interval;
     vp_Timer.m_NewEvent.LifeTime   = 0f;
     vp_Timer.m_NewEvent.Paused     = false;
     vp_Timer.m_Active.Add(vp_Timer.m_NewEvent);
     if (timerHandle != null)
     {
         if (timerHandle.Active)
         {
             timerHandle.Cancel();
         }
         timerHandle.Id = vp_Timer.m_NewEvent.Id;
     }
 }
Exemplo n.º 11
0
    /// <summary>
    /// Resets the crosshair to it's default state.
    /// </summary>
    protected virtual void ResetCrosshair(bool reset = true)
    {
        if (m_OriginalCrosshair == null || m_Player.Crosshair.Get() == m_OriginalCrosshair)
        {
            return;
        }

        m_ShowTextTimer.Cancel();
        if (reset)
        {
            m_Player.Crosshair.Set(m_OriginalCrosshair);
        }
        m_CurrentCrosshairInteractable = null;
    }
Exemplo n.º 12
0
    /// <summary>
    ///	detects cases where the connection process has stalled,
    ///	disconnects and tries to connect again
    /// </summary>
    protected virtual void UpdateConnectionState()
    {
        if (!StayConnected)
        {
            return;
        }

        if (PhotonNetwork.connectionStateDetailed != m_LastClientState)
        {
            string s = PhotonNetwork.connectionStateDetailed.ToString();
            s = ((PhotonNetwork.connectionStateDetailed == ClientState.Joined) ? "--- " + s + " ---" : s);
            if (s == "PeerCreated")
            {
                s = "Connecting to the " + PhotonNetwork.PhotonServerSettings.PreferredRegion.ToString().ToUpper() + " cloud ...";
            }
            vp_MPDebug.Log(s);
        }

        if (PhotonNetwork.connectionStateDetailed == ClientState.Joined)
        {
            if (m_ConnectionTimer.Active)
            {
                m_ConnectionTimer.Cancel();
                m_ConnectionAttempts = 0;
            }
        }
        else if ((PhotonNetwork.connectionStateDetailed != m_LastClientState) && !m_ConnectionTimer.Active)
        {
            Reconnect();
            vp_Timer.In(LogOnTimeOut, delegate()
            {
                m_ConnectionAttempts++;
                if (m_ConnectionAttempts < MaxConnectionAttempts)
                {
                    vp_MPDebug.Log("Retrying (" + m_ConnectionAttempts + ") ...");
                    Reconnect();
                }
                else
                {
                    vp_MPDebug.Log("Failed to connect (tried " + m_ConnectionAttempts + " times).");
                    Disconnect();
                }
            }, m_ConnectionTimer);
        }

        m_LastClientState = PhotonNetwork.connectionStateDetailed;
    }
Exemplo n.º 13
0
    /// <summary>
    /// execute when this control is touched
    /// </summary>
    protected override void TouchesBegan(vp_Touch touch)
    {
        if (LastFingerID != -1)
        {
            return;
        }

        if (!RaycastControl(touch))
        {
            return;
        }

        base.TouchesBegan(touch);

        m_ShouldAutoPitch = false;
        m_AutoPitchTimer.Cancel();
    }
Exemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnStart_Attack()
 {
     // TEMP: time body animation better to throwing weapon projectile spawn
     if (Player.CurrentWeaponType.Get() == (int)vp_Weapon.Type.Thrown)
     {
         vp_Timer.In(WeaponHandler.CurrentWeapon.GetComponent <vp_Shooter>().ProjectileSpawnDelay * 0.7f, () =>
         {
             m_AttackDoneTimer.Cancel();
             Animator.SetBool(IsAttacking, true);
             OnStop_Attack();
         });
     }
     else
     {
         // ---
         Animator.SetBool(IsAttacking, true);
     }
 }
Exemplo n.º 15
0
    /// <summary>
    /// handles respawn position, scaleup, rendering activation
    /// and sets a new random bob value if applicable
    /// </summary>
    protected virtual void Respawn()
    {
        if (m_Transform == null)
        {
            return;
        }

        if (Camera.main != null)
        {
            m_CameraMainTransform = Camera.main.transform;
        }

        m_RespawnTimer.Cancel();                // cancel timer in case we didn't get here via timer

        m_Transform.position = m_SpawnPosition;

        if ((m_Rigidbody == null) && RespawnScaleUpDuration > 0.0f)
        {
            m_Transform.localScale = Vector3.zero;
        }

        GetComponent <Renderer>().enabled = true;
        vp_Utility.Activate(gameObject);
        m_Audio.pitch = (RespawnSoundSlomo ? Time.timeScale : 1.0f);
        m_Audio.PlayOneShot(RespawnSound);
        m_Depleted = false;

        if (BobOffset == -1.0f)
        {
            BobOffset = Random.value;
        }

        if (m_Rigidbody != null)
        {
            m_Rigidbody.isKinematic = false;
            foreach (Collider c in GetComponents <Collider>())
            {
                if (!c.isTrigger)
                {
                    c.enabled = true;
                }
            }
        }
    }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void OnStart_Attack()
 {
     // TEST: time body animation better to throwing weapon projectile spawn
     if (Player.CurrentWeaponType.Get() == (int)vp_Weapon.Type.Thrown)
     {
         if (WeaponHandler.CurrentShooter != null)
         {
             vp_Timer.In(WeaponHandler.CurrentShooter.ProjectileSpawnDelay * 0.7f, () =>
             {
                 if ((this != null) && (Animator != null))
                 {
                     m_AttackDoneTimer.Cancel();
                     Animator.SetBool(IsAttacking, true);
                     OnStop_Attack();
                 }
             });
         }
     }
     else
     {
         // ---
         Animator.SetBool(IsAttacking, true);
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// activates the gameobject containing this vp_Component.
 /// a virtual activation method provided for classes
 /// inheriting vp_Component to add additional activation
 /// routines
 /// </summary>
 public virtual void Activate()
 {
     m_DeactivationTimer.Cancel();
     vp_Utility.Activate(gameObject);
     //ActivateInternal(gameObject);		// TEMP: reverted due to weapons going invisible in 3rd person
 }
Exemplo n.º 18
0
 /// <summary>
 ///
 /// </summary>
 void OnDisable()
 {
     m_DestroyTimer.Cancel();
 }
Exemplo n.º 19
0
    /// <summary>
    /// this method contains all timer example code. NOTE: timer code
    /// does not have to be located in 'OnGUI'. it can exist anywhere
    /// </summary>
    void OnGUI()
    {
        // make the status text fade back to invisible if made yellow
        m_StatusColor = Color.Lerp(m_StatusColor, new Color(1, 1, 0, 0), Time.deltaTime * 0.5f);

        // draw the header text
        GUI.color = Color.white;
        GUILayout.Space(50);
        GUILayout.BeginHorizontal();
        GUILayout.Space(50);
        GUILayout.Label("SCHEDULING EXAMPLE\n    - Each of these examples will schedule some functionality in one (1)\n      second using different options.\n    - Please study the source code in 'Examples/Scheduling/Scheduling.cs' ...");
        GUILayout.EndHorizontal();

        // create an area for all the example buttons
        GUILayout.BeginArea(new Rect(100, 150, 400, 600));
        GUI.color = Color.white;
        GUILayout.Label("Methods, Arguments, Delegates, Iterations, Intervals & Canceling");

        // --- Example 1 ---
        if (DoButton("A simple method"))
        {
            vp_Timer.In(1.0f, DoMethod);
        }

        // --- Example 2 ---
        if (DoButton("A method with a single argument"))
        {
            vp_Timer.In(1.0f, DoMethodWithSingleArgument, 242);
        }

        // --- Example 3 ---
        if (DoButton("A method with multiple arguments"))
        {

            object[] arg = new object[3];
            arg[0] = "December";
            arg[1] = 31;
            arg[2] = 2012;
            vp_Timer.In(1.0f, DoMethodWithMultipleArguments, arg);

            // TIP: you can also create the object array in-line like this:
            //vp_Timer.In(1.0f, DoMethodWithMultipleArguments, new object[] { "December", 31, 2012 });

        }

        // --- Example 4 ---
        if (DoButton("A delegate"))
        {
            vp_Timer.In(1.0f, delegate()
            {
                SmackCube();
            });
        }

        // --- Example 5 ---
        if (DoButton("A delegate with a single argument"))
        {
            vp_Timer.In(1.0f, delegate(object o)
            {
                int i = (int)o;
                SmackCube();
                SetStatus("A delegate with a single argument ... \"" + i + "\"");
            }, 242);
        }

        // --- Example 6 ---
        if (DoButton("A delegate with multiple arguments"))
        {
            vp_Timer.In(1.0f, delegate(object o)
            {

                object[] argument = (object[])o;		// 'unpack' object into an array
                string month = (string)argument[0];		// convert the first argument to a string
                int day = (int)argument[1];				// convert the second argument to an integer
                int year = (int)argument[2];			// convert the third argument to an integer

                SmackCube();
                SetStatus("A delegate with multiple arguments ... \"" + month + " " + day + ", " + year + "\"");

            }, new object[] { "December", 31, 2012 });
        }

        // --- Example 7 ---
        if (DoButton("5 iterations of a method"))
        {
            vp_Timer.In(1.0f, SmackCube, 5);
        }

        // --- Example 8 ---
        if (DoButton("5 iterations of a method, with 0.2 sec intervals"))
        {
            vp_Timer.In(1.0f, SmackCube, 5, 0.2f);
        }

        // --- Example 9 ---
        if (DoButton("5 iterations of a delegate, canceled after 3 seconds"))
        {
            vp_Timer.Handle timer = new vp_Timer.Handle();
            vp_Timer.In(0.0f, delegate() { SmackCube(); }, 5, 1,
                timer);
            vp_Timer.In(3, delegate() { timer.Cancel(); });
        }

        GUILayout.Label("\nMethod & object accessibility:");

        // --- Example 10 ---
        if (DoButton("Running a method from a non-monobehaviour class", false))
        {
            vp_Timer.In(1, delegate()
            {
                NonMonoBehaviour test = new NonMonoBehaviour();
                test.Test();
            });

        }

        // --- Example 11 ---
        if (DoButton("Running a method from a specific external gameobject", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = (TestComponent)GameObject.Find("ExternalGameObject").GetComponent("TestComponent");
                tc.Test("Hello World!");
            });
        }

        // --- Example 12 ---
        if (DoButton("Running a method from the first component of a certain type\nin current transform or any of its children", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = transform.root.GetComponentInChildren<TestComponent>();
                tc.Test("Hello World!");
            });
        }

        // --- Example 13 ---
        if (DoButton("Running a method from the first component of a certain type\nin the whole Hierarchy", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = (TestComponent)FindObjectOfType(typeof(TestComponent));
                tc.Test("Hello World!");
            });
        }

        GUILayout.EndArea();

        GUI.color = m_StatusColor;

        GUILayout.BeginArea(new Rect(Screen.width - 255, 205, 240, 600));
        GUILayout.Label(m_StatusString);
        GUILayout.EndArea();
    }
Exemplo n.º 20
0
    /// <summary>
    /// this method is used to set ragdoll physics either on (default)
    /// or off. when toggled, any conflicting components will be either
    /// disabled or enabled
    /// </summary>
    public virtual void SetRagdoll(bool enabled = true)
    {
        // --- postpone ragdolling if necessary ---

        // NOTE: unfortunately, enabling a fast falling ragdoll might provoke a
        // unity culling bug where the mesh goes permanently invisible to other
        // players due to ragdoll falling 'out of bounds'. to prevent this we
        // postpone ragdolling in 0.1 second steps until reliably grounded
        if (vp_Gameplay.IsMultiplayer && enabled)
        {
            // allow ragdolling of dead players only. this cancels any postponed
            // ragdolling when player has come back alive
            if (!Player.Dead.Active)
            {
                return;
            }

            // only allow one 'postponement' at a time
            PostponeTimer.Cancel();

            if (!Animator.GetBool("IsGrounded"))                // fetching grounding from the Animator is more reliable for (lerped) remote players
            {
                //Debug.Log("Not grounded -> POSTPONING ragdolling");
                vp_Timer.In(0.1f, () => SetRagdoll(true), PostponeTimer);
                return;
            }
            //else Debug.Log("Grounded -> RAGDOLLING");
        }

        // --- toggle components that conflict with ragdoll physics ---

        if (Animator != null)
        {
            Animator.enabled = !enabled;
        }
        if (BodyAnimator != null)
        {
            BodyAnimator.enabled = !enabled;
        }
        if (Controller != null)
        {
            Controller.EnableCollider(!enabled);
        }

        // --- disable / enable rigidbodies and colliders ---

        foreach (Rigidbody r in Rigidbodies)
        {
            r.isKinematic = !enabled;
            if (enabled)
            {
                r.AddForce(Player.Velocity.Get() * VelocityMultiplier);                         // pass on momentum of controller into the rigidbodies
            }
        }

        foreach (Collider c in Colliders)
        {
            c.enabled = enabled;
        }

        // if disabling, restore the initial state of all the rigidbodies
        if (!enabled)
        {
            RestoreStartPose();
        }
    }
Exemplo n.º 21
0
 /// <summary>
 /// activates the gameobject containing this vp_Component.
 /// a virtual activation method provided for classes
 /// inheriting vp_Component to add additional activation
 /// routines
 /// </summary>
 public virtual void Activate()
 {
     m_DeactivationTimer.Cancel();
     vp_Utility.Activate(gameObject);
 }
Exemplo n.º 22
0
    /// <summary>
    ///
    /// </summary>
    void DemoPhysics()
    {
        m_Demo.DrawBoxes("part iii: physics", "Ultimate FPS features a cool, tweakable MOTOR and PHYSICS simulation.\nAll motion is forwarded to the camera and weapon for some CRAZY MOVES that you won't see in an everyday FPS. Click these buttons for some quick examples ...", null, ImageRightArrow);
        if (m_Demo.FirstFrame)
        {
            m_Demo.DrawCrosshair = true;
            m_Demo.Teleport(m_SlimePos, m_SlimeAngle);                                                          // place the player at start point
            m_Demo.FirstFrame      = false;
            m_Demo.ButtonSelection = 0;
            m_Demo.Camera.SnapSprings();
            m_Demo.RefreshDefaultState();
            m_Demo.Input.ForceCursor = true;
            m_Demo.Teleport(m_SlimePos, m_SlimeAngle);
            m_Demo.WeaponHandler.SetWeapon(1);
            m_ExamplesCurrentSel = -1;
            m_RunForward         = false;
            m_LookPoint          = 0;
            m_Demo.LockControls();
        }

        // 'go again' button
        if (m_Demo.ShowGUI && !m_GoAgainTimer.Active && m_Demo.ButtonSelection != 3)
        {
            GUI.color            = new Color(1, 1, 1, m_GoAgainButtonAlpha);
            m_GoAgainButtonAlpha = Mathf.Lerp(0, 1, m_GoAgainButtonAlpha + (Time.deltaTime));
            if (GUI.Button(new Rect((Screen.width / 2) - 60, 210, 120, 30), "Go again!"))
            {
                m_GoAgainButtonAlpha = 0.0f;
                m_ExamplesCurrentSel = -1;
            }
            GUI.color = new Color(1, 1, 1, 1 * m_Demo.GlobalAlpha);
        }

        // toggle examples using the buttons
        if (m_Demo.ButtonSelection != m_ExamplesCurrentSel)
        {
            m_WASDInfoClickTime = Time.time;
            m_Demo.Controller.Stop();
            m_Jump               = false;
            m_LookPoint          = 0;
            m_GoAgainButtonAlpha = 0.0f;
            m_ForceTimer.Cancel();
            m_Demo.Controller.Stop();
            m_Demo.PlayerEventHandler.RefreshActivityStates();
            m_Demo.Input.ForceCursor = true;

            // reset some values to default on the controller
            m_Demo.Controller.PhysicsSlopeSlidiness = 0.15f;
            m_Demo.Controller.MotorAirSpeed         = 0.7f;
            m_Demo.Controller.MotorAcceleration     = 0.18f;
            m_Demo.Controller.PhysicsWallBounce     = 0.0f;

            // cancel all example timers
            m_HeadBumpTimer1.Cancel();
            m_HeadBumpTimer2.Cancel();
            m_ActionTimer1.Cancel();
            m_ActionTimer2.Cancel();
            m_ActionTimer3.Cancel();
            m_ActionTimer4.Cancel();
            m_ActionTimer5.Cancel();
            m_GoAgainTimer.Cancel();
            m_ForceTimer.Cancel();

            Screen.lockCursor = true;

            m_Demo.Camera.SnapSprings();

            if (m_Demo.WeaponHandler.CurrentWeapon != null)
            {
                m_Demo.Camera.SnapSprings();
            }

            m_Demo.PlayerEventHandler.Platform.Set(null);

            switch (m_Demo.ButtonSelection)
            {
            case 0:
                vp_Timer.In(29, delegate() { }, m_GoAgainTimer);
                m_Demo.Teleport(m_SlimePos, m_SlimeAngle);
                break;

            case 1:
                vp_Timer.In(5, delegate()
                {
                }, m_GoAgainTimer);
                m_Demo.Teleport(m_WetRoofPos, m_WetRoofAngle);
                m_Demo.Controller.PhysicsSlopeSlidiness = 1.0f;
                break;

            case 2:
                m_Demo.Controller.MotorAirSpeed = 0.0f;
                m_Demo.Teleport(m_ActionPos, m_ActionAngle);
                m_Demo.SnapLookAt(m_LookPoints[1]);
                m_LookPoint  = 1;
                m_RunForward = true;
                vp_Timer.In(1.75f, delegate() { m_LookPoint = 2; m_Jump = true; m_Demo.LookDamping = 1.0f; }, m_ActionTimer1);
                vp_Timer.In(2.25f, delegate() { m_LookPoint = 3; m_Jump = false; m_Demo.LookDamping = 1.0f; }, m_ActionTimer2);
                vp_Timer.In(3.5f, delegate() { m_LookPoint = 4; m_Demo.Controller.MotorAcceleration = 0.0f; m_Demo.LookDamping = 3.0f; }, m_ActionTimer3);
                vp_Timer.In(5.0f, delegate() { m_LookPoint = 5; m_RunForward = false; m_Demo.Controller.MotorAcceleration = 0.18f; m_Demo.LookDamping = 1.0f; }, m_ActionTimer4);
                vp_Timer.In(9.0f, delegate() { m_LookPoint = 8; }, m_ActionTimer5);
                vp_Timer.In(11, delegate() { }, m_GoAgainTimer);
                break;

            case 4:
                m_Demo.Teleport(m_HeadBumpPos, m_HeadBumpAngle);
                vp_Timer.In(1.0f, delegate() { m_Jump = true; }, m_HeadBumpTimer1);
                vp_Timer.In(1.25f, delegate() { m_Jump = false; }, m_HeadBumpTimer2);
                vp_Timer.In(2, delegate() { }, m_GoAgainTimer);
                break;

            case 5:
                m_Demo.Teleport(m_WallBouncePos, m_WallBounceAngle);
                m_LookPoint        = 6;
                m_Demo.LookDamping = 0;
                vp_Timer.In(1, delegate()
                {
                    m_LookPoint        = 7;
                    m_Demo.LookDamping = 3;
                    m_Demo.Controller.PhysicsWallBounce = 0.0f;
                    GameObject.Instantiate(m_ExplosionFX, m_Demo.Controller.transform.position + new Vector3(3, 0, 0), Quaternion.identity);
                    m_Demo.PlayerEventHandler.BombShake.Send(0.3f);
                    m_Demo.Controller.AddForce(Vector3.right * 3.0f);
                    if (m_Demo.WeaponHandler.CurrentWeapon != null)
                    {
                        m_Demo.WeaponHandler.CurrentWeapon.audio.PlayOneShot(m_ExplosionSound);
                    }
                }, m_ForceTimer);
                vp_Timer.In(5, delegate()
                {
                    m_Demo.Controller.PhysicsWallBounce = 0.0f;
                    m_LookPoint        = 6;
                    m_Demo.LookDamping = 0.5f;
                    m_Demo.Teleport(m_WallBouncePos, m_WallBounceAngle);
                }, m_GoAgainTimer);
                break;

            case 6:
                vp_Timer.In(5, delegate() { }, m_GoAgainTimer);
                m_Demo.Teleport(m_FallDeflectPos, m_FallDeflectAngle);
                break;

            case 7:
                vp_Timer.In(7, delegate() { }, m_GoAgainTimer);
                vp_Timer.In(1, delegate()
                {
                    GameObject.Instantiate(m_ExplosionFX, m_Demo.Controller.transform.position + new Vector3(-3, 0, 0), Quaternion.identity);
                    m_Demo.PlayerEventHandler.BombShake.Send(0.5f);
                    m_Demo.Controller.AddForce(Vector3.forward * 0.55f);
                    if (m_Demo.WeaponHandler.CurrentWeapon != null)
                    {
                        m_Demo.WeaponHandler.CurrentWeapon.audio.PlayOneShot(m_ExplosionSound);
                    }
                }, m_ForceTimer);
                m_Demo.Teleport(m_BlownAwayPos, m_BlownAwayAngle);
                break;

            case 3:
                m_Demo.Input.ForceCursor = false;
                m_Demo.WeaponHandler.SetWeapon(2);
                m_Demo.Teleport(m_ExplorePos, m_ExploreAngle);
                m_Demo.Input.AllowGameplayInput = true;
                break;
            }

            m_Demo.LastInputTime = Time.time;
            m_ExamplesCurrentSel = m_Demo.ButtonSelection;
        }

        // some special cases to be run every frame

        if (m_Demo.ButtonSelection != 2 && m_Demo.ButtonSelection != 3)
        {
            m_Demo.LockControls();
            m_Demo.Input.AllowGameplayInput = false;
        }
        else if (m_Demo.ButtonSelection != 3)
        {
            m_Demo.LockControls();
            m_Demo.Input.AllowGameplayInput = false;
        }

        if (m_Demo.ButtonSelection != 3 && m_Demo.WeaponHandler.CurrentWeaponID != 1)
        {
            m_Demo.WeaponHandler.SetWeapon(1);
        }

        switch (m_Demo.ButtonSelection)
        {
        case 0:
            // force this camera angle since it has a tendency to get
            // altered by buffered mouse input during loading
            m_Demo.Camera.Angle = m_SlimeAngle;
            break;

        case 2:
            Vector2 input = m_Demo.PlayerEventHandler.InputMoveVector.Get();
            input.y = m_RunForward ? 1.0f : 0.0f;
            m_Demo.PlayerEventHandler.InputMoveVector.Set(input);
            m_Demo.PlayerEventHandler.Jump.Active = m_Jump;
            if (m_Demo.Controller.StateEnabled("Run") != m_RunForward)
            {
                m_Demo.Controller.SetState("Run", m_RunForward, true);
            }
            m_Demo.SmoothLookAt(m_LookPoints[m_LookPoint]);
            break;

        case 4:
            m_Demo.PlayerEventHandler.Jump.Active = m_Jump;
            break;

        case 5:
            m_Demo.SmoothLookAt(m_LookPoints[m_LookPoint]);
            break;

        case 3:
            // draw menu re-enable text
            if (m_Demo.ShowGUI && Screen.lockCursor)
            {
                GUI.color = new Color(1, 1, 1, ((m_Demo.ClosingDown) ? m_Demo.GlobalAlpha : 1.0f));
                GUI.Label(new Rect((Screen.width / 2) - 200, 140, 400, 20), "(Press ENTER to reenable menu)", m_Demo.CenterStyle);
                GUI.color = new Color(0, 0, 0, 1 * (1.0f - ((Time.time - m_WASDInfoClickTime) * 0.05f)));
                GUI.Label(new Rect((Screen.width / 2) - 200, 170, 400, 20), "(Use WASD to move around freely)", m_Demo.CenterStyle);
                GUI.color = new Color(1, 1, 1, 1 * m_Demo.GlobalAlpha);
            }
            break;
        }

        // show a toggle column, a compound control displaying a
        // column of buttons that can be toggled like radio buttons
        if (m_Demo.ShowGUI)
        {
            m_ExamplesCurrentSel = m_Demo.ButtonSelection;
            string[] strings = new string[] { "Mud... or Slime", "Wet Roof", "Action Hero", "Moving Platforms", "Head Bumps", "Wall Deflection", "Fall Deflection", "Blown Away" }; m_Demo.ButtonSelection = m_Demo.ToggleColumn(140, 150, m_Demo.ButtonSelection, strings, false, true, ImageRightPointer, ImageLeftPointer);
        }
    }
Exemplo n.º 23
0
    /// <summary>
    ///
    /// </summary>
    protected virtual void Climbing()
    {
        // no need to run through here if we aren't climbing
        if (m_Player == null || !m_IsClimbing)
        {
            return;
        }

        // turn physics off
        m_Controller.PhysicsGravityModifier = 0.0f;

        // limit yaw and pitch
        m_Camera.RotationYawLimit   = new Vector2(m_CachedRotation.y - 90, m_CachedRotation.y + 90);
        m_Camera.RotationPitchLimit = new Vector2(90, -90);

        // Store the position so we can alter it towards the climbable
        Vector3 newPosition = GetNewPosition();

        // get our move vector from controls and camera direction
        Vector3 moveVector = Vector3.zero;
        float   pitch      = m_Player.Rotation.Get().x / 90;

        float minimumClimbSpeed = MinimumClimbSpeed / ClimbSpeed;

        if (Mathf.Abs(pitch) < minimumClimbSpeed)
        {
            pitch = pitch > 0 ? minimumClimbSpeed : minimumClimbSpeed * -1;
        }

        if (pitch < 0)
        {
            moveVector = Vector3.up * -pitch;
        }
        else if (pitch > 0)
        {
            moveVector = Vector3.down * pitch;
        }

        float speed         = ClimbSpeed;
        float testDirection = (moveVector * Input.GetAxisRaw("Vertical")).y;

        if (SimpleClimb)
        {
            moveVector    = Vector3.up;
            speed        *= .75f;
            testDirection = Input.GetAxisRaw("Vertical");
        }

        // If we reach the top or bottom of the current climbable, stop climbing
        if ((testDirection > 0 && newPosition.y > GetTopOfCollider(m_Transform) - m_Controller.CharacterController.height * 0.25f) ||
            (testDirection < 0 && m_Controller.Grounded && m_Controller.GroundTransform.GetInstanceID() != m_Transform.GetInstanceID()))
        {
            m_Player.Climb.TryStop();
            return;
        }

        // cancel the climbing sound timer if not moving
        if (Input.GetAxisRaw("Vertical") == 0)
        {
            m_ClimbingSoundTimer.Cancel();
        }

        // play climbing sounds
        if (Input.GetAxisRaw("Vertical") != 0 && !m_ClimbingSoundTimer.Active && Sounds.ClimbingSounds.Count > 0)
        {
            float t = Mathf.Abs((5 / moveVector.y) * (Time.deltaTime * 5) / Sounds.ClimbingSoundSpeed);
            vp_Timer.In(SimpleClimb ? t * 3 : t, delegate() {
                PlaySound(Sounds.ClimbingSounds);
            }, m_ClimbingSoundTimer);
        }

        // Move our player by the climbSpeed
        newPosition += moveVector * speed * Time.deltaTime * Input.GetAxisRaw("Vertical");

        m_Player.Position.Set(Vector3.Slerp(m_Controller.Transform.position, newPosition, Time.deltaTime * speed));
    }
Exemplo n.º 24
0
    /// <summary>
    ///
    /// </summary>
    void Update()
    {
        m_Demo.Update();

        // special case to make sure the weapon doesn't flicker into
        // view briefly in the first frame
        if (m_Demo.CurrentScreen == 1 && m_Demo.WeaponHandler.CurrentWeapon != null)
        {
            m_Demo.WeaponHandler.SetWeapon(0);
        }

        // input special cases for the 'EXAMPLES' screen
        if (m_Demo.CurrentScreen == 2)
        {
            // switch weapon examples using the 1-0 number keys
            if (Input.GetKeyDown(KeyCode.Backspace))
            {
                m_Demo.ButtonSelection = 0;
            }
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                m_Demo.ButtonSelection = 1;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                m_Demo.ButtonSelection = 2;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                m_Demo.ButtonSelection = 3;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                m_Demo.ButtonSelection = 4;
            }
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                m_Demo.ButtonSelection = 5;
            }
            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                m_Demo.ButtonSelection = 6;
            }
            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                m_Demo.ButtonSelection = 7;
            }
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                m_Demo.ButtonSelection = 8;
            }
            if (Input.GetKeyDown(KeyCode.Alpha9))
            {
                m_Demo.ButtonSelection = 9;
            }
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                m_Demo.ButtonSelection = 10;
            }

            // cycle to previous example
            if (Input.GetKeyDown(KeyCode.Q))
            {
                m_Demo.ButtonSelection--;
                if (m_Demo.ButtonSelection < 1)
                {
                    m_Demo.ButtonSelection = 10;
                }
            }

            // cycle to next example
            if (Input.GetKeyDown(KeyCode.E))
            {
                m_Demo.ButtonSelection++;
                if (m_Demo.ButtonSelection > 10)
                {
                    m_Demo.ButtonSelection = 1;
                }
            }
        }

        // special case to cancel the crashing airplane example zoom reset
        // if user navigates away from the 'EXTERNAL FORCES' screen
        if (m_Demo.CurrentScreen != 3 && m_ChrashingAirplaneRestoreTimer.Active)
        {
            m_ChrashingAirplaneRestoreTimer.Cancel();
        }
    }
Exemplo n.º 25
0
    /// <summary>
    /// this method contains all timer example code. NOTE: timer code
    /// does not have to be located in 'OnGUI'. it can exist anywhere
    /// </summary>
    void OnGUI()
    {
        // make the status text fade back to invisible if made yellow
        m_StatusColor = Color.Lerp(m_StatusColor, new Color(1, 1, 0, 0), Time.deltaTime * 0.5f);

        // draw the header text
        GUI.color = Color.white;
        GUILayout.Space(50);
        GUILayout.BeginHorizontal();
        GUILayout.Space(50);
        GUILayout.Label("SCHEDULING EXAMPLE\n    - Each of these examples will schedule some functionality in one (1)\n      second using different options.\n    - Please study the source code in 'Examples/Scheduling/Scheduling.cs' ...");
        GUILayout.EndHorizontal();

        // create an area for all the example buttons
        GUILayout.BeginArea(new Rect(100, 150, 400, 600));
        GUI.color = Color.white;
        GUILayout.Label("Methods, Arguments, Delegates, Iterations, Intervals & Canceling");

        // --- Example 1 ---
        if (DoButton("A simple method"))
        {
            vp_Timer.In(1.0f, DoMethod);
        }

        // --- Example 2 ---
        if (DoButton("A method with a single argument"))
        {
            vp_Timer.In(1.0f, DoMethodWithSingleArgument, 242);
        }

        // --- Example 3 ---
        if (DoButton("A method with multiple arguments"))
        {
            object[] arg = new object[3];
            arg[0] = "December";
            arg[1] = 31;
            arg[2] = 2012;
            vp_Timer.In(1.0f, DoMethodWithMultipleArguments, arg);

            // TIP: you can also create the object array in-line like this:
            //vp_Timer.In(1.0f, DoMethodWithMultipleArguments, new object[] { "December", 31, 2012 });
        }

        // --- Example 4 ---
        if (DoButton("A delegate"))
        {
            vp_Timer.In(1.0f, delegate()
            {
                SmackCube();
            });
        }

        // --- Example 5 ---
        if (DoButton("A delegate with a single argument"))
        {
            vp_Timer.In(1.0f, delegate(object o)
            {
                int i = (int)o;
                SmackCube();
                SetStatus("A delegate with a single argument ... \"" + i + "\"");
            }, 242);
        }

        // --- Example 6 ---
        if (DoButton("A delegate with multiple arguments"))
        {
            vp_Timer.In(1.0f, delegate(object o)
            {
                object[] argument = (object[])o;                                // 'unpack' object into an array
                string month      = (string)argument[0];                        // convert the first argument to a string
                int day           = (int)argument[1];                           // convert the second argument to an integer
                int year          = (int)argument[2];                           // convert the third argument to an integer

                SmackCube();
                SetStatus("A delegate with multiple arguments ... \"" + month + " " + day + ", " + year + "\"");
            }, new object[] { "December", 31, 2012 });
        }

        // --- Example 7 ---
        if (DoButton("5 iterations of a method"))
        {
            vp_Timer.In(1.0f, SmackCube, 5);
        }

        // --- Example 8 ---
        if (DoButton("5 iterations of a method, with 0.2 sec intervals"))
        {
            vp_Timer.In(1.0f, SmackCube, 5, 0.2f);
        }

        // --- Example 9 ---
        if (DoButton("5 iterations of a delegate, canceled after 3 seconds"))
        {
            vp_Timer.Handle timer = new vp_Timer.Handle();
            vp_Timer.In(0.0f, delegate() { SmackCube(); }, 5, 1,
                        timer);
            vp_Timer.In(3, delegate() { timer.Cancel(); });
        }

        GUILayout.Label("\nMethod & object accessibility:");

        // --- Example 10 ---
        if (DoButton("Running a method from a non-monobehaviour class", false))
        {
            vp_Timer.In(1, delegate()
            {
                NonMonoBehaviour test = new NonMonoBehaviour();
                test.Test();
            });
        }

        // --- Example 11 ---
        if (DoButton("Running a method from a specific external gameobject", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = (TestComponent)GameObject.Find("ExternalGameObject").GetComponent("TestComponent");
                tc.Test("Hello World!");
            });
        }

        // --- Example 12 ---
        if (DoButton("Running a method from the first component of a certain type\nin current transform or any of its children", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = transform.root.GetComponentInChildren <TestComponent>();
                tc.Test("Hello World!");
            });
        }

        // --- Example 13 ---
        if (DoButton("Running a method from the first component of a certain type\nin the whole Hierarchy", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = (TestComponent)FindObjectOfType(typeof(TestComponent));
                tc.Test("Hello World!");
            });
        }

        GUILayout.EndArea();

        GUI.color = m_StatusColor;

        GUILayout.BeginArea(new Rect(Screen.width - 255, 205, 240, 600));
        GUILayout.Label(m_StatusString);
        GUILayout.EndArea();
    }
Exemplo n.º 26
0
 /// <summary>
 /// if the AI is told to stop
 /// cancel timers for this class
 /// </summary>
 protected virtual void OnStart_Stop()
 {
     m_ReloadTimer.Cancel();
     m_MeleeAttackTimer.Cancel();
 }