Ejemplo n.º 1
0
 public StateIndex(StateIndex _src)
 {
     m_ValueNow            = _src.m_ValueNow;
     m_PreviousValue       = _src.m_PreviousValue;
     m_ChangeTime          = _src.m_ChangeTime;
     m_JustChangeStateFlag = _src.m_JustChangeStateFlag;
     m_FirstElapsedFlag    = _src.m_FirstElapsedFlag;
 }
Ejemplo n.º 2
0
    public void ChangeState(StateIndex nextState)
    {
        if (StateBase != null)
        {
            StateBase.Exit();
        }

        StateBase = CreateStateInstance(nextState);

        StateBase.Initiate();
    }
Ejemplo n.º 3
0
    public State CreateStateInstance(StateIndex NextState)
    {
        switch (NextState)
        {
        //case StateIndex.IDLE: return new State_Idle(mono);
        case StateIndex.PATROL: StateBase = new State_Patrol(mono); break;

        case StateIndex.CHASE: StateBase = new State_Chase(mono); break;

        case StateIndex.ATTACK: StateBase = new State_Attack(mono); break;

        case StateIndex.JUMP: StateBase = new State_Jump(mono); break;

        case StateIndex.STURN: StateBase = new State_Sturn(mono); break;
        }
        return(StateBase);
    }
