Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Daftcube · Apr 28, 2014 at 03:48 AM · guionguiguilayoutrepaint

Work around for, "Getting control 0's position in a group with only 0 controls when doing repaint?" (Trouble Spot Spotted)

So, I left for dinner after I concluded that an error was caused by Unity being drunk (bug in unity,) and then I come back, and I'm satisfied that I am right! Until I hit the play button...

EDIT! I have found out the trouble spot for the error, and it's at the fittingWindow(int id) function. What happens is that if I put a GUI element in this function, the error is spit out. How does one work around this issue?

There are 2 scripts that work together, 1 in a gameobject and a few others as children of that gameobject. (I don't think this matters as it seems a OnGUI() issue rather than a script communication issue.

-This is the fitting script. (As parent)

 public class fittingScript : Photon.MonoBehaviour {
     //Remember to change the unfit id to 20 if exceeding 10 turrets
 
     public bool isEditor = true;
 
     private Vector2 scrollPosition = new Vector2(300,300);
     private Rect fittingServiceRect = new Rect(10,10,Screen.width / 5 - 20, Screen.height/5 - 20);
     private Rect subWindowRect = new Rect(10,Screen.height / 5 * 3 + 10,Screen.width / 5 * 2 - 20, Screen.height/5 * 2 - 20);
     private Rect statsRect = new Rect(Screen.width/5 * 4 - 20, 10, Screen.width/5 - 20, Screen.height/5 * 2 - 20);
 
 
     public hardpointInitialization[] hardpoints; //How we find our hardpoints. Hardpoints must contain this to be recognized.
     private hardpointInitialization selectedPoint; //The currently selected point.
 
     private int currentlySelectedItem = 0;
 
     //Ship Stats For Saving and Fitting
     public string ship = "";
     public float power = 0.0f;
     public float maxPower = 100.0f;
     public float detection = 100.0f;
     public float speed = 0.0f;
     public float maxHp = 0.0f;
 
     // Use this for initialization
     void Start () {
         hardpoints = new hardpointInitialization[GetComponentsInChildren<hardpointInitialization>().Length];
         hardpoints = GetComponentsInChildren<hardpointInitialization>();
         foreach (hardpointInitialization h in hardpoints) {
         }
         Debug.Log(hardpoints);
         if (isEditor) {
             return;
         }
         //Do all the turret instantiation and locking here.
     }
     void Update () {
         foreach(hardpointInitialization hp in hardpoints) {
             power += hp.powerRequirement;
             detection += hp.stealthPenalty;
             speed -= hp.speedPenalty;
         }//
     }
     // Update is called once per frame
     void OnGUI () {
 
         if (isEditor) {
             GUI.Window(0,fittingServiceRect,fittingEditor,"Fitting");
             GUI.Window(2,statsRect,shipInfoWindow,"Ship Stats");
             if (selectedPoint != null) {
                 GUI.Window(1,subWindowRect,selectedGunWindow,"Selected Slot");
             }
 
         }
     }
     //BELOW IS EDITOR FUNCTIONS
     //--------------------------------------------------------------------------------------------------
     void fittingEditor (int id) {
         foreach(hardpointInitialization hp in hardpoints) {
             GUILayout.BeginHorizontal();
             if(GUILayout.Button("|" + hp.itemName + "|")) { //IT HAPPENS RIGHT HERE.
                 selectedPoint = hp; //REMOVE THE IF STATEMENT WITH THE GUI ELEMENT AND THE ERROR GOES AWAY. HOW DO I WORK AROUND THIS?
             }
             GUILayout.EndHorizontal();
         }
     }
     void selectedGunWindow(int id) {
         //The item database is stored here!
 
         if (selectedPoint == null) {
             return;
         }
         GUILayout.BeginHorizontal();
         if (GUILayout.Button("<")) {
             currentlySelectedItem--;
         }
         switch(currentlySelectedItem) {
         case 0:
             GUILayout.Label("X-4 Heavy Railgun Double");
             break;
         case 1:
             GUILayout.Label("X-2 Saron Laser Double");
             break;
         case 2:
             GUILayout.Label("L-32 Flyswatter");
             break;
         }
 
         if (GUILayout.Button(">")) { //Make the item selection go up 
             currentlySelectedItem++;
         }
         GUILayout.EndHorizontal();
         scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Width (Screen.width/5*2),GUILayout.Height(100));
         switch(currentlySelectedItem) {
             case 0:
                 GUILayout.TextArea("This is a heavy railgun double. Nothin special... YET!",GUILayout.Width(Screen.width/5 * 2-40));
                 break;
             case 1:
                 GUILayout.TextArea(" Stuff about this gun",GUILayout.Width(Screen.width/5 * 2-40));
                 break;
             case 2:
                 GUILayout.TextArea(" Stuff about this gun",GUILayout.Width(Screen.width/5 * 2-40));
                 break;
         }
         GUILayout.EndScrollView();
         currentlySelectedItem = Mathf.Clamp(currentlySelectedItem,0,2);
 
         if(GUILayout.Button("Fit")) {
             //TODO add checks for power, calibration etc.
             switch(currentlySelectedItem) {
             case 0:
                 selectedPoint.itemName = "turret_HeavyRailgunDouble";
                 selectedPoint.itemId = 0;
                 //ITEM STATISTICS!
                 //--------------------------------
                 selectedPoint.editorChange ();
                 //TODO edit power and stuff.
                 break;
             case 1:
                 selectedPoint.itemName = "turret_SaronDouble";
                 selectedPoint.itemId = 1;
                 //ITEM STATISTICS!
                 //--------------------------------
                 selectedPoint.editorChange ();
                 break;
             case 2:
                 selectedPoint.itemName = "turret_FlySwatter";
                 selectedPoint.itemId = 2;
                 //ITEM STATISTICS!
                 
                 //--------------------------------
                 selectedPoint.editorChange ();
                 break;
             }
 
         }
 
 
     
     }
     void shipInfoWindow (int id) {
         GUILayout.Label("Ship: " + ship);
         GUILayout.Label("_______________");
         if (power > maxPower) {
             GUI.contentColor = Color.red;
             GUILayout.Label("Power: (" + power.ToString() + " GW/" + maxPower.ToString() + " GW)");
             GUI.contentColor = Color.white;
         }
         else {
             GUILayout.Label("Power: (" + power.ToString() + " GW/" + maxPower.ToString() + " GW)");
         }
         GUILayout.Label("Detection :" + detection.ToString() + " U");
         GUILayout.Label("Speed: " + speed.ToString() + " U/second");
     }
 }
 



