Esempio n. 1
0
 private static List<string> GetFieldsAndProperties(GameObject go, ActionBase comparer, string extendPath, Type[] accepatbleTypes) {
     var propertyResolver = new PropertyResolver {AllowedTypes = accepatbleTypes, ExcludedFieldNames = comparer.GetExcludedFieldNames()};
     var options = propertyResolver.GetFieldsAndPropertiesFromGameObject(go, comparer.GetDepthOfSearch(), extendPath).ToList();
     options.Sort((x, y) => {
         if (char.IsLower(x[0]))
             return -1;
         if (char.IsLower(y[0]))
             return 1;
         return x.CompareTo(y);
     });
     return options;
 }
        protected object GetPropertyValue(GameObject gameObject, string path, Type[] acceptableTypes)
        {
            var objVal = PropertyResolver.GetPropertyValueFromString(gameObject,
                                                                     path);

            if (acceptableTypes != null && !acceptableTypes.Contains(objVal.GetType(), new IsTypeComparer()))
            {
                Debug.LogWarning(gameObject.GetType() + "." + thisPropertyPath + " is not acceptable type for the comparer");
            }

            return(objVal);
        }
        public object GetOtherPropertyValue()
        {
            switch (compareToType)
            {
            case CompareToType.CompareToObject:
                return(PropertyResolver.GetPropertyValueFromString(other,
                                                                   otherPropertyPath));

            case CompareToType.CompareToConstantValue:
                return(ConstValue);

            case CompareToType.CompareToNull:
            default:
                return(null);
            }
        }
Esempio n. 4
0
 private static ErrorType DoesPropertyExist(GameObject go, string propertPath)
 {
     try
     {
         PropertyResolver.GetPropertyValueFromString(go,
                                                     propertPath);
         return(ErrorType.None);
     }
     catch (Exception e)
     {
         if (e.InnerException is MissingComponentException)
         {
             return(ErrorType.MissingComponent);
         }
         return(ErrorType.DoesNotExist);
     }
 }
Esempio n. 5
0
        private static List <string> GetFieldsAndProperties(GameObject go, ActionBase comparer, string extendPath, Type[] accepatbleTypes)
        {
            var propertyResolver = new PropertyResolver {
                AllowedTypes = accepatbleTypes, ExcludedFieldNames = comparer.GetExcludedFieldNames()
            };
            var options = propertyResolver.GetFieldsAndPropertiesFromGameObject(go, comparer.GetDepthOfSearch(), extendPath).ToList();

            options.Sort((x, y) => {
                if (char.IsLower(x[0]))
                {
                    return(-1);
                }
                if (char.IsLower(y[0]))
                {
                    return(1);
                }
                return(x.CompareTo(y));
            });
            return(options);
        }
		private string DrawManualPropertyEditField(GameObject go, string propertPath, Type[] acceptableTypes, DropDownControl<string> dropDown)
		{
			var propertyResolver = new PropertyResolver { AllowedTypes = acceptableTypes };
			IList<string> list;

			var loadProps = new Func<string[]> (() =>
			{
				try
				{
					list = propertyResolver.GetFieldsAndPropertiesUnderPath (go,
																			propertPath);
				}
				catch (ArgumentException)
				{
					list = propertyResolver.GetFieldsAndPropertiesUnderPath (go,
																			"");
				}
				return list.ToArray ();
			});

			EditorGUILayout.BeginHorizontal();

			var labelSize = EditorStyles.label.CalcSize(new GUIContent(go.name + '.'));
			GUILayout.Label (go.name + (propertPath.Length > 0 ? "." : ""), EditorStyles.label, GUILayout.Width (labelSize.x));

			string btnName = "hintBtn";
			if ( GUI.GetNameOfFocusedControl () == btnName
				&& Event.current.type == EventType.KeyDown
				&& Event.current.keyCode == KeyCode.DownArrow)
			{
				Event.current.Use ();
				dropDown.PrintMenu (loadProps ());
				GUI.FocusControl ("");
				focusBackToEdit = true;
			}

			EditorGUI.BeginChangeCheck ();
			GUI.SetNextControlName (btnName);
			var result = GUILayout.TextField(propertPath, EditorStyles.textField);
			if (EditorGUI.EndChangeCheck ())
			{
				errorType = DoesPropertyExist (go, result);
			}

			if (focusBackToEdit)
			{
				focusBackToEdit = false;
				GUI.FocusControl (btnName);
			}

			if (GUILayout.Button ("clear",
								EditorStyles.miniButton,
								GUILayout.Width (38)))
			{
				result = "";
				GUI.FocusControl (null);
				focusBackToEdit = true;
				errorType = DoesPropertyExist (go, result);
			}
			EditorGUILayout.EndHorizontal();
			EditorGUILayout.BeginHorizontal ();
			GUILayout.Label ("", GUILayout.Width (labelSize.x));

			dropDown.Draw("", result ?? "", loadProps, s =>
			{
				result = s;
				GUI.FocusControl (null);
				focusBackToEdit = true;
				errorType = DoesPropertyExist (go, result);
			});
			EditorGUILayout.EndHorizontal();

			if (errorType != ErrorType.None)
			{
				if (errorType == ErrorType.MissingComponent)
					EditorGUILayout.HelpBox ("This property or field is not attached or set. It will fail unless it will be attached before check is perfomed.", MessageType.Warning);
				else if (errorType == ErrorType.DoesNotExist)
					EditorGUILayout.HelpBox ("This property does not exist", MessageType.Error);
			}
			return result;
		}
Esempio n. 7
0
        private string DrawManualPropertyEditField(GameObject go, string propertPath, Type[] acceptableTypes, DropDownControl <string> dropDown)
        {
            var propertyResolver = new PropertyResolver {
                AllowedTypes = acceptableTypes
            };
            IList <string> list;

            var loadProps = new Func <string[]> (() =>
            {
                try
                {
                    list = propertyResolver.GetFieldsAndPropertiesUnderPath(go,
                                                                            propertPath);
                }
                catch (ArgumentException)
                {
                    list = propertyResolver.GetFieldsAndPropertiesUnderPath(go,
                                                                            "");
                }
                return(list.ToArray());
            });

            EditorGUILayout.BeginHorizontal();

            var labelSize = EditorStyles.label.CalcSize(new GUIContent(go.name + '.'));

            GUILayout.Label(go.name + (propertPath.Length > 0 ? "." : ""), EditorStyles.label, GUILayout.Width(labelSize.x));

            string btnName = "hintBtn";

            if (GUI.GetNameOfFocusedControl() == btnName &&
                Event.current.type == EventType.KeyDown &&
                Event.current.keyCode == KeyCode.DownArrow)
            {
                Event.current.Use();
                dropDown.PrintMenu(loadProps());
                GUI.FocusControl("");
                focusBackToEdit = true;
            }

            EditorGUI.BeginChangeCheck();
            GUI.SetNextControlName(btnName);
            var result = GUILayout.TextField(propertPath, EditorStyles.textField);

            if (EditorGUI.EndChangeCheck())
            {
                errorType = DoesPropertyExist(go, result);
            }

            if (focusBackToEdit)
            {
                focusBackToEdit = false;
                GUI.FocusControl(btnName);
            }

            if (GUILayout.Button("clear",
                                 EditorStyles.miniButton,
                                 GUILayout.Width(38)))
            {
                result = "";
                GUI.FocusControl(null);
                focusBackToEdit = true;
                errorType       = DoesPropertyExist(go, result);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(labelSize.x));

            dropDown.Draw("", result ?? "", loadProps, s =>
            {
                result = s;
                GUI.FocusControl(null);
                focusBackToEdit = true;
                errorType       = DoesPropertyExist(go, result);
            });
            EditorGUILayout.EndHorizontal();

            if (errorType != ErrorType.None)
            {
                if (errorType == ErrorType.MissingComponent)
                {
                    EditorGUILayout.HelpBox("This property or field is not attached or set. It will fail unless it will be attached before check is perfomed.", MessageType.Warning);
                }
                else if (errorType == ErrorType.DoesNotExist)
                {
                    EditorGUILayout.HelpBox("This property does not exist", MessageType.Error);
                }
            }
            return(result);
        }
 public object GetPropertyValue()
 {
     return(PropertyResolver.GetPropertyValueFromString(go,
                                                        thisPropertyPath));
 }