private static bool DrawSharedVariable(IVariableSource variableSource, SharedVariable sharedVariable, bool selected)
        {
            if (sharedVariable == null || sharedVariable.GetType().GetProperty("Value") == null)
            {
                return(false);
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            bool result = false;

            if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping))
            {
                if (selected)
                {
                    GUILayout.Label("Property", new GUILayoutOption[0]);
                }
                else
                {
                    GUILayout.Label(sharedVariable.Name, new GUILayoutOption[0]);
                }
                string[] array = sharedVariable.PropertyMapping.Split(new char[]
                {
                    '.'
                });
                GUILayout.Label(array[array.Length - 1].Replace('/', '.'), new GUILayoutOption[0]);
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                FieldInspector.DrawFields(null, sharedVariable, new GUIContent(sharedVariable.Name));
                result = EditorGUI.EndChangeCheck();
            }
            if (!sharedVariable.IsGlobal && GUILayout.Button(BehaviorDesignerUtility.VariableMapButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }))
            {
                VariableInspector.ShowPropertyMappingMenu(variableSource as BehaviorSource, sharedVariable);
            }
            GUILayout.EndHorizontal();
            return(result);
        }
 public static SharedVariable DrawSharedVariable(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, SharedVariable sharedVariable)
 {
     if (!fieldType.Equals(typeof(SharedVariable)) && sharedVariable == null)
     {
         sharedVariable = (Activator.CreateInstance(fieldType, true) as SharedVariable);
         if (TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable.IsShared = true;
         }
         GUI.changed = true;
     }
     if (sharedVariable == null || sharedVariable.IsShared)
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         string[] array           = null;
         int      num             = -1;
         int      num2            = FieldInspector.GetVariablesOfType((sharedVariable == null) ? null : sharedVariable.GetType().GetProperty("Value").PropertyType, sharedVariable != null && sharedVariable.IsGlobal, (sharedVariable == null) ? string.Empty : sharedVariable.Name, FieldInspector.behaviorSource, out array, ref num, fieldType.Equals(typeof(SharedVariable)));
         Color    backgroundColor = GUI.backgroundColor;
         if (num2 == 0 && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             GUI.backgroundColor = Color.red;
         }
         int num3 = num2;
         num2 = EditorGUILayout.Popup(guiContent.text, num2, array, BehaviorDesignerUtility.SharedVariableToolbarPopup, new GUILayoutOption[0]);
         GUI.backgroundColor = backgroundColor;
         if (num2 != num3)
         {
             if (num2 == 0)
             {
                 if (fieldType.Equals(typeof(SharedVariable)))
                 {
                     sharedVariable = null;
                 }
                 else
                 {
                     sharedVariable          = (Activator.CreateInstance(fieldType, true) as SharedVariable);
                     sharedVariable.IsShared = true;
                 }
             }
             else if (num != -1 && num2 >= num)
             {
                 sharedVariable = GlobalVariables.Instance.GetVariable(array[num2].Substring(8, array[num2].Length - 8));
             }
             else
             {
                 sharedVariable = FieldInspector.behaviorSource.GetVariable(array[num2]);
             }
             GUI.changed = true;
         }
         if (!fieldType.Equals(typeof(SharedVariable)) && !TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable = FieldInspector.DrawSharedVariableToggleSharedButton(sharedVariable);
             GUILayout.Space(-3f);
         }
         GUILayout.EndHorizontal();
         GUILayout.Space(3f);
     }
     else
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         ObjectDrawerAttribute[] array2;
         ObjectDrawer            objectDrawer;
         if (fieldInfo != null && (array2 = (fieldInfo.GetCustomAttributes(typeof(ObjectDrawerAttribute), true) as ObjectDrawerAttribute[])).Length > 0 && (objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, array2[0])) != null)
         {
             objectDrawer.Value = sharedVariable;
             objectDrawer.OnGUI(guiContent);
         }
         else
         {
             FieldInspector.DrawFields(task, sharedVariable, guiContent);
         }
         if (!TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable = FieldInspector.DrawSharedVariableToggleSharedButton(sharedVariable);
         }
         GUILayout.EndHorizontal();
     }
     return(sharedVariable);
 }
 public static object DrawFields(Task task, object obj)
 {
     return(FieldInspector.DrawFields(task, obj, null));
 }
        private static object DrawSingleField(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, object value)
        {
            if (fieldType.Equals(typeof(int)))
            {
                return(EditorGUILayout.IntField(guiContent, (int)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(float)))
            {
                return(EditorGUILayout.FloatField(guiContent, (float)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(double)))
            {
                return(EditorGUILayout.FloatField(guiContent, Convert.ToSingle((double)value), new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(long)))
            {
                return((long)EditorGUILayout.IntField(guiContent, Convert.ToInt32((long)value), new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(bool)))
            {
                return(EditorGUILayout.Toggle(guiContent, (bool)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(string)))
            {
                return(EditorGUILayout.TextField(guiContent, (string)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(byte)))
            {
                return(Convert.ToByte(EditorGUILayout.IntField(guiContent, Convert.ToInt32(value), new GUILayoutOption[0])));
            }
            if (fieldType.Equals(typeof(Vector2)))
            {
                return(EditorGUILayout.Vector2Field(guiContent.text, (Vector2)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Vector3)))
            {
                return(EditorGUILayout.Vector3Field(guiContent.text, (Vector3)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Vector4)))
            {
                return(EditorGUILayout.Vector4Field(guiContent.text, (Vector4)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Quaternion)))
            {
                Quaternion quaternion = (Quaternion)value;
                Vector4    value2     = Vector4.zero;
                value2.Set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                value2 = EditorGUILayout.Vector4Field(guiContent.text, value2, new GUILayoutOption[0]);
                quaternion.Set(value2.x, value2.y, value2.z, value2.w);
                return(quaternion);
            }
            if (fieldType.Equals(typeof(Color)))
            {
                return(EditorGUILayout.ColorField(guiContent, (Color)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Rect)))
            {
                return(EditorGUILayout.RectField(guiContent, (Rect)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(Matrix4x4)))
            {
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                if (FieldInspector.DrawFoldout(value.GetHashCode(), guiContent))
                {
                    EditorGUI.indentLevel++;
                    Matrix4x4 matrix4x = (Matrix4x4)value;
                    for (int i = 0; i < 4; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            EditorGUI.BeginChangeCheck();
                            matrix4x[i, j] = EditorGUILayout.FloatField("E" + i.ToString() + j.ToString(), matrix4x[i, j], new GUILayoutOption[0]);
                            if (EditorGUI.EndChangeCheck())
                            {
                                GUI.changed = true;
                            }
                        }
                    }
                    value = matrix4x;
                    EditorGUI.indentLevel--;
                }
                GUILayout.EndVertical();
                return(value);
            }
            if (fieldType.Equals(typeof(AnimationCurve)))
            {
                if (value == null)
                {
                    value = new AnimationCurve();
                }
                return(EditorGUILayout.CurveField(guiContent, (AnimationCurve)value, new GUILayoutOption[0]));
            }
            if (fieldType.Equals(typeof(LayerMask)))
            {
                return(FieldInspector.DrawLayerMask(guiContent, (LayerMask)value));
            }
            if (typeof(SharedVariable).IsAssignableFrom(fieldType))
            {
                return(FieldInspector.DrawSharedVariable(task, guiContent, fieldInfo, fieldType, value as SharedVariable));
            }
            if (typeof(UnityEngine.Object).IsAssignableFrom(fieldType))
            {
                return(EditorGUILayout.ObjectField(guiContent, (UnityEngine.Object)value, fieldType, true, new GUILayoutOption[0]));
            }
            if (fieldType.IsEnum)
            {
                return(EditorGUILayout.EnumPopup(guiContent, (Enum)value, new GUILayoutOption[0]));
            }
            if (!fieldType.IsClass && (!fieldType.IsValueType || fieldType.IsPrimitive))
            {
                EditorGUILayout.LabelField("Unsupported Type: " + fieldType, new GUILayoutOption[0]);
                return(null);
            }
            int hashCode = guiContent.text.GetHashCode();

            if (FieldInspector.drawnObjects.Contains(hashCode))
            {
                return(null);
            }
            FieldInspector.drawnObjects.Add(hashCode);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            if (fieldType.IsAbstract)
            {
                EditorGUILayout.LabelField(guiContent, new GUILayoutOption[0]);
                GUILayout.EndVertical();
                return(null);
            }
            if (value == null)
            {
                if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    fieldType = Nullable.GetUnderlyingType(fieldType);
                }
                value = Activator.CreateInstance(fieldType, true);
            }
            if (FieldInspector.DrawFoldout(value.GetHashCode(), guiContent))
            {
                EditorGUI.indentLevel++;
                value = FieldInspector.DrawFields(task, value);
                EditorGUI.indentLevel--;
            }
            GUILayout.EndVertical();
            FieldInspector.drawnObjects.Remove(hashCode);
            return(value);
        }