SebLague / Portals

Portals in Unity
https://www.youtube.com/watch?v=cWpFZbjtSQg
MIT License
773 stars 167 forks source link

Mutliple portal pairs simultaneously #19

Open andriypartyshev opened 1 year ago

andriypartyshev commented 1 year ago

Hey! I was wondering how would you go about making it possible for more than one visible pair of portals in the scene? How would you render the view from the other pair of portals? image

A setup sort of like this

MinerMinerMods commented 1 year ago

Well you could go in and specify portal channels by making a portal Array[2] dictionary PortDict. Also if you want to use 2 cameras then you need to specify the exact active camera for checking. Anyways you check for any portal in view(This is in the code) and then get one of the item's channel ID and then find the partner by getting saving our target like this private Portal target = <the checked portal>; and prep the partner like this private Portal partner; and then check and validate that the channel has a length of 2 in its array by running 'if ((PortDict.item(target.channel).length())!=2){return 1;}' if we are still running we can check each item like this if (!(target.equals(PortDict.item(target.channel).item(i)))){partner = PortDict.item(target.channel).item(i);} then we can tell the partner to initialize a camera as its child and move it to the relative position. Deinitalize any cameras of portals where the partner has not been on screen in 40 draws for efficiency

MinerMinerMods commented 1 year ago

This method also allows you to change the portals in real time. However you need to add to portal.cs the function `public int ChangeChannel(int channel){

if (channel == this.channel){ return 2;/No need to change here, Exiting/ } bool valid = false bool fixInvalid = true foreach (var i in PortalDict.item(this.channel)) { if (target.equals(PortDict.item(target.channel).item(i))){ PortDict[i] = nulll; valid = true } index++; } if valid == false{ if (fixInvaild){ foreach(var di in PortalDict.items) foreach(var ii in PortalDict.item(di)) { if (target.equals(PortDict.item(di).item(ii))){ PortDict[ii] = nulll; channel = di valid = true } ii++; }

}else{ return 3; /Invalid data, incorrect channel/ }

} /to add more/ return 0; }`