public void GenerateGuid()
        {
            string path = UnityEditor.AssetDatabase.GetAssetPath(this);

            Guid = UnityEditor.AssetDatabase.AssetPathToGUID(path);
            ScriptableObjectDatabase.UpdateEntry(Guid, path, ScriptableObjectDatabase.c_ObjectFullPath);
        }
예제 #2
0
 private void DeleteCurrentObject()
 {
     OnDeletedObject(m_CurrentObject);
     ScriptableObjectDatabase.DeleteEntry(m_CurrentObject.Guid, null, ScriptableObjectDatabase.c_ObjectFullPath);
     AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(m_CurrentObject));
     m_Dirty = false;
     RefreshObjectList();
 }
 public void Load(string fieldName = null, bool async = false)
 {
     foreach (FieldInfo field in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
     {
         object[] attributes = field.GetCustomAttributes(typeof(LoadOnDemand), true);
         if (attributes.Length == 1)
         {
             LoadOnDemand attribute          = (LoadOnDemand)attributes[0];
             string       attributeFieldName = attribute.FieldName;
             if (fieldName == null || attributeFieldName == fieldName)
             {
                 FieldInfo linkedField = GetType().GetField(attributeFieldName);
                 string    fieldValue  = (string)field.GetValue(this);
                 if (fieldValue != null)
                 {
                     if (fieldValue.Length == 32 && Regex.IsMatch(fieldValue, c_GUIDRegex))
                     {
                         // it's a guid
                         linkedField.SetValue(this, ScriptableObjectDatabase.GetAsset(fieldValue, ScriptableObjectDatabase.c_ObjectResourcePath));
                     }
                     else
                     {
                         // it's a path
                         if (async)
                         {
                             Resources.LoadAsync(fieldValue);
                         }
                         else
                         {
                             // Sprite special case since by default Unity loads images as textures
                             if (typeof(Sprite) == linkedField.FieldType)
                             {
                                 linkedField.SetValue(this, Resources.Load <Sprite>(fieldValue));
                             }
                             else
                             {
                                 linkedField.SetValue(this, Resources.Load(fieldValue));
                             }
                         }
                     }
                 }
             }
         }
     }
 }