x


Avoid Base Values being public via Custom Inspector

Hi guys,

First: Sorry for my bad english ^.^

I am editing the base values for my Player's hitpoints via the Standard Inspector. But by doing this, I have a lot of public values that i do NOT want to have public!

They are not going to be modified in any situation. So I want them to have the innermost scope they could have. Best would be private/const/readonly etc.

Is there any way to edit private values via a Custom Inspector, because I really dont want them to be modify-able.

I hope you all understood me :)

greetz

more ▼

asked Jul 19 '12 at 10:03 AM

lenny.myr gravatar image

lenny.myr
7 1 3 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Yes if you write a custom inspector and make some function or property to set those values you would be able to have them as private (but not const or readonly) - but that function will still exist so they could be set by it when called by another piece of the code.

more ▼

answered Jul 19 '12 at 10:46 AM

whydoidoit gravatar image

whydoidoit
33k 11 23 100

Thanks for your answer.

I tried this:

`using UnityEditor; using UnityEngine; using System.Collections;

[CustomEditor(typeof(Mob))] public class MobInspector : Editor { void OnInspectorGUI() { GUILayout.Label("This is a Label in a Custom Editor"); } }`

but it does not seem to work. I don't see any label, when I inspect my Mob Script that is attached to a gameobject.

Can you give me a short introduction maybe?

Jul 19 '12 at 02:14 PM lenny.myr

You need public override void OnInspectorGUI()

Jul 19 '12 at 02:27 PM whydoidoit

That's what I messed up :D

Jul 20 '12 at 01:56 PM lenny.myr
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x466
x199
x21

asked: Jul 19 '12 at 10:03 AM

Seen: 269 times

Last Updated: Jul 20 '12 at 01:56 PM