Log in or register to post comments

public variable doesn't show in inspector

April 4, 2013 - 12:37am #1

Hi , I'm trying to change my static marker app to a userdefinedMarker app . I have GUIs of my own in the app and I want to only make them enable after the user adds a new target . but I can't control my gameObject which holds my GUIs from "UserDefinedTargetBuilder" game object . and the reason is that when I add a public variable to "UserDefinedTargetEventHandler.cs" the variable doesn't show up in the inspector . is there any limitations for adding new variables to that script ?

I'll appreciate if someone can help me with this .

thanks

public variable doesn't show in inspector

April 11, 2013 - 12:48am #8

Thanks , it's solved . the problem was I was using "target.myObj" instead of "udtehb.myObj" . and I was using GameObject in "UDTEventHandlerEditor.cs" without "using UnityEngine;" 

now I have a field in UserDefinedTargetBuilder to put my gameobject in .

thanks so much

public variable doesn't show in inspector

April 9, 2013 - 8:56pm #7

thanks for your great support . I'm getting five errors as follows : 

- Assets/Editor/QCAR/UserDefinedTargetScripts/UDTEventHandlerEditor.cs(29,87): error CS1061: Type `UnityEngine.Object' does not contain a definition for `myObj' and no extension method `myObj' of type `UnityEngine.Object' could be found (are you missing a using directive or an assembly reference?)

- Assets/Editor/QCAR/UserDefinedTargetScripts/UDTEventHandlerEditor.cs(29,95): error CS0103: The name `GameObject' does not exist in the current context

- Assets/Editor/QCAR/UserDefinedTargetScripts/UDTEventHandlerEditor.cs(29,50): error CS1502: The best overloaded method match for `UnityEditor.EditorGUILayout.ObjectField(string, UnityEngine.Object, System.Type, params UnityEngine.GUILayoutOption[])' has some invalid arguments

- Assets/Editor/QCAR/UserDefinedTargetScripts/UDTEventHandlerEditor.cs(29,50): error CS1503: Argument `#2' cannot convert `object' expression to type `UnityEngine.Object'
 
I'll appreciate if you can help me with this too . 
thanks again for your great support . 
 

public variable doesn't show in inspector

April 9, 2013 - 8:16am #6

Please post the errors that you're seeing.

public variable doesn't show in inspector

April 9, 2013 - 4:07am #5

Thanks so much , It helped a lot , I wasn't familiar with the concept of custome editors . but I couldn't make the code work . according to the links you sent I should create a public variable in the "UserDefinedTargetEventHandler.cs" like this :

public GameObject myObj;

 

and then I should be able to write this line in the "UDTEventHandlerMonitor.cs" :

 

target.myObj= EditorGUILayout.ObjectField("Object myObj", target.myObj , GameObject, allowSceneObjects);
 
but unfortunately I still get errors . 
I'll appreciate if you can help me with this too . 
thanks so much
 

public variable doesn't show in inspector

April 7, 2013 - 10:11am #4

Take a look at how the UserDefinedTargetEventHandler instance is handled below. You'll use a similar approach for GameObjects. Also see ..

http://docs.unity3d.com/Documentation/Components/gui-ExtendingEditor.html

http://docs.unity3d.com/Documentation/ScriptReference/Editor.html

* there are examples of GameObject fields in the second doc.

public variable doesn't show in inspector

April 7, 2013 - 10:01am #3

Thanks so much  , now it works with simple types like int but is there any way to use GameObject type? I want to enable and disable a gameObject in the scene and I need to address that gameObject in the script . 

thanks so much

public variable doesn't show in inspector

April 4, 2013 - 8:55am #2

The UDT event handler component uses a custom inspector that is defined in Editor/QCAR/UserDefinedTargetScripts/UDTEventHandlerEditor.cs. See below for an example of how to extend this Inspector to accept an integer - custom Inspectors are implemented differently from standard Inspector scripts.

 

/*==============================================================================
Copyright (c) 2012 QUALCOMM Austria Research Center GmbH.
All Rights Reserved.
Qualcomm Confidential and Proprietary
==============================================================================*/

using UnityEditor;

/// <summary>
/// This editor class renders the custom inspector for the UserDefinedTargetEventHandler MonoBehaviour
/// </summary>
[CustomEditor(typeof(UserDefinedTargetEventHandler))]
public class UDTEventHandlerEditor : Editor
{
	
    #region UNITY_EDITOR_METHODS

    // Draws a custom UI for the user defined target event handler inspector
    public override void OnInspectorGUI()
    {
        UserDefinedTargetEventHandler udtehb = (UserDefinedTargetEventHandler)target;
	int number = 23;

        EditorGUILayout.HelpBox("Here you can set the ImageTargetBehaviour from the scene that will be used to augment user created targets.", MessageType.Info);
        bool allowSceneObjects = !EditorUtility.IsPersistent(target);
        udtehb.ImageTargetTemplate = (ImageTargetBehaviour)EditorGUILayout.ObjectField("Image Target Template",
                                                    udtehb.ImageTargetTemplate, typeof(ImageTargetBehaviour), allowSceneObjects);
		
	number = EditorGUILayout.IntField("mynumber", number );
    }

    #endregion // UNITY_EDITOR_METHODS
}

 

Log in or register to post comments