private void SetVariable (GVar newVar, VariableLocation _newLocation, GVar oldVar)
		{
			if (newVar == null || oldVar == null)
			{
				return;
			}

			if (oldLocation == VariableLocation.Global)
			{
				oldVar.Download ();
			}

			if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean)
			{
				int oldValue = oldVar.val;
				newVar.SetValue (oldValue, SetVarMethod.SetValue);
			}
			else if (newVar.type == VariableType.Float)
			{
				float oldValue = oldVar.floatVal;
				newVar.SetValue (oldValue, AC.SetVarMethod.SetValue);
			}
			else if (newVar.type == VariableType.String)
			{
				string oldValue = oldVar.textVal;
				newVar.SetValue (oldValue);
			}

			if (_newLocation == VariableLocation.Global)
			{
				newVar.Upload ();
			}

			GameObject.FindWithTag (Tags.gameEngine).GetComponent <ActionListManager>().VariableChanged ();
		}
Exemple #2
0
        public override void ShowGUI(List <ActionParameter> parameters)
        {
            location = (VariableLocation)EditorGUILayout.EnumPopup("Source:", location);

            switch (location)
            {
            case VariableLocation.Global:
                if (AdvGame.GetReferences().variablesManager != null)
                {
                    parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.GlobalVariable);
                    if (parameterID >= 0)
                    {
                        placeholderPopUpLabelDataID = AdvGame.GetReferences().variablesManager.ShowPlaceholderPresetData(placeholderPopUpLabelDataID);
                        if (placeholderPopUpLabelDataID <= 0)
                        {
                            placeholderNumValues = EditorGUILayout.DelayedIntField("Placeholder # of values:", placeholderNumValues);
                            if (placeholderNumValues < 1)
                            {
                                placeholderNumValues = 1;
                            }
                        }
                    }
                    else
                    {
                        variableID = AdvGame.GlobalVariableGUI("PopUp variable:", variableID, VariableType.PopUp);
                    }
                }
                break;

            case VariableLocation.Local:
                if (isAssetFile)
                {
                    EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info);
                }
                else if (localVariables == null)
                {
                    EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                }
                else
                {
                    parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.LocalVariable);
                    if (parameterID >= 0)
                    {
                        placeholderPopUpLabelDataID = AdvGame.GetReferences().variablesManager.ShowPlaceholderPresetData(placeholderPopUpLabelDataID);
                        if (placeholderPopUpLabelDataID <= 0)
                        {
                            placeholderNumValues = EditorGUILayout.DelayedIntField("Placeholder # of values:", placeholderNumValues);
                            if (placeholderNumValues < 1)
                            {
                                placeholderNumValues = 1;
                            }
                        }
                    }
                    else
                    {
                        variableID = AdvGame.LocalVariableGUI("PopUp variable:", variableID, VariableType.PopUp);
                    }
                }
                break;

            case VariableLocation.Component:
                parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.ComponentVariable);
                if (parameterID >= 0)
                {
                    placeholderPopUpLabelDataID = AdvGame.GetReferences().variablesManager.ShowPlaceholderPresetData(placeholderPopUpLabelDataID);
                    if (placeholderPopUpLabelDataID <= 0)
                    {
                        placeholderNumValues = EditorGUILayout.DelayedIntField("Placeholder # of values:", placeholderNumValues);
                        if (placeholderNumValues < 1)
                        {
                            placeholderNumValues = 1;
                        }
                    }
                }
                else
                {
                    variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                    variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                    variables           = IDToField <Variables> (variables, variablesConstantID, false);

                    if (variables != null)
                    {
                        variableID = AdvGame.ComponentVariableGUI("PopUp variable:", variableID, VariableType.PopUp, variables);
                    }
                }
                break;
            }

            if (parameterID >= 0)
            {
                numSockets = placeholderNumValues;
                PopUpLabelData popUpLabelData = AdvGame.GetReferences().variablesManager.GetPopUpLabelData(placeholderPopUpLabelDataID);
                if (popUpLabelData != null)
                {
                    numSockets           = popUpLabelData.Length;
                    placeholderNumValues = numSockets;
                }
            }
            else
            {
                GVar _var = GetVariable();
                if (_var != null)
                {
                    numSockets                  = _var.GetNumPopUpValues();
                    placeholderNumValues        = numSockets;
                    placeholderPopUpLabelDataID = _var.popUpID;
                }
            }

            if (numSockets == 0)
            {
                EditorGUILayout.HelpBox("The selected variable has no values!", MessageType.Warning);
            }
        }
        private void ShowVarGUI(VariableLocation location, List <VarPreset> _varPresets = null, string apiPrefix = "")
        {
            EditorGUILayout.BeginVertical(CustomStyles.thinBox);
            showVariablesProperties = CustomGUILayout.ToggleHeader(showVariablesProperties, location + " variable '" + selectedVar.label + "' properties");
            if (showVariablesProperties)
            {
                selectedVar.label = CustomGUILayout.TextField("Label:", selectedVar.label, apiPrefix + ".label");
                selectedVar.type  = (VariableType)CustomGUILayout.EnumPopup("Type:", selectedVar.type, apiPrefix + ".type");

                if (selectedVar.type == VariableType.Boolean)
                {
                    if (selectedVar.val != 1)
                    {
                        selectedVar.val = 0;
                    }
                    selectedVar.val = CustomGUILayout.Popup("Initial value:", selectedVar.val, boolType, apiPrefix + ".val");
                }
                else if (selectedVar.type == VariableType.Integer)
                {
                    selectedVar.val = CustomGUILayout.IntField("Initial value:", selectedVar.val, apiPrefix + ".val");
                }
                else if (selectedVar.type == VariableType.PopUp)
                {
                    selectedVar.popUps       = PopupsGUI(selectedVar.popUps);
                    selectedVar.val          = CustomGUILayout.Popup("Initial value:", selectedVar.val, selectedVar.popUps, apiPrefix + ".val");
                    selectedVar.canTranslate = CustomGUILayout.Toggle("Values can be translated?", selectedVar.canTranslate, apiPrefix + ".canTranslate");
                }
                else if (selectedVar.type == VariableType.String)
                {
                    selectedVar.textVal      = CustomGUILayout.TextField("Initial value:", selectedVar.textVal, apiPrefix + ".textVal");
                    selectedVar.canTranslate = CustomGUILayout.Toggle("Values can be translated?", selectedVar.canTranslate, apiPrefix + ".canTranslate");
                }
                else if (selectedVar.type == VariableType.Float)
                {
                    selectedVar.floatVal = CustomGUILayout.FloatField("Initial value:", selectedVar.floatVal, apiPrefix + ".floatVal");
                }
                else if (selectedVar.type == VariableType.Vector3)
                {
                    selectedVar.vector3Val = CustomGUILayout.Vector3Field("Initial value:", selectedVar.vector3Val, apiPrefix + ".vector3Val");
                }

                if (location == VariableLocation.Local)
                {
                    CustomGUILayout.TokenLabel("[localvar:" + selectedVar.id.ToString() + "]");
                }
                else
                {
                    CustomGUILayout.TokenLabel("[var:" + selectedVar.id.ToString() + "]");
                }

                if (_varPresets != null)
                {
                    foreach (VarPreset _varPreset in _varPresets)
                    {
                        // Local
                        string apiPrefix2 = (location == VariableLocation.Local) ?
                                            "AC.KickStarter.localVariables.GetPreset (" + _varPreset.ID + ").GetPresetValue (" + selectedVar.id + ")" :
                                            "AC.KickStarter.runtimeVariables.GetPreset (" + _varPreset.ID + ").GetPresetValue (" + selectedVar.id + ")";

                        _varPreset.UpdateCollection(selectedVar);

                        string      label       = "'" + _varPreset.label + "' value:";
                        PresetValue presetValue = _varPreset.GetPresetValue(selectedVar);
                        if (selectedVar.type == VariableType.Boolean)
                        {
                            presetValue.val = CustomGUILayout.Popup(label, presetValue.val, boolType, apiPrefix2 + ".val");
                        }
                        else if (selectedVar.type == VariableType.Integer)
                        {
                            presetValue.val = CustomGUILayout.IntField(label, presetValue.val, apiPrefix2 + ".val");
                        }
                        else if (selectedVar.type == VariableType.PopUp)
                        {
                            presetValue.val = CustomGUILayout.Popup(label, presetValue.val, selectedVar.popUps, apiPrefix2 + ".val");
                        }
                        else if (selectedVar.type == VariableType.String)
                        {
                            presetValue.textVal = CustomGUILayout.TextField(label, presetValue.textVal, apiPrefix2 + ".textVal");
                        }
                        else if (selectedVar.type == VariableType.Float)
                        {
                            presetValue.floatVal = CustomGUILayout.FloatField(label, presetValue.floatVal, apiPrefix2 + ".floatVal");
                        }
                        else if (selectedVar.type == VariableType.Vector3)
                        {
                            presetValue.vector3Val = CustomGUILayout.Vector3Field(label, presetValue.vector3Val, apiPrefix2 + ".vector3Val");
                        }
                    }
                }

                EditorGUILayout.Space();
                if (location == VariableLocation.Local)
                {
                    selectedVar.link = VarLink.None;
                }
                else
                {
                    selectedVar.link = (VarLink)CustomGUILayout.EnumPopup("Link to:", selectedVar.link, apiPrefix + ".link");
                    if (selectedVar.link == VarLink.PlaymakerGlobalVariable)
                    {
                        if (PlayMakerIntegration.IsDefinePresent())
                        {
                            selectedVar.pmVar             = CustomGUILayout.TextField("Playmaker Global Variable:", selectedVar.pmVar, apiPrefix + ".pmVar");
                            selectedVar.updateLinkOnStart = CustomGUILayout.Toggle("Use PM for initial value?", selectedVar.updateLinkOnStart, apiPrefix + ".updateLinkOnStart");
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The 'PlayMakerIsPresent' Scripting Define Symbol must be listed in the\nPlayer Settings. Please set it from Edit -> Project Settings -> Player", MessageType.Warning);
                        }
                    }
                    else if (selectedVar.link == VarLink.OptionsData)
                    {
                        EditorGUILayout.HelpBox("This Variable will be stored in PlayerPrefs, and not in saved game files.", MessageType.Info);
                    }
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Internal description:", GUILayout.MaxWidth(146f));
                selectedVar.description = EditorGUILayout.TextArea(selectedVar.description);
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
        }
Exemple #4
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            parameterID = Action.ChooseParameterGUI("Moveable object:", parameters, parameterID, ParameterType.GameObject);
            if (parameterID >= 0)
            {
                constantID = 0;
                linkedProp = null;
            }
            else
            {
                linkedProp = (Moveable)EditorGUILayout.ObjectField("Moveable object:", linkedProp, typeof(Moveable), true);

                constantID = FieldToID <Moveable> (linkedProp, constantID);
                linkedProp = IDToField <Moveable> (linkedProp, constantID, false);
            }

            EditorGUILayout.BeginHorizontal();
            transformType = (TransformType)EditorGUILayout.EnumPopup(transformType);
            if (transformType != TransformType.CopyMarker)
            {
                toBy = (ToBy)EditorGUILayout.EnumPopup(toBy);
            }
            EditorGUILayout.EndHorizontal();

            if (transformType == TransformType.CopyMarker)
            {
                markerParameterID = Action.ChooseParameterGUI("Marker:", parameters, markerParameterID, ParameterType.GameObject);
                if (markerParameterID >= 0)
                {
                    markerID = 0;
                    marker   = null;
                }
                else
                {
                    marker = (Marker)EditorGUILayout.ObjectField("Marker:", marker, typeof(Marker), true);

                    markerID = FieldToID <Marker> (marker, markerID);
                    marker   = IDToField <Marker> (marker, markerID, false);
                }
            }
            else
            {
                setVectorMethod = (SetVectorMethod)EditorGUILayout.EnumPopup("Vector is: ", setVectorMethod);
                if (setVectorMethod == SetVectorMethod.EnteredHere)
                {
                    newVectorParameterID = Action.ChooseParameterGUI("Value:", parameters, newVectorParameterID, ParameterType.Vector3);
                    if (newVectorParameterID < 0)
                    {
                        newVector = EditorGUILayout.Vector3Field("Value:", newVector);
                    }
                }
                else if (setVectorMethod == SetVectorMethod.FromVector3Variable)
                {
                    if (isAssetFile)
                    {
                        variableLocation = VariableLocation.Global;
                    }
                    else
                    {
                        variableLocation = (VariableLocation)EditorGUILayout.EnumPopup("Source:", variableLocation);
                    }

                    if (variableLocation == VariableLocation.Global)
                    {
                        vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.GlobalVariable);
                        if (vectorVarParameterID < 0)
                        {
                            vectorVarID = AdvGame.GlobalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                        }
                    }
                    else if (variableLocation == VariableLocation.Local)
                    {
                        vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.LocalVariable);
                        if (vectorVarParameterID < 0)
                        {
                            vectorVarID = AdvGame.LocalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                        }
                    }
                }

                clearExisting = EditorGUILayout.Toggle("Stop existing transforms?", clearExisting);
            }

            if (transformType == TransformType.CopyMarker ||
                (transformType == TransformType.Translate && toBy == ToBy.To) ||
                (transformType == TransformType.Rotate && toBy == ToBy.To))
            {
                inWorldSpace = EditorGUILayout.Toggle("Act in world-space?", inWorldSpace);

                if (inWorldSpace && transformType == TransformType.CopyMarker)
                {
                    EditorGUILayout.HelpBox("The moveable object's scale will be changed in local space.", MessageType.Info);
                }
            }

            transitionTimeParameterID = Action.ChooseParameterGUI("Transition time (s):", parameters, transitionTimeParameterID, ParameterType.Float);
            if (transitionTimeParameterID < 0)
            {
                transitionTime = EditorGUILayout.Slider("Transition time (s):", transitionTime, 0, 10f);
            }

            if (transitionTime > 0f)
            {
                if (transformType == TransformType.Rotate)
                {
                    doEulerRotation = EditorGUILayout.Toggle("Euler rotation?", doEulerRotation);
                }
                moveMethod = (MoveMethod)EditorGUILayout.EnumPopup("Move method:", moveMethod);
                if (moveMethod == MoveMethod.CustomCurve)
                {
                    timeCurve = EditorGUILayout.CurveField("Time curve:", timeCurve);
                }
                willWait = EditorGUILayout.Toggle("Wait until finish?", willWait);
            }

            AfterRunningOption();
        }
