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

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

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

            selectedType = VariableType.Unknown;

            return(false);
        }
        void ScanAttributesIfNeeded(SerializedProperty property)
        {
            if (!attributeScanned)
            {
                attributeScanned = true;


                // check for FsmVariableTargetVariable Attribute
                object[] _variableTargets = this.fieldInfo.GetCustomAttributes(typeof(FsmVariableTargetVariable), true);

                if (_variableTargets.Length > 0)
                {
                    string variableName = (_variableTargets[0] as FsmVariableTargetVariable).variable;
                    variableTargetVariable = property.serializedObject.FindProperty(variableName);

                    _variabletargetTarget = PlayMakerInspectorUtils.GetBaseProperty <PlayMakerFsmVariableTarget>(variableTargetVariable);
                }

                if (variableTargetVariable != null)
                {
                    variableTarget    = variableTargetVariable.FindPropertyRelative("variableTarget");
                    gameObject        = variableTargetVariable.FindPropertyRelative("gameObject");
                    fsmComponent      = variableTargetVariable.FindPropertyRelative("fsmComponent");
                    isTargetAvailable = variableTargetVariable.FindPropertyRelative("isTargetAvailable");
                }

                // check for FsmVariableType Attribute
                //	object[] _variableTypes = this.fieldInfo.GetCustomAttributes(typeof(),true);

                /*
                 * if (_variableTypes.Length>0)
                 * {
                 *      VariableType variableType = (_variableTypes[0] as FsmVariableType).variableType;
                 * }
                 */
            }
        }
		public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label)
		{
			_target = PlayMakerInspectorUtils.GetBaseProperty<PlayMakerFsmVariableTarget>(prop);

			bool isDirty = false;

			fsmVariableTarget = prop.FindPropertyRelative("variableTarget");
			int _variableTargetIndex = fsmVariableTarget.enumValueIndex;

			gameObject = prop.FindPropertyRelative("gameObject");
			fsmName = prop.FindPropertyRelative("fsmName");
			fsmComponent = prop.FindPropertyRelative("_fsmComponent");

			CacheOwnerGameObject(prop.serializedObject);

			int row = 0;

			// draw the enum popup Field
			int oldEnumIndex = fsmVariableTarget.enumValueIndex;

			// force the GameObject value to be the owner when switching to it
			// this is just to fall back nicely on a preset that is the expected one, as opposed to target nothing
			if (oldEnumIndex==0 && gameObject.objectReferenceValue!=ownerGameObject)
			{
				gameObject.objectReferenceValue = ownerGameObject;
				fsmName.stringValue = "";
				isDirty = true;
			}

			EditorGUI.PropertyField(
				GetRectforRow(pos,++row -1),
				fsmVariableTarget,label,true);

			if (_variableTargetIndex != fsmVariableTarget.enumValueIndex)
			{
				prop.serializedObject.ApplyModifiedProperties();
				prop.serializedObject.Update();
				_target.Initialize(true);

				//Debug.Log("Initialized isTargetAvailable?"+_target.isTargetAvailable);
				return;
			}

			// force the GameObject value to be the owner when switching to it
			// this is just to fall back nicely on a preset that is the expected one, as opposed to target nothing
			if (oldEnumIndex==0 && gameObject.objectReferenceValue!=ownerGameObject)
			{
				gameObject.objectReferenceValue = ownerGameObject;
				fsmName.stringValue = "";
				isDirty = true;
			}

			// Additional fields
			if (fsmVariableTarget.enumValueIndex==0 || fsmVariableTarget.enumValueIndex==1) // targeting Owner or GameObject:
			{

				if (string.IsNullOrEmpty(fsmName.stringValue) || !updateFsmList())
				{
					GameObject _go = (GameObject)gameObject.objectReferenceValue;
					if (_go!=null)
					{
						PlayMakerFSM _fsm = _go.GetComponent<PlayMakerFSM>();
						if (_fsm!=null)
						{
							fsmName.stringValue = _fsm.FsmName;
							isDirty = true;
						}
					}
				}

				EditorGUI.indentLevel++;

				if (fsmVariableTarget.enumValueIndex==1)
				{
					int _goId =  gameObject.objectReferenceInstanceIDValue;
					EditorGUI.PropertyField(
						GetRectforRow(pos,++row -1),
						gameObject,new GUIContent("Game Object"),true);

					if (_goId!=gameObject.objectReferenceInstanceIDValue)
					{
						isDirty=true;
					}
				}

				Rect _rect= GetRectforRow(pos,++row -1);


				string _name = fsmName.stringValue;
				Rect _fieldRect = new Rect(_rect);
				_fieldRect.width -= 18;
				EditorGUI.PropertyField(
					_fieldRect,
					fsmName,new GUIContent("Fsm Name"),true);

				if (_name!= fsmName.stringValue)
				{
					isDirty = true;
				}

				_rect.xMin = _rect.xMax -16;
			
				// Fsm Name Popup 
				if (GUI.Button(
					_rect,
					"", 
					EditorStyles.popup)
				    )
				{	
					updateFsmList();

					GenericMenu menu = GenerateFsmMenu(fsmList,fsmName.stringValue);
					menu.DropDown(_fieldRect);

					// move the focus out to reflect the change of the menu selection
					GUI.SetNextControlName("noFocus");
					GUI.FocusControl("noFocus");
				}


				EditorGUI.indentLevel--;
			}else if (fsmVariableTarget.enumValueIndex==3) { // targeting  FsmComponent;

				EditorGUI.indentLevel++;

				int _objId = fsmComponent.objectReferenceInstanceIDValue;
				EditorGUI.PropertyField(
					GetRectforRow(pos,++row -1),
					fsmComponent,new GUIContent("Fsm Component"),true);

				if (_objId!=fsmComponent.objectReferenceInstanceIDValue)
				{
					Debug.Log("yo "+_objId+" "+fsmComponent.objectReferenceInstanceIDValue);
					isDirty = true;
				}

				EditorGUI.indentLevel--;
			}

			// attempt to refresh UI and avoid glitch
			if (row!=rowCount || isDirty)
			{
				prop.serializedObject.ApplyModifiedProperties();
				prop.serializedObject.Update();

				_target.Initialize(true);
			}

		

			// update the rowCount to compute the right interface height
			rowCount = row;
		}
Exemple #4
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            _target = PlayMakerInspectorUtils.GetBaseProperty <PlayMakerFsmVariableTarget>(prop);

            bool isDirty = false;

            fsmVariableTarget = prop.FindPropertyRelative("variableTarget");
            int _variableTargetIndex = fsmVariableTarget.enumValueIndex;

            gameObject   = prop.FindPropertyRelative("gameObject");
            fsmName      = prop.FindPropertyRelative("fsmName");
            fsmComponent = prop.FindPropertyRelative("_fsmComponent");

            CacheOwnerGameObject(prop.serializedObject);

            int row = 0;

            // draw the enum popup Field
            int oldEnumIndex = fsmVariableTarget.enumValueIndex;

            // force the GameObject value to be the owner when switching to it
            // this is just to fall back nicely on a preset that is the expected one, as opposed to target nothing
            if (oldEnumIndex == 0 && gameObject.objectReferenceValue != ownerGameObject)
            {
                gameObject.objectReferenceValue = ownerGameObject;
                fsmName.stringValue             = "";
                isDirty = true;
            }

            EditorGUI.PropertyField(
                GetRectforRow(pos, ++row - 1),
                fsmVariableTarget, label, true);

            if (_variableTargetIndex != fsmVariableTarget.enumValueIndex)
            {
                prop.serializedObject.ApplyModifiedProperties();
                prop.serializedObject.Update();
                _target.Initialize(true);

                //Debug.Log("Initialized isTargetAvailable?"+_target.isTargetAvailable);
                return;
            }

            // force the GameObject value to be the owner when switching to it
            // this is just to fall back nicely on a preset that is the expected one, as opposed to target nothing
            if (oldEnumIndex == 0 && gameObject.objectReferenceValue != ownerGameObject)
            {
                gameObject.objectReferenceValue = ownerGameObject;
                fsmName.stringValue             = "";
                isDirty = true;
            }

            // Additional fields
            if (fsmVariableTarget.enumValueIndex == 0 || fsmVariableTarget.enumValueIndex == 1)         // targeting Owner or GameObject:
            {
                if (string.IsNullOrEmpty(fsmName.stringValue) || !updateFsmList())
                {
                    GameObject _go = (GameObject)gameObject.objectReferenceValue;
                    if (_go != null)
                    {
                        PlayMakerFSM _fsm = _go.GetComponent <PlayMakerFSM>();
                        if (_fsm != null)
                        {
                            fsmName.stringValue = _fsm.FsmName;
                            isDirty             = true;
                        }
                    }
                }

                EditorGUI.indentLevel++;

                if (fsmVariableTarget.enumValueIndex == 1)
                {
                    int _goId = gameObject.objectReferenceInstanceIDValue;
                    EditorGUI.PropertyField(
                        GetRectforRow(pos, ++row - 1),
                        gameObject, new GUIContent("Game Object"), true);

                    if (_goId != gameObject.objectReferenceInstanceIDValue)
                    {
                        isDirty = true;
                    }
                }

                Rect _rect = GetRectforRow(pos, ++row - 1);


                string _name      = fsmName.stringValue;
                Rect   _fieldRect = new Rect(_rect);
                _fieldRect.width -= 18;
                EditorGUI.PropertyField(
                    _fieldRect,
                    fsmName, new GUIContent("Fsm Name"), true);

                if (_name != fsmName.stringValue)
                {
                    isDirty = true;
                }

                _rect.xMin = _rect.xMax - 16;

                // Fsm Name Popup
                if (GUI.Button(
                        _rect,
                        "",
                        EditorStyles.popup)
                    )
                {
                    updateFsmList();

                    GenericMenu menu = GenerateFsmMenu(fsmList, fsmName.stringValue);
                    menu.DropDown(_fieldRect);

                    // move the focus out to reflect the change of the menu selection
                    GUI.SetNextControlName("noFocus");
                    GUI.FocusControl("noFocus");
                }


                EditorGUI.indentLevel--;
            }
            else if (fsmVariableTarget.enumValueIndex == 3)              // targeting  FsmComponent;

            {
                EditorGUI.indentLevel++;

                int _objId = fsmComponent.objectReferenceInstanceIDValue;
                EditorGUI.PropertyField(
                    GetRectforRow(pos, ++row - 1),
                    fsmComponent, new GUIContent("Fsm Component"), true);

                if (_objId != fsmComponent.objectReferenceInstanceIDValue)
                {
                    Debug.Log("yo " + _objId + " " + fsmComponent.objectReferenceInstanceIDValue);
                    isDirty = true;
                }

                EditorGUI.indentLevel--;
            }

            // attempt to refresh UI and avoid glitch
            if (row != rowCount || isDirty)
            {
                prop.serializedObject.ApplyModifiedProperties();
                prop.serializedObject.Update();

                _target.Initialize(true);
            }



            // update the rowCount to compute the right interface height
            rowCount = row;
        }
		public bool GetVariable(PlayMakerFsmVariableTarget variableTarget)
		{
			initialized = true;
			targetUndefined = true;
			if (variableTarget.FsmVariables !=null)
			{
				targetUndefined = false;
				variableNameToUse = string.IsNullOrEmpty(variableName)?defaultVariableName:variableName;

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

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

			selectedType = VariableType.Unknown;
			
			return false;
		}
		void ScanAttributesIfNeeded(SerializedProperty property)
		{
			if (!attributeScanned)
			{
				attributeScanned = true;

			
				// check for FsmVariableTargetVariable Attribute
				object[] _variableTargets = this.fieldInfo.GetCustomAttributes(typeof(FsmVariableTargetVariable),true);
				
				if (_variableTargets.Length>0)
				{
					string variableName = (_variableTargets[0] as FsmVariableTargetVariable).variable;
					variableTargetVariable = property.serializedObject.FindProperty(variableName);

					_variabletargetTarget =  PlayMakerInspectorUtils.GetBaseProperty<PlayMakerFsmVariableTarget>(variableTargetVariable);
				}

				if (variableTargetVariable!=null)
				{
					variableTarget = variableTargetVariable.FindPropertyRelative("variableTarget");
					gameObject = variableTargetVariable.FindPropertyRelative("gameObject");
					fsmComponent = variableTargetVariable.FindPropertyRelative("fsmComponent");
					isTargetAvailable = variableTargetVariable.FindPropertyRelative("isTargetAvailable");
				}

				// check for FsmVariableType Attribute
			//	object[] _variableTypes = this.fieldInfo.GetCustomAttributes(typeof(),true);

				/*
				if (_variableTypes.Length>0)
				{
					VariableType variableType = (_variableTypes[0] as FsmVariableType).variableType;
				}
*/

				
			}
		}