Example #1
0
 public static bool IsEqual(object a, object b, bool tryConverted)
 {
     if (a == null && b == null)
     {
         return(true);
     }
     if (a != null && b != null)
     {
         if (object.Equals(a, b))
         {
             return(true);
         }
         UnityEngine.Object x       = a as UnityEngine.Object;
         UnityEngine.Object @object = b as UnityEngine.Object;
         if ((x != (UnityEngine.Object)null || @object != (UnityEngine.Object)null) && x == @object)
         {
             return(true);
         }
         if (tryConverted)
         {
             object objB = null;
             BloxUtil.TryConvert(b, a.GetType(), out objB);
             return(object.Equals(a, objB));
         }
         return(false);
     }
     return(false);
 }
Example #2
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                if (array.Length > 0)
                {
                    if (base.owningBlock == null)
                    {
                        BloxUtil.ArraySort(array);
                        return(null);
                    }
                    return(BloxUtil.ArraySortRes(array));
                }
                if (base.owningBlock != null)
                {
                    return(array);
                }
            }
            else
            {
                base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            }
            return(null);
        }
Example #3
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                BloxBlock obj2  = base.paramBlocks[0];
                object    value = (obj2 != null) ? obj2.Run() : null;
                try
                {
                    Array val = BloxUtil.ArrayAdd(array, value);
                    base.contextBlock.UpdateWith(val);
                }
                catch (Exception ex)
                {
                    base.LogError(ex.Message, null);
                }
            }
            else
            {
                base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            }
            return(null);
        }
Example #4
0
 public static void ArrayReverse(Array arr)
 {
     if (((arr != null) ? arr.Length : 0) != 0)
     {
         BloxUtil.ArrayReverseRes(arr).CopyTo(arr, 0);
     }
 }
Example #5
0
        public static Array ArrayAdd(Array arr, object value)
        {
            if (arr == null)
            {
                return(null);
            }
            Type  elementType = arr.GetType().GetElementType();
            Array array       = Array.CreateInstance(elementType, arr.Length + 1);

            arr.CopyTo(array, 0);
            try
            {
                array.SetValue(value, array.Length - 1);
                return(array);
            }
            catch (Exception)
            {
                if (BloxUtil.TryConvert(value, elementType, out value))
                {
                    array.SetValue(value, array.Length - 1);
                    return(array);
                }
                throw new Exception("Expected value type was [" + elementType + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
            }
        }
Example #6
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                int num = 0;
                try
                {
                    num = ((base.paramBlocks[0] != null) ? ((int)base.paramBlocks[0].Run()) : 0);
                }
                catch (Exception e)
                {
                    object value = base.paramBlocks[0].Run();
                    object obj2  = null;
                    if (BloxUtil.TryConvert(value, typeof(int), out obj2))
                    {
                        num = (int)obj2;
                        goto end_IL_003d;
                    }
                    base.LogError("The index is invalid. Expected Integer value.", e);
                    return(null);

                    end_IL_003d :;
                }
                if (array.Length == 0)
                {
                    base.LogError("There are no values in the list.", null);
                    return(null);
                }
                if (num >= 0 && num < array.Length)
                {
                    BloxBlock obj3   = base.paramBlocks[1];
                    object    value2 = (obj3 != null) ? obj3.Run() : null;
                    try
                    {
                        array.SetValue(value2, num);
                        base.contextBlock.UpdateWith(array);
                    }
                    catch (Exception ex)
                    {
                        base.LogError(ex.Message, null);
                    }
                    goto IL_0148;
                }
                base.LogError("The index [" + num + "] is out of range. It should be a value between Array Start:[0] and Array Size:[" + array.Length + "]. Remember that arrays start indexing at 0 and not 1.", null);
                return(null);
            }
            base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            goto IL_0148;
IL_0148:
            return(null);
        }
        protected override object RunBlock()
        {
            object obj  = base.contextBlock.Run();
            IList  list = obj as IList;

            if (list != null)
            {
                return(BloxUtil.ListToArray(list));
            }
            base.LogError("The context must be a List but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            return(null);
        }
Example #8
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                return(BloxUtil.ArrayToList(array));
            }
            base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            return(null);
        }
