示例#1
0
    public virtual IEnumerator RepulsionFX(GameObject whichCube)
    {
        GameObject fx = Instantiate(GlobalVariables.Instance.repulseFX[playerNumber], whichCube.transform.position, transform.rotation) as GameObject;

        attractionRepulsionFX.Add(fx);
        ParticleSystem ps = fx.GetComponent <ParticleSystem>();

        fx.transform.SetParent(GlobalVariables.Instance.ParticulesClonesParent);

        ps.startSize = 3 + whichCube.transform.lossyScale.x;

        StartCoroutine(SetRepulsionParticles(whichCube, fx, ps));

        MovableScript script = whichCube.GetComponent <MovableScript>();

        yield return(new WaitWhile(() => playerScript.cubesRepulsed.Contains(script)));

        ps.Stop();

        yield return(new WaitWhile(() => ps.IsAlive()));

        attractionRepulsionFX.Remove(fx);

        if (fx.GetComponent <ReplayParticles>() == null)
        {
            Destroy(fx);
        }
        else
        {
            fx.gameObject.SetActive(false);
        }
    }
示例#2
0
    protected virtual void OnTriggerExit(Collider other)
    {
        if (GlobalVariables.Instance.GameState == GameStateEnum.Playing)
        {
            if (other.tag == "Movable" || other.tag == "ThrownMovable" || other.tag == "Suggestible")
            {
                MovableScript movableScript = other.GetComponent <MovableScript>();

                if (movableScript.attracedBy.Contains(player.gameObject))
                {
                    movableScript.attracedBy.Remove(player.gameObject);
                }

                if (movableScript.repulsedBy.Contains(player.gameObject))
                {
                    movableScript.repulsedBy.Remove(player.gameObject);
                }


                if (playerScript.cubesAttracted.Contains(movableScript))
                {
                    playerScript.cubesAttracted.Remove(movableScript);
                }

                if (playerScript.cubesRepulsed.Contains(movableScript))
                {
                    playerScript.cubesRepulsed.Remove(movableScript);
                }
            }
        }
    }
    public override void OnEpisodeBegin()
    {
        _isPrepared = false;
        if (_carryingMovable != null)
        {
            _carryingMovable.Drop();
        }
        _carryingMovable = null;
        if (_fJoint != null)
        {
            Destroy(_fJoint);
        }
        _fJoint = null;
        //fJoint.connectedBody = dummyJoint;

        _rBody.angularVelocity = Vector3.zero;
        _rBody.velocity        = Vector3.zero;

        transform.Rotate(0, Random.value * 360 - 180f, 0);

        int attempts = _config.maxRespawnAttempts;

        while (_config.maxRespawnAttempts == attempts || _spawnHelper.AnyCollisionDetected(transform) && attempts > 0)
        {
            attempts--;
            transform.localPosition = team == Team.Hider
                ? _spawnHelper.GetVectorInsideRoom()
                : _spawnHelper.GetVectorOutsideRoom();
            Physics.SyncTransforms();
        }
        Physics.SyncTransforms();
        _isPrepared = true;
    }
示例#4
0
    public virtual void Shoot()
    {
        holdState   = HoldState.CanHold;
        playerState = PlayerState.None;

        holdMovableTransform.gameObject.tag = "ThrownMovable";

        MovableScript movableScript = holdMovableTransform.gameObject.GetComponent <MovableScript>();

        movableScript.slowMoTrigger.triggerEnabled = true;

        movableScript.hold = false;
        holdMovableTransform.transform.SetParent(null);
        holdMovableTransform.transform.SetParent(movableParent);
        movableScript.playerThatThrew = gameObject;
        movableScript.AddRigidbody();
        holdMovableRB = movableScript.rigidbodyMovable;
        movableScript.OnRelease();


        movableScript.currentVelocity = 250;
        holdMovableRB.AddForce(transform.forward * shootForce, ForceMode.VelocityChange);

        playerRigidbody.AddForce(transform.forward * -holdMovableRB.mass * 5, ForceMode.VelocityChange);

        if (OnShoot != null)
        {
            OnShoot();
        }
    }
