Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Status system for personal FSM.

Discussion in 'Scripting' started by KiwiYz, Apr 15, 2021.

  1. KiwiYz

    KiwiYz

    Joined:
    Aug 31, 2020
    Posts:
    3
    Hi, I am trying to implement my own version of a Finite State Machine (due to a lot of reasons) and I am trying to implement status systems that follows the next rules:

    - Every status must belong to a predefined category, for example, ORIENTATION, STATUS_EFFECT, SPEED, etc.

    - Some status (statuses?) have a limited set of options, for example, ORIENTATION can only be a N,E,S,W. Which type is relative since it can be fixed later.

    - Finally for the FSM transitions I want to be capable of choosing, similar to the Unity Animation FSM, choose a state and a value for comparison. And yeah, an operation (such as ==, !=, >=, etcetc but that comes later).

    - States of the FSM are scriptable objects.

    As of now, If used only one, and one status, I could just do this:
    Code (csharp):
    1.  
    2. enum Orientation{
    3. N,
    4. E,
    5. S,
    6. W
    7. }
    8.  
    9. public Orientation orientation = Orientation.N \\Default;
    10.  
    That would let me choose an orientation within a dropdown box.
    But what I kindofish want is to have two dropdown boxes, one to choose the kind of status, and another one to choose it's value.

    I tried this but didnt work
    Code (csharp):
    1.  
    2. public enum status_list{
    3.     placeholder,
    4.     orientation
    5. }
    6.  
    7. public class Orientation{
    8.     public enum Orientation_options{N,E,W,S}
    9.  
    10.     public Orientation_options value;
    11. }
    12.  
    13. class Status : MonoBehaviour{
    14.     public Dictionary<status_list,System.Type> status_dict =
    15.            new Dictionary<status_list, System.Type>();
    16.     status_dict.Add(status_list.orientation,Character.Orientation);
    17.    
    18.  
    19.     public status_list status_to_choose = status_list.placeholder;
    20.  
    21.     public void OnValidate()
    22.     {
    23.         if (status_to_choose!=status_list.placeholder)
    24.         {
    25.                object o =
    26.                System.Activator.CreateInstance(status_dict[status_to_choose]);
    27.         }
    28.     }
    29. }
    30.  
    31.  
    But it didnt even remotely work. Prolly cause lot's of reasons.
    Any ideas?
     
  2. KiwiYz

    KiwiYz

    Joined:
    Aug 31, 2020
    Posts:
    3
    The
    Character.Orientation
    class is the one above Orientation, copy/pasted and I am a dummy.