public static Entry[] GetFields(object obj, bool seen)
        {
            var type      = obj.GetType();
            var accessors = GetAccessors(type);

            Debug.Log("[Available Properties]");
            if (accessors != null && accessors[1] != null)
            {
                Array.ForEach(accessors[1], (x) => { if (x != null && x.Info != null)
                                                     {
                                                         Debug.LogFormat("{0}", x.Info.Name);
                                                     }
                              });
            }
            Debug.Log("[/Available Properties]");

            return((from a in accessors[seen ? 1 : 3]
                    let value = a.Get(obj)
                                select new Entry()
            {
                FieldInfo = a.FieldInfo,
                MustHaveName = true,
                Value = value,
                IsStatic = a.IsStatic
            }).ToArray());
        }
예제 #2
0
 internal static void UpdateCheck(bool successEnabled = false)
 {
     if (!File.Exists(localVersionFilepath))
     {
         JSONHelpers.SerializeToFile(localVersionFilepath, new LerpedUpdater(), true);
     }
     if (!noConnection)
     {
         try
         {
             WWW www = new WWW("https://raw.githubusercontent.com/Lerp2Dev/Lerp2API/master/Lerp2API.version");
             wh = new WWWHandler();
             wh.Add(www);
             wh.Start <WWW>(false, (x) =>
             {
                 var updater = x.text.Deserialize <LerpedUpdater>();
                 if (updater.versionStr != curVersion)
                 {
                     WarnOutdated(updater.versionStr);
                 }
                 else
                 {
                     if (successEnabled)
                     {
                         Debug.Log("Lerp2API is up-to-date!");
                     }
                 }
             });
         }
         catch (Exception e)
         {
             Debug.LogError("Internet connection couldn't be detected, Updates are disabled!\nMaybe it can be another problem, check the log by clicking this message.\n" + e.Message + "\n" + e.StackTrace);
             noConnection = true;
         }
     }
     else
     {
         CheckForConnection();
     }
 }
예제 #3
0
 internal static void SaveCommands()
 {
     JSONHelpers.SerializeToFile(commandPath, myTarget.commandList);
     Debug.Log("Command file saved!");     //Better a dialog, not?
 }
예제 #4
0
        public static string SaveAsAsset <T>(Transporter value, T obj, string name)
        {
            bool emptyName = string.IsNullOrEmpty(name),
                 derivedClass = obj != null && typeof(T).IsSubclassOf(typeof(Object)), alreadyExists = false;
            string n = name, path = "", fpath = "", rpath = "";

            if (emptyName && derivedClass)
            {
                n = ((Object)(object)obj).name;
            }
            else if (emptyName && !derivedClass)
            {
                n = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString("F0");
            }
            path          = Path.Combine(Application.streamingAssetsPath, typeof(T).Name);
            fpath         = Path.Combine(path, n + ".asset");
            rpath         = typeof(T).Name + "/" + n + ".asset";
            alreadyExists = File.Exists(fpath);
            if (!alreadyExists)
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (value.type.Equals(typeof(string)))
                {
                    if (value.write)
                    {
                        File.WriteAllText(fpath, (string)value.obj);
                    }
                    else
                    {
                        File.AppendAllText(fpath, (string)value.obj + Environment.NewLine);
                    }
                }
                else if (value.type.Equals(typeof(string[])))
                {
                    File.WriteAllLines(fpath, (string[])value.obj);
                }
                else if (value.type.Equals(typeof(byte[])))
                {
                    File.WriteAllBytes(fpath, (byte[])value.obj);
                }
                else
                {
                    throw new Exception("Not recognised type!");
                }
                Debug.Log("Asset saved at " + fpath + "!");
            }
            if (typeof(T).Equals(typeof(GameObject)))
            {
                //if (Application.isPlaying)
                //    Object.Destroy(GameObject.Find(((GameObject)(object)obj).name));
                //else
                if (Application.isEditor)
                {
                    Object.DestroyImmediate(GameObject.Find(((GameObject)(object)obj).name));
                }
            }
            return(rpath);
        }