Ejemplo n.º 1
0
 protected override bool AddElement(IHashedSO obj)
 {
     if (obj is T t)
     {
         _list.Add(t);
     }
     return(obj is T);
 }
Ejemplo n.º 2
0
    bool IHashedSOCollectionEditor.EditorRequestMember(Object obj, bool forceCorrectPosition = false)
    {
        var t = obj as IHashedSO;

        if (t == null)
        {
            return(false);
        }

        int       hashID  = t.HashID;
        IHashedSO element = (hashID < Count && hashID >= 0) ? GetElementBase(hashID) : null;

        if (element == null && hashID >= 0)
        {
            SetRealPosition(t);
            Editor_Log.Add($"Request Member:\nOn [{hashID}] set {t.ToStringOrNull()}, was NULL before");
            return(false);
        }

        if (Contains(t))
        {
            if ((t != element && hashID != element.HashID) || forceCorrectPosition)
            {
                Editor_Log.Add($"Request Member:\nOn [{hashID}] removed {element.ToStringOrNull()} and replace with {t.ToStringOrNull()}");
                SetRealPosition(t);
            }
            return(false);
        }

        bool fromDialog = false;

        if (hashID < 0 || hashID >= Count || element != t)
        {
            var  assetPath = AssetDatabase.GetAssetPath((Object)t);
            var  assetGuid = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
            bool isDuplicateFromOtherFile = t.GUID != assetGuid;

            if (!isDuplicateFromOtherFile)
            {
                if (!ResolveConflictedFile(t, assetPath))
                {
                    return(false);
                }
                fromDialog = !EditorCanChangeIDsToOptimizeSpace;
            }
        }

        var newID = Count;

        Editor_Log.Add($"Request Member:\nOn [{newID}] setted {t.ToStringOrNull()} with new hashID{(fromDialog ? " with dialog permission" : "")}");
        AddElement(t);
        ((IHashedSOEditor)t).SetHashID(newID);

        UnityEditor.EditorUtility.SetDirty((Object)t);
        UnityEditor.EditorUtility.SetDirty(this);

        return(true);
    }
Ejemplo n.º 3
0
 protected override bool ResolveConflictedFile(IHashedSO t, string assetPath)
 {
     if (!UnityEditor.EditorUtility.DisplayDialog("Conflict on PermanentHashedSOCollection",
                                                  $"{( (Object)t ).NameOrNull()} already has an ID but it's not on the appropriate list ({this.name}). Assign a new ID for it?",
                                                  "Yes",
                                                  "No, delete it"))
     {
         AssetDatabase.DeleteAsset(assetPath);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
    protected override bool SetRealPosition(IHashedSO obj)
    {
        var t = obj as T;

        if (t == null)
        {
            return(false);
        }
        var id = obj.HashID;

        if (id < 0)
        {
            return(false);
        }
        while (id >= _list.Count)
        {
            _list.Add(null);
        }
        _list[id] = t;
        UnityEditor.EditorUtility.SetDirty(this);
        return(true);
    }
Ejemplo n.º 5
0
 public abstract bool Contains(IHashedSO element);
Ejemplo n.º 6
0
 protected abstract bool SetRealPosition(IHashedSO obj);
Ejemplo n.º 7
0
 protected abstract bool ResolveConflictedFile(IHashedSO t, string assetPath);
Ejemplo n.º 8
0
 protected abstract bool AddElement(IHashedSO obj);
Ejemplo n.º 9
0
 public static int HashIdOrNull(this IHashedSO hso) => (hso != null) ? hso.HashID : -1;
Ejemplo n.º 10
0
 protected override bool ResolveConflictedFile(IHashedSO t, string assetPath) => true;
Ejemplo n.º 11
0
 public override bool Contains(IHashedSO obj) => _list.Contains(obj as T);