Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

show / hide variables according to an enum in a an array

Discussion in 'Scripting' started by Hishicorne, Sep 12, 2017.

  1. Hishicorne

    Hishicorne

    Joined:
    Jun 25, 2017
    Posts:
    26
    Hey everyone,

    I'm trying to hide or show variables according to the current state of an enum in an array - here's the code of the concerned array.

    Code (CSharp):
    1. public enum ActionType { Move, Shoot, RotateShoot, Wait, Explode, Replay };
    2. public enum ShootType { Classic, Laser };
    3.  
    4. public EnemyPattern Pattern = new EnemyPattern();
    5. [System.Serializable] public class EnemyPattern {
    6.     public List<PatternAction> state;
    7. } [System.Serializable] public class PatternAction {
    8.     public ActionType Action;
    9.  
    10.     [Header("For Action Move")]
    11.     [Range(2, 20)] public int Speed = 2;
    12.     public Vector2 distance;
    13.  
    14.     [Header("For Action Shoot")]
    15.     public ShootType Shoot;
    16.     public GameObject ShotPrefab;
    17.     [Range(1, 50)] public int NumberShoot = 1;
    18.     [Range(1, 50)] public float ShootSpeed = 5;
    19.     [Range(0, 10)] public float TimeBetweenShoot = 0.2f;
    20.  
    21.     [Header("For Action Rotate Shoot")]
    22.     [Range(-360, 360)] public float Rotation = 0f;
    23.  
    24.     [Header("For Action Wait")]
    25.     [Range(0, 60)] public int TimeToWait = 0;
    26. }    
    Also I have this code in the editor code :

    Code (CSharp):
    1.  using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4. [CustomEditor(typeof(EnemyController))]
    5. public class EnemyControllerInspector : Editor {
    6.     override public void OnInspectorGUI () {
    7.         EnemyController script = (EnemyController)target;
    8.        
    9.         EnemyController.PatternAction.Action = (EnemyController.ActionType)EditorGUILayout.EnumPopup("Action", EnemyController.PatternAction.Action);
    10.        
    11.         for (int i = 0; i < script.Pattern.state.Count; i++) {
    12.             if (script.Pattern.state[i].Action == script.ActionType.Move) {
    13.                 script.Pattern.state[i].Speed = EditorGUILayout.IntField("Speed", script.Pattern.state[i].Speed);
    14.                 script.Pattern.state[i].distance = EditorGUILayout.Vector2Field("Test int", script.Pattern.state[i].distance);
    15.             }
    16.         }
    17.     }
    18. }
    The problem is that I don't know how to access to the values, I know this is wrong but I don't know how to do it correctly... May I have a bit of help ? Thank you !
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    2,843