void UpdateSubParameters()
 {
     Terrain_Bounds_center = TerrainParameter + "_Bounds_center";
     Terrain_Bounds_size   = TerrainParameter + "_Bounds_size";
     Terrain_HeightMap     = TerrainParameter + "_HeightMap";
     Terrain_Height        = TerrainParameter + "_Height";
 }
Пример #2
0
        VisualElement CreateParameterVariantView(ExposedParameter param, SerializedObject serializedInspector)
        {
            VisualElement prop = new VisualElement();

            prop.AddToClassList("Indent");
            prop.style.display = DisplayStyle.Flex;
            var parameterView = overrideParameterView.CloneTree();

            prop.Add(parameterView);

            var parameterValueField = exposedParameterFactory.GetParameterValueField(param, (newValue) => {
                param.value = newValue;
                UpdateOverrideParameter(param, newValue);
            });

            prop.AddManipulator(new ContextualMenuManipulator(e => {
                e.menu.AppendAction("Reset", _ => RemoveOverride(param));
            }));

            parameterValueField.Bind(serializedInspector);
            var paramContainer = parameterView.Q("Parameter");

            paramContainer.Add(parameterValueField);

            parameterViews[param] = parameterView;

            if (variant.overrideParameters.Contains(param))
            {
                AddOverrideClass(parameterView);
            }

            return(prop);
        }
