Ejemplo n.º 1
0
 void OnEventSendInternal(string eventName, GameObject source, GameObject destination, EventManager.EventType eventType)
 {
     OnEventSent(eventName, source, destination, eventType);
     foreach (var listener in listeners)
     {
         try
         {
             listener.Value(eventName, source, destination);
         }
         catch (Exception e)
         {
             WeaverLog.LogError("Event Listener Error: " + e);
         }
     }
 }
Ejemplo n.º 2
0
 private void ShakePosition_UpdateShaking(On.HutongGames.PlayMaker.Actions.ShakePosition.orig_UpdateShaking orig, ShakePosition self)
 {
     try
     {
         if (CustomShake && self.State.Name.Contains("Shake") && self.State.Fsm == shakerFSM.Fsm)
         {
             bool    value = self.isLooping.Value;
             float   num   = Mathf.Clamp01(1f - GetTimer(self) / ShakeDuration);
             Vector3 a     = Vector3.Scale(ShakeExtents, new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)));
             transform.position = GetStartingWorldPosition(self) + a * ((!value) ? num : 1f);
             //this.timer += Time.deltaTime;
             SetTimer(self, GetTimer(self) + Time.deltaTime);
             if (!value && GetTimer(self) > ShakeDuration)
             {
                 CustomShake = false;
                 StopAndReset(self);
                 self.Fsm.Event(self.stopEvent);
                 self.Finish();
             }
         }
         else if (CustomRumble && self.State.Name.Contains("Rumbling") && self.State.Fsm == shakerFSM.Fsm)
         {
             bool    value = self.isLooping.Value;
             float   num   = Mathf.Clamp01(1f - GetTimer(self));
             Vector3 a     = Vector3.Scale(RumbleExtents, new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)));
             transform.position = GetStartingWorldPosition(self) + a * ((!value) ? num : 1f);
             //this.timer += Time.deltaTime;
             SetTimer(self, GetTimer(self) + Time.deltaTime);
             if (!value && GetTimer(self) > 1f)
             {
                 CustomRumble = false;
                 StopAndReset(self);
                 self.Fsm.Event(self.stopEvent);
                 self.Finish();
             }
         }
         else
         {
             orig(self);
         }
     }
     catch (Exception e)
     {
         WeaverLog.LogError("Camera Shaker Exception = " + e);
     }
 }
Ejemplo n.º 3
0
        public static void ExecuteMethodsWithAttribute <T>(Assembly assembly, Func <MethodInfo, T, bool> ExecuteIf = null, BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, bool throwOnError = false) where T : Attribute
        {
            List <ValueTuple <MethodInfo, T> > methods = new List <ValueTuple <MethodInfo, T> >();

            methods.AddRange(GetMethodsWithAttribute <T>(assembly, flags));

            if (methods.Count == 0)
            {
                return;
            }

            if (methods[0].Item2 is PriorityAttribute)
            {
                methods.Sort(new PriorityAttribute.PairSorter <T>());
            }

            while (methods.Count > 0)
            {
                var method = methods[0];
                methods.RemoveAt(0);
                try
                {
                    if (ExecuteIf == null || ExecuteIf(method.Item1, method.Item2))
                    {
                        method.Item1.Invoke(null, null);
                    }
                }
                catch (Exception e)
                {
                    if (throwOnError)
                    {
                        throw;
                    }
                    else
                    {
                        WeaverLog.LogError("Error running function [" + method.Item1.DeclaringType.FullName + ":" + method.Item1.Name + "\n" + e);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void ExecuteMethodsWithAttribute <T>(Func <MethodInfo, T, bool> ExecuteIf = null, BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, bool throwOnError = false) where T : Attribute
        {
            List <ValueTuple <MethodInfo, T> > methods = new List <ValueTuple <MethodInfo, T> >();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                methods.AddRange(GetMethodsWithAttribute <T>(assembly, flags));
            }

            if (methods.Count == 0)
            {
                return;
            }

            //bool sortable = false;

            if (typeof(PriorityAttribute).IsAssignableFrom(typeof(T)))
            {
                //sortable = true;
                methods.Sort(new PriorityAttribute.PairSorter <T>());
            }

            /*if (methods[0].Item2 is PriorityAttribute)
             * {
             *
             * }*/

            /*AssemblyLoadEventHandler NewAssemblyLoad = (s, args) =>
             * {
             *      methods.AddRange(GetMethodsWithAttribute<T>(args.LoadedAssembly, flags));
             *      if (sortable)
             *      {
             *              methods.Sort(new PriorityAttribute.PairSorter<T>());
             *      }
             * };*/
            //try
            //{
            //AppDomain.CurrentDomain.AssemblyLoad += NewAssemblyLoad;

            while (methods.Count > 0)
            {
                var method = methods[0];
                methods.RemoveAt(0);
                try
                {
                    if (ExecuteIf == null || ExecuteIf(method.Item1, method.Item2))
                    {
                        method.Item1.Invoke(null, null);
                    }
                }
                catch (Exception e)
                {
                    if (throwOnError)
                    {
                        throw;
                    }
                    else
                    {
                        WeaverLog.LogError("Error running function [" + method.Item1.DeclaringType.FullName + ":" + method.Item1.Name + "\n" + e);
                    }
                }
            }

            /*}
             * finally
             * {
             *      AppDomain.CurrentDomain.AssemblyLoad -= NewAssemblyLoad;
             * }*/
        }