Example #9
0
        protected override object RunBlock()
        {
            object obj  = base.contextBlock.Run();
            IList  list = obj as IList;

            if (list != null)
            {
                int num = 0;
                try
                {
                    num = ((base.paramBlocks[0] != null) ? ((int)base.paramBlocks[0].Run()) : 0);
                }
                catch (Exception e)
                {
                    object value = base.paramBlocks[0].Run();
                    object obj2  = null;
                    if (BloxUtil.TryConvert(value, typeof(int), out obj2))
                    {
                        num = (int)obj2;
                        goto end_IL_003d;
                    }
                    base.LogError("The index is invalid. Expected Integer value.", e);
                    return(null);

                    end_IL_003d :;
                }
                if (list.Count == 0)
                {
                    base.LogError("There are no values in the list.", null);
                    return(null);
                }
                if (num >= 0 && num < list.Count)
                {
                    BloxBlock obj3   = base.paramBlocks[1];
                    object    value2 = (obj3 != null) ? obj3.Run() : null;
                    try
                    {
                        BloxUtil.ListSet(list, value2, num);
                    }
                    catch (Exception ex)
                    {
                        base.LogError(ex.Message, null);
                    }
                    goto IL_013c;
                }
                base.LogError("The index [" + num + "] is out of range. It should be a value between List Start:[0] and List Size:[" + list.Count + "]. Remember that lists start indexing at 0 and not 1.", null);
                return(null);
            }
            base.LogError("The context must be a List but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            goto IL_013c;
IL_013c:
            return(null);
        }
Example #10
0
 public static void ListRemove(IList list, object value)
 {
     if (list != null)
     {
         Type type = list.GetType().GetGenericArguments()[0];
         if (value != null && value.GetType() != type)
         {
             BloxUtil.TryConvert(value, type, out value);
         }
         list.Remove(value);
     }
 }
Example #11
0
 public object Invoke(object context, object[] args)
 {
     try
     {
         if (this.mi != null)
         {
             return(this.mi.Invoke(context, args));
         }
         if (this.ci != null)
         {
             return(this.ci.Invoke(args));
         }
     }
     catch (ArgumentException)
     {
         bool            flag       = true;
         ParameterInfo[] parameters = this.GetParameters();
         object[]        array      = new object[parameters.Length];
         for (int i = 0; i < array.Length; i++)
         {
             array[i] = ((i >= args.Length) ? null : args[i]);
             if (array[i] == null)
             {
                 if (!parameters[i].ParameterType.IsAssignableFrom(typeof(Nullable)))
                 {
                     flag = false;
                     break;
                 }
             }
             else if (!BloxUtil.TryConvert(array[i], parameters[i].ParameterType, out array[i]))
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             if (this.mi != null)
             {
                 return(this.mi.Invoke(context, array));
             }
             if (this.ci == null)
             {
                 goto end_IL_003a;
             }
             return(this.ci.Invoke(array));
         }
         throw new Exception("One or more parameters/field values could not be converted to the correct type(s) expected.");
         end_IL_003a :;
     }
     return(null);
 }
Example #12
0
        public static int ListIndexOf(IList list, object value)
        {
            if (list == null)
            {
                return(-1);
            }
            Type type = list.GetType().GetGenericArguments()[0];

            if (value != null && value.GetType() != type)
            {
                BloxUtil.TryConvert(value, type, out value);
            }
            return(list.IndexOf(value));
        }
Example #13
0
        public static bool ListContains(IList list, object value)
        {
            if (list == null)
            {
                return(false);
            }
            Type type = list.GetType().GetGenericArguments()[0];

            if (value != null && value.GetType() != type)
            {
                BloxUtil.TryConvert(value, type, out value);
            }
            return(list.Contains(value));
        }
Example #14
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                BloxBlock obj2  = base.paramBlocks[0];
                object    value = (obj2 != null) ? obj2.Run() : null;
                return(BloxUtil.ArrayContains(array, value));
            }
            base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            return(false);
        }
