Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name_"></param>
 public NamedVariableNode(string name_)
     : base()
 {
     m_Value = NamedVariableManager.Instance.GetNamedVariable(name_);
     m_Value.PropertyChanged += new PropertyChangedEventHandler(OnNamedVariablePropertyChanged);
     AddSlot(0, string.Empty, SlotType.VarInOut, m_Value.VariableType, true, VariableControlType.ReadOnly);
 }
Пример #2
0
            static void LogFields(object obj, int tabbing)
            {
                foreach (FieldInfo field in obj.GetType().GetFields())
                {
                    object fieldVal = field.GetValue(obj);

                    switch (fieldVal)
                    {
                    case FsmEventTarget target:
                        LogWithTabbing($"{field.FieldType.Name} {field.Name} = ", tabbing);
                        LogFields(target, tabbing + 1);
                        continue;
                    }

                    string fieldText = fieldVal switch
                    {
                        null => "null",
                        FsmEvent e => e.Name,
                        FsmOwnerDefault od => od.GameObject?.ToString() ?? "null",
                        NamedVariable v => v.RawValue + " (" + v.VariableType + " " + v.GetDisplayName() + ")",
                        not null => fieldVal.ToString()
                    };

                    LogWithTabbing($"{field.FieldType.Name} {field.Name} = {fieldText}", tabbing);
                }
            }
        }
Пример #3
0
        private void MoveToGlobals(object userdata)
        {
            SkillVariable fsmVariable = userdata as SkillVariable;

            if (fsmVariable != null && fsmVariable.NamedVar != null)
            {
                if (SkillVariables.get_GlobalVariables().Contains(fsmVariable.Name))
                {
                    NamedVariable variable = SkillVariables.get_GlobalVariables().GetVariable(fsmVariable.Name);
                    if (variable.get_VariableType() != fsmVariable.NamedVar.get_VariableType())
                    {
                        Dialogs.OkDialog(Strings.get_Dialog_Make_Global_Variable(), Strings.get_VariableManager_MoveToGlobals_Warning());
                        return;
                    }
                    if (Dialogs.YesNoDialog(Strings.get_Dialog_Make_Global_Variable(), Strings.get_VariableManager_MoveToGlobals_Confirm()))
                    {
                        this.RemoveLocalVariable(fsmVariable);
                        return;
                    }
                }
                else
                {
                    if (Dialogs.AreYouSure(Strings.get_Dialog_Make_Global_Variable()))
                    {
                        SkillVariable.AddVariable(SkillVariables.get_GlobalVariables(), fsmVariable.NamedVar.Clone());
                        this.RemoveLocalVariable(fsmVariable);
                    }
                }
            }
        }
Пример #4
0
        public void Clear()
        {
            List <NamedVariable> list = new List <NamedVariable>(SkillSearch.globalVariablesUsage.get_Keys());

            using (List <NamedVariable> .Enumerator enumerator = list.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    NamedVariable    current = enumerator.get_Current();
                    List <SkillInfo> globalVariablesUsageList = SkillSearch.GetGlobalVariablesUsageList(current);
                    List <SkillInfo> list2 = new List <SkillInfo>(globalVariablesUsageList);
                    using (List <SkillInfo> .Enumerator enumerator2 = globalVariablesUsageList.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            SkillInfo current2 = enumerator2.get_Current();
                            if (current2.fsm == this.fsm)
                            {
                                list2.Remove(current2);
                            }
                        }
                    }
                    SkillSearch.globalVariablesUsage.set_Item(current, list2);
                }
            }
            this.eventUsage.Clear();
            this.variableUsage.Clear();
            this.globalVariablesUsed.Clear();
            this.actionUsage.Clear();
        }
Пример #5
0
        /// <summary>
        /// Deletes the specified named variable from all scriptings.
        /// </summary>
        /// <param name="namedVariable">The named variable to delete.</param>
        /// <returns>Items to delete.</returns>
        public static HashSet <ItemForDeletion> DeleteFromScripting(NamedVariable namedVariable)
        {
            HashSet <ItemForDeletion> items = new HashSet <ItemForDeletion>();

            DeleteFromScripting(namedVariable, items);
            return(items);
        }
Пример #6
0
        void InitFsmVar()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                return;
            }

            if (go != cachedGO)
            {
                sourceFsm      = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
                sourceVariable = sourceFsm.FsmVariables.GetVariable(setValue.variableName);
                targetVariable = Fsm.Variables.GetVariable(setValue.variableName);

                setValue.Type = FsmUtility.GetVariableType(targetVariable);

                if (!string.IsNullOrEmpty(setValue.variableName) && sourceVariable == null)
                {
                    LogWarning("Missing Variable: " + setValue.variableName);
                }

                cachedGO = go;
            }
        }
