示例#1
0
        private void InitializationButton()
        {
            int index = 0;

            //Initialization for all entity state tags would be to clear the state
            //change event and rig it up to initialize itself with the dispatchers to
            //the object itself and a broadcast component if one exists
            gameObject.GetComponents(typeof(IEntityStateListener))
            .Cast <IEntityStateListener>()
            .ToList()
            .ForEach(listener =>
            {
                if (OnStateChanged.GetPersistentEventCount() <= index)
                {
                    //We must call this internal method to expand the persistent listener collection before
                    //attempting to hack register a new one
                    OnStateChanged.CallMethod("AddPersistentListener", Flags.InstanceAnyVisibility);
                }

                //We can't easily register new persistent methods so this hack allows us to contrary to Unity
                //allows us to do.
                OnStateChanged.CallMethod("RegisterPersistentListener", Flags.InstanceAnyVisibility,
                                          index, listener, typeof(IEntityStateListener).Method(nameof(IEntityStateListener.OnEntityStateChanged)));
                index++;
            });
        }