Semi Mod Loader
Static Public Member Functions | Static Public Attributes | List of all members
Semi.FakePrefab Class Reference

This class allows the creation of "fake prefabs". In Unity, prefabs are a special kind of GameObject. A prefab is never active, even if its activeSelf field is true. However, if you instantiate such an object, your new instance will inherit the activeSelf field and if true, will create an alive object. On many occassions we want to be able to create our own "prefabs", in other words, objects that act as a template to make other objects from. Unfortunately, the closest way to do this in Unity normally is to have objects that are created as inactive. This creates a problem, because now our new custom "prefab" has to remain inactive, and any object that is instantiated from it will be inactive as well. Semi works around this in two parts - this class is the first part, and the other part is in a patch for the UnityEngine.Object class. When we create a fake prefab with this class, we're doing the same workaround mentioned before (inactive object), but we also add it to a global static list. The second part of this workaround patches Unity to check every object that is being instantiated and verify it against this list. If it is found that the original object does in fact belong in this list, the new object is immediately set as active. More...

Inheritance diagram for Semi.FakePrefab:

Static Public Member Functions

static bool IsFakePrefab (UnityEngine.Object o)
 Checks if an object is marked as a fake prefab. More...
 
static GameObject Create (string name=null)
 Creates a new fake prefab (you can add components to this like usual) More...
 
static void MarkAsFakePrefab (GameObject obj)
 Marks an object as a fake prefab. More...
 
static GameObject Clone (GameObject obj)
 Clones a real prefab or a fake prefab into a new fake prefab. More...
 
static UnityEngine.Object Instantiate (UnityEngine.Object o, UnityEngine.Object new_o)
 Activates objects that have been created from a fake prefab, otherwise simply returns them. More...
 

Static Public Attributes

static Func< UnityEngine.Object, UnityEngine.Object > RawInstantiateMethod
 

Detailed Description

This class allows the creation of "fake prefabs". In Unity, prefabs are a special kind of GameObject. A prefab is never active, even if its activeSelf field is true. However, if you instantiate such an object, your new instance will inherit the activeSelf field and if true, will create an alive object. On many occassions we want to be able to create our own "prefabs", in other words, objects that act as a template to make other objects from. Unfortunately, the closest way to do this in Unity normally is to have objects that are created as inactive. This creates a problem, because now our new custom "prefab" has to remain inactive, and any object that is instantiated from it will be inactive as well. Semi works around this in two parts - this class is the first part, and the other part is in a patch for the UnityEngine.Object class. When we create a fake prefab with this class, we're doing the same workaround mentioned before (inactive object), but we also add it to a global static list. The second part of this workaround patches Unity to check every object that is being instantiated and verify it against this list. If it is found that the original object does in fact belong in this list, the new object is immediately set as active.

Member Function Documentation

◆ Clone()

static GameObject Semi.FakePrefab.Clone ( GameObject  obj)
inlinestatic

Clones a real prefab or a fake prefab into a new fake prefab.

Returns
The new game object.
Parameters
objGameObject to clone.

◆ Create()

static GameObject Semi.FakePrefab.Create ( string  name = null)
inlinestatic

Creates a new fake prefab (you can add components to this like usual)

◆ Instantiate()

static UnityEngine.Object Semi.FakePrefab.Instantiate ( UnityEngine.Object  o,
UnityEngine.Object  new_o 
)
inlinestatic

Activates objects that have been created from a fake prefab, otherwise simply returns them.

Returns
The same Unity object as the one passed in new_o, activated if o is a fake prefab..
Parameters
oOriginal object.
new_oThe object instantiated from the original object.

◆ IsFakePrefab()

static bool Semi.FakePrefab.IsFakePrefab ( UnityEngine.Object  o)
inlinestatic

Checks if an object is marked as a fake prefab.

Returns
true, if object is in the list of fake prefabs, false otherwise.
Parameters
oUnity object to test.

◆ MarkAsFakePrefab()

static void Semi.FakePrefab.MarkAsFakePrefab ( GameObject  obj)
inlinestatic

Marks an object as a fake prefab.

Parameters
objGameObject to add to the list.

Member Data Documentation

◆ RawInstantiateMethod

Func<UnityEngine.Object, UnityEngine.Object> Semi.FakePrefab.RawInstantiateMethod
static

The documentation for this class was generated from the following file: