예제 #1
0
 private void Refresh()
 {
     // find SharedVariable Subclasses
     attribNames = SharedDataEditorUtilities.FindSharedVariablesTypes();
     // create editors
     this.FindSharedVariableAndCreateEditor();
 }
        public override void OnGUI(Rect p, SerializedProperty property, GUIContent label)
        {
            SharedVariableAttribute attrib = attribute as SharedVariableAttribute;

            // create object by name
            if (!string.IsNullOrEmpty(attrib.name) &&
                (!property.objectReferenceValue || (property.objectReferenceValue as SharedVariable).name != attrib.name))
            {
                property.objectReferenceValue =
                    SharedDataEditorUtilities.FindOrCreateSharedVariableBySerializedProperty(property, attrib.name);
            }

            // init property
            EditorGUI.BeginChangeCheck();

            // initialize properties
            label = EditorGUI.BeginProperty(p, label, property);

            // has SharedVariable?
            if (property.objectReferenceValue)
            {
                SerializedObject   so   = new SerializedObject(property.objectReferenceValue);
                SerializedProperty prop = so.FindProperty("_value");

                // SharedVariable.value field
                so.Update();
                EditorGUI.PropertyField(
                    new Rect(p.x, p.y, p.width * 0.6f, p.height),
                    prop,
                    label);
                so.ApplyModifiedProperties();

                // SharedVariable field
                EditorGUI.PropertyField(
                    new Rect(p.x + p.width * 0.6f, p.y, p.width * 0.4f, p.height),
                    property,
                    GUIContent.none);
            }
            else
            {
                // Fill SharedVariable... is empty
                EditorGUI.PropertyField(p, property, label);
            }

            // end
            EditorGUI.EndProperty();

            // apply
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }
예제 #3
0
 private void DrawCreate()
 {
     // create new SharedVariable
     EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
     GUILayout.FlexibleSpace();
     attribIndex = EditorGUILayout.Popup(attribIndex, attribNames, EditorStyles.toolbarDropDown);
     if (GUILayout.Button("Add", EditorStyles.toolbarButton, GUILayout.Width(60)))
     {
         SharedDataEditorUtilities.CreateSharedVariable(attribNames [attribIndex]);
         Refresh();
     }
     EditorGUILayout.EndHorizontal();
 }
예제 #4
0
 private void FindSharedVariableAndCreateEditor()
 {
     // fill SharedVariable list
     SharedVariable[] variables = SharedDataEditorUtilities.FindVariables();
     // destroy editors
     for (int i = 0; i < this.editors.Length; i++)
     {
         Object.DestroyImmediate(this.editors [i]);
     }
     // create editors
     this.editors = new Editor[variables.Length];
     for (int i = 0; i < this.editors.Length; i++)
     {
         this.editors [i] = Editor.CreateEditor(variables [i]);
     }
 }