Jump to content

Handling Views


iamchairs

Recommended Posts

I made a thread a few days ago about possibly using html for views. That's not possible so I'm going to give the legacy gui a shot but I'm having trouble structuring.

I have a View class with a `paint` method. I'll create subclasses for the views I need and modify `paint`. To actually call paint I need an OnGUI method to call them. So in one class I'm calling the ViewManager you can register your view and in the OnGUI loop it calls paint on each view that should be painting. Here is my ViewManager class-

[FONT=Menlo]
[/FONT]using System;
using System.Collections;
using UnityEngine;


namespace StateFunding {
[KSPAddon (KSPAddon.Startup.MainMenu, false)]
public class ViewManager: MonoBehaviour {


public View[] views = new View[0];


public void addView(View V) {
View[] newViews = new View[views.Length+1];
for(int i = 0; i < views.Length; i++) {
newViews[i] = views[i];
}
newViews[newViews.Length-1] = V;


views = newViews;
}


public void OnGUI() {
Debug.Log ("guiiii");
for (var i = 0; i < views.Length; i++) {
Debug.Log ("In a looooop");
View V = views [i];
if (V.isPainting ()) {
V.paint ();
}
}
}


}
}

The log shows "guiiii" and "In a loooop" being repeated up until I enter a game. I'm guessing the ViewManager object is unregistered during that transition. How do I keep this alive? I just want to have the ViewManager running all the time and I can register/unregister views from it when needed.

- - - Updated - - -

Whats up with the whitespace :\

- - - Updated - - -

Fixed

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...