Thanks for the response guys.
Hmm, so in return it’s best practice to not use any access modifiers, unless you really need them, to save code bloat?
I’m afraid that is not a got idea, posting thousands of lines of code, that cross-connect in between multiple scripts. I was asking if maybe the wrong usage of access modifiers, is causing the issue. But I deem not. I’m trying my luck with coroutine and/or lateUpdate now.
But if you really feel like breaking your head, here you go:
void logManager(int windowID)
{
toggleLogArea = GUI.Toggle(new Rect(2, 2.5f, 15, 15), toggleLogArea, string.Empty);
if (toggleLogArea) {
logToSave = logString;
homeToSave = homeString;
constPosXToSave = constPosXFloat;
constPosYToSave = constPosYFloat;
constPosZToSave = constPosZFloat;
if (GUI.Button(new Rect(Screen.width / 2 - 850, 2.5f, 100, 21), "Save Data"))
saveLog();
if (GUI.Button(new Rect(Screen.width / 2 - 750, 2.5f, 100, 21), "Load Data")){
loadConst();
loadLog();
}
logRect.size = new Vector2 (1007, 845);
logLabelString = GUI.TextField (new Rect (18, 2.5f, 85.5f, 21), logLabelString, 15);
if(logString != null){
logString = GUI.TextArea (new Rect (2.5f, 25, 1000.5f, 816.5f), logString, 7000);
} else if(logString != null){
logString = GUI.TextArea (new Rect (2.5f, 25, 1000.5f, 816.5f), "", 7000);
}
} else {
logRect.size = new Vector2 (35, 27);
//GUI.DragWindow(new Rect(15, 0, 92, 27));//dragable window, but removed it for release to prevent bugs
}
}
public static void saveLog()
{
if(toggleHome == true){
homeString = main.homeStar.GetComponent<system> ().name;
}
if(toggleHome == false){
homeString = null;
}
if(toggleHome == true && main.homeStar.GetComponent<system> ().name == "Sol"){
homeString = "Sol";
}
constPosXFloat = constPos.x;
constPosYFloat = constPos.y;
constPosZFloat = constPos.z;
PlayerPrefs.SetString("SavedLog", logString);
PlayerPrefs.SetString("SavedHome", homeString);
PlayerPrefs.SetFloat("ConstPosX", constPosXFloat);
PlayerPrefs.SetFloat("ConstPosY", constPosYFloat);
PlayerPrefs.SetFloat("ConstPosZ", constPosZFloat);
PlayerPrefs.Save();
Log("Data saved!");
}
public static void loadConst()
{
constPosXToSave = PlayerPrefs.GetFloat("ConstPosX");
constPosYToSave = PlayerPrefs.GetFloat("ConstPosY");
constPosZToSave = PlayerPrefs.GetFloat("ConstPosZ");
constPos.x = constPosXFloat;
constPos.y = constPosYFloat;
constPos.z = constPosZFloat;
constPosXFloat = constPosXToSave;
constPosYFloat = constPosYToSave;
constPosZFloat = constPosZToSave;
}
//done the extra loadConst blog, since it would mess up with isnide the original load block
public static void loadLog()
{
SetCursorPos(Screen.width/2, Screen.height/2);
if (PlayerPrefs.HasKey("SavedLog"))
{
logToSave = PlayerPrefs.GetString("SavedLog");
homeToSave = PlayerPrefs.GetString("SavedHome");
logString = logToSave;
GameObject[] star = GameObject.FindGameObjectsWithTag ("star_system");
for (var i = 0; i < star.Length; i ++) {
if(star[i] && homeToSave != null){
if(star[i].name == homeToSave){
homeStar = star[i];
} else if(star[i].name != homeToSave){
return;
}
homeStar.gameObject.GetComponent<system>().select(true);
homeStar.gameObject.GetComponent<system>().select(false);
MouseEvent(main.MouseEventFlags.RightUp | main.MouseEventFlags.RightDown);
system.loadSelection = false;
homeStar.name = homeString;
} else if(!star[i]){
Log ("No Home Star set!");
}
}
homeString = homeToSave;
return;
}
else
Log("There is no log data!");
}
The coordinate problem might happen due to an extremely weird Camera.main setup.
I’m working on an inherited Editor for Stellaris, made with 4.7.1(which I have to stay with, since updating to latest Unity would be a devastating pita). I’m using two cameras, one as top down 2D on a 3D setup -don’t ask me why, the org creator did it for a reason? I don’t know-, and one camera as static background projector for a background sprite. I would utilize code like this, to get correct coordinates for objects placed in the game world:
mousePos.x = Input.mousePosition.x;
mousePos.y = cam.pixelHeight - Input.mousePosition.y; //cam.pixelHeight is used to make mouse position 0,0 at the top left corner
mousePoint = cam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, 460)); //default 3rd variable ---> cam.nearClipPlane; 460 is used for correct coordinates, see upside!
The problem is, it can’t be utilized when trying to save coordinate data from a dragable Texture2d(the one with the messed up coordinate save date), since I would need dynamic position/rotation code, for an object placed in the game world, moved by a mouse pointer which I catch with a Physics.Raycaster, and then needs to be transformed to that weird 2D/3D setup. So while I get the exact raycaster data on the mouse pointer, I can never exactly pinpoint the coordinate data, for a dragged object after repositioning/rerotating it. And yes, I was using euler, delta, event strategys a lot. None of them worked.
I verified I save/load the correct Data via PlayerPrefs, but the Texture2D object will never end up in the position it gets feeded with, unless I didn’t rotated it.
The Camera.main is “sliding” on a CameraAxe, which uses the middle of the game map as anchor point, and it is rotated by x:90, y:180, z:0. It also sits on z:460, hence why you see the number 460 in any of my position definition code.
Ain’t it complicated? Happy new year…