Example #15
0
        protected override object RunBlock()
        {
            object obj  = base.contextBlock.Run();
            IList  list = obj as IList;

            if (list != null)
            {
                BloxBlock obj2  = base.paramBlocks[0];
                object    value = (obj2 != null) ? obj2.Run() : null;
                return(BloxUtil.ListContains(list, value));
            }
            base.LogError("The context must be a List but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            return(false);
        }
Example #16
0
 protected override void InitBlock()
 {
     if (string.IsNullOrEmpty(this.typeName))
     {
         base.LogError("No type name given.", null);
     }
     else
     {
         this.t = BloxUtil.FindType(this.typeName);
         if (this.t == null)
         {
             base.LogError("The type could not be found: " + this.typeName, null);
         }
     }
 }
Example #17
0
        protected override object RunBlock()
        {
            object obj  = (base.paramBlocks[0] == null) ? base.DefaultParamVals[0] : base.paramBlocks[0].Run();
            object obj2 = (base.paramBlocks[1] == null) ? base.DefaultParamVals[1] : base.paramBlocks[1].Run();

            try
            {
                return(BloxUtil.Compare(obj, obj2) < 0);
            }
            catch (Exception ex)
            {
                base.LogError("The values [" + obj + "] and [" + obj2 + "] can't be compared. " + ex.Message, null);
                return(false);
            }
        }
Example #18
0
        protected override object RunBlock()
        {
            object obj   = base.contextBlock.Run();
            Array  array = obj as Array;

            if (array != null)
            {
                Array val = BloxUtil.ArrayClear(array);
                base.contextBlock.UpdateWith(val);
            }
            else
            {
                base.LogError("The context must be an Array but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            }
            return(null);
        }
Example #19
0
        protected override object RunBlock()
        {
            object obj  = base.contextBlock.Run();
            IList  list = obj as IList;

            if (list != null)
            {
                if (base.owningBlock == null)
                {
                    BloxUtil.ListReverse(list);
                    return(null);
                }
                return(BloxUtil.ListReverseRes(list));
            }
            base.LogError("The context must be a List but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            return(null);
        }
Example #20
0
 protected void OnEnable()
 {
     this.bloxLoaded = false;
     if (this.scriptDirty)
     {
         Debug.Log("OnEnable", "BloxEditorWindow", Color.yellow);
         this.Deserialize();
     }
     else
     {
         plyVariables obj = this.variables;
         if (obj != null)
         {
             obj.BuildCache();
         }
         this.scriptType = BloxUtil.GetType("BloxGenerated." + this.ident, "Assembly-CSharp, Version=0.0.0.0, Culture=neutral");
     }
 }
Example #21
0
        public static Array ArrayRemove(Array arr, object value)
        {
            if (arr == null)
            {
                return(null);
            }
            if (arr.Length == 0)
            {
                return(Array.CreateInstance(arr.GetType().GetElementType(), arr.Length));
            }
            int num = BloxUtil.ArrayIndexOf(arr, value);

            if (num >= 0)
            {
                return(BloxUtil.ArrayRemoveAt(arr, num));
            }
            return(arr);
        }
Example #22
0
 public static void ListSet(IList list, object value, int index)
 {
     if (list != null)
     {
         try
         {
             list[index] = value;
         }
         catch (Exception)
         {
             Type type = list.GetType().GetGenericArguments()[0];
             if (BloxUtil.TryConvert(value, type, out value))
             {
                 list[index] = value;
                 goto end_IL_000f;
             }
             throw new Exception("Expected value type was [" + type + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
             end_IL_000f :;
         }
     }
 }
Example #23
0
        public static int ArrayIndexOf(Array arr, object value)
        {
            if (arr == null)
            {
                return(-1);
            }
            Type elementType = arr.GetType().GetElementType();

            if (value != null && value.GetType() != elementType)
            {
                BloxUtil.TryConvert(value, elementType, out value);
            }
            for (int i = 0; i < arr.Length; i++)
            {
                if (BloxUtil.IsEqual(arr.GetValue(i), value, false))
                {
                    return(i);
                }
            }
            return(-1);
        }
Example #24
0
 public static Array ArraySet(Array arr, object value, int index)
 {
     if (arr == null)
     {
         return(null);
     }
     try
     {
         arr.SetValue(value, index);
         return(arr);
     }
     catch (Exception)
     {
         Type elementType = arr.GetType().GetElementType();
         if (BloxUtil.TryConvert(value, elementType, out value))
         {
             arr.SetValue(value, arr.Length - 1);
             return(arr);
         }
         throw new Exception("Expected value type was [" + elementType + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
     }
 }
Example #25
0
        public static float AsFloat(object o)
        {
            float result = 0f;

            try
            {
                result = (float)o;
                return(result);
            }
            catch (Exception ex)
            {
                if (o != null && o.GetType() == typeof(int))
                {
                    result = (float)(int)o;
                    return(result);
                }
                if (!BloxUtil.TryConvert <float>(o, out result))
                {
                    Debug.LogError(ex.Message);
                    return(result);
                }
                return(result);
            }
        }
Example #26
0
        protected override object RunBlock()
        {
            object obj  = base.contextBlock.Run();
            IList  list = obj as IList;

            if (list != null)
            {
                BloxBlock obj2  = base.paramBlocks[0];
                object    value = (obj2 != null) ? obj2.Run() : null;
                try
                {
                    BloxUtil.ListAdd(list, value);
                }
                catch (Exception ex)
                {
                    base.LogError(ex.Message, null);
                }
            }
            else
            {
                base.LogError("The context must be a List but was [" + ((obj != null) ? obj.GetType() : null) + "]", null);
            }
            return(null);
        }
Example #27
0
        public static Array ArrayInsert(Array arr, object value, int index)
        {
            if (arr == null)
            {
                return(null);
            }
            Type  elementType = arr.GetType().GetElementType();
            Array array       = Array.CreateInstance(elementType, arr.Length + 1);
            int   num         = 0;

            for (int i = 0; i < array.Length; i++)
            {
                if (i == index)
                {
                    try
                    {
                        array.SetValue(value, i);
                    }
                    catch (Exception)
                    {
                        if (BloxUtil.TryConvert(value, elementType, out value))
                        {
                            array.SetValue(value, array.Length - 1);
                            return(array);
                        }
                        throw new Exception("Expected value type was [" + elementType + "] but the value was of type [" + ((value != null) ? value.GetType() : null) + "]");
                    }
                }
                else
                {
                    array.SetValue(arr.GetValue(num), i);
                    num++;
                }
            }
            return(array);
        }
Example #28
0
        protected override object RunBlock()
        {
            BloxContainer bloxContainer = (base.paramBlocks[1] == null) ? base.owningEvent.container : BloxUtil.GetComponent <BloxContainer>(base.paramBlocks[1].Run());

            if ((UnityEngine.Object)bloxContainer == (UnityEngine.Object)null)
            {
                base.LogError("Could not find a Blox Container component on the target GameObject", null);
                return(null);
            }
            string text = (string)base.paramBlocks[0].Run();

            if (string.IsNullOrEmpty(text))
            {
                base.LogError("The target Event name is invalid", null);
                return(null);
            }
            float afterSeconds = (float)((base.paramBlocks[2] == null) ? 0.0 : ((float)base.paramBlocks[2].Run()));

            if (base.paramBlocks.Length > 3)
            {
                BloxEventArg[] array = new BloxEventArg[base.paramBlocks.Length - 3];
                for (int i = 3; i < base.paramBlocks.Length; i++)
                {
                    BloxBlock obj = base.paramBlocks[i];
                    object    val = (obj != null) ? obj.Run() : null;
                    array[i - 3] = new BloxEventArg("param" + (i - 3).ToString(), val);
                }
                bloxContainer.TriggerEvent(text, afterSeconds, array);
            }
            else
            {
                bloxContainer.TriggerEvent(text, afterSeconds);
            }
            return(null);
        }