Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    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:
    21
    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,507