示例#5
0
    protected override void OnCollisionEnter(Collision other)
    {
        if (ReplayManager.Instance.isReplaying)
        {
            return;
        }

        if (playerState == PlayerState.Startup)
        {
            return;
        }

        if (other.gameObject.tag == "DeadZone" && gameObject.layer != LayerMask.NameToLayer("Safe"))
        {
            if (playerState != PlayerState.Dead && GlobalVariables.Instance.GameState == GameStateEnum.Playing)
            {
                Death(DeathFX.All, other.contacts[0].point);
            }
        }

        if (other.collider.tag != "HoldMovable" && other.gameObject.tag == "Player")
        {
            PlayersGameplay playerScript = other.gameObject.GetComponent <PlayersGameplay> ();

            if (playerScript.playerState != PlayerState.Stunned && dashState == DashState.Dashing && !playersHit.Contains(other.gameObject))
            {
                playersHit.Add(other.gameObject);
                playerScript.StunVoid(false);
                playerScript.playerThatHit = this;

                GlobalVariables.Instance.screenShakeCamera.CameraShaking(FeedbackType.DashStun);
                GlobalVariables.Instance.zoomCamera.Zoom(FeedbackType.DashStun);
            }
        }

        if (other.collider.tag == "HoldMovable" && dashState == DashState.Dashing)
        {
            other.collider.GetComponent <MovableScript> ().player.GetComponent <PlayersGameplay> ().playerThatHit = this;
            //other.gameObject.GetComponent<PlayersGameplay> ().playerThatHit = this;
        }

        if (other.collider.gameObject.layer == LayerMask.NameToLayer("Movables"))
        {
            MovableScript script = other.collider.gameObject.GetComponent <MovableScript> ();

            if (script != null && script.playerThatThrew != null)
            {
                playerThatHit = script.playerThatThrew.GetComponent <PlayersGameplay> ();
            }
        }

        if (other.collider.gameObject.layer == LayerMask.NameToLayer("Walls"))
        {
            aiAnimator.SetTrigger("touchedWall");
        }
    }
示例#6
0
    IEnumerator SpawnPlayerDeadCube(PlayerName playerName, int controllerNumber, MovableScript script, float scaleDuration = defaultScaleDuration)
    {
        Vector3 newPos     = new Vector3();
        int     randomCube = Random.Range(0, GlobalVariables.Instance.deadCubesPrefabs.Length);
        int     loopCount  = 0;

        if (GlobalVariables.Instance.GameState == GameStateEnum.Playing)
        {
            yield return(new WaitForSeconds(1f));

            do
            {
                loopCount++;
                newPos = new Vector3(Random.Range(xLimits.x, xLimits.y), 1, Random.Range(zLimits.x, zLimits.y));
                yield return(null);
            }while(Physics.CheckSphere(newPos, checkSphereRadius, gameplayLayer) && loopCount < maxWhileLoop);

            newPos.y = cubeYPosition;
            GameObject deadCube = Instantiate(GlobalVariables.Instance.deadCubesPrefabs[randomCube], newPos, GlobalVariables.Instance.deadCubesPrefabs[randomCube].transform.rotation, GameObject.FindGameObjectWithTag("MovableParent").transform) as GameObject;

            deadCube.GetComponent <PlayersDeadCube>().controllerNumber = controllerNumber;
            deadCube.GetComponent <PlayersDeadCube>().playerName       = playerName;

            //
            var clonedScript = CopyComponent(script, deadCube);

            //Physic Material
            if (script.gameObject.GetComponent <Collider>().material != null)
            {
                deadCube.GetComponent <Collider>().material = script.gameObject.GetComponent <Collider>().material;
            }

            clonedScript.Awake();
            clonedScript.Start();
            clonedScript.OnEnable();

            Vector3 scale = deadCube.transform.lossyScale;
            deadCube.transform.localScale = Vector3.zero;

            deadCube.transform.DOScale(scale, scaleDuration).SetEase(Ease.OutElastic).SetUpdate(false);
            StartCoroutine(ChangeMovableTag(deadCube, deadCube.tag, scaleDuration));

            GameObject instantiatedParticles = Instantiate(GlobalVariables.Instance.PlayerSpawnParticles, deadCube.transform.position, GlobalVariables.Instance.PlayerSpawnParticles.transform.rotation) as GameObject;

            instantiatedParticles.transform.SetParent(GlobalVariables.Instance.ParticulesClonesParent);
            instantiatedParticles.GetComponent <ParticleSystemRenderer>().material.color = GlobalVariables.Instance.playersColors[(int)playerName];

            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DynamicCamera>().otherTargetsList.Add(deadCube);

            GlobalVariables.Instance.AllMovables.Add(deadCube);

            MasterAudio.PlaySound3DAtTransformAndForget(SoundsManager.Instance.cubeSpawnSound, deadCube.transform);

            SteamAchievements.Instance.UnlockAchievement(AchievementID.ACH_FIRST_REINCARNATION);
        }
    }
示例#7
0
        IEnumerator Enable()
        {
            yield return(new WaitUntil(() => GetComponent <MovableScript>() != null));

            if (cubeScript == null)
            {
                cubeScript = GetComponent <MovableScript>();
            }

            deadlyData.Add(new DeadlyData(cubeScript.cubeColor == CubeColor.Deadly));
        }
示例#8
0
    public void RemoveCubeAttractionRepulsion(MovableScript script)
    {
        if (cubesAttracted.Contains(script))
        {
            cubesAttracted.Remove(script);
        }

        if (cubesRepulsed.Contains(script))
        {
            cubesRepulsed.Remove(script);
        }
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        rigidBody     = GetComponent <Rigidbody> ();
        movableScript = GetComponent <MovableScript> ();

        movableScript.OnReleaseEvent += () => rigidBody = GetComponent <Rigidbody> ();

        halfScale = transform.lossyScale.x * 0.5f;

        Controller();
        SetReincarnationFX();
        //movableScript.ToColor (playerName);
    }
示例#10
0
    public virtual void OnHoldMovable(GameObject movable, bool forceHold = false)
    {
        if (!forceHold)
        {
            if (playerState == PlayerState.Dead || playerState == PlayerState.Stunned || holdState == HoldState.CannotHold)
            {
                return;
            }
        }

        gettingMovable = true;

        holdState = HoldState.Holding;

        SetMagnetPointPosition(movable);

        MovableScript movableScript = movable.GetComponent <MovableScript>();

        movable.tag          = "HoldMovable";
        movableScript.player = transform;
        movableScript.DestroyRigibody();
        movableScript.OnHold();

        holdMovableTransform = movable.transform;
        holdMovableTransform.SetParent(transform);

        for (int i = 0; i < GlobalVariables.Instance.EnabledPlayersList.Count; i++)
        {
            PlayersGameplay playerScript = GlobalVariables.Instance.EnabledPlayersList[i].GetComponent <PlayersGameplay>();

            if (playerScript.cubesAttracted.Contains(movableScript))
            {
                playerScript.cubesAttracted.Remove(movableScript);
            }

            if (playerScript.cubesRepulsed.Contains(movableScript))
            {
                playerScript.cubesRepulsed.Remove(movableScript);
            }
        }

        cubesAttracted.Clear();
        cubesRepulsed.Clear();

        if (OnHold != null)
        {
            OnHold();
        }

        gettingMovable = false;
    }