Пример #7
0
        private void DoGetGameObjectByFsmVariableValue()
        {
            string varName = string.IsNullOrEmpty(variableName.Value) ||
                             variableName.IsNone ? variableValue.variableName : variableName.Value;

            foreach (var fsm in Fsm.FsmList)
            {
                if (fsm.GameObject == Owner)
                {
                    continue;
                }

                NamedVariable foundVar = fsm.Variables.FindVariable(variableValue.Type, varName);

                if (foundVar != null)
                {
                    result.Value = fsm.GameObject;
                }
            }

            if (result.Value == null)
            {
                Fsm.Event(noneFoundEvent);
            }
        }
        public bool GetVariable(PlayMakerFsmVariableTarget variableTarget)
        {
            initialized     = true;
            targetUndefined = true;
            if (variableTarget.FsmVariables != null)
            {
                targetUndefined   = false;
                variableNameToUse = string.IsNullOrEmpty(variableName)?defaultVariableName:variableName;

                fsmVariables   = variableTarget.FsmVariables;
                _namedVariable = fsmVariables.GetVariable(variableNameToUse);

                if (_namedVariable != null)
                {
                                        #if PLAYMAKER_1_8
                    selectedType = _namedVariable.VariableType;
                                        #else
                    selectedType = GetTypeFromChoice(variableSelectionChoice);
                                        #endif
                    return(true);
                }
            }

            selectedType = VariableType.Unknown;

            return(false);
        }
