コード例 #1
0
    public void Init(Entity player, PlayerController controller, LevelCamera levelCam, FollowTransform followCam, EntityHUD hud, SaverOwner gameSaver, EntityObjectAttacher.Attacher attacher, EntityObjectAttacher.AttachTag attachTag, EntityLocalVarOverrider varOverrider, Vector3 P, Vector3 D)
    {
        this.ent        = player;
        this.controller = controller;
        this.RegEvents(player);
        this.levelCam     = levelCam;
        this.followCam    = followCam;
        this.spawnPos     = P;
        this.roomSpawnPos = P;
        this.spawnDir     = D;
        this.roomSpawnDir = D;
        this.hud          = hud;
        this.gameSaver    = gameSaver;
        this.attacher     = attacher;
        this.attachTag    = attachTag;
        this.varOverrider = varOverrider;
        base.enabled      = false;
        IDataSaver saver = gameSaver.GetSaver("/local/start", true);

        if (saver != null)
        {
            string  a = saver.LoadData("level");
            Vector3 vector;
            Vector3 vector2;
            if (a == Utility.GetCurrentSceneName() && SceneDoor.GetSpawnPoint(saver.LoadData("door"), out vector, out vector2))
            {
                this.spawnPos = vector;
                this.spawnDir = vector2;
            }
        }
    }
コード例 #2
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);
    }