示例#11
0
    protected virtual IEnumerator DeathCoroutine()
    {
        playerState = PlayerState.Dead;

        GameAnalytics.NewDesignEvent("Player:" + name + ":" + GlobalVariables.Instance.CurrentModeLoaded.ToString() + ":LifeDuration",
                                     StatsManager.Instance.playersStats[playerName.ToString()].playersStats[WhichStat.LifeDuration.ToString()]);

        GlobalVariables.Instance.screenShakeCamera.CameraShaking(FeedbackType.Death);
        GlobalVariables.Instance.zoomCamera.Zoom(FeedbackType.Death);

        PlayerStats(playerThatHit);

        if (gettingMovable || holdState == HoldState.Holding)
        {
            yield return(new WaitWhile(() => gettingMovable == true));

            MovableScript movableScript = holdMovableTransform.gameObject.GetComponent <MovableScript>();

            movableScript.hold       = false;
            holdMovableTransform.tag = "Movable";
            holdMovableTransform.SetParent(null);
            holdMovableTransform.SetParent(movableParent);

            if (movableScript.rigidbodyMovable == null)
            {
                movableScript.AddRigidbody();
            }

            movableScript.OnRelease();
        }

        holdState = HoldState.CannotHold;

        gameObject.SetActive(false);

        RemoveFromAIObjectives();

        if (GlobalVariables.Instance != null)
        {
            GlobalVariables.Instance.ListPlayers();
        }

        GlobalVariables.Instance.lastManManager.PlayerDeath(playerName, gameObject);

        if (OnDeath != null)
        {
            OnDeath();
        }
    }
示例#12
0
    protected virtual void Repulse(Collider other)
    {
        MovableScript movableScript = other.GetComponent <MovableScript>();

        if (!movableScript.repulsedBy.Contains(player.gameObject))
        {
            movableScript.repulsedBy.Add(player.gameObject);
        }

        if (!playerScript.cubesRepulsed.Contains(movableScript))
        {
            playerScript.cubesRepulsed.Add(movableScript);
            StartCoroutine(fxAnimationsScript.RepulsionFX(other.gameObject));
        }
    }
示例#13
0
        protected override void Start()
        {
            base.Start();

            cubeScript = GetComponent <MovableScript>();

            cubeMaterial = transform.GetChild(1).GetComponent <Renderer>().material;

            bombManager = FindObjectOfType <BombManager>();

            if (bombManager != null)
            {
                text = GetComponentInChildren <Text>();
            }

            cubeScript.OnNeutral += () => deadlyData.Add(new DeadlyData(false));
            cubeScript.OnDeadly  += () => deadlyData.Add(new DeadlyData(true));
        }
示例#14
0
    protected virtual void OnCollisionEnter(Collision other)
    {
        if (ReplayManager.Instance.isReplaying)
        {
            return;
        }

        if (playerState == PlayerState.Startup || rewiredPlayer == null)
        {
            return;
        }

        if (other.collider.tag != "HoldMovable" && other.gameObject.tag == "Player")
        {
            PlayersGameplay playerScript = other.gameObject.GetComponent <PlayersGameplay>();

            if (playerScript.playerState != PlayerState.Stunned && dashState == DashState.Dashing && !playersHit.Contains(other.gameObject))
            {
                playersHit.Add(other.gameObject);
                playerScript.StunVoid(false);
                playerScript.playerThatHit = this;

                GlobalVariables.Instance.screenShakeCamera.CameraShaking(FeedbackType.DashStun);
                GlobalVariables.Instance.zoomCamera.Zoom(FeedbackType.DashStun);
            }
        }

        if (other.collider.tag == "HoldMovable" && dashState == DashState.Dashing)
        {
            other.collider.GetComponent <MovableScript>().player.GetComponent <PlayersGameplay>().playerThatHit = this;
//			other.gameObject.GetComponent<PlayersGameplay> ().playerThatHit = this;
        }

        if (other.collider.gameObject.layer == LayerMask.NameToLayer("Movables"))
        {
            MovableScript script = other.collider.gameObject.GetComponent <MovableScript>();

            if (script != null && script.playerThatThrew != null)
            {
                playerThatHit = script.playerThatThrew.GetComponent <PlayersGameplay>();
            }
        }
    }