Ejemplo n.º 4
0
 public BasicTrigger( BasicTrigger _src )
 {
     m_State = new StateIndex( _src.m_State ) ;
     Debug_StateNow = _src.Debug_StateNow ;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (!running)
            {
                foreach (GameComponent comp in this.Components)
                {
                    comp.Enabled = false;
                }
            }
            MouseState ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            KeyboardState ks = Keyboard.GetState();

            if (gameMenu.Enabled == true && 305 < ms.X && ms.X < 495 && 178 < ms.Y && ms.Y < 222)
            {
                if (ms.LeftButton == ButtonState.Released && prevStateMouse.LeftButton == ButtonState.Pressed)
                {
                    stateChanged = true;
                    state = StateIndex.GAMESTATE;
                }
            }
            if (gameMap.Enabled == false && ks.IsKeyUp(Keys.P) && prevStateKeyB.IsKeyDown(Keys.P) && togglePause == true) //unpause
            {
                stateChanged = true;
                togglePause = false;
                state = StateIndex.GAMESTATE;
            }

            if (gameMap.Enabled == true && ks.IsKeyUp(Keys.P) && prevStateKeyB.IsKeyDown(Keys.P) && togglePause == false) //pause
            {
                stateChanged = true;
                togglePause = true;
                state = StateIndex.PAUSESTATE;

            }
            prevStateKeyB = ks;
            prevStateMouse = ms;

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (stateChanged)
            {
                switch (state)
                {
                    case StateIndex.MENUSTATE:
                        foreach (GameComponent Component in this.Components)
                        {
                            if (!(Component is MenuStateMachine))
                            {
                                Component.Enabled = false;

                                if (Component is DrawableGameComponent)
                                {
                                    (Component as DrawableGameComponent).Visible = false;
                                }
                            }
                        }
                        stateChanged = false;
                        break;
                    case StateIndex.GAMESTATE:
                        foreach (GameComponent Component in this.Components)
                        {
                            if (!(Component is MenuStateMachine))
                            {
                                Component.Enabled = true;

                                if (Component is DrawableGameComponent)
                                {
                                    (Component as DrawableGameComponent).Visible = true;
                                }
                            }
                            gameMenu.Visible = false;
                            gameMenu.Enabled = false;
                            IsMouseVisible = false;
                        }
                        stateChanged = false;
                        break;
                    case StateIndex.PAUSESTATE:
                        foreach (GameComponent Component in this.Components)
                        {
                            if (!(Component is MenuStateMachine)||!(Component is hud))
                            {
                                Component.Enabled = false;
                            }
                            else
                            {
                                Component.Enabled = true;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }

            /*this.graphics.PreferredBackBufferHeight = 1050;
            this.graphics.PreferredBackBufferWidth = 1200;
            this.graphics.ApplyChanges();*/

            base.Update(gameTime);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            //spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            this.state = StateIndex.MENUSTATE;
            base.LoadContent();
        }
Ejemplo n.º 7
0
	public StateIndex( StateIndex _src )
	{
		m_ValueNow = _src.m_ValueNow ;
		m_PreviousValue = _src.m_PreviousValue ;
		m_ChangeTime = _src.m_ChangeTime ;
		m_JustChangeStateFlag = _src.m_JustChangeStateFlag ;
		m_FirstElapsedFlag = _src.m_FirstElapsedFlag ;
	}
Ejemplo n.º 8
0
        public async Task <IActionResult> Get(Int64 id)
        {
            StateIndex result = await _repo.GetEntry(id);

            return(Ok(result));
        }
Ejemplo n.º 9
0
        //---------------------------------------------------------------------
        // Load
        //---------------------------------------------------------------------
        public void Load()
        {
            //-------------------------------------------------
            // Assets
            //-------------------------------------------------
#if UNITY_EDITOR
            if (Asset == null)
            {
                Asset = ScriptableObject.CreateInstance <GolemAsset>();
            }
#endif
            if (Asset == null)
            {
                gameObject.SetActive(false);
                throw new InvalidProgramException("entity has no data");
            }

            //-------------------------------------------------
            // Deserialize
            //-------------------------------------------------
            var serializer = Serialization.GetSerializer(References);
            Dictionary <string, object> deserialized = new Dictionary <string, object>();
            {
                fsData   data;
                fsResult result;

                if (Asset.Data != null)
                {
                    data = Asset.Data;
                }
                else
                {
                    result = fsJsonParser.Parse(Asset.Json, out data);
                    if (result.Failed)
                    {
                        Debug.LogError(result, this);
                        return;
                    }
                    Asset.Data = data;
                }

                result = serializer.TryDeserialize(data, ref deserialized);
                if (result.Failed)
                {
                    Debug.LogError(result, this);
                    return;
                }
            }

            //-------------------------------------------------
            // Variables
            //-------------------------------------------------
            if (deserialized.ContainsKey("Variables"))
            {
                Variables.NextFrameValues = deserialized["Variables"] as Dictionary <string, object>;
                Variables.Values          = new Dictionary <string, object>(Variables.NextFrameValues);
            }

            //-------------------------------------------------
            // Aspects
            //-------------------------------------------------
            if (deserialized.ContainsKey("Aspects"))
            {
                var thisType = GetType();
                var aspects  = deserialized["Aspects"] as Dictionary <string, Aspect>;
                foreach (var kvp in aspects)
                {
                    var aspect = kvp.Value;
                    aspect.Golem     = this;
                    aspect.Variables = Variables;
                    var field = thisType.GetField(kvp.Key);
                    if (field == null)
                    {
                        Debug.LogError("No field available for aspect type " + kvp.Key, this);
                        continue;
                    }
                    field.SetValue(this, aspect);
                }
            }

            //-------------------------------------------------
            // Circuit
            //-------------------------------------------------
            if (deserialized.ContainsKey("Registers"))
            {
                _registers = deserialized["Registers"] as object[];
            }
            else
            {
                _registers = new object[0];
            }

            if (deserialized.ContainsKey("VariablesThatWriteRegister"))
            {
                _variablesThatWriteRegister = deserialized["VariablesThatWriteRegister"] as Dictionary <string, int[]>;
            }
            else
            {
                _variablesThatWriteRegister = new Dictionary <string, int[]>();
            }

            if (deserialized.ContainsKey("CellsThatReadRegister"))
            {
                _cellsThatReadRegister = deserialized["CellsThatReadRegister"] as int[][];
            }
            else
            {
                _cellsThatReadRegister = new int[0][];
            }

            if (deserialized.ContainsKey("Cells"))
            {
                Cells = deserialized["Cells"] as Cell[];
            }
            else
            {
                Cells = new Cell[0];
            }

            foreach (var kvp in _variablesThatWriteRegister)
            {
                object value            = Variables.Get(kvp.Key);
                int[]  registersToWrite = kvp.Value;
                for (int i = 0; i < registersToWrite.Length; ++i)
                {
                    _registers[i] = value;
                }
            }

            _dirty   = new bool[Cells.Length];
            _running = new bool[Cells.Length];
            for (int i = 0; i < _dirty.Length; ++i)
            {
                Cells[i].Acquire(this, ref _running[i]);
            }

            //-------------------------------------------------
            // Program
            //-------------------------------------------------
            if (deserialized.ContainsKey("Scripts"))
            {
                Layers  = deserialized["Layers"] as Layer[];
                States  = deserialized["States"] as State[];
                Scripts = deserialized["Scripts"] as Script[];
            }
            else
            {
                Layers  = new Layer[0];
                States  = new State[0];
                Scripts = new Script[0];
            }
            Triggers   = new bool[(int)Trigger.__COUNT__];
            LayerState = new StateIndex[Layers.Length];
            for (int i = 0; i < LayerState.Length; ++i)
            {
                LayerState[i] = StateIndex.Idle;
            }
            for (int i = 0; i < Scripts.Length; ++i)
            {
                Scripts[i].Acquire(this);
            }
        }
Ejemplo n.º 10
0
    private void DrawEventData(EventData data)
    {
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

        using (new EditorGUILayout.HorizontalScope())
        {
            EditorGUILayout.LabelField("Display Name: ", GUILayout.MaxWidth(100));
            _selectedName = EditorGUILayout.TextField(_selectedName);
            if (GUILayout.Button("Rename", EditorStyles.toolbarButton, GUILayout.Width(60)))
            {
                data.Name = _selectedName;
            }
        }

        using (new EditorGUILayout.HorizontalScope())
        {
            using (var check = new EditorGUI.ChangeCheckScope())
            {
                EditorGUILayout.LabelField("Target Controller: ", GUILayout.MaxWidth(100));
                data.TargetController = EditorGUILayout.ObjectField(data.TargetController,
                                                                    typeof(AnimatorController), false) as AnimatorController;

                if (check.changed)
                {
                }
            }
        }

        if (data.TargetController != null)
        {
            // Draw Layers
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.LabelField("1. Select Layer", EditorStyles.centeredGreyMiniLabel);

            var animatorController = (AnimatorController)data.TargetController;
            for (var i = 0; i < animatorController.layers.Length; i++)
            {
                var layer = animatorController.layers[i];

                if (i == _selectedLayer)
                {
                    GUI.backgroundColor = Color.green;
                }

                if (GUILayout.Button(i + " - " + layer.name))
                {
                    _selectedLayer = i;
                }

                GUI.backgroundColor = Color.white;
            }

            EditorGUILayout.EndVertical();

            // Draw States
            if (_selectedLayer != -1)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.LabelField("2. Select State", EditorStyles.centeredGreyMiniLabel);

                var stateMachine = animatorController.layers[_selectedLayer].stateMachine;
                for (var i = 0; i < stateMachine.states.Length; i++)
                {
                    var state = stateMachine.states[i];

                    if (state.state.nameHash == _selectedState)
                    {
                        GUI.backgroundColor = Color.green;
                    }

                    if (GUILayout.Button(state.state.name))
                    {
                        SetupPreview(state.state.motion);
                        previewedMotion = state.state.motion;
                        _selectedState  = state.state.nameHash;
//                        Debug.Log(_selectedState);
                        _selectedEventArg = null;
                    }

                    GUI.backgroundColor = Color.white;
                }

                EditorGUILayout.EndVertical();
            }

            // Draw Events
            if (_selectedState != -1)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                var index = new StateIndex(_selectedLayer, _selectedState);
                if (!data.Configs.ContainsKey(index))
                {
                    data.Configs.Add(index, new AnimatorEvents());
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField("Normalized", GUILayout.Width(100));

                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        _normalizedSetting = EditorGUILayout.Slider(_normalizedSetting, 0, 1);
                        if (check.changed)
                        {
                            if (_avatarPreview != null)
                            {
                                _avatarPreview.Animator.Play(0, 0, _normalizedSetting);
                                _avatarPreview.timeControl.normalizedTime = _normalizedSetting;
                            }

                            if (_selectedEventArg != null)
                            {
                                _selectedEventArg.NormalizedTime = _normalizedSetting;
                                data.Configs[index] =
                                    new AnimatorEvents(data.Configs[index].Value.OrderBy(x => x.NormalizedTime));
                            }
                        }
                    }

                    if (GUILayout.Button("Add Event", EditorStyles.toolbarButton))
                    {
                        var countNum = data.Configs[index].Value.Count;

                        var newEventArg = new AnimatorEventArgs
                        {
                            Name           = "New Event " + countNum,
                            NormalizedTime = _normalizedSetting
                        };

                        data.Configs[index].Value.Add(newEventArg);
                        data.Configs[index] = new AnimatorEvents(data.Configs[index].Value.OrderBy(x => x.NormalizedTime));

                        _selectedEventArg = newEventArg;
                        EditorUtility.SetDirty(_dataSet);
                    }
                }

                EditorGUILayout.LabelField("3. Edit Events", EditorStyles.centeredGreyMiniLabel);

                for (var i = 0; i < data.Configs[index].Value.Count; i++)
                {
                    var evt            = data.Configs[index].Value[i];
                    var normalizedTime = evt.NormalizedTime.ToString("F3");

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        if (_selectedEventArg == evt)
                        {
                            GUI.backgroundColor = Color.green;
                        }

                        if (GUILayout.Button(normalizedTime + " - " + evt.Name))
                        {
                            if (_selectedEventArg == evt)
                            {
                                _selectedEventArg = null;
                                continue;
                            }

                            _selectedEventArg  = evt;
                            _selectedEventName = evt.Name;
                            _normalizedSetting = evt.NormalizedTime;

                            if (_avatarPreview != null)
                            {
                                _avatarPreview.Animator.Play(0, 0, evt.NormalizedTime);
                                _avatarPreview.timeControl.normalizedTime = evt.NormalizedTime;
                            }
                        }

                        GUI.backgroundColor = Color.white;

                        if (GUILayout.Button("DEL", GUILayout.Width(45)))
                        {
                            _delayedActions.Add(() => data.Configs[index].Value.Remove(evt));
                            if (_selectedEventArg == evt)
                            {
                                _selectedEventArg = null;
                            }
                        }
                    }
                }

                if (_selectedEventArg != null)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.LabelField("Display Name: ", GUILayout.MaxWidth(100));
                        _selectedEventName = EditorGUILayout.TextField(_selectedEventName);
                        if (GUILayout.Button("Rename", EditorStyles.toolbarButton, GUILayout.Width(60)))
                        {
                            _selectedEventArg.Name = _selectedEventName;
                        }
                    }

                    _selectedEventArg.Type =
                        (AnimatorEventType)EditorGUILayout.EnumPopup("Event Type", _selectedEventArg.Type);

                    switch (_selectedEventArg.Type)
                    {
                    case AnimatorEventType.Pure:
                        break;

                    case AnimatorEventType.Float:
                        _selectedEventArg.FloatParm =
                            EditorGUILayout.FloatField("Float Parameter", _selectedEventArg.FloatParm);
                        break;

                    case AnimatorEventType.Int:
                        _selectedEventArg.IntParm =
                            EditorGUILayout.IntField("Int Parameter", _selectedEventArg.IntParm);
                        break;

                    case AnimatorEventType.String:
                        _selectedEventArg.StringParm =
                            EditorGUILayout.TextField("String Parameter", _selectedEventArg.StringParm);
                        break;

                    case AnimatorEventType.Object:
                        _selectedEventArg.ObjectParm = EditorGUILayout.ObjectField("Object Parameter",
                                                                                   _selectedEventArg.ObjectParm, typeof(Object), false);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    EditorGUILayout.EndVertical();
                }

                EditorGUILayout.EndVertical();
            }
        }

        EditorGUILayout.EndVertical();
    }
Ejemplo n.º 11
0
    /*______________________________________________________________________________________*/

    public void SetState(StateIndex state, int value)
    {
        realTimeStates[(int)state] = value;
    }
Ejemplo n.º 12
0
 public BasicTrigger(BasicTrigger _src)
 {
     m_State        = new StateIndex(_src.m_State);
     Debug_StateNow = _src.Debug_StateNow;
 }