Exemple #5
0
        public static string CreateVariablesData(List<GVar> vars, bool isOptionsData, VariableLocation location)
        {
            System.Text.StringBuilder variablesString = new System.Text.StringBuilder ();

            foreach (GVar _var in vars)
            {
                if ((isOptionsData && _var.link == VarLink.OptionsData) || (!isOptionsData && _var.link != VarLink.OptionsData) || location == VariableLocation.Local)
                {
                    variablesString.Append (_var.id.ToString ());
                    variablesString.Append (":");
                    if (_var.type == VariableType.String)
                    {
                        string textVal = _var.textVal;
                        textVal = textVal.Replace ("|", "*PIPE*");
                        textVal = textVal.Replace (":", "*COLON*");
                        variablesString.Append (textVal);
                    }
                    else if (_var.type == VariableType.Float)
                    {
                        variablesString.Append (_var.floatVal.ToString ());
                    }
                    else
                    {
                        variablesString.Append (_var.val.ToString ());
                    }
                    variablesString.Append ("|");
                }
            }

            if (variablesString.Length > 0)
            {
                variablesString.Remove (variablesString.Length-1, 1);
            }

            return variablesString.ToString ();
        }
Exemple #6
0
        private void SetVariable(GVar newVar, VariableLocation _newLocation, GVar oldVar)
        {
            if (newVar == null || oldVar == null)
            {
                ACDebug.LogWarning ("Cannot copy variable since it cannot be found!");
                return;
            }

            if (oldLocation == VariableLocation.Global)
            {
                oldVar.Download ();
            }

            if (newVar.type == VariableType.Integer || newVar.type == VariableType.Boolean)
            {
                int oldValue = oldVar.val;
                newVar.SetValue (oldValue, SetVarMethod.SetValue);
            }
            else if (newVar.type == VariableType.Float)
            {
                float oldValue = oldVar.floatVal;
                newVar.SetFloatValue (oldValue, AC.SetVarMethod.SetValue);
            }
            else if (newVar.type == VariableType.String)
            {
                string oldValue = oldVar.textVal;
                newVar.SetStringValue (oldValue);
            }

            if (_newLocation == VariableLocation.Global)
            {
                newVar.Upload ();
            }

            KickStarter.actionListManager.VariableChanged ();
        }
Exemple #7
0
        private void ShowVarGUI(VariableLocation location, List<VarPreset> _varPresets = null)
        {
            EditorGUILayout.LabelField (location + " variable '" + selectedVar.label + "' properties", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical("Button");

            selectedVar.label = EditorGUILayout.TextField ("Label:", selectedVar.label);
            selectedVar.type = (VariableType) EditorGUILayout.EnumPopup ("Type:", selectedVar.type);

            if (location == VariableLocation.Local)
            {
                EditorGUILayout.LabelField ("Replacement token:", "[localvar:" + selectedVar.id.ToString () + "]");
            }
            else
            {
                EditorGUILayout.LabelField ("Replacement token:", "[var:" + selectedVar.id.ToString () + "]");
            }

            if (selectedVar.type == VariableType.Boolean)
            {
                if (selectedVar.val != 1)
                {
                    selectedVar.val = 0;
                }
                selectedVar.val = EditorGUILayout.Popup ("Initial value:", selectedVar.val, boolType);
            }
            else if (selectedVar.type == VariableType.Integer)
            {
                selectedVar.val = EditorGUILayout.IntField ("Initial value:", selectedVar.val);
            }
            else if (selectedVar.type == VariableType.PopUp)
            {
                selectedVar.popUps = PopupsGUI (selectedVar.popUps);
                selectedVar.val = EditorGUILayout.Popup ("Initial value:", selectedVar.val, selectedVar.popUps);
            }
            else if (selectedVar.type == VariableType.String)
            {
                selectedVar.textVal = EditorGUILayout.TextField ("Initial value:", selectedVar.textVal);
            }
            else if (selectedVar.type == VariableType.Float)
            {
                selectedVar.floatVal = EditorGUILayout.FloatField ("Initial value:", selectedVar.floatVal);
            }

            if (_varPresets != null)
            {
                foreach (VarPreset _varPreset in _varPresets)
                {
                    _varPreset.UpdateCollection (selectedVar);

                    string label = "'" + _varPreset.label + "' value:";
                    PresetValue presetValue = _varPreset.GetPresetValue (selectedVar);
                    if (selectedVar.type == VariableType.Boolean)
                    {
                        presetValue.val = EditorGUILayout.Popup (label, presetValue.val, boolType);
                    }
                    else if (selectedVar.type == VariableType.Integer)
                    {
                        presetValue.val = EditorGUILayout.IntField (label, presetValue.val);
                    }
                    else if (selectedVar.type == VariableType.PopUp)
                    {
                        presetValue.val = EditorGUILayout.Popup (label, presetValue.val, selectedVar.popUps);
                    }
                    else if (selectedVar.type == VariableType.String)
                    {
                        presetValue.textVal = EditorGUILayout.TextField (label, presetValue.textVal);
                    }
                    else if (selectedVar.type == VariableType.Float)
                    {
                        presetValue.floatVal = EditorGUILayout.FloatField (label, presetValue.floatVal);
                    }
                }
            }

            if (location == VariableLocation.Local)
            {
                selectedVar.link = VarLink.None;
            }
            else
            {
                EditorGUILayout.Space ();
                selectedVar.link = (VarLink) EditorGUILayout.EnumPopup ("Link to:", selectedVar.link);
                if (selectedVar.link == VarLink.PlaymakerGlobalVariable)
                {
                    if (PlayMakerIntegration.IsDefinePresent ())
                    {
                        selectedVar.pmVar = EditorGUILayout.TextField ("Playmaker Global Variable:", selectedVar.pmVar);
                        selectedVar.updateLinkOnStart = EditorGUILayout.Toggle ("Use PM for initial value?", selectedVar.updateLinkOnStart);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox ("The 'PlayMakerIsPresent' Scripting Define Symbol must be listed in the\nPlayer Settings. Please set it from Edit -> Project Settings -> Player", MessageType.Warning);
                    }
                }
                else if (selectedVar.link == VarLink.OptionsData)
                {
                    EditorGUILayout.HelpBox ("This Variable will be stored in PlayerPrefs, and not in saved game files.", MessageType.Info);
                }
            }
            EditorGUILayout.EndVertical ();
        }
        public override void ShowGUI(List<ActionParameter> parameters)
        {
            if (isAssetFile)
            {
                location = VariableLocation.Global;
            }
            else
            {
                location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
            }

            if (location == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    variableID = ShowVarGUI (AdvGame.GetReferences ().variablesManager.vars, variableID, true);
                }
            }

            else if (location == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    variableID = ShowVarGUI (KickStarter.localVariables.localVars, variableID, true);
                }
            }

            GVar _var = GetVariable ();
            if (_var != null)
            {
                numSockets = _var.popUps.Length;
            }
        }
Exemple #9
0
 public void StoreArgument(int index)
 {
     Contract.Requires(VariableLocation.IsValidIndex(index));
     Instruction(Opcode.StoreArgument(index), index);
 }
Exemple #10
0
 public void LoadArgumentAddress(int index)
 {
     Contract.Requires(VariableLocation.IsValidIndex(index));
     Instruction(Opcode.LoadArgumentAddress(index), index);
 }
Exemple #11
0
 public void Store(VariableLocation location)
 {
     Instruction(Opcode.Store(location), location.Index);
 }
Exemple #12
0
 public void LoadAddress(VariableLocation location)
 {
     Instruction(Opcode.LoadAddress(location), location.Index);
 }
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            inventoryManager = AdvGame.GetReferences().inventoryManager;

            // Select Inventory item

            setVarAsPropertyMethod = (SetVarAsPropertyMethod)EditorGUILayout.EnumPopup("Get property of:", setVarAsPropertyMethod);
            if (setVarAsPropertyMethod == SetVarAsPropertyMethod.SpecificItem)
            {
                ShowInvSelectGUI(parameters);
            }

            // Select item property
            ShowInvPropertyGUI();

            EditorGUILayout.Space();

            // Select variable
            varLocation = (VariableLocation)EditorGUILayout.EnumPopup("Variable source:", varLocation);
            switch (varLocation)
            {
            case VariableLocation.Global:
                if (AdvGame.GetReferences().variablesManager)
                {
                    ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable);
                }
                break;

            case VariableLocation.Local:
                if (!isAssetFile)
                {
                    if (localVariables)
                    {
                        ShowVarGUI(localVariables.localVars, parameters, ParameterType.LocalVariable);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info);
                }
                break;

            case VariableLocation.Component:
                varParameterID = Action.ChooseParameterGUI("Component variable:", parameters, varParameterID, ParameterType.ComponentVariable);
                if (varParameterID >= 0)
                {
                    variables           = null;
                    variablesConstantID = 0;
                }
                else
                {
                    variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                    variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                    variables           = IDToField <Variables> (variables, variablesConstantID, false);

                    if (variables != null)
                    {
                        ShowVarGUI(variables.vars, null, ParameterType.ComponentVariable);
                    }
                }
                break;
            }

            if (inventoryManager != null && inventoryManager.invVars != null && inventoryManager.invVars.Count > 0)
            {
                if (varType != propertyType && varType != VariableType.String)
                {
                    EditorGUILayout.HelpBox("The chosen Inventory Item Property and Variable must share the same Type, or the Variable must be a String.", MessageType.Warning);
                }
            }

            AfterRunningOption();
        }
        //Functionality Methods =======
        protected void SetGoal(string variable_name, OperatorType operator_type, object variable_value, VariableLocation location = VariableLocation._local)
        {
            //First check if the variable exists in the current world state
            Variable_GS target_variable = null;

            if (location == VariableLocation._local)
            {
                target_variable = _agent.blackboard.GetObjectVariable(variable_name);
            }
            else
            {
                target_variable = GlobalBlackboard_GS.blackboard.GetObjectVariable(variable_name);
            }

            if (target_variable == null)
            {
                //In null case goal set is cancelled
                Debug.LogError("Variable: " + variable_name + " does not exist and can't be setted as goal");
                return;
            }

            //Check of the new goal value uses the correct type
            if (variable_value.GetType() != target_variable.value.GetType())
            {
                //In different types case the goal is not valid
                Debug.LogError("Behaviour " + _name + " is trying to set a " + variable_value.GetType() + "goal to a " + target_variable.value.GetType() + "variable");
                return;
            }

            string prefixed_name = (location == VariableLocation._local ? "Local/" : "Global/") + variable_name;

            //Check if the new goal is already defined in the goal world state
            Property_GS already_existing_property = null;

            if (agent.goal_world_state.properties.TryGetValue(prefixed_name, out already_existing_property))
            {
                //If the goal already exists we only change the goal value
                already_existing_property.value = variable_value;
            }
            else
            {
                //In correct and new goal case we simply add it to the goal world state
                agent.goal_world_state.SetGoal(prefixed_name, new Property_GS(prefixed_name, variable_value.GetType().ToVariableType(), operator_type, variable_value, target_variable.planning_value));
            }
        }
		override public void ShowGUI (List<ActionParameter> parameters)
		{
			if (isAssetFile)
			{
				location = VariableLocation.Global;
			}
			else
			{
				location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
			}
			
			if (location == VariableLocation.Global)
			{
				if (!variablesManager)
				{
					variablesManager = AdvGame.GetReferences ().variablesManager;
				}
				
				if (variablesManager)
				{
					ShowVarGUI (variablesManager.vars, parameters, ParameterType.GlobalVariable);
				}
			}
			
			else if (location == VariableLocation.Local)
			{
				if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>())
				{
					localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>();
				}
				
				if (localVariables)
				{
					ShowVarGUI (localVariables.localVars, parameters, ParameterType.LocalVariable);
				}
			}
		}
        private void SetVariable(GVar var, VariableLocation location, bool doSkip)
        {
            if (var == null)
            {
                return;
            }

            if (location == VariableLocation.Global)
            {
                var.Download();
            }

            if (var.type == VariableType.Integer)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables));
                    }
                    else
                    {
                        _value = intValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value       = animator.GetInteger(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            if (var.type == VariableType.Float)
            {
                float _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables));
                    }
                    else
                    {
                        _value = floatValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value       = animator.GetFloat(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetFloatValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            else if (var.type == VariableType.Boolean)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    _value = (int)boolValue;
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        if (animator.GetBool(parameterName))
                        {
                            _value = 1;
                        }
                    }
                }

                var.SetValue(_value, SetVarMethod.SetValue);
            }
            else if (var.type == VariableType.Vector3)
            {
                Vector3 newValue = vector3Value;
                if (setVarMethodVector == SetVarMethodVector.IncreaseByValue)
                {
                    newValue += var.vector3Val;
                }

                var.SetVector3Value(newValue);
            }
            else if (var.type == VariableType.PopUp)
            {
                int _value = 0;

                if (setVarMethod == SetVarMethod.Formula)
                {
                    _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula, Options.GetLanguage(), localVariables));
                }
                else if (setVarMethod == SetVarMethod.SetAsRandom)
                {
                    if (var.popUps != null)
                    {
                        _value = var.popUps.Length;
                    }
                }
                else
                {
                    _value = intValue;
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            else if (var.type == VariableType.String)
            {
                string _value = "";

                if (setVarMethodString == SetVarMethodString.EnteredHere)
                {
                    _value = AdvGame.ConvertTokens(stringValue, Options.GetLanguage(), localVariables);
                }
                else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText)
                {
                    MenuElement menuElement = PlayerMenus.GetElementWithName(menuName, elementName);
                    if (menuElement != null)
                    {
                        if (menuElement is MenuInput)
                        {
                            MenuInput menuInput = (MenuInput)menuElement;
                            _value = menuInput.GetContents();

                            if (KickStarter.runtimeLanguages.LanguageReadsRightToLeft(Options.GetLanguage()) && _value.Length > 0)
                            {
                                // Invert
                                char[] charArray = _value.ToCharArray();
                                _value = "";
                                for (int i = charArray.Length - 1; i >= 0; i--)
                                {
                                    _value += charArray[i];
                                }
                            }
                        }
                        else
                        {
                            PlayerMenus.GetMenuWithName(menuName).Recalculate();
                            menuElement.PreDisplay(slotNumber, Options.GetLanguage(), false);
                            _value = menuElement.GetLabel(slotNumber, Options.GetLanguage());
                        }
                    }
                    else
                    {
                        ACDebug.LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'");
                    }
                }

                var.SetStringValue(_value);
            }

            if (location == VariableLocation.Global)
            {
                var.Upload();
            }

            KickStarter.actionListManager.VariableChanged();
        }
		override public void ShowGUI (List<ActionParameter> parameters)
		{
			if (isAssetFile)
			{
				location = VariableLocation.Global;
			}
			else
			{
				location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
			}
			
			if (location == VariableLocation.Global)
			{
				if (!variablesManager)
				{
					variablesManager = AdvGame.GetReferences ().variablesManager;
				}
				
				if (variablesManager)
				{
					parameterID = Action.ChooseParameterGUI ("Integer variable:", parameters, parameterID, ParameterType.GlobalVariable);
					if (parameterID >= 0)
					{
						variableID = ShowVarGUI (variablesManager.vars, variableID, false);
					}
					else
					{
						variableID = ShowVarGUI (variablesManager.vars, variableID, true);
					}
				}
			}
			
			else if (location == VariableLocation.Local)
			{
				if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>())
				{
					localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>();
				}
				
				if (localVariables)
				{
					parameterID = Action.ChooseParameterGUI ("Integer variable:", parameters, parameterID, ParameterType.LocalVariable);
					if (parameterID >= 0)
					{
						variableID = ShowVarGUI (localVariables.localVars, variableID, false);
					}
					else
					{
						variableID = ShowVarGUI (localVariables.localVars, variableID, true);
					}
				}
			}
			
			numSockets = EditorGUILayout.IntSlider ("# of possible values:", numSockets, 1, 10);
			doLoop = EditorGUILayout.Toggle ("Run on a loop?", doLoop);
		}
		override public void ShowGUI (List<ActionParameter> parameters)
		{
			if (isAssetFile)
			{
				location = VariableLocation.Global;
			}
			else
			{
				location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
			}

			if (isAssetFile && getVarMethod == GetVarMethod.LocalVariable)
			{
				EditorGUILayout.HelpBox ("Local Variables cannot be referenced by Asset-based Actions.", MessageType.Warning);
			}

			if (location == VariableLocation.Global)
			{
				if (!variablesManager)
				{
					variablesManager = AdvGame.GetReferences ().variablesManager;
				}
				
				if (variablesManager)
				{
					parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, ParameterType.GlobalVariable);
					if (parameterID >= 0)
					{
						variableID = ShowVarGUI (parameters, variablesManager.vars, variableID, false);
					}
					else
					{
						variableID = ShowVarGUI (parameters, variablesManager.vars, variableID, true);
					}
				}
			}

			else if (location == VariableLocation.Local)
			{
				if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>())
				{
					localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>();
				}
				
				if (localVariables)
				{
					parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, ParameterType.LocalVariable);
					if (parameterID >= 0)
					{
						variableID = ShowVarGUI (parameters, localVariables.localVars, variableID, false);
					}
					else
					{
						variableID = ShowVarGUI (parameters, localVariables.localVars, variableID, true);
					}
				}
			}

		}
        public override void ShowGUI(List <ActionParameter> parameters)
        {
            numSockets = EditorGUILayout.DelayedIntField("# of possible values:", numSockets);
            numSockets = Mathf.Clamp(numSockets, 1, 100);

            disallowSuccessive = EditorGUILayout.Toggle("Prevent same value twice?", disallowSuccessive);

            if (disallowSuccessive)
            {
                saveToVariable = EditorGUILayout.Toggle("Save last value?", saveToVariable);
                if (saveToVariable)
                {
                    location = (VariableLocation)EditorGUILayout.EnumPopup("Variable source:", location);

                    if (location == VariableLocation.Local && KickStarter.localVariables == null)
                    {
                        EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                    }
                    else if (location == VariableLocation.Local && isAssetFile)
                    {
                        EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info);
                    }

                    if ((location == VariableLocation.Global && AdvGame.GetReferences().variablesManager != null) ||
                        (location == VariableLocation.Local && KickStarter.localVariables != null && !isAssetFile) ||
                        (location == VariableLocation.Component))
                    {
                        ParameterType _parameterType = ParameterType.GlobalVariable;
                        if (location == VariableLocation.Local)
                        {
                            _parameterType = ParameterType.LocalVariable;
                        }
                        else if (location == VariableLocation.Component)
                        {
                            _parameterType = ParameterType.ComponentVariable;
                        }

                        parameterID = Action.ChooseParameterGUI("Integer variable:", parameters, parameterID, _parameterType);
                        if (parameterID >= 0)
                        {
                            if (location == VariableLocation.Component)
                            {
                                variablesConstantID = 0;
                                variables           = null;
                            }

                            variableID = ShowVarGUI(variableID, false);
                        }
                        else
                        {
                            if (location == VariableLocation.Component)
                            {
                                variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                                variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                                variables           = IDToField <Variables> (variables, variablesConstantID, false);

                                if (variables != null)
                                {
                                    variableID = ShowVarGUI(variableID, true);
                                }
                            }
                            else
                            {
                                EditorGUILayout.BeginHorizontal();
                                variableID = ShowVarGUI(variableID, true);

                                if (GUILayout.Button(string.Empty, CustomStyles.IconCog))
                                {
                                    SideMenu();
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }
                }
            }
        }
Exemple #20
0
        private void SideMenu(GVar _var, List<GVar> _vars, VariableLocation location)
        {
            GenericMenu menu = new GenericMenu ();
            sideVar = _vars.IndexOf (_var);
            sideVarLocation = location;

            menu.AddItem (new GUIContent ("Insert after"), false, Callback, "Insert after");
            if (_vars.Count > 0)
            {
                menu.AddItem (new GUIContent ("Delete"), false, Callback, "Delete");
            }
            if (sideVar > 0 || sideVar < _vars.Count-1)
            {
                menu.AddSeparator ("");
            }
            if (sideVar > 0)
            {
                menu.AddItem (new GUIContent ("Move up"), false, Callback, "Move up");
            }
            if (sideVar < _vars.Count-1)
            {
                menu.AddItem (new GUIContent ("Move down"), false, Callback, "Move down");
            }

            menu.ShowAsContext ();
        }
Exemple #21
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            // OLD

            if (isAssetFile)
            {
                oldLocation = VariableLocation.Global;
            }
            else
            {
                oldLocation = (VariableLocation)EditorGUILayout.EnumPopup("'From' source:", oldLocation);
            }

            if (oldLocation == VariableLocation.Global)
            {
                if (AdvGame.GetReferences().variablesManager)
                {
                    oldVariableID = ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable, oldVariableID, oldParameterID, false);
                }
            }
            else if (oldLocation == VariableLocation.Local)
            {
                if (localVariables)
                {
                    oldVariableID = ShowVarGUI(localVariables.localVars, parameters, ParameterType.LocalVariable, oldVariableID, oldParameterID, false);
                }
            }

            EditorGUILayout.Space();

            // NEW

            if (isAssetFile)
            {
                newLocation = VariableLocation.Global;
            }
            else
            {
                newLocation = (VariableLocation)EditorGUILayout.EnumPopup("'To' source:", newLocation);
            }

            if (newLocation == VariableLocation.Global)
            {
                if (AdvGame.GetReferences().variablesManager)
                {
                    newVariableID = ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable, newVariableID, newParameterID, true);
                }
            }
            else if (newLocation == VariableLocation.Local)
            {
                if (localVariables)
                {
                    newVariableID = ShowVarGUI(localVariables.localVars, parameters, ParameterType.LocalVariable, newVariableID, newParameterID, true);
                }
                else
                {
                    EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                }
            }

            // Types match?
            if (oldParameterID == -1 && newParameterID == -1 && newVarType != oldVarType)
            {
                EditorGUILayout.HelpBox("The chosen Variables do not share the same Type - a conversion will be attemped", MessageType.Info);
            }

            AfterRunningOption();
        }
        public override void ShowGUI(List<ActionParameter> parameters)
        {
            if (isAssetFile)
            {
                location = VariableLocation.Global;
            }
            else
            {
                location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
            }

            if (location == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    ShowVarGUI (AdvGame.GetReferences ().variablesManager.vars, parameters, ParameterType.GlobalVariable);
                }
            }

            else if (location == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    ShowVarGUI (KickStarter.localVariables.localVars, parameters, ParameterType.LocalVariable);
                }
            }
        }
        /**
         * <summary>Copies the value of another variable onto itself.</summary>
         * <param name = "oldVar">The variable to copy from</param>
         * <param name = "oldLocation">The location of the variable to copy (Global, Local)</param>
         */
        public void CopyFromVariable(GVar oldVar, VariableLocation oldLocation)
        {
            if (oldLocation == VariableLocation.Global)
            {
                oldVar.Download(oldLocation);
            }

            if (type == VariableType.Integer || type == VariableType.Boolean || type == VariableType.PopUp)
            {
                int oldValue = oldVar.val;

                if (oldVar.type == VariableType.Float)
                {
                    oldValue = (int)oldVar.floatVal;
                }
                else if (oldVar.type == VariableType.String)
                {
                    float oldValueAsFloat = 0f;
                    float.TryParse(oldVar.textVal, out oldValueAsFloat);
                    oldValue = (int)oldValueAsFloat;
                }

                if (type == VariableType.PopUp && oldVar.HasTranslations())
                {
                    runtimeTranslations = oldVar.GetTranslations();
                }
                else
                {
                    runtimeTranslations = null;
                }

                SetValue(oldValue, SetVarMethod.SetValue);
            }
            else if (type == VariableType.Float)
            {
                float oldValue = oldVar.floatVal;

                if (oldVar.type == VariableType.Integer || oldVar.type == VariableType.Boolean || oldVar.type == VariableType.PopUp)
                {
                    oldValue = (float)oldVar.val;
                }
                else if (oldVar.type == VariableType.String)
                {
                    float.TryParse(oldVar.textVal, out oldValue);
                }

                SetFloatValue(oldValue, AC.SetVarMethod.SetValue);
            }
            else if (type == VariableType.String)
            {
                string oldValue = oldVar.GetValue();
                textVal = oldValue;

                if (oldVar.HasTranslations())
                {
                    runtimeTranslations = oldVar.GetTranslations();
                }
                else
                {
                    runtimeTranslations = null;
                }
            }
            else if (type == VariableType.Vector3)
            {
                Vector3 oldValue = oldVar.vector3Val;
                vector3Val = oldValue;
            }
        }
Exemple #24
0
        private static void FindInputs(Instruction instruction, InstructionInputList inputs, List <Instruction> seen, VariableLocation location)
        {
            if (instruction == null || seen.Contains(instruction))
            {
                return;
            }

            seen.Add(instruction);

            var expression = instruction as ExpressionInstruction;

            if (expression != null)
            {
                foreach (var statement in expression.Statements)
                {
                    statement.FindInputs(inputs, location);
                }
            }

            var variableFields        = instruction.GetType().GetFields().Where(field => field.FieldType == typeof(VariableReference));
            var promptFields          = instruction.GetType().GetFields().Where(field => field.FieldType == typeof(PromptString));
            var instructionFields     = instruction.GetType().GetFields().Where(field => typeof(Instruction).IsAssignableFrom(field.FieldType));
            var instructionListFields = instruction.GetType().GetFields().Where(field => field.FieldType.IsGenericType && field.FieldType.GetGenericTypeDefinition() == typeof(List <>) && typeof(Instruction).IsAssignableFrom(field.FieldType.GetGenericArguments()[0]));

            foreach (var field in variableFields)
            {
                var value = field.GetValue(instruction) as VariableReference;

                if (value != null && value.Location == location)
                {
                    inputs.Add(value, field);
                }
            }

            foreach (var field in promptFields)
            {
                var value = field.GetValue(instruction) as PromptString;

                if (value != null)
                {
                    foreach (var input in value.Input)
                    {
                        if (input != null && input.Location == location)
                        {
                            inputs.Add(input, field);
                        }
                    }
                }
            }

            foreach (var field in instructionFields)
            {
                var value = field.GetValue(instruction) as Instruction;
                FindInputs(value, inputs, seen, location);
            }

            foreach (var listField in instructionListFields)
            {
                var instructions = listField.GetValue(instruction) as IList <Instruction>;

                for (var i = 0; i < instructions.Count; i++)
                {
                    var value = instructions[i] as Instruction;
                    FindInputs(value, inputs, seen, location);
                }
            }
        }
Exemple #25
0
        public override void ShowGUI(List <ActionParameter> parameters)
        {
            location = (VariableLocation)EditorGUILayout.EnumPopup("Source:", location);

            if (isAssetFile && getVarMethod == GetVarMethod.LocalVariable)
            {
                EditorGUILayout.HelpBox("Local Variables cannot be referenced by Asset-based Actions.", MessageType.Warning);
                return;
            }

            switch (location)
            {
            case VariableLocation.Global:
                if (AdvGame.GetReferences().variablesManager)
                {
                    VariablesManager variablesManager = AdvGame.GetReferences().variablesManager;

                    parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.GlobalVariable);
                    if (parameterID >= 0)
                    {
                        placeholderType = (VariableType)EditorGUILayout.EnumPopup("Placeholder type:", placeholderType);
                        variableID      = ShowVarGUI(parameters, variablesManager.vars, variableID, false);
                    }
                    else
                    {
                        variableID = ShowVarGUI(parameters, variablesManager.vars, variableID, true);
                    }
                }
                break;

            case VariableLocation.Local:
                if (localVariables != null)
                {
                    parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.LocalVariable);
                    if (parameterID >= 0)
                    {
                        placeholderType = (VariableType)EditorGUILayout.EnumPopup("Placeholder type:", placeholderType);
                        variableID      = ShowVarGUI(parameters, localVariables.localVars, variableID, false);
                    }
                    else
                    {
                        variableID = ShowVarGUI(parameters, localVariables.localVars, variableID, true);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                }
                break;

            case VariableLocation.Component:
                parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.ComponentVariable);
                if (parameterID >= 0)
                {
                    placeholderType = (VariableType)EditorGUILayout.EnumPopup("Placeholder type:", placeholderType);
                    variableID      = ShowVarGUI(parameters, (variables != null) ? variables.vars : null, variableID, false);
                }
                else
                {
                    variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                    variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                    variables           = IDToField <Variables> (variables, variablesConstantID, false);

                    if (variables != null)
                    {
                        variableID = ShowVarGUI(parameters, variables.vars, variableID, true);
                    }
                }
                break;
            }
        }
Exemple #26
0
        private void ShowVarList(List <GVar> _vars, VariableLocation location, bool allowEditing)
        {
            EditorGUILayout.BeginVertical(CustomStyles.thinBox);
            showVariablesList = CustomGUILayout.ToggleHeader(showVariablesList, location + " variables");
            if (showVariablesList)
            {
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(Mathf.Min(_vars.Count * 21, 235f) + 5));
                bool varFound = false;

                foreach (GVar _var in _vars)
                {
                    if (VarMatchesFilter(_var))
                    {
                        varFound = true;
                        EditorGUILayout.BeginHorizontal();

                        string buttonLabel = _var.id + ": ";
                        if (buttonLabel == "")
                        {
                            _var.label += "(Untitled)";
                        }
                        else
                        {
                            buttonLabel += _var.label;

                            if (buttonLabel.Length > 30)
                            {
                                buttonLabel = buttonLabel.Substring(0, 30);
                            }
                        }

                        string varValue = _var.GetValue();
                        if (varValue.Length > 20)
                        {
                            varValue = varValue.Substring(0, 20);
                        }

                        buttonLabel += " (" + _var.type.ToString() + " - " + varValue + ")";

                        if (allowEditing)
                        {
                            if (GUILayout.Toggle(_var.isEditing, buttonLabel, "Button"))
                            {
                                if (selectedVar != _var)
                                {
                                    DeactivateAllVars();
                                    ActivateVar(_var);
                                }
                            }

                            if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                            {
                                SideMenu(_var, _vars, location);
                            }
                        }
                        else
                        {
                            GUILayout.Label(buttonLabel, "Button");
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                }

                if (!varFound)
                {
                    if (_vars.Count > 0 && !string.IsNullOrEmpty(filter))
                    {
                        EditorGUILayout.HelpBox("No variables with '" + filter + "' in their " + ((varFilter == VarFilter.ByName) ? "name" : "description") + " found.", MessageType.Info);
                    }
                }

                EditorGUILayout.EndScrollView();

                if (allowEditing)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Create new " + location + " variable"))
                    {
                        ResetFilter();
                        Undo.RecordObject(this, "Add " + location + " variable");
                        _vars.Add(new GVar(GetIDArray(_vars)));
                        DeactivateAllVars();
                        ActivateVar(_vars [_vars.Count - 1]);
                    }

                    if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                    {
                        ExportSideMenu();
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
        }
		override public void ShowGUI (List<ActionParameter> parameters)
		{
			// OLD

			if (isAssetFile)
			{
				oldLocation = VariableLocation.Global;
			}
			else
			{
				oldLocation = (VariableLocation) EditorGUILayout.EnumPopup ("'From' source:", oldLocation);
			}
			
			if (oldLocation == VariableLocation.Global)
			{
				if (!variablesManager)
				{
					variablesManager = AdvGame.GetReferences ().variablesManager;
				}
				
				if (variablesManager)
				{
					oldVariableID = ShowVarGUI (variablesManager.vars, parameters, ParameterType.GlobalVariable, oldVariableID, oldParameterID, false);
				}
			}
			else if (oldLocation == VariableLocation.Local)
			{
				if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>())
				{
					localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>();
				}
				
				if (localVariables)
				{
					oldVariableID = ShowVarGUI (localVariables.localVars, parameters, ParameterType.LocalVariable, oldVariableID, oldParameterID, false);
				}
			}

			EditorGUILayout.Space ();

			// NEW

			if (isAssetFile)
			{
				newLocation = VariableLocation.Global;
			}
			else
			{
				newLocation = (VariableLocation) EditorGUILayout.EnumPopup ("'To' source:", newLocation);
			}
			
			if (newLocation == VariableLocation.Global)
			{
				if (!variablesManager)
				{
					variablesManager = AdvGame.GetReferences ().variablesManager;
				}
				
				if (variablesManager)
				{
					newVariableID = ShowVarGUI (variablesManager.vars, parameters, ParameterType.GlobalVariable, newVariableID, newParameterID, true);
				}
			}
			else if (newLocation == VariableLocation.Local)
			{
				if (!localVariables && GameObject.FindWithTag (Tags.gameEngine) && GameObject.FindWithTag (Tags.gameEngine).GetComponent<LocalVariables>())
				{
					localVariables = GameObject.FindWithTag (Tags.gameEngine).GetComponent <LocalVariables>();
				}
				
				if (localVariables)
				{
					newVariableID = ShowVarGUI (localVariables.localVars, parameters, ParameterType.LocalVariable, newVariableID, newParameterID, true);
				}
			}

			// Types match?
			if (oldParameterID == -1 && newParameterID == -1 && newVarType != oldVarType)
			{
				EditorGUILayout.HelpBox ("The chosen Variables do not share the same Type", MessageType.Warning);
			}

			AfterRunningOption ();
		}
Exemple #28
0
        private List <VarPreset> ShowPresets(List <VarPreset> _varPresets, List <GVar> _vars, VariableLocation location)
        {
            if (_vars == null || _vars.Count == 0)
            {
                return(_varPresets);
            }

            if (!Application.isPlaying || _varPresets.Count > 0)
            {
                EditorGUILayout.BeginVertical(CustomStyles.thinBox);
                showPresets = CustomGUILayout.ToggleHeader(showPresets, "Preset configurations");
            }

            if (showPresets && (!Application.isPlaying || _varPresets.Count > 0))
            {
                List <string> labelList = new List <string>();

                int i            = 0;
                int presetNumber = -1;

                if (_varPresets.Count > 0)
                {
                    foreach (VarPreset _varPreset in _varPresets)
                    {
                        if (_varPreset.label != "")
                        {
                            labelList.Add(i.ToString() + ": " + _varPreset.label);
                        }
                        else
                        {
                            labelList.Add(i.ToString() + ": (Untitled)");
                        }

                        if (_varPreset.ID == chosenPresetID)
                        {
                            presetNumber = i;
                        }
                        i++;
                    }

                    if (presetNumber == -1)
                    {
                        chosenPresetID = 0;
                    }
                    else if (presetNumber >= _varPresets.Count)
                    {
                        presetNumber = Mathf.Max(0, _varPresets.Count - 1);
                    }
                    else
                    {
                        presetNumber   = EditorGUILayout.Popup("Created presets:", presetNumber, labelList.ToArray());
                        chosenPresetID = _varPresets[presetNumber].ID;
                    }
                }
                else
                {
                    chosenPresetID = presetNumber = -1;
                }

                if (presetNumber >= 0)
                {
                    string apiPrefix = ((location == VariableLocation.Local) ? "AC.KickStarter.localVariables.GetPreset (" + chosenPresetID + ")" : "AC.KickStarter.runtimeVariables.GetPreset (" + chosenPresetID + ")");

                    if (!Application.isPlaying)
                    {
                        _varPresets [presetNumber].label = CustomGUILayout.TextField("Preset name:", _varPresets [presetNumber].label, apiPrefix + ".label");
                    }

                    EditorGUILayout.BeginHorizontal();
                    if (!Application.isPlaying)
                    {
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button("Bulk-assign"))
                    {
                        if (presetNumber >= 0 && _varPresets.Count > presetNumber)
                        {
                            if (location == VariableLocation.Global)
                            {
                                if (KickStarter.runtimeVariables)
                                {
                                    KickStarter.runtimeVariables.AssignFromPreset(_varPresets [presetNumber]);
                                    ACDebug.Log("Global variables updated to " + _varPresets [presetNumber].label);
                                }
                            }
                            else if (location == VariableLocation.Local)
                            {
                                if (KickStarter.localVariables)
                                {
                                    KickStarter.localVariables.AssignFromPreset(_varPresets [presetNumber]);
                                    ACDebug.Log("Local variables updated to " + _varPresets [presetNumber].label);
                                }
                            }
                        }
                    }

                    GUI.enabled = !Application.isPlaying;
                    if (GUILayout.Button("Delete"))
                    {
                        _varPresets.RemoveAt(presetNumber);
                        presetNumber   = 0;
                        chosenPresetID = 0;
                    }

                    GUI.enabled = true;
                    EditorGUILayout.EndHorizontal();
                }

                if (!Application.isPlaying)
                {
                    if (GUILayout.Button("Create new preset"))
                    {
                        VarPreset newVarPreset = new VarPreset(_vars, GetIDArray(_varPresets));
                        _varPresets.Add(newVarPreset);
                        chosenPresetID = newVarPreset.ID;
                    }
                }
            }
            if (!Application.isPlaying || _varPresets.Count > 0)
            {
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Space();

            return(_varPresets);
        }
Exemple #29
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            isPlayer = EditorGUILayout.Toggle("Record Player?", isPlayer);
            if (!isPlayer)
            {
                obToReadParameterID = Action.ChooseParameterGUI("Object to record:", parameters, obToReadParameterID, ParameterType.GameObject);
                if (obToReadParameterID >= 0)
                {
                    obToReadConstantID = 0;
                    obToRead           = null;
                }
                else
                {
                    obToRead = (GameObject)EditorGUILayout.ObjectField("Object to record:", obToRead, typeof(GameObject), true);

                    obToReadConstantID = FieldToID(obToRead, obToReadConstantID);
                    obToRead           = IDToField(obToRead, obToReadConstantID, false);
                }
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Record:", GUILayout.MaxWidth(100f));
            transformLocation   = (GlobalLocal)EditorGUILayout.EnumPopup(transformLocation);
            transformRecordType = (TransformRecordType)EditorGUILayout.EnumPopup(transformRecordType);
            EditorGUILayout.EndHorizontal();

            variableLocation = (VariableLocation)EditorGUILayout.EnumPopup("Variable location:", variableLocation);

            switch (variableLocation)
            {
            case VariableLocation.Global:
                variableParameterID = Action.ChooseParameterGUI("Record to variable:", parameters, variableParameterID, ParameterType.GlobalVariable);
                if (variableParameterID < 0)
                {
                    variableID = AdvGame.GlobalVariableGUI("Record to variable:", variableID, VariableType.Vector3);
                }
                break;

            case VariableLocation.Local:
                if (!isAssetFile)
                {
                    variableParameterID = Action.ChooseParameterGUI("Record to variable:", parameters, variableParameterID, ParameterType.LocalVariable);
                    if (variableParameterID < 0)
                    {
                        variableID = AdvGame.LocalVariableGUI("Record to variable:", variableID, VariableType.Vector3);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info);
                }
                break;

            case VariableLocation.Component:
                variableParameterID = Action.ChooseParameterGUI("Record to variable:", parameters, variableParameterID, ParameterType.ComponentVariable);
                if (variableParameterID >= 0)
                {
                    variables           = null;
                    variablesConstantID = 0;
                }
                else
                {
                    variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                    variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                    variables           = IDToField <Variables> (variables, variablesConstantID, false);

                    if (variables != null)
                    {
                        variableID = AdvGame.ComponentVariableGUI("Record to variable:", variableID, VariableType.Vector3, variables);
                    }
                }
                break;
            }

            AfterRunningOption();
        }
Exemple #30
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            numSockets = EditorGUILayout.IntSlider("# of possible values:", numSockets, 1, 20);
            doLoop     = EditorGUILayout.Toggle("Run on a loop?", doLoop);

            saveToVariable = EditorGUILayout.Toggle("Save sequence value?", saveToVariable);
            if (saveToVariable)
            {
                if (isAssetFile)
                {
                    location = VariableLocation.Global;
                }
                else
                {
                    location = (VariableLocation)EditorGUILayout.EnumPopup("Source:", location);
                }

                if (location == VariableLocation.Global)
                {
                    if (AdvGame.GetReferences().variablesManager)
                    {
                        parameterID = Action.ChooseParameterGUI("Integer variable:", parameters, parameterID, ParameterType.GlobalVariable);
                        if (parameterID >= 0)
                        {
                            variableID = ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, variableID, false);
                        }
                        else
                        {
                            EditorGUILayout.BeginHorizontal();
                            variableID = ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, variableID, true);
                            if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                            {
                                SideMenu();
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                else if (location == VariableLocation.Local)
                {
                    if (KickStarter.localVariables)
                    {
                        parameterID = Action.ChooseParameterGUI("Integer variable:", parameters, parameterID, ParameterType.LocalVariable);
                        if (parameterID >= 0)
                        {
                            variableID = ShowVarGUI(KickStarter.localVariables.localVars, variableID, false);
                        }
                        else
                        {
                            EditorGUILayout.BeginHorizontal();
                            variableID = ShowVarGUI(KickStarter.localVariables.localVars, variableID, true);
                            if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                            {
                                SideMenu();
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                    }
                }
            }
        }
Exemple #31
0
        /**
         * <summary>Creates a new instance of the 'Object: Record transform' Action</summary>
         * <param name = "objectToRecord">The GameObject whose transform to record</param>
         * <param name = "recordType">The type of recording to take</param>
         * <param name = "inWorldSpace">If True, the GameObjects's transform values will be read in world space</param>
         * <param name = "variableLocation">The location of the Vector3 variable to store the values</param>
         * <param name = "variableID">The ID number of the Vector3 variable to store the values</param>
         * <param name = "variables">The variable's associated Variables component, if a Component Variable</param>
         * <returns>The generated Action</returns>
         */
        public static ActionTransformRecord CreateNew(GameObject objectToRecord, TransformRecordType recordType, bool inWorldSpace, VariableLocation variableLocation, int variableID, Variables variables = null)
        {
            ActionTransformRecord newAction = (ActionTransformRecord)CreateInstance <ActionTransformRecord>();

            newAction.obToRead            = objectToRecord;
            newAction.transformRecordType = recordType;
            newAction.transformLocation   = (inWorldSpace) ? GlobalLocal.Global : GlobalLocal.Local;
            newAction.variableLocation    = variableLocation;
            newAction.variableID          = variableID;
            newAction.variables           = variables;
            return(newAction);
        }
		private void SetVariable (GVar var, VariableLocation location)
		{
			if (var == null)
			{
				return;
			}

			if (location == VariableLocation.Global)
			{
				var.Download ();
			}

			if (var.type == VariableType.Integer)
			{
				int _value = 0;

				if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
				{
					if (setVarMethod == SetVarMethod.Formula)
					{
						_value = (int) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula));
					}
					else
					{
						_value = intValue;
					}
				}
				else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
				{
					if (animator && parameterName != "")
					{
						_value = animator.GetInteger (parameterName);
						setVarMethod = SetVarMethod.SetValue;
					}	
				}

				var.SetValue (_value, setVarMethod);
			}
			if (var.type == VariableType.Float)
			{
				float _value = 0;
				
				if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
				{
					if (setVarMethod == SetVarMethod.Formula)
					{
						_value = (float) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula));
					}
					else
					{
						_value = floatValue;
					}
				}
				else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
				{
					if (animator && parameterName != "")
					{
						_value = animator.GetFloat (parameterName);
						setVarMethod = SetVarMethod.SetValue;
					}	
				}
				
				var.SetValue (_value, setVarMethod);
			}
			else if (var.type == VariableType.Boolean)
			{
				int _value = 0;

				if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
				{
					_value = (int) boolValue;
				}
				else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
				{
					if (animator && parameterName != "")
					{
						if (animator.GetBool (parameterName))
						{
							_value = 1;
						}
					}
				}

				var.SetValue (_value, SetVarMethod.SetValue);
			}
			else if (var.type == VariableType.PopUp)
			{
				var.SetValue (intValue);
			}
			else if (var.type == VariableType.String)
			{
				string _value = "";

				if (setVarMethodString == SetVarMethodString.EnteredHere)
				{
					_value = AdvGame.ConvertTokens (stringValue);
				}
				else if (setVarMethodString == SetVarMethodString.SetAsMenuInputLabel)
				{
					if (PlayerMenus.GetElementWithName (menuName, elementName) != null)
					{
						MenuInput menuInput = (MenuInput) PlayerMenus.GetElementWithName (menuName, elementName);
						_value = menuInput.label;

						if ((Options.GetLanguageName () == "Arabic" || Options.GetLanguageName () == "Hebrew") && _value.Length > 0)
						{
							// Invert
							char[] charArray = _value.ToCharArray ();
							_value = "";
							for (int i = charArray.Length-1; i >= 0; i --)
							{
								_value += charArray[i];
							}
						}
					}
					else
					{
						Debug.LogWarning ("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'");
					}
				}

				var.SetValue (_value);
			}

			if (location == VariableLocation.Global)
			{
				var.Upload ();
			}

			GameObject.FindWithTag (Tags.gameEngine).GetComponent <ActionListManager>().VariableChanged ();
		}
Exemple #33
0
        private void SetVariable(GVar var, VariableLocation location, bool doSkip)
        {
            if (var == null)
            {
                return;
            }

            if (location == VariableLocation.Global)
            {
                var.Download();
            }

            if (var.type == VariableType.Integer)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (int)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula));
                    }
                    else
                    {
                        _value = intValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value       = animator.GetInteger(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            if (var.type == VariableType.Float)
            {
                float _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (float)AdvGame.CalculateFormula(AdvGame.ConvertTokens(formula));
                    }
                    else
                    {
                        _value = floatValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value       = animator.GetFloat(parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue();
                }

                var.SetValue(_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue();
                }
            }
            else if (var.type == VariableType.Boolean)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    _value = (int)boolValue;
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        if (animator.GetBool(parameterName))
                        {
                            _value = 1;
                        }
                    }
                }

                var.SetValue(_value, SetVarMethod.SetValue);
            }
            else if (var.type == VariableType.PopUp)
            {
                var.SetValue(intValue);
            }
            else if (var.type == VariableType.String)
            {
                string _value = "";

                if (setVarMethodString == SetVarMethodString.EnteredHere)
                {
                    _value = AdvGame.ConvertTokens(stringValue);
                }
                else if (setVarMethodString == SetVarMethodString.SetAsMenuInputLabel)
                {
                    if (PlayerMenus.GetElementWithName(menuName, elementName) != null)
                    {
                        MenuInput menuInput = (MenuInput)PlayerMenus.GetElementWithName(menuName, elementName);
                        _value = menuInput.GetContents();

                        if ((Options.GetLanguageName() == "Arabic" || Options.GetLanguageName() == "Hebrew") && _value.Length > 0)
                        {
                            // Invert
                            char[] charArray = _value.ToCharArray();
                            _value = "";
                            for (int i = charArray.Length - 1; i >= 0; i--)
                            {
                                _value += charArray[i];
                            }
                        }
                    }
                    else
                    {
                        Debug.LogWarning("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'");
                    }
                }

                var.SetValue(_value);
            }

            if (location == VariableLocation.Global)
            {
                var.Upload();
            }

            KickStarter.actionListManager.VariableChanged();
        }
		public static string CreateVariablesData (List<GVar> vars, bool isOptionsData, VariableLocation location)
		{
			System.Text.StringBuilder variablesString = new System.Text.StringBuilder ();

			foreach (GVar _var in vars)
			{
				if ((isOptionsData && _var.link == VarLink.OptionsData) || (!isOptionsData && _var.link != VarLink.OptionsData) || location == VariableLocation.Local)
				{
					variablesString.Append (_var.id.ToString ());
					variablesString.Append (":");
					if (_var.type == VariableType.String)
					{
						string textVal = _var.textVal;
						if (textVal.Contains ("|"))
						{
							textVal = textVal.Replace ("|", "");
							Debug.LogWarning ("Removed pipe delimeter from variable " + _var.label);
						}
						variablesString.Append (textVal);
					}
					else if (_var.type == VariableType.Float)
					{
						variablesString.Append (_var.floatVal.ToString ());
					}
					else
					{
						variablesString.Append (_var.val.ToString ());
					}
					variablesString.Append ("|");
				}
			}
			
			if (variablesString.Length > 0)
			{
				variablesString.Remove (variablesString.Length-1, 1);
			}

			return variablesString.ToString ();		
		}
Exemple #35
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            location = (VariableLocation)EditorGUILayout.EnumPopup("Source:", location);

            if (location == VariableLocation.Global)
            {
                if (AdvGame.GetReferences().variablesManager != null)
                {
                    parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.GlobalVariable);

                    if (parameterID >= 0)
                    {
                        SetPlaceholderVar(AdvGame.GetReferences().variablesManager.vars, variableID);
                        ShowPlaceholderVar();
                        ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable, false);
                    }
                    else
                    {
                        setPlaceholder = false;
                        ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable, true);
                    }
                }
            }
            else if (location == VariableLocation.Local)
            {
                if (isAssetFile)
                {
                    EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info);
                }
                else if (localVariables != null)
                {
                    parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.LocalVariable);

                    if (parameterID >= 0)
                    {
                        SetPlaceholderVar(localVariables.localVars, variableID);
                        ShowPlaceholderVar();
                        ShowVarGUI(localVariables.localVars, parameters, ParameterType.LocalVariable, false);
                    }
                    else
                    {
                        setPlaceholder = false;
                        ShowVarGUI(localVariables.localVars, parameters, ParameterType.LocalVariable, true);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No 'Local Variables' component found in the scene. Please add an AC GameEngine object from the Scene Manager.", MessageType.Info);
                }
            }
            else if (location == VariableLocation.Component)
            {
                parameterID = Action.ChooseParameterGUI("Variable:", parameters, parameterID, ParameterType.ComponentVariable);
                if (parameterID >= 0)
                {
                    ShowPlaceholderVar();
                    ShowVarGUI((variables != null) ? variables.vars : null, parameters, ParameterType.ComponentVariable, false);
                }
                else
                {
                    variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                    variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                    variables           = IDToField <Variables> (variables, variablesConstantID, false);

                    if (variables != null)
                    {
                        ShowVarGUI(variables.vars, parameters, ParameterType.ComponentVariable, true);
                        setPlaceholder = false;
                        SetPlaceholderVar(variables.vars, variableID);
                    }
                }
            }
        }
        public override void ShowGUI(List<ActionParameter> parameters)
        {
            if (isAssetFile)
            {
                location = VariableLocation.Global;
            }
            else
            {
                location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
            }

            if (isAssetFile && getVarMethod == GetVarMethod.LocalVariable)
            {
                EditorGUILayout.HelpBox ("Local Variables cannot be referenced by Asset-based Actions.", MessageType.Warning);
            }

            if (location == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    VariablesManager variablesManager = AdvGame.GetReferences ().variablesManager;

                    parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, ParameterType.GlobalVariable);
                    if (parameterID >= 0)
                    {
                        variableID = ShowVarGUI (parameters, variablesManager.vars, variableID, false);
                    }
                    else
                    {
                        variableID = ShowVarGUI (parameters, variablesManager.vars, variableID, true);
                    }
                }
            }

            else if (location == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    parameterID = Action.ChooseParameterGUI ("Variable:", parameters, parameterID, ParameterType.LocalVariable);
                    if (parameterID >= 0)
                    {
                        variableID = ShowVarGUI (parameters, KickStarter.localVariables.localVars, variableID, false);
                    }
                    else
                    {
                        variableID = ShowVarGUI (parameters, KickStarter.localVariables.localVars, variableID, true);
                    }
                }
            }
        }
Exemple #37
0
        public override void ShowGUI(List <ActionParameter> parameters)
        {
            invAction = (InvAction)EditorGUILayout.EnumPopup("Method:", invAction);

            string _label = "Object to instantiate:";

            if (invAction == InvAction.Remove)
            {
                _label = "Object to delete:";
            }

            ParameterType[] parameterTypes = new ParameterType[2] {
                ParameterType.GameObject, ParameterType.InventoryItem
            };
            parameterID = Action.ChooseParameterGUI(_label, parameters, parameterID, parameterTypes);
            if (parameterID >= 0)
            {
                constantID = 0;
                gameObject = null;
            }
            else
            {
                gameObject = (GameObject)EditorGUILayout.ObjectField(_label, gameObject, typeof(GameObject), true);

                constantID = FieldToID(gameObject, constantID);
                gameObject = IDToField(gameObject, constantID, false);
            }

            if (invAction == InvAction.Add)
            {
                positionRelativeTo = (PositionRelativeTo)EditorGUILayout.EnumPopup("Position relative to:", positionRelativeTo);

                if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
                {
                    relativeGameObjectParameterID = Action.ChooseParameterGUI("Relative GameObject:", parameters, relativeGameObjectParameterID, ParameterType.GameObject);
                    if (relativeGameObjectParameterID >= 0)
                    {
                        relativeGameObjectID = 0;
                        relativeGameObject   = null;
                    }
                    else
                    {
                        relativeGameObject = (GameObject)EditorGUILayout.ObjectField("Relative GameObject:", relativeGameObject, typeof(GameObject), true);

                        relativeGameObjectID = FieldToID(relativeGameObject, relativeGameObjectID);
                        relativeGameObject   = IDToField(relativeGameObject, relativeGameObjectID, false);
                    }
                }
                else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
                {
                    relativeVectorParameterID = Action.ChooseParameterGUI("Value:", parameters, relativeVectorParameterID, ParameterType.Vector3);
                    if (relativeVectorParameterID < 0)
                    {
                        relativeVector = EditorGUILayout.Vector3Field("Value:", relativeVector);
                    }
                }
                else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
                {
                    variableLocation = (VariableLocation)EditorGUILayout.EnumPopup("Source:", variableLocation);

                    switch (variableLocation)
                    {
                    case VariableLocation.Global:
                        vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.GlobalVariable);
                        if (vectorVarParameterID < 0)
                        {
                            vectorVarID = AdvGame.GlobalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                        }
                        break;

                    case VariableLocation.Local:
                        if (!isAssetFile)
                        {
                            vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.LocalVariable);
                            if (vectorVarParameterID < 0)
                            {
                                vectorVarID = AdvGame.LocalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                            }
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("Local variables cannot be accessed in ActionList assets.", MessageType.Info);
                        }
                        break;

                    case VariableLocation.Component:
                        vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.ComponentVariable);
                        if (vectorVarParameterID >= 0)
                        {
                            variables           = null;
                            variablesConstantID = 0;
                        }
                        else
                        {
                            variables           = (Variables)EditorGUILayout.ObjectField("Component:", variables, typeof(Variables), true);
                            variablesConstantID = FieldToID <Variables> (variables, variablesConstantID);
                            variables           = IDToField <Variables> (variables, variablesConstantID, false);

                            if (variables != null)
                            {
                                vectorVarID = AdvGame.ComponentVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3, variables);
                            }
                        }
                        break;
                    }
                }

                spawnedObjectParameterID = ChooseParameterGUI("Send to parameter:", parameters, spawnedObjectParameterID, ParameterType.GameObject);
            }
            else if (invAction == InvAction.Replace)
            {
                EditorGUILayout.Space();
                replaceParameterID = Action.ChooseParameterGUI("Object to delete:", parameters, replaceParameterID, ParameterType.GameObject);
                if (replaceParameterID >= 0)
                {
                    replaceConstantID = 0;
                    replaceGameObject = null;
                }
                else
                {
                    replaceGameObject = (GameObject)EditorGUILayout.ObjectField("Object to delete:", replaceGameObject, typeof(GameObject), true);

                    replaceConstantID = FieldToID(replaceGameObject, replaceConstantID);
                    replaceGameObject = IDToField(replaceGameObject, replaceConstantID, false);
                }
            }

            AfterRunningOption();
        }
Exemple #38
0
        private List<VarPreset> ShowPresets(List<VarPreset> _varPresets, List<GVar> _vars, VariableLocation location)
        {
            if (_vars == null || _vars.Count == 0)
            {
                return _varPresets;
            }

            if (!Application.isPlaying || _varPresets.Count > 0)
            {
                EditorGUILayout.LabelField ("Preset configurations", EditorStyles.boldLabel);
            }

            List<string> labelList = new List<string>();

            int i = 0;
            int presetNumber = -1;

            if (_varPresets.Count > 0)
            {
                foreach (VarPreset _varPreset in _varPresets)
                {
                    if (_varPreset.label != "")
                    {
                        labelList.Add (i.ToString () + ": " + _varPreset.label);
                    }
                    else
                    {
                        labelList.Add (i.ToString () + ": (Untitled)");
                    }

                    if (_varPreset.ID == chosenPresetID)
                    {
                        presetNumber = i;
                    }
                    i++;
                }

                if (presetNumber == -1)
                {
                    chosenPresetID = 0;
                }
                else if (presetNumber >= _varPresets.Count)
                {
                    presetNumber = Mathf.Max (0, _varPresets.Count - 1);
                }
                else
                {
                    presetNumber = EditorGUILayout.Popup ("Created presets:", presetNumber, labelList.ToArray());
                    chosenPresetID = _varPresets[presetNumber].ID;
                }
            }
            else
            {
                chosenPresetID = presetNumber = -1;
            }

            if (presetNumber >= 0)
            {
                if (!Application.isPlaying)
                {
                    _varPresets [presetNumber].label = EditorGUILayout.TextField ("Preset name:", _varPresets [presetNumber].label);
                }

                EditorGUILayout.BeginHorizontal ();
                if (!Application.isPlaying)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button ("Bulk-assign"))
                {
                    if (presetNumber >= 0 && _varPresets.Count > presetNumber)
                    {
                        if (location == VariableLocation.Global)
                        {
                            if (KickStarter.runtimeVariables)
                            {
                                KickStarter.runtimeVariables.AssignFromPreset (_varPresets [presetNumber]);
                                ACDebug.Log ("Global variables updated to " + _varPresets [presetNumber].label);
                            }
                        }
                        else if (location == VariableLocation.Local)
                        {
                            if (KickStarter.localVariables)
                            {
                                KickStarter.localVariables.AssignFromPreset (_varPresets [presetNumber]);
                                ACDebug.Log ("Local variables updated to " + _varPresets [presetNumber].label);
                            }
                        }
                    }
                }

                GUI.enabled = !Application.isPlaying;
                if (GUILayout.Button ("Delete"))
                {
                    _varPresets.RemoveAt (presetNumber);
                    presetNumber = 0;
                    chosenPresetID = 0;
                }

                GUI.enabled = true;
                EditorGUILayout.EndHorizontal ();
            }

            if (!Application.isPlaying)
            {
                if (GUILayout.Button ("Create new preset"))
                {
                    VarPreset newVarPreset = new VarPreset (_vars, GetIDArray (_varPresets));
                    _varPresets.Add (newVarPreset);
                    chosenPresetID = newVarPreset.ID;
                }
            }
            EditorGUILayout.Space ();

            return _varPresets;
        }
Exemple #39
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            // OLD

            if (isAssetFile)
            {
                oldLocation = VariableLocation.Global;
            }
            else
            {
                oldLocation = (VariableLocation)EditorGUILayout.EnumPopup("'From' source:", oldLocation);
            }

            if (oldLocation == VariableLocation.Global)
            {
                if (AdvGame.GetReferences().variablesManager)
                {
                    oldVariableID = ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable, oldVariableID, oldParameterID, false);
                }
            }
            else if (oldLocation == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    oldVariableID = ShowVarGUI(KickStarter.localVariables.localVars, parameters, ParameterType.LocalVariable, oldVariableID, oldParameterID, false);
                }
            }

            EditorGUILayout.Space();

            // NEW

            if (isAssetFile)
            {
                newLocation = VariableLocation.Global;
            }
            else
            {
                newLocation = (VariableLocation)EditorGUILayout.EnumPopup("'To' source:", newLocation);
            }

            if (newLocation == VariableLocation.Global)
            {
                if (AdvGame.GetReferences().variablesManager)
                {
                    newVariableID = ShowVarGUI(AdvGame.GetReferences().variablesManager.vars, parameters, ParameterType.GlobalVariable, newVariableID, newParameterID, true);
                }
            }
            else if (newLocation == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    newVariableID = ShowVarGUI(KickStarter.localVariables.localVars, parameters, ParameterType.LocalVariable, newVariableID, newParameterID, true);
                }
            }

            // Types match?
            if (oldParameterID == -1 && newParameterID == -1 && newVarType != oldVarType)
            {
                EditorGUILayout.HelpBox("The chosen Variables do not share the same Type", MessageType.Warning);
            }

            AfterRunningOption();
        }
Exemple #40
0
        private void ShowVarList(List<GVar> _vars, VariableLocation location, bool allowEditing)
        {
            EditorGUILayout.LabelField (location + " variables", EditorStyles.boldLabel);

            scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUILayout.Height (Mathf.Min (_vars.Count * 21, 235f)+5));
            foreach (GVar _var in _vars)
            {
                if (filter == "" || _var.label.ToLower ().Contains (filter.ToLower ()))
                {
                    EditorGUILayout.BeginHorizontal ();

                    string buttonLabel = _var.id + ": ";
                    if (buttonLabel == "")
                    {
                        _var.label += "(Untitled)";
                    }
                    else
                    {
                        buttonLabel += _var.label;

                        if (buttonLabel.Length > 30)
                        {
                            buttonLabel = buttonLabel.Substring (0, 30);
                        }
                    }

                    string varValue = _var.GetValue ();
                    if (varValue.Length > 20)
                    {
                        varValue = varValue.Substring (0, 20);
                    }

                    buttonLabel += " (" + _var.type.ToString () + " - " + varValue + ")";

                    if (allowEditing)
                    {
                        if (GUILayout.Toggle (_var.isEditing, buttonLabel, "Button"))
                        {
                            if (selectedVar != _var)
                            {
                                DeactivateAllVars ();
                                ActivateVar (_var);
                            }
                        }

                        if (GUILayout.Button (icon, GUILayout.Width (20f), GUILayout.Height (15f)))
                        {
                            SideMenu (_var, _vars, location);
                        }
                    }
                    else
                    {
                        GUILayout.Label (buttonLabel, "Button");
                    }

                    EditorGUILayout.EndHorizontal ();
                }
            }
            EditorGUILayout.EndScrollView ();

            if (allowEditing)
            {
                EditorGUILayout.Space ();
                if (GUILayout.Button("Create new " + location + " variable"))
                {
                    ResetFilter ();
                    Undo.RecordObject (this, "Add " + location + " variable");
                    _vars.Add (new GVar (GetIDArray (_vars)));
                    DeactivateAllVars ();
                    ActivateVar (_vars [_vars.Count-1]);
                }
            }
        }
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            invAction = (InvAction)EditorGUILayout.EnumPopup("Method:", invAction);

            string _label = "Object to instantiate:";

            if (invAction == InvAction.Remove)
            {
                _label = "Object to delete:";
            }

            parameterID = Action.ChooseParameterGUI(_label, parameters, parameterID, ParameterType.GameObject);
            if (parameterID >= 0)
            {
                constantID = 0;
                gameObject = null;
            }
            else
            {
                gameObject = (GameObject)EditorGUILayout.ObjectField(_label, gameObject, typeof(GameObject), true);

                constantID = FieldToID(gameObject, constantID);
                gameObject = IDToField(gameObject, constantID, false);
            }

            if (invAction == InvAction.Add)
            {
                positionRelativeTo = (PositionRelativeTo)EditorGUILayout.EnumPopup("Position relative to:", positionRelativeTo);

                if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
                {
                    relativeGameObjectParameterID = Action.ChooseParameterGUI("Relative GameObject:", parameters, relativeGameObjectParameterID, ParameterType.GameObject);
                    if (relativeGameObjectParameterID >= 0)
                    {
                        relativeGameObjectID = 0;
                        relativeGameObject   = null;
                    }
                    else
                    {
                        relativeGameObject = (GameObject)EditorGUILayout.ObjectField("Relative GameObject:", relativeGameObject, typeof(GameObject), true);

                        relativeGameObjectID = FieldToID(relativeGameObject, relativeGameObjectID);
                        relativeGameObject   = IDToField(relativeGameObject, relativeGameObjectID, false);
                    }
                }
                else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
                {
                    relativeVectorParameterID = Action.ChooseParameterGUI("Value:", parameters, relativeVectorParameterID, ParameterType.Vector3);
                    if (relativeVectorParameterID < 0)
                    {
                        relativeVector = EditorGUILayout.Vector3Field("Value:", relativeVector);
                    }
                }
                else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
                {
                    if (isAssetFile)
                    {
                        variableLocation = VariableLocation.Global;
                    }
                    else
                    {
                        variableLocation = (VariableLocation)EditorGUILayout.EnumPopup("Source:", variableLocation);
                    }

                    if (variableLocation == VariableLocation.Global)
                    {
                        vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.GlobalVariable);
                        if (vectorVarParameterID < 0)
                        {
                            vectorVarID = AdvGame.GlobalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                        }
                    }
                    else if (variableLocation == VariableLocation.Local)
                    {
                        vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.LocalVariable);
                        if (vectorVarParameterID < 0)
                        {
                            vectorVarID = AdvGame.LocalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                        }
                    }
                }
            }
            else if (invAction == InvAction.Replace)
            {
                EditorGUILayout.Space();
                replaceParameterID = Action.ChooseParameterGUI("Object to delete:", parameters, replaceParameterID, ParameterType.GameObject);
                if (replaceParameterID >= 0)
                {
                    replaceConstantID = 0;
                    replaceGameObject = null;
                }
                else
                {
                    replaceGameObject = (GameObject)EditorGUILayout.ObjectField("Object to delete:", replaceGameObject, typeof(GameObject), true);

                    replaceConstantID = FieldToID(replaceGameObject, replaceConstantID);
                    replaceGameObject = IDToField(replaceGameObject, replaceConstantID, false);
                }
            }

            AfterRunningOption();
        }
Exemple #42
0
        public override void ShowGUI(List<ActionParameter> parameters)
        {
            // OLD

            if (isAssetFile)
            {
                oldLocation = VariableLocation.Global;
            }
            else
            {
                oldLocation = (VariableLocation) EditorGUILayout.EnumPopup ("'From' source:", oldLocation);
            }

            if (oldLocation == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    oldVariableID = ShowVarGUI (AdvGame.GetReferences ().variablesManager.vars, parameters, ParameterType.GlobalVariable, oldVariableID, oldParameterID, false);
                }
            }
            else if (oldLocation == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    oldVariableID = ShowVarGUI (KickStarter.localVariables.localVars, parameters, ParameterType.LocalVariable, oldVariableID, oldParameterID, false);
                }
            }

            EditorGUILayout.Space ();

            // NEW

            if (isAssetFile)
            {
                newLocation = VariableLocation.Global;
            }
            else
            {
                newLocation = (VariableLocation) EditorGUILayout.EnumPopup ("'To' source:", newLocation);
            }

            if (newLocation == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    newVariableID = ShowVarGUI (AdvGame.GetReferences ().variablesManager.vars, parameters, ParameterType.GlobalVariable, newVariableID, newParameterID, true);
                }
            }
            else if (newLocation == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    newVariableID = ShowVarGUI (KickStarter.localVariables.localVars, parameters, ParameterType.LocalVariable, newVariableID, newParameterID, true);
                }
            }

            // Types match?
            if (oldParameterID == -1 && newParameterID == -1 && newVarType != oldVarType)
            {
                EditorGUILayout.HelpBox ("The chosen Variables do not share the same Type", MessageType.Warning);
            }

            AfterRunningOption ();
        }
Exemple #43
0
        private void ShowVarList(List <GVar> _vars, VariableLocation location, bool allowEditing)
        {
            EditorGUILayout.LabelField(location + " variables", EditorStyles.boldLabel);

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(Mathf.Min(_vars.Count * 21, 235f) + 5));
            foreach (GVar _var in _vars)
            {
                if (filter == "" || _var.label.ToLower().Contains(filter.ToLower()))
                {
                    EditorGUILayout.BeginHorizontal();

                    string buttonLabel = _var.id + ": ";
                    if (buttonLabel == "")
                    {
                        _var.label += "(Untitled)";
                    }
                    else
                    {
                        buttonLabel += _var.label;

                        if (buttonLabel.Length > 30)
                        {
                            buttonLabel = buttonLabel.Substring(0, 30);
                        }
                    }

                    string varValue = _var.GetValue();
                    if (varValue.Length > 20)
                    {
                        varValue = varValue.Substring(0, 20);
                    }

                    buttonLabel += " (" + _var.type.ToString() + " - " + varValue + ")";

                    if (allowEditing)
                    {
                        if (GUILayout.Toggle(_var.isEditing, buttonLabel, "Button"))
                        {
                            if (selectedVar != _var)
                            {
                                DeactivateAllVars();
                                ActivateVar(_var);
                            }
                        }

                        if (GUILayout.Button(icon, GUILayout.Width(20f), GUILayout.Height(15f)))
                        {
                            SideMenu(_var, _vars, location);
                        }
                    }
                    else
                    {
                        GUILayout.Label(buttonLabel, "Button");
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndScrollView();

            if (allowEditing)
            {
                EditorGUILayout.Space();
                if (GUILayout.Button("Create new " + location + " variable"))
                {
                    ResetFilter();
                    Undo.RecordObject(this, "Add " + location + " variable");
                    _vars.Add(new GVar(GetIDArray(_vars)));
                    DeactivateAllVars();
                    ActivateVar(_vars [_vars.Count - 1]);
                }
            }
        }
        private void SetVariable(GVar var, VariableLocation location, bool doSkip)
        {
            if (var == null)
            {
                return;
            }

            if (location == VariableLocation.Global)
            {
                var.Download ();
            }

            if (var.type == VariableType.Integer)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (int) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula));
                    }
                    else
                    {
                        _value = intValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value = animator.GetInteger (parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue ();
                }

                var.SetValue (_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue ();
                }
            }
            if (var.type == VariableType.Float)
            {
                float _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    if (setVarMethod == SetVarMethod.Formula)
                    {
                        _value = (float) AdvGame.CalculateFormula (AdvGame.ConvertTokens (formula));
                    }
                    else
                    {
                        _value = floatValue;
                    }
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        _value = animator.GetFloat (parameterName);
                        setVarMethod = SetVarMethod.SetValue;
                    }
                }

                if (setVarMethod == SetVarMethod.IncreaseByValue && doSkip)
                {
                    var.RestoreBackupValue ();
                }

                var.SetFloatValue (_value, setVarMethod);

                if (doSkip)
                {
                    var.BackupValue ();
                }
            }
            else if (var.type == VariableType.Boolean)
            {
                int _value = 0;

                if (setVarMethodIntBool == SetVarMethodIntBool.EnteredHere)
                {
                    _value = (int) boolValue;
                }
                else if (setVarMethodIntBool == SetVarMethodIntBool.SetAsMecanimParameter)
                {
                    if (animator && parameterName != "")
                    {
                        if (animator.GetBool (parameterName))
                        {
                            _value = 1;
                        }
                    }
                }

                var.SetValue (_value, SetVarMethod.SetValue);
            }
            else if (var.type == VariableType.PopUp)
            {
                var.SetValue (intValue);
            }
            else if (var.type == VariableType.String)
            {
                string _value = "";

                if (setVarMethodString == SetVarMethodString.EnteredHere)
                {
                    _value = AdvGame.ConvertTokens (stringValue);
                }
                else if (setVarMethodString == SetVarMethodString.SetAsMenuElementText)
                {
                    MenuElement menuElement = PlayerMenus.GetElementWithName (menuName, elementName);
                    if (menuElement != null)
                    {
                        if (menuElement is MenuInput)
                        {
                            MenuInput menuInput = (MenuInput) menuElement;
                            _value = menuInput.GetContents ();

                            if ((Options.GetLanguageName () == "Arabic" || Options.GetLanguageName () == "Hebrew") && _value.Length > 0)
                            {
                                // Invert
                                char[] charArray = _value.ToCharArray ();
                                _value = "";
                                for (int i = charArray.Length-1; i >= 0; i --)
                                {
                                    _value += charArray[i];
                                }
                            }
                        }
                        else
                        {
                            PlayerMenus.GetMenuWithName (menuName).Recalculate ();
                            menuElement.PreDisplay (slotNumber, Options.GetLanguage (), false);
                            _value = menuElement.GetLabel (slotNumber, Options.GetLanguage ());
                        }
                    }
                    else
                    {
                        Debug.LogWarning ("Could not find MenuInput '" + elementName + "' in Menu '" + menuName + "'");
                    }
                }

                var.SetStringValue (_value);
            }

            if (location == VariableLocation.Global)
            {
                var.Upload ();
            }

            KickStarter.actionListManager.VariableChanged ();
        }
