示例#1
0
    public void DoRespawn()
    {
        this.inForceRespawn = false;
        if (this._doDeathOffset && this.levelRoot != null)
        {
            this.levelRoot.gameObject.SetActive(true);
        }
        ProjectileFactory.Instance.DeactivateAll();
        Vector3 vector = (!this.useRoomSpawn) ? this.spawnPos : this.roomSpawnPos;
        Vector3 dir    = (!this.useRoomSpawn) ? this.spawnDir : this.roomSpawnDir;

        this.ent.RealTransform.position = vector;
        this.ent.Activate();
        this.ent.TurnTo(dir, 0f);
        if (this.varOverrider != null)
        {
            this.varOverrider.Apply(this.ent);
        }
        this.RegEvents(this.ent);
        base.enabled      = false;
        this.roomSpawnPos = vector;
        this.roomSpawnDir = dir;
        this.controller.ControlEntity(this.ent);
        if (this.attachTag != null)
        {
            this.attachTag.Free();
        }
        this.attachTag = null;
        if (this.attacher != null)
        {
            this.attachTag = this.attacher.Attach(this.ent);
        }
        if (this.followCam != null)
        {
            this.followCam.ClearFollowScale();
        }
        LevelRoom roomForPosition = LevelRoom.GetRoomForPosition(vector + Vector3.up * 0.25f, null);

        if (roomForPosition != null)
        {
            roomForPosition.SetImportantPoint(vector);
            LevelRoom.SetCurrentActiveRoom(roomForPosition, true);
            if (this.levelCam != null)
            {
                this.levelCam.SetRoom(roomForPosition);
            }
        }
        if (this.hud != null)
        {
            this.hud.Observe(this.ent, this.controller);
        }
        if (this._fadeIn != null || this._fadeOut != null)
        {
            FadeEffectData data  = this._fadeIn ?? this._fadeOut;
            Vector3        value = new Vector3(0f, 0f, 0f);
            OverlayFader.StartFade(data, false, null, new Vector3?(value));
        }
        EventListener.PlayerSpawn(true);         // Invoke custom event
    }
示例#2
0
    void PlayerDied(Entity player)
    {
        Killable entityComponent = player.GetEntityComponent <Killable>();
        bool     flag            = entityComponent != null && (entityComponent.CurrentHp > 0f || entityComponent.SilentDeath);

        this.mayChangeLevel = !flag;
        this.UnregEvents(player);
        base.enabled = true;
        this.timer   = this._deathTime;
        player.SaveState();
        if (!flag)
        {
            ProjectileFactory.Instance.DeactivateAll();
            if (this._doDeathOffset)
            {
                LevelRoom roomForPosition = LevelRoom.GetRoomForPosition(player.WorldTracePosition, null);
                this.levelCam.ReleaseRoom(this._releaseCamTime);
                player.RealTransform.position = player.WorldPosition + this._deathOffset;
                if (roomForPosition != null)
                {
                    this.levelRoot = roomForPosition.LevelRoot;
                    LevelRoom.SetCurrentActiveRoom(null, false);
                    if (this.levelRoot != null)
                    {
                        this.levelRoot.gameObject.SetActive(false);
                    }
                }
            }
            if (this.backCam != null)
            {
                this.fadeTimer     = this._bgFadeTime;
                this.fadeTimeScale = 1f / this.fadeTimer;
            }
            this.useRoomSpawn = false;
        }
        else
        {
            this.timer        = this._weakDeathTime;
            this.fadeTimer    = 0f;
            this.useRoomSpawn = true;
        }
        if (this.followCam != null)
        {
            this.followCam.SetFollowScale(new Vector3(0.9f, 0.25f, 0.9f));
        }
        this.noFadeOut = false;
        if (entityComponent != null && entityComponent.SilentDeath)
        {
            this.mayChangeLevel = true;
            this.useRoomSpawn   = false;
            this.noFadeOut      = true;
            this.timer          = 0f;
        }
    }
示例#3
0
    void DoSpawn(Vector3 P, Vector3 dir)
    {
        Vector3 vector;

        if (this._spawnOnFloor && PhysicsUtility.GetFloorPoint(P, 20f, 50f, this._floorLayer, out vector))
        {
            P.y = vector.y;
        }
        Vector3    vector2    = P + this._playerEnt.transform.localPosition;
        GameObject gameObject = Object.Instantiate <GameObject>(this._playerCamera, vector2 + this._playerCamera.transform.localPosition, this._playerCamera.transform.localRotation);

        gameObject.transform.localScale = this._playerCamera.transform.localScale;
        gameObject.name = this._playerCamera.name;
        CameraContainer component = gameObject.GetComponent <CameraContainer>();

        component.Init(this._playerCamera);
        Entity entity = Object.Instantiate <Entity>(this._playerEnt, vector2, base.transform.rotation);

        entity.name = this._playerEnt.name;
        if (component != null)
        {
            RoomSwitchable componentInChildren = entity.GetComponentInChildren <RoomSwitchable>();
            if (componentInChildren != null)
            {
                componentInChildren.SetLevelCamera(component);
            }
        }
        if (this._playerGraphics != null)
        {
            GameObject gameObject2 = Object.Instantiate <GameObject>(this._playerGraphics, entity.transform.position + this._playerGraphics.transform.localPosition, this._playerGraphics.transform.localRotation);
            gameObject2.transform.parent     = entity.transform;
            gameObject2.transform.localScale = this._playerGraphics.transform.localScale;
            gameObject2.name = this._playerGraphics.name;
        }
        entity.Init();
        entity.TurnTo(dir, 0f);
        FollowTransform componentInChildren2 = gameObject.GetComponentInChildren <FollowTransform>();

        if (componentInChildren2 != null)
        {
            componentInChildren2.SetTarget(entity.transform);
        }
        LevelCamera componentInChildren3 = gameObject.GetComponentInChildren <LevelCamera>();

        if (componentInChildren3 != null)
        {
            LevelRoom roomForPosition = LevelRoom.GetRoomForPosition(entity.WorldTracePosition, null);
            if (roomForPosition != null)
            {
                componentInChildren3.SetRoom(roomForPosition);
                roomForPosition.SetImportantPoint(vector2);
                LevelRoom.SetCurrentActiveRoom(roomForPosition, false);
            }
        }
        PlayerController controller = ControllerFactory.Instance.GetController <PlayerController>(this._controller);

        controller.ControlEntity(entity);
        controller.name = this._controller.name;
        entity.Activate();
        if (this._varOverrider != null)
        {
            this._varOverrider.Apply(entity);
        }
        EntityHUD componentInChildren4 = gameObject.GetComponentInChildren <EntityHUD>();

        if (componentInChildren4 != null)
        {
            componentInChildren4.Observe(entity, controller);
        }
        EntityObjectAttacher.Attacher attacher   = null;
        EntityObjectAttacher          component2 = base.GetComponent <EntityObjectAttacher>();

        if (component2 != null)
        {
            attacher = component2.GetAttacher();
        }
        EntityObjectAttacher.AttachTag attachTag = null;
        if (attacher != null)
        {
            attachTag = attacher.Attach(entity);
        }
        PlayerRespawner playerRespawner;

        if (this._respawner != null)
        {
            playerRespawner      = Object.Instantiate <PlayerRespawner>(this._respawner);
            playerRespawner.name = this._respawner.name;
        }
        else
        {
            GameObject gameObject3 = new GameObject("PlayerRespawer");
            playerRespawner = gameObject3.AddComponent <PlayerRespawner>();
        }
        playerRespawner.Init(entity, controller, componentInChildren3, componentInChildren2, componentInChildren4, this._gameSaver, attacher, attachTag, this._varOverrider, P, dir);
        VarHelper.PlayerObj = entity.gameObject;         // Store reference to player obj
        PlayerSpawner.OnSpawnedFunc onSpawnedFunc = PlayerSpawner.onSpawned;
        PlayerSpawner.onSpawned = null;
        if (onSpawnedFunc != null)
        {
            onSpawnedFunc(entity, gameObject, controller);
        }
        EventListener.PlayerSpawn(false);         // Invoke custom event
        Object.Destroy(base.gameObject);
    }
 public static LevelRoom GetRoomPlayerIsIn()
 {
     return(LevelRoom.GetRoomForPosition(GameObject.Find("PlayerEnt").transform.position));
 }