Exemple #1
0
        /// <summary>
        /// Adds a component to given Game Object that listens for it to be enabled.
        /// </summary>
        /// <param name="obj">The Game Object to listen to</param>
        /// <param name="callback">The function to call when enabled</param>
        /// <param name="skipFirstTime">Skip the first enable?</param>
        public static void AddOnEnableListener(GameObject obj, Callback callback, bool skipFirstTime = false)
        {
            OnEnableListener listener = obj.AddComponent <OnEnableListener>();

            listener.Callback      = callback;
            listener.SkipFirstTime = skipFirstTime;
        }
 private void Start()
 {
     callback = Callback;
     foreach (GameObject gameObject in gameObjects)
     {
         OnEnableListener listener = gameObject.GetComponent <OnEnableListener>();
         if (listener == null)
         {
             listener = gameObject.AddComponent(typeof(OnEnableListener)) as OnEnableListener;
         }
         listener.SetCallback(callback);
     }
 }