private void DrawValueFieldInPropertyMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper)
        {
            _selectComponentDrawer.AllowNonComponents = true;
            _selectComponentDrawer.RestrictionType    = null;
            _selectComponentDrawer.ShowXButton        = false;
            var targProp   = property.FindPropertyRelative(PROP_OBJREF);
            var memberProp = property.FindPropertyRelative(PROP_STRING);
            var vtypeProp  = property.FindPropertyRelative(PROP_TYPE);

            if (targProp.objectReferenceValue == null)
            {
                _selectComponentDrawer.OnGUI(position, targProp);
            }
            else
            {
                var r1 = new Rect(position.xMin, position.yMin, position.width * 0.4f, position.height);
                var r2 = new Rect(r1.xMax, position.yMin, position.width - r1.width, position.height);
                _selectComponentDrawer.OnGUI(r1, targProp);

                System.Reflection.MemberInfo selectedMember;
                EditorGUI.BeginChangeCheck();
                memberProp.stringValue = SPEditorGUI.ReflectedPropertyField(r2, targProp.objectReferenceValue, memberProp.stringValue, com.spacepuppy.Dynamic.DynamicMemberAccess.Read, out selectedMember);
                if (EditorGUI.EndChangeCheck())
                {
                    vtypeProp.SetEnumValue <VariantType>(selectedMember != null ? VariantReference.GetVariantType(DynamicUtil.GetReturnType(selectedMember)) : VariantType.Null);
                }
            }
        }
        public void TweenTo(com.spacepuppy.Tween.TweenHash hash, com.spacepuppy.Tween.Ease ease, float dur)
        {
            var e = _table.GetEnumerator();

            while (e.MoveNext())
            {
                var value = e.Current.Value.Value;
                if (value == null)
                {
                    continue;
                }

                switch (VariantReference.GetVariantType(value.GetType()))
                {
                case VariantType.Integer:
                case VariantType.Float:
                case VariantType.Double:
                case VariantType.Vector2:
                case VariantType.Vector3:
                case VariantType.Vector4:
                case VariantType.Quaternion:
                case VariantType.Color:
                case VariantType.Rect:
                    hash.To(e.Current.Key, ease, value, dur);
                    break;
                }
            }
        }
Пример #3
0
        private void _lst_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            if (_currentValuesProp.arraySize <= index)
            {
                _currentValuesProp.arraySize = index + 1;
            }
            var keyProp     = _currentKeysProp.GetArrayElementAtIndex(index);
            var variantProp = _currentValuesProp.GetArrayElementAtIndex(index);

            var w = area.width / 3f;

            if (_propertyListTargetType != null)
            {
                var nameRect = new Rect(area.xMin, area.yMin, w, EditorGUIUtility.singleLineHeight);
                EditorGUI.BeginChangeCheck();
                int i = EditorGUI.Popup(nameRect, _propertyListNames.IndexOf(keyProp.stringValue), _propertyListNames);
                if (EditorGUI.EndChangeCheck() && i >= 0 && !NameIsInUse(_currentKeysProp, _propertyListNames[i]))
                {
                    keyProp.stringValue = _propertyListNames[i];
                }

                var variantRect = new Rect(nameRect.xMax + 1f, area.yMin, area.width - (nameRect.width + 1f), area.height);
                if (i >= 0)
                {
                    var propType = com.spacepuppy.Dynamic.DynamicUtil.GetReturnType(_propertyListMembers[i]);
                    var argType  = VariantReference.GetVariantType(propType);
                    _variantDrawer.RestrictVariantType     = true;
                    _variantDrawer.VariantTypeRestrictedTo = argType;
                    _variantDrawer.ForcedObjectType        = propType;
                    _variantDrawer.DrawValueField(variantRect, variantProp);
                }
                else
                {
                    EditorGUI.LabelField(variantRect, "Select Property");
                }
            }
            else
            {
                var nameRect = new Rect(area.xMin, area.yMin, w, EditorGUIUtility.singleLineHeight);
                keyProp.stringValue = EditorGUI.TextField(nameRect, keyProp.stringValue);

                var variantRect = new Rect(nameRect.xMax + 1f, area.yMin, area.width - (nameRect.width + 1f), area.height);
                _variantDrawer.DrawValueField(variantRect, variantProp);
            }
        }
Пример #4
0
 private void DrawVariant(Rect position, GUIContent label, System.Type propType, SerializedProperty valueProp)
 {
     if (propType == typeof(object))
     {
         //draw the default variant as the method accepts anything
         _variantDrawer.RestrictVariantType = false;
         _variantDrawer.ForcedObjectType    = null;
         _variantDrawer.OnGUI(position, valueProp, label);
     }
     else
     {
         var argType = VariantReference.GetVariantType(propType);
         _variantDrawer.RestrictVariantType     = true;
         _variantDrawer.VariantTypeRestrictedTo = argType;
         _variantDrawer.ForcedObjectType        = (TypeUtil.IsType(propType, typeof(Component))) ? propType : null;
         _variantDrawer.OnGUI(position, valueProp, label);
     }
 }
Пример #5
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept("_target", "_memberName", "_value", "_mode");
            this.DrawPropertyField("_target"); //uses the SelectableComponent PropertyDrawer

            var targProp   = this.serializedObject.FindProperty("_target");
            var memberProp = this.serializedObject.FindProperty("_memberName");
            var valueProp  = this.serializedObject.FindProperty("_value");
            var modeProp   = this.serializedObject.FindProperty("_mode");

            //SELECT MEMBER
            System.Reflection.MemberInfo selectedMember;
            memberProp.stringValue = SPEditorGUILayout.ReflectedRecursingPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                       targProp.objectReferenceValue,
                                                                                       memberProp.stringValue,
                                                                                       com.spacepuppy.Dynamic.DynamicMemberAccess.ReadWrite,
                                                                                       out selectedMember);
            this.serializedObject.ApplyModifiedProperties();


            //MEMBER VALUE TO SET TO
            if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetInputType(selectedMember);
                var emode    = modeProp.GetEnumValue <i_SetValue.SetMode>();
                if (emode == i_SetValue.SetMode.Toggle)
                {
                    //EditorGUILayout.LabelField(EditorHelper.TempContent(valueProp.displayName), EditorHelper.TempContent(propType.Name));
                    var evtp  = VariantReference.GetVariantType(propType);
                    var cache = SPGUI.Disable();
                    EditorGUILayout.EnumPopup(EditorHelper.TempContent(valueProp.displayName), evtp);
                    cache.Reset();
                }
                else
                {
                    if (DynamicUtil.TypeIsVariantSupported(propType))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        var label = EditorHelper.TempContent("Value", "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                    else
                    {
                        _variantDrawer.RestrictVariantType = true;
                        _variantDrawer.TypeRestrictedTo    = propType;
                        _variantDrawer.ForcedObjectType    = (TypeUtil.IsType(propType, typeof(UnityEngine.Object))) ? propType : null;
                        var label = EditorHelper.TempContent("Value", "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                }

                if (com.spacepuppy.Dynamic.Evaluator.WillArithmeticallyCompute(propType))
                {
                    EditorGUILayout.PropertyField(modeProp);
                }
                else
                {
                    //modeProp.SetEnumValue(i_SetValue.SetMode.Set);
                    EditorGUI.BeginChangeCheck();
                    emode = (i_SetValue.SetMode)SPEditorGUILayout.EnumPopupExcluding(EditorHelper.TempContent(modeProp.displayName), emode, i_SetValue.SetMode.Decrement, i_SetValue.SetMode.Increment);
                    if (EditorGUI.EndChangeCheck())
                    {
                        modeProp.SetEnumValue(emode);
                    }
                }
            }
            else
            {
                modeProp.SetEnumValue(i_SetValue.SetMode.Set);
            }

            this.serializedObject.ApplyModifiedProperties();
        }
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept("_target", "_restrictedType", "_memberName", "_values", "_mode");
            this.DrawPropertyField("_target"); //uses the SelectableComponent PropertyDrawer
            this.DrawPropertyField("_restrictedType");
            this.serializedObject.ApplyModifiedProperties();

            var targProp         = this.serializedObject.FindProperty("_target");
            var restrictTypeProp = this.serializedObject.FindProperty("_restrictedType");
            var memberProp       = this.serializedObject.FindProperty("_memberName");
            var valuesArrProp    = this.serializedObject.FindProperty("_values");
            var modeProp         = this.serializedObject.FindProperty("_mode");

            var targetRef = EditorHelper.GetTargetObjectOfProperty(targProp) as TriggerableTargetObject;

            if (targetRef == null)
            {
                return;
            }

            //SELECT MEMBER
            System.Reflection.MemberInfo selectedMember = null;
            var restrictType = TypeReferencePropertyDrawer.GetTypeFromTypeReference(restrictTypeProp);

            if (restrictType == null && !targetRef.TargetsTriggerArg && targetRef.Target != null &&
                targetRef.Find == TriggerableTargetObject.FindCommand.Direct && targetRef.ResolveBy != TriggerableTargetObject.ResolveByCommand.WithType &&
                targetRef.Target.GetType() != restrictType)
            {
                memberProp.stringValue = SPEditorGUILayout.ReflectedPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                  targetRef.Target,
                                                                                  memberProp.stringValue,
                                                                                  com.spacepuppy.Dynamic.DynamicMemberAccess.ReadWrite,
                                                                                  out selectedMember,
                                                                                  true);
            }
            else
            {
                if (restrictType == null)
                {
                    if (targetRef.ResolveBy == TriggerableTargetObject.ResolveByCommand.WithType)
                    {
                        restrictType = TypeUtil.FindType(targetRef.ResolveByQuery);
                    }
                    if (restrictType == null)
                    {
                        restrictType = typeof(object);
                    }
                    else
                    {
                        TypeReferencePropertyDrawer.SetTypeToTypeReference(restrictTypeProp, restrictType);
                    }
                }
                memberProp.stringValue = SPEditorGUILayout.ReflectedPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                  restrictType,
                                                                                  memberProp.stringValue,
                                                                                  out selectedMember,
                                                                                  true);
            }
            this.serializedObject.ApplyModifiedProperties();


            //MEMBER VALUE TO SET TO
            if (selectedMember != null && selectedMember.MemberType == System.Reflection.MemberTypes.Method)
            {
                var methodInfo = selectedMember as System.Reflection.MethodInfo;
                if (methodInfo == null)
                {
                    return;
                }

                var parameters = methodInfo.GetParameters();
                valuesArrProp.arraySize = parameters.Length;

                for (int i = 0; i < parameters.Length; i++)
                {
                    var p         = parameters[i];
                    var valueProp = valuesArrProp.GetArrayElementAtIndex(i);
                    var propType  = p.ParameterType;

                    if (DynamicUtil.TypeIsVariantSupported(propType))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        var label = EditorHelper.TempContent("Parameter " + i.ToString(), "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                    else
                    {
                        _variantDrawer.RestrictVariantType = true;
                        _variantDrawer.TypeRestrictedTo    = propType;
                        _variantDrawer.ForcedObjectType    = (TypeUtil.IsType(propType, typeof(UnityEngine.Object))) ? propType : null;
                        var label = EditorHelper.TempContent("Parameter " + i.ToString(), "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                }

                modeProp.SetEnumValue(i_SetValueOnTarget.SetMode.Set);
            }
            else if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetInputType(selectedMember);
                var emode    = modeProp.GetEnumValue <i_SetValueOnTarget.SetMode>();
                if (emode == i_SetValueOnTarget.SetMode.Toggle)
                {
                    //EditorGUILayout.LabelField(EditorHelper.TempContent(valueProp.displayName), EditorHelper.TempContent(propType.Name));
                    valuesArrProp.arraySize = 0;
                    var evtp  = VariantReference.GetVariantType(propType);
                    var cache = SPGUI.Disable();
                    EditorGUILayout.EnumPopup(EditorHelper.TempContent("Value"), evtp);
                    cache.Reset();
                }
                else
                {
                    valuesArrProp.arraySize = 1;
                    var valueProp = valuesArrProp.GetArrayElementAtIndex(0);
                    if (DynamicUtil.TypeIsVariantSupported(propType))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        var label = EditorHelper.TempContent("Value", "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                    else
                    {
                        _variantDrawer.RestrictVariantType = true;
                        _variantDrawer.TypeRestrictedTo    = propType;
                        _variantDrawer.ForcedObjectType    = (TypeUtil.IsType(propType, typeof(UnityEngine.Object))) ? propType : null;
                        var label = EditorHelper.TempContent("Value", "The value to set to.");
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(true, _variantDrawer.GetPropertyHeight(valueProp, label)), valueProp, label);
                    }
                }

                if (com.spacepuppy.Dynamic.Evaluator.WillArithmeticallyCompute(propType))
                {
                    EditorGUILayout.PropertyField(modeProp);
                }
                else
                {
                    //modeProp.SetEnumValue(i_SetValueOnTarget.SetMode.Set);
                    EditorGUI.BeginChangeCheck();
                    emode = (i_SetValueOnTarget.SetMode)SPEditorGUILayout.EnumPopupExcluding(EditorHelper.TempContent(modeProp.displayName), emode, i_SetValueOnTarget.SetMode.Decrement, i_SetValueOnTarget.SetMode.Increment);
                    if (EditorGUI.EndChangeCheck())
                    {
                        modeProp.SetEnumValue(emode);
                    }
                }
            }
            else
            {
                modeProp.SetEnumValue(i_SetValueOnTarget.SetMode.Set);
            }

            this.serializedObject.ApplyModifiedProperties();
        }
Пример #7
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var r0 = new Rect(position.xMin, position.yMin, position.width / 2f, position.height);
            var r1 = new Rect(r0.xMax, position.yMin, position.width - r0.width, position.height);

            var propName  = property.FindPropertyRelative(PROP_NAME);
            var propValue = property.FindPropertyRelative(PROP_VALUE);
            var propRef   = property.FindPropertyRelative(PROP_REF);

            int index = System.Array.IndexOf(_knownPlayerSettingPropNames, propName.stringValue);

            EditorGUI.BeginChangeCheck();
            index = EditorGUI.Popup(r0, GUIContent.none, index, _knownPlayerSettingPropNamesPretty);
            if (EditorGUI.EndChangeCheck())
            {
                if (index >= 0 && index < _knownPlayerSettingPropNames.Length)
                {
                    propName.stringValue = _knownPlayerSettingPropNames[index];
                }
                else
                {
                    propName.stringValue = string.Empty;
                }

                propValue.stringValue        = string.Empty;
                propRef.objectReferenceValue = null;
            }

            if (index < 0 || index >= _knownPlayerSettings.Length)
            {
                return;
            }

            var info = _knownPlayerSettings[index];

            if (info.PropertyType.IsEnum)
            {
                int ei = ConvertUtil.ToInt(propValue.stringValue);
                propValue.stringValue        = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(info.PropertyType, ei))).ToString();
                propRef.objectReferenceValue = null;
            }
            else
            {
                var etp = VariantReference.GetVariantType(info.PropertyType);
                switch (etp)
                {
                case VariantType.Null:
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.String:
                    propValue.stringValue        = EditorGUI.TextField(r1, propValue.stringValue);
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Boolean:
                    propValue.stringValue        = EditorGUI.Toggle(r1, GUIContent.none, ConvertUtil.ToBool(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Integer:
                    propValue.stringValue        = EditorGUI.IntField(r1, GUIContent.none, ConvertUtil.ToInt(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Float:
                    propValue.stringValue        = EditorGUI.FloatField(r1, GUIContent.none, ConvertUtil.ToSingle(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Double:
                    propValue.stringValue        = EditorGUI.DoubleField(r1, GUIContent.none, ConvertUtil.ToDouble(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector2:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector2Field(r1, GUIContent.none, ConvertUtil.ToVector2(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector3:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector3Field(r1, GUIContent.none, ConvertUtil.ToVector3(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector4:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector4Field(r1, (string)null, ConvertUtil.ToVector4(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Quaternion:
                    propValue.stringValue        = QuaternionUtil.Stringify(SPEditorGUI.QuaternionField(r1, GUIContent.none, ConvertUtil.ToQuaternion(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Color:
                    propValue.stringValue        = ConvertUtil.ToInt(EditorGUI.ColorField(r1, ConvertUtil.ToColor(propValue.stringValue))).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.DateTime:
                    //TODO - should never actually occur
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.GameObject:
                case VariantType.Component:
                case VariantType.Object:
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = EditorGUI.ObjectField(r1, GUIContent.none, propValue.objectReferenceValue, info.PropertyType, false);
                    break;

                case VariantType.LayerMask:
                    propValue.stringValue        = SPEditorGUI.LayerMaskField(r1, GUIContent.none, ConvertUtil.ToInt(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Rect:
                    //TODO - should never actually occur
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Numeric:

                    break;
                }
            }
        }
        private void DrawAdvanced_CallMethodOnSelected(Rect area, SerializedProperty property)
        {
            //Draw Target
            var targRect  = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
            var targProp  = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLETARG);
            var targLabel = new GUIContent("Triggerable Target");
            var targGo    = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue);
            var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject;

            if (newTargGo != targGo)
            {
                targGo = newTargGo;
                targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null;
            }

            var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight);

            if (targGo != null)
            {
                EditorGUI.BeginChangeCheck();
                var selectedComp = SPEditorGUI.SelectComponentFromSourceField(targCompPopupRect, "Target Component", targGo, targProp.objectReferenceValue as Component);
                if (EditorGUI.EndChangeCheck())
                {
                    targProp.objectReferenceValue = selectedComp;
                }
            }
            else
            {
                EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)");
            }

            //Draw Method Name
            var methNameRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width, EditorGUIUtility.singleLineHeight);

            System.Reflection.MemberInfo selectedMember = null;
            if (targProp.objectReferenceValue != null)
            {
                var methProp = property.FindPropertyRelative(TriggerTargetProps.PROP_METHODNAME);

                //var tp = targProp.objectReferenceValue.GetType();
                //var members = GetAvailableMethods(tp).ToArray();

                //var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.Method).ToArray();
                var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.All, spacepuppy.Dynamic.DynamicMemberAccess.Write).ToArray();
                System.Array.Sort(members, (a, b) => string.Compare(a.Name, b.Name, true));
                var memberNames = members.Select((m) => m.Name).ToArray();

                int index = System.Array.IndexOf(memberNames, methProp.stringValue);
                index = EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), index, (from n in memberNames select new GUIContent(n)).ToArray());
                methProp.stringValue = (index >= 0) ? memberNames[index] : null;
                selectedMember       = (index >= 0) ? members[index] : null;
            }
            else
            {
                EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), -1, new GUIContent[0]);
            }

            property.serializedObject.ApplyModifiedProperties();

            //Draw Triggerable Arg
            var parr = (selectedMember != null) ? com.spacepuppy.Dynamic.DynamicUtil.GetDynamicParameterInfo(selectedMember) : null;

            if (parr == null || parr.Length == 0)
            {
                //NO PARAMETERS
                _callMethodModeExtraLines = 1;

                var argRect      = new Rect(area.xMin, methNameRect.yMax, area.width, EditorGUIUtility.singleLineHeight);
                var argArrayProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLEARGS);
                if (argArrayProp.arraySize > 0)
                {
                    argArrayProp.arraySize = 0;
                    argArrayProp.serializedObject.ApplyModifiedProperties();
                }

                var cache = SPGUI.Disable();
                EditorGUI.LabelField(argRect, GUIContent.none, new GUIContent("*Zero Parameter Count*"));
                cache.Reset();
            }
            else
            {
                //MULTIPLE PARAMETERS - special case, does not support trigger event arg
                _callMethodModeExtraLines = parr.Length;

                var argArrayProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLEARGS);

                if (argArrayProp.arraySize != parr.Length)
                {
                    argArrayProp.arraySize = parr.Length;
                    argArrayProp.serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.indentLevel++;
                for (int i = 0; i < parr.Length; i++)
                {
                    var paramType = parr[i].ParameterType;
                    var argRect   = new Rect(area.xMin, methNameRect.yMax + i * EditorGUIUtility.singleLineHeight, area.width, EditorGUIUtility.singleLineHeight);
                    var argProp   = argArrayProp.GetArrayElementAtIndex(i);

                    if (paramType == typeof(object))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed."));
                    }
                    else
                    {
                        var argType = VariantReference.GetVariantType(paramType);
                        _variantDrawer.RestrictVariantType     = true;
                        _variantDrawer.VariantTypeRestrictedTo = argType;
                        _variantDrawer.ForcedObjectType        = (paramType.IsInterface || TypeUtil.IsType(paramType, typeof(Component))) ? paramType : null;
                        _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed."));
                    }
                }
                EditorGUI.indentLevel--;
            }
        }
        public static TweenHash TweenToToken(this TweenHash hash, com.spacepuppy.Tween.Ease ease, float dur, object token)
        {
            if (hash == null || token == null)
            {
                return(hash);
            }

            object value;

            if (token is IStateToken)
            {
                var st = token as IStateToken;
                foreach (var sname in st.GetMemberNames(false))
                {
                    value = st.GetValue(sname);
                    if (value == null)
                    {
                        continue;
                    }

                    switch (VariantReference.GetVariantType(value.GetType()))
                    {
                    case VariantType.String:
                    case VariantType.Boolean:
                    case VariantType.Integer:
                    case VariantType.Float:
                    case VariantType.Double:
                    case VariantType.Vector2:
                    case VariantType.Vector3:
                    case VariantType.Vector4:
                    case VariantType.Quaternion:
                    case VariantType.Color:
                    case VariantType.Rect:
                        hash.To(sname, ease, dur, value);
                        break;
                    }
                }
            }
            else
            {
                foreach (var sname in DynamicUtil.GetMemberNames(token, false, System.Reflection.MemberTypes.Field | System.Reflection.MemberTypes.Property))
                {
                    value = DynamicUtil.GetValue(token, sname);
                    if (value == null)
                    {
                        continue;
                    }

                    switch (VariantReference.GetVariantType(value.GetType()))
                    {
                    case VariantType.String:
                    case VariantType.Boolean:
                    case VariantType.Integer:
                    case VariantType.Float:
                    case VariantType.Double:
                    case VariantType.Vector2:
                    case VariantType.Vector3:
                    case VariantType.Vector4:
                    case VariantType.Quaternion:
                    case VariantType.Color:
                    case VariantType.Rect:
                        hash.To(sname, ease, dur, value);
                        break;
                    }
                }
            }

            return(hash);
        }
Пример #10
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept("_searchEntity", "_componentType", "_memberName", "_value", "_mode");
            this.DrawPropertyField("_searchEntity");
            this.DrawPropertyField("_componentType"); //uses the TypeReference PropertyDrawer

            var compTypeProp = this.serializedObject.FindProperty("_componentType");
            var memberProp   = this.serializedObject.FindProperty("_memberName");
            var valueProp    = this.serializedObject.FindProperty("_value");
            var modeProp     = this.serializedObject.FindProperty("_mode");


            //SELECT MEMBER
            System.Reflection.MemberInfo selectedMember;
            memberProp.stringValue = SPEditorGUILayout.ReflectedPropertyField(EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                              TypeReferencePropertyDrawer.GetTypeFromTypeReference(compTypeProp),
                                                                              memberProp.stringValue,
                                                                              out selectedMember);
            this.serializedObject.ApplyModifiedProperties();


            //MEMBER VALUE TO SET TO
            if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetParameters(selectedMember).FirstOrDefault();
                var emode    = modeProp.GetEnumValue <i_SetValue.SetMode>();
                if (emode == i_SetValue.SetMode.Toggle)
                {
                    //EditorGUILayout.LabelField(EditorHelper.TempContent(valueProp.displayName), EditorHelper.TempContent(propType.Name));
                    var evtp = VariantReference.GetVariantType(propType);
                    GUI.enabled = false;
                    EditorGUILayout.EnumPopup(EditorHelper.TempContent(valueProp.displayName), evtp);
                    GUI.enabled = true;
                }
                else
                {
                    if (propType == typeof(object))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(), valueProp, EditorHelper.TempContent("Value", "The value to set to."));
                    }
                    else
                    {
                        var argType = VariantReference.GetVariantType(propType);
                        _variantDrawer.RestrictVariantType     = true;
                        _variantDrawer.VariantTypeRestrictedTo = argType;
                        _variantDrawer.ForcedObjectType        = (TypeUtil.IsType(propType, typeof(Component))) ? propType : null;
                        _variantDrawer.OnGUI(EditorGUILayout.GetControlRect(), valueProp, EditorHelper.TempContent("Value", "The value to set to."));
                    }
                }

                if (com.spacepuppy.Dynamic.Evaluator.WillArithmeticallyCompute(propType))
                {
                    EditorGUILayout.PropertyField(modeProp);
                }
                else
                {
                    //modeProp.SetEnumValue(i_SetValue.SetMode.Set);
                    EditorGUI.BeginChangeCheck();
                    emode = (i_SetValue.SetMode)SPEditorGUILayout.EnumPopupExcluding(EditorHelper.TempContent(modeProp.displayName), emode, i_SetValue.SetMode.Decrement, i_SetValue.SetMode.Increment);
                    if (EditorGUI.EndChangeCheck())
                    {
                        modeProp.SetEnumValue(emode);
                    }
                }
            }
            else
            {
                modeProp.SetEnumValue(i_SetValue.SetMode.Set);
            }

            this.serializedObject.ApplyModifiedProperties();
        }