This is the hardpointInitialization script. (As child gameObjects.) In this case I tested with three child gameobjects with this script attached to them.

 public class hardpointInitialization : Photon.MonoBehaviour {
     //This class should only be used for turret initialization and storage of data.
     public int hardpointType = 0; //0 = turret, 1 = Utility, 2 = Capital.
     public string itemName = "None"; //This is used for identifying the item the hardpoint has. Will be updated via script.
     public int itemId = 0; //This is the more explicit way of doing things.
     public bool isEnabled = false;
     public GameObject currentTurret = null;
     public GameObject currentTurretInEditor = null;
     public fittingScript editor;
 
     public GameObject[] turretModels;
 
     public float powerRequirement = 0.0f;
     public float speedPenalty = 0.0f;
     public float stealthPenalty = 0.0f;
 
 
 
     void Start () {
         if (!isEnabled) {
             currentTurret = PhotonNetwork.Instantiate(itemName,transform.position,transform.rotation,0);//What this does is that it creates the turret TODO Test it.
             currentTurret.transform.parent = gameObject.transform; //Then locks it in place. This is all according to the fitting menu TODO make it according to fitting menu.
         }
     }
     void Update () {
     
     }
     public void editorChange () {
         if (!isEnabled) {
             return;
         }
         if(currentTurretInEditor != null) {
             GameObject.Destroy(currentTurretInEditor);
             powerRequirement = 0f;
             speedPenalty = 0f;
             stealthPenalty = 0f;
         }
         switch (itemId) {
         case 0:
             currentTurretInEditor = GameObject.Instantiate(turretModels[0],transform.position,transform.rotation) as GameObject; //Heavy Double Railgun
             currentTurretInEditor.transform.parent = gameObject.transform;
             powerRequirement = 30f;
             speedPenalty = 1f;
             break;
         case 1:
             currentTurretInEditor = GameObject.Instantiate(turretModels[1],transform.position,transform.rotation) as GameObject; //Saron Double
             currentTurretInEditor.transform.parent = gameObject.transform;
             powerRequirement = 25f;
             speedPenalty = 1f;
             break;
         case 2:
             currentTurretInEditor = GameObject.Instantiate(turretModels[2],transform.position,transform.rotation) as GameObject; //Flyswatter
             currentTurretInEditor.transform.parent = gameObject.transform;
             powerRequirement = 20f;
             speedPenalty = 0f;
             break;
         case 10:
             Debug.Log("Nothing!");
             break;
         }
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUILayout ArgumentException when combining with GUI.Tooltip 1 Answer

How completly remove GUI.Repaint() calls ? 1 Answer

GUILayout, is there a way to bunch horizontal elements together? 1 Answer

(Solution) - Can't use GUILayout stuff in PropertyDrawer.OnGUI? 2 Answers

How to force Unity to Repaint an EditorWindow? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges