Beispiel #1
0
    /// <summary>
    /// creates the gameobject and scripts (which values are not loaded yet).
    /// this is called recursiv for all children of this game object
    /// </summary>
    public GameObject createObject(Transform parent, int siblingIndex = -1)
    {
        GameObject gameObject;

        gameObject = getSceneGameObject(parent);

        BaseSaveableGameObject saveableObject = gameObject.GetComponent <BaseSaveableGameObject>();

        inGameObject = gameObject;

        gameObject.SetActive(active);
        gameObject.tag = tag;
        gameObject.transform.parent = parent;
        gameObject.layer            = layer;
        gameObject.name             = gameObjectName;

        if (siblingIndex >= 0)
        {
            gameObject.transform.SetSiblingIndex(siblingIndex);
        }

        reconstructAttachedComponentList(saveableObject);

        foreach (TreeNode <IRestorableGameObject> node in childTree.getAllNodesWithValues())
        {
            node.Value.createObject(
                SaveableScene.getTransformFromPath(
                    gameObject.transform, node.getParentTreePath())
                , node.Key);
        }

        return(gameObject);
    }
    private List <BaseSaveableGameObject> findAllSaveableTransferableChilds(Transform t)
    {
        List <BaseSaveableGameObject> result = new List <BaseSaveableGameObject>();

        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            BaseSaveableGameObject saveableObject = child.GetComponent <BaseSaveableGameObject>();
            if (saveableObject != null)
            {
                if (saveableObject.IsTransferable)
                {
                    result.Add(saveableObject);
                }
            }
            else
            {
                result.AddRange(findAllSaveableTransferableChilds(child));
            }
        }
        return(result);
    }
Beispiel #3
0
    /// <summary>
    /// attaches all saved scripts to the current GameObject which arent attached already.
    /// Also deletes all saveable Scripts from the GameObject, which werent saved.
    /// Doesnt set any value to the scripts yet.
    /// </summary>
    /// <param name="saveableGameObject"></param>
    private void reconstructAttachedComponentList(BaseSaveableGameObject saveableGameObject)
    {
        ///add all saved unity components to the game object, and adds the reference to the
        ///saveableComponent list
        ISaveableComponent savableComponent;

        foreach (IRestorableComponent component in restoreableComponents)
        {
            savableComponent = component.addComponent(saveableGameObject.gameObject, this);
        }

        ///destroy all saveable scripts, which where not created during this process
        ///(WasCreated property is false)
        ///(this only applies for the saveableBehaviours, not the UnitComponents)
        foreach (BaseSaveableMonoBehaviour saveableMonoBehaviour
                 in saveableGameObject.GetComponents <BaseSaveableMonoBehaviour>())
        {
            if (!saveableMonoBehaviour.WasCreated)
            {
                UnityEngine.Object.Destroy(saveableMonoBehaviour);
            }
        }
    }
Beispiel #4
0
 private void OnEnable()
 {
     inspectorTarget = (BaseSaveableGameObject)target;
 }