Last active
September 7, 2019 20:56
-
-
Save psuong/7e8ad9f8fb82588a4ffd3a83d36cd9fc to your computer and use it in GitHub Desktop.
PrefabUtils Extended
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Mode : int { | |
ConvertAndDestroy = 0, | |
ConvertAndInjectOriginal = 1 | |
} | |
// Allows you to just create a copy of the asset and convert it. | |
public static void ConstructEntityFromPrefab(string name, string folder, Mode mode, out GameObject src) { | |
src = GetInstantiatedAsset<GameObject>(name, folder).transform.root.gameObject; | |
switch (mode) { | |
case Mode.ConvertAndDestroy: | |
ConvertAndInjectOriginal(src); | |
Object.DestroyImmediate(src); | |
src = null; | |
return; | |
case Mode.ConvertAndInjectOriginal: | |
ConvertAndInjectOriginal(src); | |
return; | |
} | |
} | |
// Allows you to pre process the instantiated asset and set values via the action param | |
public static void ConstructEntityFromPrefab(string name, string folder, Mode mode, | |
Action<GameObject> action, out GameObject src) { | |
src = GetInstantiatedAsset<GameObject>(name, folder); | |
action?.Invoke(src); | |
switch (mode) { | |
case Mode.ConvertAndDestroy: | |
ConvertAndInjectOriginal(src); | |
Object.DestroyImmediate(src); | |
src = null; | |
return; | |
case Mode.ConvertAndInjectOriginal: | |
ConvertAndInjectOriginal(src); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment