public override void OnGUI(SerializedNodeProperty property, BehaviourMachine.ActionNode node, GUIContent guiContent)
        {
            // Now draw the property as a Slider or an IntSlider based on whether it’s a float or integer.
            if (property.type != typeof(MinMaxRangeSO))
            {
                Debug.LogWarning("Use only with MinMaxRange type");
            }
            else
            {
                var range = attribute as MinMaxRangeSAttribute;
                var so    = (MinMaxRangeSO)property.value;


                //set or reset to default full range
                if (so.rangeStart == so.rangeEnd)
                {
                    so.rangeStart = range.minLimit;
                    so.rangeEnd   = range.maxLimit;
                }

                var newMin = so.rangeStart;
                var newMax = so.rangeEnd;


                Rect position = GUILayoutUtility.GetRect(Screen.width - 32f, 32f);

                var xDivision = position.width * 0.33f;
                var yDivision = position.height * 0.5f;
                EditorGUI.LabelField(new Rect(position.x, position.y, xDivision, yDivision)
                                     , guiContent);

                EditorGUI.LabelField(new Rect(position.x, position.y + yDivision, position.width, yDivision)
                                     , range.minLimit.ToString("0.##"));
                EditorGUI.LabelField(new Rect(position.x + position.width - 28f, position.y + yDivision, position.width, yDivision)
                                     , range.maxLimit.ToString("0.##"));


                EditorGUI.MinMaxSlider(new Rect(position.x + 24f, position.y + yDivision, position.width - 48f, yDivision)
                                       , ref newMin, ref newMax, range.minLimit, range.maxLimit);

                EditorGUI.LabelField(new Rect(position.x + xDivision, position.y, xDivision, yDivision)
                                     , "From: ");
                newMin = Mathf.Clamp(EditorGUI.FloatField(new Rect(position.x + xDivision + 30, position.y, xDivision - 30, yDivision)
                                                          , newMin)
                                     , range.minLimit, newMax);
                EditorGUI.LabelField(new Rect(position.x + xDivision * 2f, position.y, xDivision, yDivision)
                                     , "To: ");
                newMax = Mathf.Clamp(EditorGUI.FloatField(new Rect(position.x + xDivision * 2f + 24, position.y, xDivision - 24, yDivision)
                                                          , newMax)
                                     , newMin, range.maxLimit);

                so.rangeStart = newMin;
                so.rangeEnd   = newMax;

                property.ValueChanged();

                property.ApplyModifiedValue();

                property.serializedNode.ApplyModifiedProperties();
            }
        }
Exemple #2
0
        public override void OnGUI(SerializedNodeProperty property, BehaviourMachine.ActionNode node, GUIContent guiContent)
        {
            Rect position = GUILayoutUtility.GetRect(Screen.width - 32f, 32f);



            Rect typePos = new Rect(position.x, position.y, 80, position.height);

            position.xMin = typePos.xMax;
            Rect varPos = new Rect(position.x, position.y, position.width, position.height);


            Type type;

            GUIContent[] displayOptionsTypes;
            Type[]       types;

            UniUnityVariablePropertyAttribute attributeUni = attribute as UniUnityVariablePropertyAttribute;


            if (property.value == null)
            {
                type = EditorGUILayoutEx.unityTypes [0];
            }
            else
            {
                type = ((UnityVariable)property.value).ValueType;
            }

            //blackboard vars LOCAL
            BlackboardCustom blackboard = node.blackboard as BlackboardCustom;

            List <UnityVariable> blackboardVariablesLocalList = blackboard.GetVariableBy(type);


            List <GUIContent> displayOptionsVariablesLocal = blackboardVariablesLocalList.Select((item) => new GUIContent("Local/" + item.name)).ToList();


            //blackboard vars GLOBAL


            if (attributeUni.typesCustom != null)
            {
                GUIContent[] displayOptionsCustom = attributeUni.typesCustom.Select((itm) => new GUIContent(itm.Name)).ToArray();

                if (attributeUni.only)
                {
                    types = attributeUni.typesCustom;
                    displayOptionsTypes = displayOptionsCustom;
                }
                else
                {
                    types = attributeUni.typesCustom.Concat <Type>(EditorGUILayoutEx.unityTypes).ToArray();

                    displayOptionsTypes = displayOptionsCustom.Concat <GUIContent>(EditorGUILayoutEx.unityTypesDisplayOptions).ToArray();
                }
            }
            else
            {
                displayOptionsTypes = EditorGUILayoutEx.unityTypesDisplayOptions;
                types = EditorGUILayoutEx.unityTypes;
            }



            //String name = attributeUni.name;

            //create types selection popup
            typeSelected = EditorGUILayoutEx.CustomObjectPopup <Type> (null, type, displayOptionsTypes, types, null, null, null, null, typePos);

            //if change of type create new variable
            if (typeSelected != type && !typeSelected.IsSubclassOf(type) /*&& type!=typeof(UnityEngine.Object)*/)
            {
                property.value = UnityVariable.CreateInstanceOf(typeSelected);
            }


            property.value = EditorGUILayoutEx.UnityVariablePopup(null, property.value as UnityVariable, typeSelected, displayOptionsVariablesLocal, blackboardVariablesLocalList, varPos);



            property.serializedNode.ApplyModifiedProperties();
        }