Пример #3
0
        void UpdateOverrideParameter(ExposedParameter parameter, object overrideValue)
        {
            if (!variant.overrideParameters.Contains(parameter))
            {
                Undo.RegisterCompleteObjectUndo(variant, "Override Parameter");
                variant.overrideParameters.Add(parameter);
                EditorUtility.SetDirty(variant);
            }
            else
            {
                Undo.RegisterCompleteObjectUndo(variant, "Override Parameter");
                int index = variant.overrideParameters.FindIndex(p => p == parameter);
                variant.overrideParameters[index].value = parameter.value;
                EditorUtility.SetDirty(variant);
            }

            // Let know variant of variants that a property value changed
            variant.NotifyOverrideValueChanged(parameter);

            UpdateIsDirtyAndPreview();

            // Enable the override overlay:
            if (parameterViews.TryGetValue(parameter, out var view))
            {
                AddOverrideClass(view);
            }
        }
        void Add(ExposedParameter parameter)
        {
            ExposedParameterRestoreData data = new ExposedParameterRestoreData {
                parameterReference = parameter, type = parameter.type
            };

            m_exposedParameters.Add(data);
        }
        /// <summary>
        /// Creates an unique exposed parameter and returns his index.
        /// </summary>
        internal int CreateUniqueExposedParameter(out ExposedParameter newParameter)
        {
            string           uniqueParameterName = GetUniqueExposedParameterName("Parameter");
            ExposedParameter parameter           = CreateInstance <ExposedParameter> ();

            parameter.name = uniqueParameterName;

            newParameter = parameter;
            ArrayUtility.Add(ref m_exposedParameters, newParameter);
            return(m_exposedParameters.Length - 1);
        }
    void LoadExposedParameter()
    {
        parameter = graph.GetExposedParameter(parameterName);

        if (parameter == null)
        {
            Debug.Log("Property \"" + parameterName + "\" Can't be found !");
            return;
        }

        output = parameter.serializedValue.value;
    }
        /// <summary>
        /// Returns true if the exposed parameter exists.
        /// </summary>
        public bool ContainsExposedParameter(ExposedParameter parameter)
        {
            foreach (ParameterReference reference in m_parameterReferences)
            {
                if (reference.exposedParameter == parameter)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #8
0
    void LoadExposedParameter()
    {
        parameter = graph.GetExposedParameterFromGUID(parameterGUID);

        if (parameter == null)
        {
            Debug.Log("Property \"" + parameterGUID + "\" Can't be found !");

            // Delete this node as the property can't be found
            graph.RemoveNode(this);
            return;
        }

        output = parameter.serializedValue.value;
    }
Пример #9
0
        void RemoveOverride(ExposedParameter parameter)
        {
            Undo.RegisterCompleteObjectUndo(variant, "Reset parameter");

            variant.overrideParameters.RemoveAll(p => p == parameter);
            parameter.value = variant.GetDefaultParameterValue(parameter);
            exposedParameterFactory.ResetOldParameter(parameter);

            variant.NotifyOverrideValueChanged(parameter);
            UpdateParameters();

            UpdateIsDirtyAndPreview();

            if (parameterViews.TryGetValue(parameter, out var view))
            {
                view.RemoveFromClassList("Override");
            }
        }
Пример #10
0
        public MixtureExposedParameterPropertyView(BaseGraphView graphView, ExposedParameter param)
        {
            mixtureGraphView = graphView as MixtureGraphView;
            parameter        = param;

            var valueField = graphView.exposedParameterFactory.GetParameterValueField(param, (newValue) => {
                graphView.RegisterCompleteObjectUndo("Updated Parameter Value");
                param.value = newValue;
                graphView.graph.NotifyExposedParameterValueChanged(param);
                mixtureGraphView.ProcessGraph();
            });

            var field = graphView.exposedParameterFactory.GetParameterSettingsField(param, (newValue) => {
                param.settings = newValue as ExposedParameter.Settings;
            });

            Add(valueField);

            Add(field);
        }
        /// <summary>
        /// Returns the exposed value for the given exposed parameter.
        /// </summary>
        /// <returns>Returns true if the exposed parameter exists.</returns>
        public bool TryGetExposedObject <T> (ExposedParameter parameter, out T value) where T : UnityEngine.Object
        {
            for (int i = 0; i < m_parameterReferences.Length; i++)
            {
                if (m_parameterReferences[i].exposedParameter == parameter)
                {
                    try {
                        value = (T)m_parameterReferences[i].unityObjectReference;
                        return(true);
                    }
                    catch (Exception) {
                        value = default(T);
                        return(false);
                    }
                }
            }

            value = default(T);
            return(false);
        }
Пример #12
0
 void ChangeExposedParameterIndex(ExposedParameter parameter, int newIndex)
 {
     controller.ChangeExposedParameterIndex(newIndex, parameter);
 }
Пример #13
0
 void RemoveExposedParameter(ExposedParameter parameterToRemove)
 {
     Serializer.RemoveExposedParameterFromController(controller, parameterToRemove);
 }
Пример #14
0
 void ChangeExposedParameterName(ExposedParameter parameter, string newName)
 {
     controller.ChangeExposedParameterName(newName, parameter);
     EditorGUIUtility.RepaintEditorsOfType <AIBehaviourInspector> ();
 }
 /// <summary>
 /// Removes the given exposed parameter.
 /// </summary>
 internal void RemoveExposedParameter(ExposedParameter parameter)
 {
     ArrayUtility.Remove(ref m_exposedParameters, parameter);
 }
 string GetUniqueExposedParameterName(string parameterName, ExposedParameter oldParameter = null)
 {
     return(GetUniqueParameterName(m_exposedParameters, parameterName, oldParameter));
 }
Пример #17
0
 void UpdateParameters(ExposedParameter param) => UpdateParameters();
 /// <summary>
 /// Change the index of the given exposed parameter.
 /// </summary>
 internal void ChangeExposedParameterIndex(int newIndex, ExposedParameter exposedParameter)
 {
     ArrayUtility.Remove(ref m_exposedParameters, exposedParameter);
     ArrayUtility.Insert(ref m_exposedParameters, newIndex, exposedParameter);
 }
        //...
        void DoExposedVariablesMapping()
        {
            if (owner.graph == null)
            {
                return;
            }

            var separatorDrawn   = false;
            var subTreeVariables = owner.graph.blackboard.variables.Values;

            foreach (var variable in subTreeVariables)
            {
                if (variable is Variable <VariableSeperator> )
                {
                    continue;
                }
                if (!variable.isExposedPublic || variable.isPropertyBound)
                {
                    continue;
                }

                if (!separatorDrawn)
                {
                    separatorDrawn = true;
                    EditorUtils.Separator();
                    EditorGUILayout.HelpBox("Exposed Graph Variables. Use the arrows button to override/parametrize the variable.\nDoing this will not change the graph serialization. Prefab overrides are also supported.", MessageType.None);
                }

                if (owner.exposedParameters == null)
                {
                    owner.exposedParameters = new System.Collections.Generic.List <ExposedParameter>();
                }
                var exposedParam = owner.exposedParameters.Find(x => x.targetVariableID == variable.ID);
                if (exposedParam == null)
                {
                    GUILayout.BeginHorizontal();
                    GUI.enabled = false;
                    EditorUtils.DrawEditorFieldDirect(new GUIContent(variable.name, "This is an Exposed Public variable of the graph local blackboard. You can use the arrows button on the right side to override/parametrize the default value."), variable.value, variable.varType, default(InspectedFieldInfo));
                    GUI.enabled = true;
                    if (GUILayout.Button(EditorUtils.GetTempContent("▽△", null, "Override Variable"), Styles.centerLabel, GUILayout.Width(24)))
                    {
                        UndoUtility.RecordObject(owner, "Add Override");
                        exposedParam = ExposedParameter.CreateInstance(variable);
                        owner.exposedParameters.Add(exposedParam);
                        exposedParam.Bind(owner.graph.blackboard);
                        UndoUtility.SetDirty(owner);
                    }
                    EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                    GUILayout.EndHorizontal();
                    continue;
                }

                GUILayout.BeginHorizontal();
                var info = new InspectedFieldInfo();
                info.unityObjectContext = owner;
                exposedParam.valueBoxed = EditorUtils.DrawEditorFieldDirect(new GUIContent(variable.name), exposedParam.valueBoxed, variable.varType, info);
                if (GUILayout.Button(EditorUtils.GetTempContent("▼▲", null, "Remove Override"), Styles.centerLabel, GUILayout.Width(24)))
                {
                    UndoUtility.RecordObject(owner, "Remove Override");
                    exposedParam.UnBind(owner.graph.blackboard);
                    owner.exposedParameters.Remove(exposedParam);
                    UndoUtility.SetDirty(owner);
                    continue;
                }
                EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
                GUILayout.EndHorizontal();

                var index            = owner.exposedParameters.IndexOf(exposedParam);
                var serProp          = exposeParamsProp.GetArrayElementAtIndex(index);
                var isPrefabOverride = serProp.prefabOverride;
                if (isPrefabOverride)
                {
                    var rect = GUILayoutUtility.GetLastRect();
                    EditorUtils.MarkLastFieldOverride();
                    if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.ContextClick)
                    {
                        var prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(owner);
                        var asset           = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(prefabAssetPath);
                        var menu            = new GenericMenu();
                        menu.AddItem(new GUIContent($"Apply to Prefab '{asset.name}'"), false, () =>
                        {
                            UndoUtility.RecordObject(owner, "Apply Exposed Parameter");
                            UndoUtility.RecordObject(asset, "Apply Exposed Parameter");
                            PrefabUtility.ApplyPropertyOverride(serProp, prefabAssetPath, InteractionMode.UserAction);
                            UndoUtility.SetDirty(owner);
                            UndoUtility.SetDirty(asset);
                        });
                        menu.AddItem(new GUIContent("Revert"), false, () =>
                        {
                            UndoUtility.RecordObject(owner, "Revert Exposed Parameter");
                            PrefabUtility.RevertPropertyOverride(serProp, InteractionMode.UserAction);
                            UndoUtility.SetDirty(owner);
                        });
                        menu.ShowAsContext();
                    }
                }
            }

            if (separatorDrawn)
            {
                EditorUtils.Separator();
            }

            //cleanup
            if (owner.exposedParameters != null)
            {
                for (var i = owner.exposedParameters.Count; i-- > 0;)
                {
                    var exposedParam = owner.exposedParameters[i];
                    var variable     = owner.graph.blackboard.GetVariableByID(exposedParam.targetVariableID);
                    if (variable == null || !variable.isExposedPublic || variable.isPropertyBound)
                    {
                        owner.exposedParameters.RemoveAt(i);
                        UndoUtility.SetDirty(owner);
                    }
                }
            }
        }
        /// <summary>
        /// Change the name of the given exposed parameter.
        /// </summary>
        internal void ChangeExposedParameterName(string newName, ExposedParameter parameter)
        {
            string uniqueParameterName = GetUniqueExposedParameterName(newName, parameter);

            parameter.name = uniqueParameterName;
        }
 /// <summary>
 /// Returns true if the exposed parameter exists in this controller.
 /// </summary>
 internal bool ContainsExposedParameter(ExposedParameter parameter)
 {
     return(ArrayUtility.Contains(m_exposedParameters, parameter));
 }
Пример #22
0
 protected void UpdateExposedParameters(ExposedParameter param) => UpdateExposedParameters();
Пример #23
0
        /*public static ExposedParameter ExposedParameter<T> (string title, ExposedParameter exposedParameter, Node node) where T : UnityEngine.Object {
         *  return ExposedParameter (title, exposedParameter, typeof (T), node);
         * }*/


        public static ExposedParameter ExposedParameter(string title, ExposedParameter exposedParameter, Type type, Node node)
        {
            if (node == null || node.controller == null)
            {
                return(exposedParameter);
            }
            if (type != typeof(UnityEngine.Object) && !type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                Debug.LogError("Cannot use exposed parameter with non UnityEngine.Object's");
                return(exposedParameter);
            }

            int selectedIndex = 0;

            string[] displayedOptions = new string[node.controller.exposedParameters.Length + 1];
            displayedOptions[0] = "None (" + type.Name + ")";

            for (int i = 1; i < displayedOptions.Length; i++)
            {
                ExposedParameter parameter = node.controller.exposedParameters[i - 1];

                if (parameter.type == null)
                {
                    displayedOptions[i] = parameter.name;
                }
                else
                {
                    displayedOptions[i] = parameter.name + " (" + parameter.type.Name + ")";
                }

                if (exposedParameter == parameter)
                {
                    selectedIndex = i;
                }
            }

            int oldSelectedIndex = selectedIndex;

            selectedIndex = EditorGUILayout.Popup(title, selectedIndex, displayedOptions);

            ExposedParameter newSelectedParameter = (selectedIndex > 0) ? node.controller.exposedParameters[selectedIndex - 1] : null;
            ExposedParameter oldSelectedParameter = (oldSelectedIndex > 0) ? node.controller.exposedParameters[oldSelectedIndex - 1] : null;

            // do nothing if nothing changed.
            if (newSelectedParameter == oldSelectedParameter)
            {
                return(exposedParameter);
            }

            // none select
            if (newSelectedParameter == null)
            {
                // unbind old parameter if it is not null
                if (oldSelectedParameter != null)
                {
                    oldSelectedParameter.Unbind(node);
                }

                EditorGUIUtility.RepaintEditorsOfType <AIBehaviourInspector> ();
                return(null);
            }

            // check type if it's not equal ask the user if he would change the type.
            if (newSelectedParameter.type != null && newSelectedParameter.type != type)
            {
                // create modal window
                bool changeType = EditorUtility.DisplayDialog("The selected parameter is already bounded.", "The selected parameter is used in other nodes with a different type.\nDo you won't to change the type and remove the parameter of the other nodes ?", "Yes", "No");

                if (changeType)
                {
                    Node[] nodes = newSelectedParameter.boundNodes;
                    newSelectedParameter.UnbindAll();

                    // set old nodes exposed parameters per reflection to null.
                    foreach (Node n in nodes)
                    {
                        FieldInfo[] fields = n.GetFields <ExposedParameter> ();

                        foreach (FieldInfo field in fields)
                        {
                            ExposedParameter parameter = field.GetValue(n) as ExposedParameter;
                            if (parameter && parameter == newSelectedParameter)
                            {
                                field.SetValue(n, null);
                            }
                        }
                    }
                }
                else
                {
                    return(exposedParameter);
                }
            }


            if (oldSelectedParameter)
            {
                oldSelectedParameter.Unbind(node);
            }

            newSelectedParameter.Bind(node, type);

            EditorGUIUtility.RepaintEditorsOfType <AIBehaviourInspector> ();

            return(newSelectedParameter);
        }
Пример #24
0
        void DrawExposedParameterReferences()
        {
            if (sharedController.objectReferenceValue != null)
            {
                AIController aiController = sharedController.objectReferenceValue as AIController;

                // add exposed parameters.
                for (int i = 0; i < aiController.exposedParameters.Length; i++)
                {
                    ExposedParameter p = aiController.exposedParameters[i];

                    if (!behaviour.ContainsExposedParameter(p))
                    {
                        int lastIndex = parameterReferences.arraySize;
                        parameterReferences.InsertArrayElementAtIndex(lastIndex);
                        SerializedProperty exposedParameterReference = parameterReferences.GetArrayElementAtIndex(lastIndex);
                        exposedParameterReference.FindPropertyRelative("exposedParameter").objectReferenceValue = p;
                    }
                }

                EditorGUILayout.BeginVertical();

                // draw exposed parameters.
                for (int i = 0; i < parameterReferences.arraySize; i++)
                {
                    SerializedProperty exposedParameterReference = parameterReferences.GetArrayElementAtIndex(i);
                    SerializedProperty exposedParameter          = exposedParameterReference.FindPropertyRelative("exposedParameter");
                    SerializedProperty unityObjectReference      = exposedParameterReference.FindPropertyRelative("unityObjectReference");

                    ExposedParameter parameter = exposedParameter.objectReferenceValue as ExposedParameter;

                    EditorGUILayout.BeginHorizontal();

                    if (parameter == null || !aiController.ContainsExposedParameter(parameter))
                    {
                        parameterReferences.DeleteArrayElementAtIndex(i);
                    }
                    else if (parameter.type != null)
                    {
                        if (parameter.type == typeof(UnityEngine.Object) || parameter.type.IsSubclassOf(typeof(UnityEngine.Object)))
                        {
                            unityObjectReference.objectReferenceValue = EditorGUILayout.ObjectField(parameter.name, unityObjectReference.objectReferenceValue, parameter.type, true);

                            if (unityObjectReference.objectReferenceValue != null)
                            {
                                if (unityObjectReference.objectReferenceValue.GetType() != parameter.type && !unityObjectReference.objectReferenceValue.GetType().IsSubclassOf(parameter.type))
                                {
                                    unityObjectReference.objectReferenceValue = null;
                                }
                            }
                        }
                        else
                        {
                            Debug.Log("Not an UnityEngine.Object");
                        }
                    }
                    else
                    {
                        unityObjectReference.objectReferenceValue = null;
                    }

                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
            }
        }
        /// <summary>
        /// Remove the given parameter from the given controller.
        /// </summary>
        public static void RemoveExposedParameterFromController(AIController controller, ExposedParameter parameter, bool autoSave = true)
        {
            controller.RemoveExposedParameter(parameter);

            #if SERIALIZER_DEBUG
            Debug.Log("Exposed Parameter [" + parameter.name + "] removed.");
            #endif

            Object.DestroyImmediate(parameter, true);

            if (autoSave)
            {
                Save();
            }

            controller.isDirty = true;
        }