Пример #9
0
        private static bool CanEditTargetRotation(RotationOptions option, NamedVariable rotation, FsmGameObject target)
        {
            if (target == null)
            {
                return(false);
            }

            switch (option)
            {
            case RotationOptions.CurrentRotation:
                return(false);

            case RotationOptions.WorldRotation:
            case RotationOptions.LocalRotation:
            case RotationOptions.WorldOffsetRotation:
            case RotationOptions.LocalOffsetRotation:
                return(!rotation.IsNone);

            case RotationOptions.MatchGameObjectRotation:
                return(target.Value != null);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public void TestOnlyConstantAssignment()
 {
     var a = new NamedVariable("a");
     IDictionary<Variable, double> result = StraightforwardSubstitutionSolver.Solve(-100, 100,
         new[] { new EqualsZeroConstraint(new BinaryExpression(a, new Plus(), new Constant(6))) });
     Assert.AreEqual(-6, result[a]);
 }
Пример #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name_"></param>
 public NamedVariableNode(string name_)
     : base()
 {
     m_Value = NamedVariableManager.Instance.GetNamedVariable(name_);
     m_Value.PropertyChanged += new PropertyChangedEventHandler(OnNamedVariablePropertyChanged);
     AddSlot(0, string.Empty, SlotType.VarInOut, m_Value.VariableType, true, VariableControlType.ReadOnly);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBoxGraphNamedVars_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (m_IsDragAndDrop == true)
            {
                // Get the current mouse position
                Point  mousePos = e.GetPosition(null);
                Vector diff     = m_DragStartPoint - mousePos;

                if (e.LeftButton == MouseButtonState.Pressed &&
                    sender is ListBox &&
                    e.OriginalSource is DependencyObject &&
                    (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                     Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
                {
                    ListBox     listBox     = sender as ListBox;
                    ListBoxItem listBoxItem =
                        Helper.FindAnchestor <ListBoxItem>((DependencyObject)e.OriginalSource);

                    if (listBoxItem != null)
                    {
                        NamedVariable var = (NamedVariable)listBox.ItemContainerGenerator.
                                            ItemFromContainer(listBoxItem);

                        if (var != null)
                        {
                            DataObject dragData = new DataObject(DataFormats.Text, DragPrefixNamedVar + var.Name);
                            DragDrop.DoDragDrop(listBoxItem, dragData, DragDropEffects.Move);
                        }
                    }
                }
            }
        }
Пример #13
0
    private static void DoVariablesMenu(GameObject go, string fsmName, UIHint hint)
    {
        GenericMenu genericMenu = new GenericMenu();

        using (List <Skill> .Enumerator enumerator = SkillEditor.FsmList.GetEnumerator())
        {
            while (enumerator.MoveNext())
            {
                Skill current = enumerator.get_Current();
                if (current.get_GameObject() == go && current.get_Name() == fsmName)
                {
                    NamedVariable[] names = current.get_Variables().GetNames(SkillVariable.GetVariableType(hint));
                    NamedVariable[] array = names;
                    for (int i = 0; i < array.Length; i++)
                    {
                        NamedVariable namedVariable = array[i];
                        genericMenu.AddItem(new GUIContent(namedVariable.get_Name()), false, new GenericMenu.MenuFunction2(StringEditor.SetStringValue), namedVariable.get_Name());
                    }
                }
            }
        }
        if (genericMenu.GetItemCount() == 0)
        {
            genericMenu.AddDisabledItem(new GUIContent(Strings.get_Label_None()));
        }
        genericMenu.ShowAsContext();
    }
Пример #14
0
 /// <summary>
 /// Deletes the specified named variable from all actors scriptings of the specified scene.
 /// </summary>
 /// <param name="namedVariable">The named variable to delete.</param>
 /// <param name="scene">The scene.</param>
 /// <param name="items">Stores items to delete.</param>
 public static void DeleteFromScripting(NamedVariable namedVariable, Scene scene, HashSet <ItemForDeletion> items)
 {
     foreach (Actor actor in scene.AllActors())
     {
         DeleteFromScripting(namedVariable, actor, items);
     }
 }
Пример #15
0
        public static NamedVariable AddVariable(VariableType type, string name)
        {
            SkillEditor.RegisterUndo(Strings.get_Command_Add_Variable());
            NamedVariable result = SkillEditor.Builder.AddVariable(type, name);

            SkillEditor.SetFsmDirty(true, false);
            return(result);
        }
Пример #16
0
        /// <summary>
        /// Deletes the specified named variable from the specified actor and its children scriptings.
        /// </summary>
        /// <param name="namedVariable">The named variable to delete.</param>
        /// <param name="actor">The actor.</param>
        /// <param name="items">Stores items to delete.</param>
        public static void DeleteFromScripting(NamedVariable namedVariable, Actor actor, HashSet <ItemForDeletion> items)
        {
            DeleteFromScripting(namedVariable, actor.Scripting, items);

            foreach (Actor child in actor.Children)
            {
                DeleteFromScripting(namedVariable, child, items);
            }
        }
Пример #17
0
 private string GetNamedVariableTypeName(NamedVariable variable)
 {
     if (variable is FsmTexture)
     {
         return("TEX");
     }
     else if (variable is FsmMaterial)
     {
         return("MAT");
     }
     else if (variable is FsmFloat)
     {
         return("FLOAT");
     }
     else if (variable is FsmBool)
     {
         return("BOOL");
     }
     else if (variable is FsmString)
     {
         return("STR");
     }
     else if (variable is FsmVector2)
     {
         return("VEC2");
     }
     else if (variable is FsmInt)
     {
         return("INT");
     }
     else if (variable is FsmRect)
     {
         return("RECT");
     }
     else if (variable is FsmQuaternion)
     {
         return("QUAT");
     }
     else if (variable is FsmColor)
     {
         return("COLOR");
     }
     else if (variable is FsmGameObject)
     {
         return("GAMEOBJ");
     }
     else if (variable is FsmObject)
     {
         return("OBJ");
     }
     else if (variable is FsmVector3)
     {
         return("VEC3");
     }
     return("UNSUPPORTED");
 }
Пример #18
0
        FsmVar IEvaluatorContext.GetVariable(string name)
        {
            NamedVariable variable = base.Fsm.Variables.GetVariable(name);

            if (variable != null)
            {
                return(new FsmVar(variable));
            }
            throw new VariableNotFoundException(name);
        }
 public void TestFoldConstants()
 {
     var a = new NamedVariable("a");
     AbstractExpr constSubExpr = new Constant(3) + new UnaryExpression(new Constant(1) * new Constant(2), new Cos());
     var expr = a * constSubExpr;
     var result = expr.Accept(new ConstantFoldingVisitor(), Ig.nore);
     double value = EvaluationVisitor.Evaluate(constSubExpr, DictionaryUtils.Empty<Variable, double>());
     AbstractExpr rhs = ((BinaryExpression)result).Rhs;
     Assert.IsInstanceOf<Constant>(rhs);
     Assert.AreEqual(value, ((Constant)rhs).Value, 1e-8);
 }
Пример #20
0
        public static int GetGlobalVariablesUsageCount(NamedVariable variable)
        {
            List <SkillInfo> list;

            SkillSearch.globalVariablesUsage.TryGetValue(variable, ref list);
            if (list == null)
            {
                return(0);
            }
            return(list.get_Count());
        }
Пример #21
0
        private void DoSetFsmVariable()
        {
            setValue.UpdateValue();
            if (setValue.IsNone || string.IsNullOrEmpty(variableName.Value))
            {
                return;
            }

            var go = Fsm.GetOwnerDefaultTarget(eventTarget.gameObject);

            if (!go)
            {
                return;
            }

            if (enable.Value)
            {
                go.SetActive(true);
                if (eventTarget.fsmComponent != null)
                {
                    eventTarget.fsmComponent.enabled = true;
                }
            }

            string fsmName = eventTarget.fsmName.Value;

            if (go != cachedGameObject || fsmName != cachedFsmName)
            {
                targetFsm = ActionHelpers.GetGameObjectFsm(go, fsmName);

                if (targetFsm == null)
                {
                    return;
                }

                cachedGameObject = go;
                cachedFsmName    = fsmName;
            }

            if (variableName.Value != cachedVariableName)
            {
                setValue.UpdateValue();
                targetVariable     = targetFsm.FsmVariables.FindVariable(setValue.Type, variableName.Value);
                cachedVariableName = variableName.Value;
            }

            if (targetVariable == null)
            {
                LogWarning("Missing Variable: " + variableName.Value);
                return;
            }
            setValue.UpdateValue();
            setValue.ApplyValueTo(targetVariable);
        }
Пример #22
0
        public List <SkillInfo> GetVariableUsageList(NamedVariable variable)
        {
            List <SkillInfo> list;

            this.variableUsage.TryGetValue(variable, ref list);
            if (list == null)
            {
                list = new List <SkillInfo>();
                this.variableUsage.Add(variable, list);
            }
            return(list);
        }
Пример #23
0
        private void DoSetFsmVariable()
        {
            var go = Fsm.GetOwnerDefaultTarget(eventTarget.gameObject);

            if (go == null)
            {
                return;
            }

            if (enable.Value)
            {
                go.SetActive(true);
                if (eventTarget.fsmComponent != null)
                {
                    eventTarget.fsmComponent.enabled = true;
                }
            }

            string fsmName = eventTarget.fsmName.Value;

            if (go != cachedGameObject || fsmName != cachedFsmName)
            {
                targetFsm = ActionHelpers.GetGameObjectFsm(go, fsmName);
                if (targetFsm == null)
                {
                    return;
                }
                cachedGameObject = go;
                cachedFsmName    = fsmName;
            }

            for (int i = 0; i < variableName.Length; i++)
            {
                //ignore values that are not set/defined
                setValue[i].UpdateValue();
                if (setValue[i].IsNone || string.IsNullOrEmpty(variableName[i].Value))
                {
                    continue;
                }

                if (targetFsm.FsmVariables.Contains(variableName[i].Value))
                {
                    targetVariable = targetFsm.FsmVariables.GetVariable(variableName[i].Value);
                }
                else
                {
                    LogError(targetFsm.name + " doesn't contain variable " + variableName[i].Value);
                    return;
                }
                setValue[i].UpdateValue();
                setValue[i].ApplyValueTo(targetVariable);
            }
        }
Пример #24
0
        public static List <SkillInfo> GetGlobalVariablesUsageList(NamedVariable variable)
        {
            List <SkillInfo> list;

            SkillSearch.globalVariablesUsage.TryGetValue(variable, ref list);
            if (list == null)
            {
                list = new List <SkillInfo>();
                SkillSearch.globalVariablesUsage.Add(variable, list);
            }
            return(list);
        }
Пример #25
0
        /// <summary>
        /// Deletes the specified named variable from all scriptings.
        /// </summary>
        /// <param name="namedVariable">The named variable to delete.</param>
        /// <param name="items">Stores items to delete.</param>
        public static void DeleteFromScripting(NamedVariable namedVariable, HashSet <ItemForDeletion> items)
        {
            foreach (Scene scene in Project.Singleton.Scenes)
            {
                DeleteFromScripting(namedVariable, scene, items);
                DeleteFromScripting(namedVariable, scene.GlobalScript, items);
            }

            foreach (Actor prototype in Project.Singleton.Prototypes)
            {
                DeleteFromScripting(namedVariable, prototype, items);
            }
        }
 public void TestSimpleCubicEquationAndDependents()
 {
     // 0 = a³-a+6 or 0 = a(a²-1)+6 --> a = -2.
     var a = new NamedVariable("a");
     var b = new NamedVariable("b");
     IDictionary<Variable, double> result = StraightforwardSubstitutionSolver.Solve(-100, 100,
         new[] {
             (b+-(-a+-new Constant(4))).EqualsZero(),
             (a*(a*a+(-new Constant(1)))+new Constant(6)).EqualsZero()
         });
     Assert.AreEqual(-2.0, result[a], 1e-8);
     Assert.AreEqual(-2.0, result[b], 1e-8);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteNamedVar_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (listBoxGraphNamedVars.SelectedItem != null &&
                listBoxGraphNamedVars.SelectedItem is NamedVariable)
            {
                NamedVariable variable = listBoxGraphNamedVars.SelectedItem as NamedVariable;

                if (MessageBox.Show(
                        "Do you really want to delete the named variable " + variable.Name + " ?",
                        "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    NamedVariableManager.Instance.Remove(variable);
                }
            }
        }
Пример #28
0
 private int GetUsedCount(NamedVariable variable)
 {
     if (this.fsmOwner != null)
     {
         return(SkillSearch.GetVariableUseCount(this.fsmOwner, variable));
     }
     if (!(this.globalsOwner != null))
     {
         return(-1);
     }
     if (SkillSearch.GlobalVariablesUsageInitialized)
     {
         return(SkillSearch.GetGlobalVariablesUsageCount(variable));
     }
     return(-1);
 }
		/// <summary>
		/// Display an _selectionIndex the fsm variable from a list of variables ( from an fsm likely).
		/// This is to paliate for the PlayMaker 1.8 that deprecated the api call VariableEditor.FsmVarPopup()
		/// </summary>
		/// <returns>The fsm variable GU.</returns>
		/// <param name="fieldLabel">Field label.</param>
		/// <param name="fsmVariables">Fsm variables.</param>
		/// <param name="selection">Selection.</param>
		/// <param name="GuiChanged">GUI changed flag</param>
		public static FsmVar EditorGUILayout_FsmVarPopup(string fieldLabel,NamedVariable[] namedVariables,FsmVar selection,out bool GuiChanged)
		{
			GuiChanged = false;

			if (namedVariables==null)
			{
				Debug.LogWarning("EditorGUILayout_FsmVarPopup: namedVariables is null");
				return null;
			}



			int _selectionIndex = 0;

			string[] _variableChoices = new string[namedVariables.Length+1];
			_variableChoices[0] = "None";
			for(int i=0;i<namedVariables.Length;i++)
			{
				if (string.Equals(selection.variableName,namedVariables[i].Name))
				{
					_selectionIndex = i+1;
				}
				_variableChoices[i+1] = namedVariables[i].Name;
			}
			
			if (_variableChoices.Length!=0)
			{

				int _choiceIndex =  EditorGUILayout.Popup(fieldLabel,_selectionIndex,_variableChoices);
				if (_choiceIndex != _selectionIndex)
				{
					GuiChanged = true;

					if (_choiceIndex==0)
					{
						return new FsmVar();
					}else{
						FsmVar _newSelection = new FsmVar(namedVariables[_choiceIndex-1]);
						_newSelection.useVariable = true;
						return _newSelection;
					}

				}
			}

			return selection;
		}
Пример #30
0
        public static GenericMenu GenerateEnumTypesMenu(NamedVariable variable)
        {
            TypeHelpers.targetVariable = variable;
            GenericMenu genericMenu = new GenericMenu();

            using (List <Type> .Enumerator enumerator = TypeHelpers.EnumTypeList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Type   current  = enumerator.get_Current();
                    string fullName = current.get_FullName();
                    string text     = fullName.Replace('.', '/');
                    genericMenu.AddItem(new GUIContent(text), false, new GenericMenu.MenuFunction2(TypeHelpers.SetVariableObjectType), fullName);
                }
            }
            return(genericMenu);
        }
Пример #31
0
        private void DoGlobalVariablesTable()
        {
            if (SkillSearch.GetGlobalVariablesUsedCount(SkillEditor.SelectedFsm) == 0)
            {
                return;
            }
            GUILayout.Space(10f);
            SkillEditorGUILayout.LightDivider(new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(SkillEditorStyles.TableRowBox, new GUILayoutOption[0]);
            GUILayout.Label(SkillEditorContent.GlobalsLabel, new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayout.Label(SkillEditorContent.VariableUseCountLabel, new GUILayoutOption[0]);
            GUILayout.EndHorizontal();
            List <NamedVariable> globalVariablesUsed = SkillSearch.GetGlobalVariablesUsed(SkillEditor.SelectedFsm);

            using (List <NamedVariable> .Enumerator enumerator = globalVariablesUsed.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    NamedVariable current = enumerator.get_Current();
                    GUILayout.BeginHorizontal(SkillEditorStyles.TableRowBox, new GUILayoutOption[0]);
                    GUIStyle tableRowText = SkillEditorStyles.TableRowText;
                    if (GUILayout.Button(new GUIContent(current.get_Name(), current.get_Tooltip()), tableRowText, new GUILayoutOption[]
                    {
                        GUILayout.MinWidth(155f)
                    }))
                    {
                        Keyboard.ResetFocus();
                        this.Deselect();
                        if (Event.get_current().get_button() == 1 || EditorGUI.get_actionKey())
                        {
                            FsmVariablesEditor.DoGlobalVariableContextMenu(current);
                        }
                    }
                    int globalVariablesUsageCount = SkillSearch.GetGlobalVariablesUsageCount(current);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label(globalVariablesUsageCount.ToString(CultureInfo.get_CurrentCulture()), tableRowText, new GUILayoutOption[0]);
                    GUILayout.Space(10f);
                    GUILayout.EndHorizontal();
                    if (FsmEditorSettings.DebugVariables)
                    {
                        SkillEditorGUILayout.ReadonlyTextField(current.ToString(), new GUILayoutOption[0]);
                    }
                }
            }
        }
Пример #32
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="vm_"></param>
        public NewNamedVarWindow(NamedVariable var_ = null)
        {
            InitializeComponent();

            if (var_ == null)
            {
                Title = "New named variable";
                comboBox.SelectedIndex = 0;
            }
            else
            {
                InputName = var_.Name;
                comboBox.IsEnabled = false;
            }

            Closing += new CancelEventHandler(OnClosing);
        }
Пример #33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vm_"></param>
        public NewNamedVarWindow(NamedVariable var_ = null)
        {
            InitializeComponent();

            if (var_ == null)
            {
                Title = "New named variable";
                comboBox.SelectedIndex = 0;
            }
            else
            {
                InputName          = var_.Name;
                comboBox.IsEnabled = false;
            }

            Closing += new CancelEventHandler(OnClosing);
        }
Пример #34
0
        private void InitFsmVar()
        {
            GameObject ownerDefaultTarget = base.Fsm.GetOwnerDefaultTarget(gameObject);

            if (!(ownerDefaultTarget == null) && ownerDefaultTarget != cachedGO)
            {
                sourceFsm       = ActionHelpers.GetGameObjectFsm(ownerDefaultTarget, fsmName.Value);
                sourceVariable  = sourceFsm.FsmVariables.GetVariable(storeValue.variableName);
                targetVariable  = base.Fsm.Variables.GetVariable(storeValue.variableName);
                storeValue.Type = targetVariable.VariableType;
                if (!string.IsNullOrEmpty(storeValue.variableName) && sourceVariable == null)
                {
                    LogWarning("Missing Variable: " + storeValue.variableName);
                }
                cachedGO = ownerDefaultTarget;
            }
        }
Пример #35
0
    void SelectFsmVariableGUI(FsmVariables fsmVariables)
    {
        NamedVariable[] _list = new NamedVariable[0];

        if (_target.fsmVariableSetup.variableType == VariableType.Bool)
        {
            _list = fsmVariables.GetNames(typeof(FsmBool));
        }
        else if (_target.fsmVariableSetup.variableType == VariableType.Int)
        {
            _list = fsmVariables.GetNames(typeof(FsmInt));
        }
        else if (_target.fsmVariableSetup.variableType == VariableType.Float)
        {
            _list = fsmVariables.GetNames(typeof(FsmFloat));
        }
        else if (_target.fsmVariableSetup.variableType == VariableType.Vector2)
        {
            _list = fsmVariables.GetNames(typeof(FsmVector2));
        }
        else if (_target.fsmVariableSetup.variableType == VariableType.String)
        {
            _list = fsmVariables.GetNames(typeof(FsmString));
        }


        _variableChoices = new string[_list.Length];
        for (int i = 0; i < _list.Length; i++)
        {
            _variableChoices[i] = _list[i].Name;
        }

        if (_variableChoices.Length == 0)
        {
            ErrorFeedbackGui("No " + _target.fsmVariableSetup.variableType + " variable on Fsm");
        }
        else
        {
            int _choiceIndex = EditorGUILayout.Popup(_target.fsmVariableSetup.variableType.ToString() + " Variable", _target.fsmVariableSetup.variableIndex, _variableChoices);
            if (_choiceIndex != _target.fsmVariableSetup.variableIndex || string.IsNullOrEmpty(_target.fsmVariableSetup.variableName))
            {
                _target.fsmVariableSetup.variableIndex = _choiceIndex;
                _target.fsmVariableSetup.variableName  = _variableChoices[_choiceIndex];
            }
        }
    }
Пример #36
0
        private void DoSetFsmVariable()
        {
            if (setValue.IsNone || string.IsNullOrEmpty(variableName.Value))
            {
                return;
            }

            var go = Fsm.GetOwnerDefaultTarget(gameObject);

            if (go == null)
            {
                return;
            }

            if (go != cachedGameObject || fsmName.Value != cachedFsmName)
            {
                targetFsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
                if (targetFsm == null)
                {
                    return;
                }
                cachedGameObject = go;
                cachedFsmName    = fsmName.Value;
            }

            if (variableName.Value != cachedVariableName)
            {
                targetVariable = targetFsm.FsmVariables.FindVariable(setValue.Type, variableName.Value);

                cachedVariableName = variableName.Value;
            }

            UnityEngine.Debug.Log(setValue);
            if (targetVariable == null)
            {
                LogWarning("Missing Variable: " + variableName.Value);
                return;
            }
                        #if PLAYMAKER_UTILS
            targetVariable.RawValue = PlayMakerUtils.GetValueFromFsmVar(this.Fsm, setValue);
                        #else
            UnityEngine.Debug.LogError("Missing PlayMaker Utils.Please get it from the Ecosystem");
                        #endif
        }
Пример #37
0
 private void InitFsmVar()
 {
     GameObject ownerDefaultTarget = base.Fsm.GetOwnerDefaultTarget(this.gameObject);
     if (ownerDefaultTarget == null)
     {
         return;
     }
     if (ownerDefaultTarget != this.cachedGO)
     {
         this.sourceFsm = ActionHelpers.GetGameObjectFsm(ownerDefaultTarget, this.fsmName.Value);
         this.sourceVariable = this.sourceFsm.FsmVariables.GetVariable(this.setValue.variableName);
         this.targetVariable = base.Fsm.Variables.GetVariable(this.setValue.variableName);
         this.setValue.Type = FsmUtility.GetVariableType(this.targetVariable);
         if (!string.IsNullOrEmpty(this.setValue.variableName) && this.sourceVariable == null)
         {
             this.LogWarning("Missing Variable: " + this.setValue.variableName);
         }
         this.cachedGO = ownerDefaultTarget;
     }
 }
        private void DoSetFsmVariable()
        {
            if (setValue.IsNone || string.IsNullOrEmpty(variableName.Value))
            {
                return;
            }

            var go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null)
            {
                return;
            }

            if (go != cachedGameObject || fsmName.Value != cachedFsmName)
            {
                targetFsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
                if (targetFsm == null)
                {
                    return;
                }
                cachedGameObject = go;
                cachedFsmName = fsmName.Value;
            }

            if (variableName.Value != cachedVariableName)
            {
                targetVariable = targetFsm.FsmVariables.FindVariable(setValue.Type, variableName.Value);
                cachedVariableName = variableName.Value;
            }

            if (targetVariable == null)
            {
                LogWarning("Missing Variable: " + variableName.Value);
                return;
            }

            setValue.ApplyValueTo(targetVariable);
        }
 public void TestOnlyConstantAssignments()
 {
     var a = new NamedVariable("a");
     var b = new NamedVariable("bb");
     var c = new NamedVariable("ccc");
     var d = new NamedVariable("dd_dd");
     IDictionary<Variable, double> result = StraightforwardSubstitutionSolver.Solve(-100, 100,
         new[] {
             new EqualsZeroConstraint(new BinaryExpression(a, new Plus(), new Constant(-6))),
             new EqualsZeroConstraint(new BinaryExpression(b, new Plus(),
                 new UnaryExpression(
                     new BinaryExpression(new Constant(3), new Times(), new Constant(2)),
                     new UnaryMinus())
                 )
             ),
             new EqualsZeroConstraint(new BinaryExpression(c, new Plus(), new UnaryExpression(new Constant(6), new UnaryMinus()))),
             new EqualsZeroConstraint(new BinaryExpression(d, new Plus(), new UnaryExpression(new UnaryExpression(new Constant(36), new Squareroot()), new UnaryMinus()))),
         });
     Assert.AreEqual(6, result[a]);
     Assert.AreEqual(6, result[b]);
     Assert.AreEqual(6, result[c]);
     Assert.AreEqual(6, result[d]);
 }
Пример #40
0
        void InitFsmVar()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null)
            {
                return;
            }

            if (go != cachedGO)
            {
                sourceFsm = ActionHelpers.GetGameObjectFsm(go, fsmName.Value);
                sourceVariable = sourceFsm.FsmVariables.GetVariable(storeValue.variableName);
                targetVariable = Fsm.Variables.GetVariable(storeValue.variableName);
                storeValue.Type = targetVariable.VariableType;

                if (!string.IsNullOrEmpty(storeValue.variableName) && sourceVariable == null)
                {
                    LogWarning("Missing Variable: " + storeValue.variableName);
                }

                cachedGO = go;
            }
        }
Пример #41
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name_"></param>
 /// <param name="var_"></param>
 public void Add(string name_, object var_)
 {
     NamedVariable namedVar = new NamedVariable(name_, new ValueContainer(var_ == null ? null : var_.GetType(), var_));
     m_Vars.Add(namedVar);
 }
 public void TestSquareRootEquation()
 {
     var a = new NamedVariable("a");
     IDictionary<Variable, double> result = StraightforwardSubstitutionSolver.Solve(-100, 100,
         new[] { new EqualsZeroConstraint(
             new BinaryExpression(a,
                 new Plus(),
                 new UnaryExpression(
                     new UnaryExpression(
                         a,
                         new Squareroot()),
                     new UnaryMinus()))) });
     Assert.IsTrue(result[a].Near(0) || result[a].Near(1));
 }
 public void TestSimpleReversedTree()
 {
     var a = new NamedVariable("a");
     var b = new NamedVariable("b");
     var c = new NamedVariable("c");
     var d = new NamedVariable("d");
     IDictionary<Variable, double> result = StraightforwardSubstitutionSolver.Solve(-100, 100,
         new[] {
                   new EqualsZeroConstraint(new BinaryExpression(a, new Plus(), new UnaryExpression(c, new Squareroot()))),
                   new EqualsZeroConstraint(new BinaryExpression(b, new Plus(), new UnaryExpression(c, new Squareroot()))),
                   new EqualsZeroConstraint(new BinaryExpression(c, new Plus(), new UnaryExpression(new UnaryExpression(d, new Squareroot()), new UnaryMinus()))),
                   new EqualsZeroConstraint(new BinaryExpression(d, new Plus(), new UnaryExpression(new Constant(81), new UnaryMinus())))
               });
     Assert.AreEqual(-3, result[a]);
     Assert.AreEqual(-3, result[b]);
     Assert.AreEqual(9, result[c]);
     Assert.AreEqual(81, result[d]);
 }
	void SelectFsmVariableGUI(FsmVariables fsmVariables)
	{
		NamedVariable[] _list = new NamedVariable[0];
		
		if (_target.fsmVariableSetup.variableType == VariableType.Bool)
		{
			_list = fsmVariables.GetNames(typeof(FsmBool));
		}else if (_target.fsmVariableSetup.variableType == VariableType.Float)
		{
			_list = fsmVariables.GetNames(typeof(FsmFloat));
		}else if (_target.fsmVariableSetup.variableType == VariableType.Vector2)
		{
			_list = fsmVariables.GetNames(typeof(FsmVector2));
		}else if (_target.fsmVariableSetup.variableType == VariableType.String)
		{
			_list = fsmVariables.GetNames(typeof(FsmString));
		}


		_variableChoices = new string[_list.Length];
		for(int i=0;i<_list.Length;i++)
		{
			_variableChoices[i] = _list[i].Name;
		}

		if (_variableChoices.Length==0)
		{
			ErrorFeedbackGui("No "+_target.fsmVariableSetup.variableType+" variable on Fsm");
		}else{
			int _choiceIndex =  EditorGUILayout.Popup(_target.fsmVariableSetup.variableType.ToString()+" Variable",_target.fsmVariableSetup.variableIndex,_variableChoices);
			if (_choiceIndex!=_target.fsmVariableSetup.variableIndex || string.IsNullOrEmpty(_target.fsmVariableSetup.variableName))
			{
				_target.fsmVariableSetup.variableIndex =_choiceIndex;
				_target.fsmVariableSetup.variableName = _variableChoices[_choiceIndex];
			}
		}

	}
Пример #45
0
		public bool GetVariable(PlayMakerFsmVariableTarget variableTarget)
		{
			initialized = true;
			targetUndefined = true;
			if (variableTarget.FsmVariables !=null)
			{
				targetUndefined = false;
				variableNameToUse = string.IsNullOrEmpty(variableName)?defaultVariableName:variableName;

				fsmVariables = variableTarget.FsmVariables;
				_namedVariable = fsmVariables.GetVariable(variableNameToUse);

				if (_namedVariable !=null)
				{
					#if PLAYMAKER_1_8
					selectedType = _namedVariable.VariableType;
					#else
					selectedType = GetTypeFromChoice(variableSelectionChoice);
					#endif
					return true;
				}
			}

			selectedType = VariableType.Unknown;
			
			return false;
		}
Пример #46
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name_"></param>
 /// <param name="var_"></param>
 private void Add(string name_, ValueContainer var_)
 {
     NamedVariable namedVar = new NamedVariable(name_, var_);
     m_Vars.Add(namedVar);
 }
 public void TestSimpleLinearEquation1()
 {
     var a = new NamedVariable("a");
     IDictionary<Variable, double> result = StraightforwardSubstitutionSolver.Solve(-100, 100,
         new[] {
             new EqualsZeroConstraint(
                 new BinaryExpression(
                     a,
                     new Plus(),
                     new UnaryExpression(
                         new BinaryExpression(
                             new Constant(4),
                             new Plus(),
                             new UnaryExpression(a, new UnaryMinus())
                         ),
                         new UnaryMinus()
                     )
                 )
             )
         });
     Assert.AreEqual(2, result[a]);
 }
        public void TestToStringPrecedence()
        {
            var a = new NamedVariable("a");
            var constraint = (a * (a * a + (-new Constant(1))) + new Constant(6)).EqualsZero();
            string[] result = constraint.ToString().Replace(" ", "").Split('[');

            Assert.AreEqual("0=a*(a*a+-1)+6", result[0]);
        }
Пример #49
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node_"></param>
 protected override void Load(XmlNode node_)
 {
     base.Load(node_);
     m_Value = (NamedVariable)LoadValue(node_.SelectSingleNode("Value"));
 }
Пример #50
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name_"></param>
 public void Remove(NamedVariable var_)
 {
     m_Vars.Remove(var_);
 }