Ejemplo n.º 1
0
    public void loadState(GameObject go)
    {
        go.transform.position   = position;
        go.transform.localScale = localScale;
        go.transform.rotation   = rotation;
        Rigidbody2D rb2d = go.GetComponent <Rigidbody2D>();

        if (rb2d != null)
        {
            rb2d.velocity        = velocity;
            rb2d.angularVelocity = angularVelocity;
        }
        foreach (SavableObject so in this.soList)
        {
            SavableMonoBehaviour smb =
                (SavableMonoBehaviour)go.GetComponent(so.ScriptType);
            if (smb == null)
            {
                if (so.isSpawnedScript)
                {
                    smb = (SavableMonoBehaviour)so.addScript(go);
                }
                else
                {
                    throw new UnityException(
                              "Object " + go + " (" + go.getKey()
                              + ") is missing non-spawnable script " + so.scriptType
                              );
                }
            }
            smb.CurrentState = so;
        }
    }
Ejemplo n.º 2
0
 public void loadState()
 {
     getGameObject();//finds and sets the game object
     if (go == null)
     {
         return;//don't load the state if go is null
     }
     go.transform.localPosition = position;
     go.transform.localScale    = localScale;
     go.transform.localRotation = rotation;
     rb2d = go.GetComponent <Rigidbody2D>();
     if (rb2d != null)
     {
         rb2d.velocity        = velocity;
         rb2d.angularVelocity = angularVelocity;
     }
     foreach (SavableObject so in this.soList)
     {
         SavableMonoBehaviour smb = (SavableMonoBehaviour)go.GetComponent(so.getSavableMonobehaviourType());
         if (smb == null)
         {
             if (so.isSpawnedScript)
             {
                 smb = (SavableMonoBehaviour)so.addScript(go);
             }
             else
             {
                 throw new UnityException("Object " + go + " is missing non-spawnable script " + so.scriptType);
             }
         }
         smb.acceptSavableObject(so);
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Constructs a SavableObject with the given pieces of data
    /// Enter data in pairs: key,object,...
    /// Example: "cracked",true,"name","CrackedGround"
    /// </summary>
    /// <param name="pairs"></param>
    public SavableObject(SavableMonoBehaviour smb, params System.Object[] pairs)
    {
        this.scriptType = smb.GetType().Name;

        more(pairs);

        if (smb.IsSpawnedScript)
        {
            isSpawnedScript = true;
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs a SavableObject with the given pieces of data
 /// Enter data in pairs: key,object,...
 /// Example: "cracked",true,"name","CrackedGround"
 /// </summary>
 /// <param name="pairs"></param>
 public SavableObject(SavableMonoBehaviour smb, params System.Object[] pairs)
 {
     this.scriptType = smb.GetType().Name;
     if (pairs.Length % 2 != 0)
     {
         throw new UnityException("Pairs has an odd amount of parameters! pairs.Length: " + pairs.Length);
     }
     for (int i = 0; i < pairs.Length; i += 2)
     {
         data.Add((string)pairs[i], pairs[i + 1]);
     }
     if (smb.isSpawnedObject())
     {
         isSpawnedObject = true;
         prefabName      = smb.getPrefabName();
     }
     if (smb.isSpawnedScript())
     {
         isSpawnedScript = true;
     }
 }