Exemple #45
0
        private void ShowVarGUI(VariableLocation location, List <VarPreset> _varPresets = null)
        {
            EditorGUILayout.LabelField(location + " variable '" + selectedVar.label + "' properties", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical("Button");

            selectedVar.label = EditorGUILayout.TextField("Label:", selectedVar.label);
            selectedVar.type  = (VariableType)EditorGUILayout.EnumPopup("Type:", selectedVar.type);

            if (location == VariableLocation.Local)
            {
                EditorGUILayout.LabelField("Replacement token:", "[localvar:" + selectedVar.id.ToString() + "]");
            }
            else
            {
                EditorGUILayout.LabelField("Replacement token:", "[var:" + selectedVar.id.ToString() + "]");
            }

            if (selectedVar.type == VariableType.Boolean)
            {
                if (selectedVar.val != 1)
                {
                    selectedVar.val = 0;
                }
                selectedVar.val = EditorGUILayout.Popup("Initial value:", selectedVar.val, boolType);
            }
            else if (selectedVar.type == VariableType.Integer)
            {
                selectedVar.val = EditorGUILayout.IntField("Initial value:", selectedVar.val);
            }
            else if (selectedVar.type == VariableType.PopUp)
            {
                selectedVar.popUps = PopupsGUI(selectedVar.popUps);
                selectedVar.val    = EditorGUILayout.Popup("Initial value:", selectedVar.val, selectedVar.popUps);
            }
            else if (selectedVar.type == VariableType.String)
            {
                selectedVar.textVal = EditorGUILayout.TextField("Initial value:", selectedVar.textVal);
            }
            else if (selectedVar.type == VariableType.Float)
            {
                selectedVar.floatVal = EditorGUILayout.FloatField("Initial value:", selectedVar.floatVal);
            }

            if (_varPresets != null)
            {
                foreach (VarPreset _varPreset in _varPresets)
                {
                    _varPreset.UpdateCollection(selectedVar);

                    string      label       = "'" + _varPreset.label + "' value:";
                    PresetValue presetValue = _varPreset.GetPresetValue(selectedVar);
                    if (selectedVar.type == VariableType.Boolean)
                    {
                        presetValue.val = EditorGUILayout.Popup(label, presetValue.val, boolType);
                    }
                    else if (selectedVar.type == VariableType.Integer)
                    {
                        presetValue.val = EditorGUILayout.IntField(label, presetValue.val);
                    }
                    else if (selectedVar.type == VariableType.PopUp)
                    {
                        presetValue.val = EditorGUILayout.Popup(label, presetValue.val, selectedVar.popUps);
                    }
                    else if (selectedVar.type == VariableType.String)
                    {
                        presetValue.textVal = EditorGUILayout.TextField(label, presetValue.textVal);
                    }
                    else if (selectedVar.type == VariableType.Float)
                    {
                        presetValue.floatVal = EditorGUILayout.FloatField(label, presetValue.floatVal);
                    }
                }
            }

            if (location == VariableLocation.Local)
            {
                selectedVar.link = VarLink.None;
            }
            else
            {
                EditorGUILayout.Space();
                selectedVar.link = (VarLink)EditorGUILayout.EnumPopup("Link to:", selectedVar.link);
                if (selectedVar.link == VarLink.PlaymakerGlobalVariable)
                {
                    if (PlayMakerIntegration.IsDefinePresent())
                    {
                        selectedVar.pmVar             = EditorGUILayout.TextField("Playmaker Global Variable:", selectedVar.pmVar);
                        selectedVar.updateLinkOnStart = EditorGUILayout.Toggle("Use PM for initial value?", selectedVar.updateLinkOnStart);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The 'PlayMakerIsPresent' Scripting Define Symbol must be listed in the\nPlayer Settings. Please set it from Edit -> Project Settings -> Player", MessageType.Warning);
                    }
                }
                else if (selectedVar.link == VarLink.OptionsData)
                {
                    EditorGUILayout.HelpBox("This Variable will be stored in PlayerPrefs, and not in saved game files.", MessageType.Info);
                }
            }
            EditorGUILayout.EndVertical();
        }
        public override void ShowGUI(List<ActionParameter> parameters)
        {
            if (isAssetFile)
            {
                location = VariableLocation.Global;
            }
            else
            {
                location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
            }

            if (location == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    ShowPresetGUI (AdvGame.GetReferences ().variablesManager.varPresets);
                    ignoreOptionLinked = EditorGUILayout.ToggleLeft ("Ignore option-linked variables?", ignoreOptionLinked);
                }
            }

            else if (location == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    ShowPresetGUI (KickStarter.localVariables.varPresets);
                }
            }

            AfterRunningOption ();
        }
Exemple #47
0
        override public void ShowGUI(List <ActionParameter> parameters)
        {
            isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer);
            if (!isPlayer)
            {
                obToMoveParameterID = Action.ChooseParameterGUI("Object to move:", parameters, obToMoveParameterID, ParameterType.GameObject);
                if (obToMoveParameterID >= 0)
                {
                    obToMoveID = 0;
                    obToMove   = null;
                }
                else
                {
                    obToMove = (GameObject)EditorGUILayout.ObjectField("Object to move:", obToMove, typeof(GameObject), true);

                    obToMoveID = FieldToID(obToMove, obToMoveID);
                    obToMove   = IDToField(obToMove, obToMoveID, false);
                }
            }

            markerParameterID = Action.ChooseParameterGUI("Teleport to:", parameters, markerParameterID, ParameterType.GameObject);
            if (markerParameterID >= 0)
            {
                markerID   = 0;
                teleporter = null;
            }
            else
            {
                teleporter = (Marker)EditorGUILayout.ObjectField("Teleport to:", teleporter, typeof(Marker), true);

                markerID   = FieldToID <Marker> (teleporter, markerID);
                teleporter = IDToField <Marker> (teleporter, markerID, false);
            }

            positionRelativeTo = (PositionRelativeTo)EditorGUILayout.EnumPopup("Position relative to:", positionRelativeTo);

            if (positionRelativeTo == PositionRelativeTo.RelativeToGameObject)
            {
                relativeGameObjectParameterID = Action.ChooseParameterGUI("Relative GameObject:", parameters, relativeGameObjectParameterID, ParameterType.GameObject);
                if (relativeGameObjectParameterID >= 0)
                {
                    relativeGameObjectID = 0;
                    relativeGameObject   = null;
                }
                else
                {
                    relativeGameObject = (GameObject)EditorGUILayout.ObjectField("Relative GameObject:", relativeGameObject, typeof(GameObject), true);

                    relativeGameObjectID = FieldToID(relativeGameObject, relativeGameObjectID);
                    relativeGameObject   = IDToField(relativeGameObject, relativeGameObjectID, false);
                }
            }
            else if (positionRelativeTo == PositionRelativeTo.EnteredValue)
            {
                relativeVectorParameterID = Action.ChooseParameterGUI("Value:", parameters, relativeVectorParameterID, ParameterType.Vector3);
                if (relativeVectorParameterID < 0)
                {
                    relativeVector = EditorGUILayout.Vector3Field("Value:", relativeVector);
                }
            }
            else if (positionRelativeTo == PositionRelativeTo.VectorVariable)
            {
                if (isAssetFile)
                {
                    variableLocation = VariableLocation.Global;
                }
                else
                {
                    variableLocation = (VariableLocation)EditorGUILayout.EnumPopup("Source:", variableLocation);
                }

                if (variableLocation == VariableLocation.Global)
                {
                    vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.GlobalVariable);
                    if (vectorVarParameterID < 0)
                    {
                        vectorVarID = AdvGame.GlobalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                    }
                }
                else if (variableLocation == VariableLocation.Local)
                {
                    vectorVarParameterID = Action.ChooseParameterGUI("Vector3 variable:", parameters, vectorVarParameterID, ParameterType.LocalVariable);
                    if (vectorVarParameterID < 0)
                    {
                        vectorVarID = AdvGame.LocalVariableGUI("Vector3 variable:", vectorVarID, VariableType.Vector3);
                    }
                }
            }

            copyRotation = EditorGUILayout.Toggle("Copy rotation?", copyRotation);

            if (isPlayer)
            {
                snapCamera = EditorGUILayout.Toggle("Teleport active camera too?", snapCamera);
            }

            if (isPlayer || (obToMove != null && obToMove.GetComponent <Char>()))
            {
                recalculateActivePathFind = EditorGUILayout.Toggle("Recalculate pathfinding?", recalculateActivePathFind);
            }

            AfterRunningOption();
        }
        public override void ShowGUI(List<ActionParameter> parameters)
        {
            if (isAssetFile)
            {
                location = VariableLocation.Global;
            }
            else
            {
                location = (VariableLocation) EditorGUILayout.EnumPopup ("Source:", location);
            }

            if (location == VariableLocation.Global)
            {
                if (AdvGame.GetReferences ().variablesManager)
                {
                    parameterID = Action.ChooseParameterGUI ("Integer variable:", parameters, parameterID, ParameterType.GlobalVariable);
                    if (parameterID >= 0)
                    {
                        variableID = ShowVarGUI (AdvGame.GetReferences ().variablesManager.vars, variableID, false);
                    }
                    else
                    {
                        variableID = ShowVarGUI (AdvGame.GetReferences ().variablesManager.vars, variableID, true);
                    }
                }
            }

            else if (location == VariableLocation.Local)
            {
                if (KickStarter.localVariables)
                {
                    parameterID = Action.ChooseParameterGUI ("Integer variable:", parameters, parameterID, ParameterType.LocalVariable);
                    if (parameterID >= 0)
                    {
                        variableID = ShowVarGUI (KickStarter.localVariables.localVars, variableID, false);
                    }
                    else
                    {
                        variableID = ShowVarGUI (KickStarter.localVariables.localVars, variableID, true);
                    }
                }
            }

            numSockets = EditorGUILayout.IntSlider ("# of possible values:", numSockets, 1, 10);
            doLoop = EditorGUILayout.Toggle ("Run on a loop?", doLoop);
        }
Exemple #49
0
        public void FindInputs(InstructionInputList inputs, VariableLocation location)
        {
            var seen = new List <Instruction>();

            FindInputs(this, inputs, seen, location);
        }