示例#15
0
    public virtual void Repulsion(MovableScript movable)
    {
        if (movable.tag == "HoldMovable" || movable.rigidbodyMovable == null)
        {
            Debug.Log("Here");
            cubesAttracted.Remove(movable);
        }

        playerState = PlayerState.Repulsing;

        Vector3 movableRepulsion = movable.transform.position - transform.position;

        movableRepulsion.Normalize();
        movable.rigidbodyMovable.AddForce(movableRepulsion * repulsionForce * 10, ForceMode.Force);

        if (OnRepulsing != null)
        {
            OnRepulsing();
        }
    }
示例#16
0
    public virtual void Attraction(MovableScript movable)
    {
        if (movable.tag == "HoldMovable" || movable.rigidbodyMovable == null)
        {
            cubesAttracted.Remove(movable);
        }

        playerState = PlayerState.Attracting;

        Vector3 movableAttraction = transform.position - movable.transform.position;

        movableAttraction.Normalize();

        if (movable.rigidbodyMovable != null)
        {
            movable.rigidbodyMovable.AddForce(movableAttraction * attractionForce * 10, ForceMode.Force);
        }

        if (OnAttracting != null)
        {
            OnAttracting();
        }
    }
示例#17
0
 void Start()
 {
     slowMotionCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <SlowMotionCamera>();
     movableScript    = transform.parent.GetComponent <MovableScript> ();
 }
    public override void OnActionReceived(ActionBuffers actions)
    {
        if (team == Team.Seeker && StepCount <= _config.preparingPhaseLength)
        {
            return;
        }

        Vector3 controlSignal = Vector3.zero;

        controlSignal.x = actions.ContinuousActions[0];
        controlSignal.z = actions.ContinuousActions[1];

        _rBody.AddForce(controlSignal * _config.agentsForceMultiplier);
        _rBody.AddTorque(transform.up * _config.agentsRotationMultiplier * actions.ContinuousActions[2]);

        Vector3 lPos = transform.localPosition;

        if (lPos.x < -10.0 || lPos.x > 10.0 || lPos.z < -10.0 || lPos.z > 10.0)
        {
            AddReward(_config.penaltyForLeaving * _config.rewardScale);
        }

        /* Discrete actions mapping:
         *   0 -- no action
         *   1 -- drop box
         *   2 -- grab box
         *   3 -- unlock box
         *   4 -- lock box
         */
        int action = actions.DiscreteActions[0];

        if (_carryingMovable != null && action == 1)
        {
            _carryingMovable.Drop();
            _carryingMovable = null;
            Destroy(_fJoint);
            _fJoint = null;
        }
        else if (_carryingMovable == null)
        {
            GameObject nearestCube   = null;
            float      minDistToCube = Single.MaxValue;

            foreach (GameObject obj in _viewField.collectVisibleObjects())
            {
                if (!obj.CompareTag(cubeTag) && !obj.CompareTag(rampTag))
                {
                    continue;
                }

                float dist = Vector3.Distance(transform.localPosition, obj.transform.localPosition);
                if (dist < minDistToCube)
                {
                    nearestCube   = obj;
                    minDistToCube = dist;
                }
            }

            // Check if agent see box nearby
            if (nearestCube == null || _config.maxDistToInteractWithBox < minDistToCube)
            {
                return;
            }

            MovableScript movableScript = nearestCube.GetComponent <MovableScript>();

            switch (action)
            {
            case 2:
            {
                if (!movableScript.Grab(_rBody))
                {
                    return;
                }
                _carryingMovable      = movableScript;
                _fJoint               = gameObject.AddComponent <FixedJoint>();
                _fJoint.connectedBody = nearestCube.GetComponent <Rigidbody>();
                break;
            }

            case 3:
            {
                movableScript.Unlock(team);
                break;
            }

            case 4:
            {
                movableScript.Lock(team);
                break;
            }

            default:
                return;
            }
        }
    }
示例#19
0
 public void SpawnPlayerDeadCubeVoid(PlayerName playerName, int controllerNumber, MovableScript script, float scaleDuration = defaultScaleDuration)
 {
     StartCoroutine(SpawnPlayerDeadCube(playerName, controllerNumber, script, scaleDuration));
 }