コード例 #1
0
        protected void RestoreDataAndResolveDependencies()
        {
            List <GameObject> goList           = new List <GameObject>();
            List <bool>       goActivationList = new List <bool>();

            //This list is necessary to deal with edge cases where Avatar for some Animators must be created using AvatarBuilder.
            //AvatarBuilder requires a hierarchy of children with names.
            //TODO: Implement a common mechanism to handle such situations. For example, add the OnAfterWrite method.
            List <int> deferredIndices = new List <int>();

            for (int i = 0; i < Data.Length; ++i)
            {
                PersistentObject data = Data[i];
                long             id   = Identifiers[i];

                UnityObject obj = FromID <UnityObject>(id);
                if (obj == null)
                {
                    Debug.LogWarningFormat("objects does not have object with instance id {0} however PersistentData of type {1} is present", id, data.GetType());
                    continue;
                }

                if (obj is Animator)
                {
                    deferredIndices.Add(i);
                    continue;
                }

                data.WriteTo(obj);

                if (obj is GameObject)
                {
                    goList.Add((GameObject)obj);
                    PersistentGameObject goData = (PersistentGameObject)data;
                    goActivationList.Add(goData.ActiveSelf);
                }
            }

            for (int i = 0; i < deferredIndices.Count; ++i)
            {
                int index = deferredIndices[i];

                PersistentObject data = Data[index];
                long             id   = Identifiers[index];

                UnityObject obj = FromID <UnityObject>(id);
                data.WriteTo(obj);
            }

            for (int i = 0; i < goList.Count; ++i)
            {
                bool       activeSelf = goActivationList[i];
                GameObject go         = goList[i];
                if (go != null)
                {
                    go.SetActive(activeSelf);
                }
            }
        }
コード例 #2
0
 private void Awake()
 {
     m_persistenceSettings  = PersistenceSettings.GetPersistenceSettings();
     m_persistentGameObject = (PersistentGameObject)target;
     if (String.IsNullOrEmpty(m_persistentGameObject.ObjectId))
     {
         m_persistentGameObject.ObjectId = m_persistentGameObject.gameObject.name + "_" + Guid.NewGuid();
     }
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (player.transform.position.x >= this.transform.position.x)
        {
            PersistentGameObject PGO = GameObject.FindGameObjectWithTag("PersistentObject").GetComponent <PersistentGameObject> ();
            PGO.setPlayerWeapon(player.transform.Find("RifleWeapon").gameObject.GetComponent <TrackMouse> ().weapon);

            LoadingScreenManager.LoadScene(sceneIndexToLoad);
        }
    }
コード例 #4
0
 private void Awake()
 {
     //Allows only one of this object to exist in the game:
     if (control == null)
     {
         control = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        playerIn       = GameObject.FindGameObjectWithTag("Player");
        anim           = GetComponent <Animator> ();
        gunAudioSource = GetComponent <AudioSource> ();
        barrel         = transform.Find("Barrel");

        //Persistent Object stuff
        PersistentGameObject PGO = GameObject.FindGameObjectWithTag("PersistentObject").GetComponent <PersistentGameObject> ();

        PGO.setPlayerLevel(SceneManager.GetActiveScene().buildIndex);
        weapon = PGO.getPlayerWeapon();
        anim.SetInteger("weapon", weapon);
    }
コード例 #6
0
//	public void EndScene ()
//	{
//		// Make sure the texture is enabled.
//		GetComponent<GUITexture>().enabled = true;
//
//		// Start fading towards black.
//		FadeToBlack();
//
//		// If the screen is almost black...
//		if(GetComponent<GUITexture>().color.a >= 0.95f)
//			// ... reload the level.
//			Application.LoadLevel(sceneToLoad);
//	}

    IEnumerator EndScene()
    {
        yield return(new  WaitForSeconds(3));         // or however long you want it to wait

        // Make sure the texture is enabled.
        GetComponent <GUITexture>().enabled = true;

        // Start fading towards black.
        FadeToBlack();

        // If the screen is almost black...
        if (GetComponent <GUITexture> ().color.a >= 0.95f)
        {
            // ... reload the level.
            //Application.LoadLevel(sceneToLoad);
            PersistentGameObject PGO = GameObject.FindGameObjectWithTag("PersistentObject").GetComponent <PersistentGameObject> ();
            //PersistentGameObject.// (player.transform.Find ("RifleWeapon").gameObject.GetComponent<TrackMouse> ().weapon);
            LoadingScreenManager.LoadScene(PGO.getPlayerLevel());
        }
    }
コード例 #7
0
    // Use this for initialization
    void Awake()
    {
        //DontDestroyOnLoad(transform.gameObject);

        //if we don't have an [_instance] set yet
        if (!_instance)
        {
            _instance    = this;
            playerLevel  = 1;
            playerWeapon = 0;
            Debug.Log("creating instance of persistent object");
        }
        //otherwise, if we do, kill this thing
        else
        {
            Debug.Log("destroying extra instance");
            Destroy(this.gameObject);
        }

        DontDestroyOnLoad(this.gameObject);
        Debug.Log("Current level: " + playerLevel);
        Debug.Log("Current weapon: " + playerWeapon);
    }
コード例 #8
0
        protected void RestoreDataAndResolveDependencies()
        {
            List <GameObject> goList           = new List <GameObject>();
            List <bool>       goActivationList = new List <bool>();

            for (int i = 0; i < Data.Length; ++i)
            {
                PersistentObject data = Data[i];
                long             id   = Identifiers[i];

                UnityObject obj = FromID <UnityObject>(id);
                if (obj == null)
                {
                    Debug.LogWarningFormat("objects does not have object with instance id {0} however PersistentData of type {1} is present", id, data.GetType());
                    continue;
                }

                data.WriteTo(obj);
                if (obj is GameObject)
                {
                    goList.Add((GameObject)obj);
                    PersistentGameObject goData = (PersistentGameObject)data;
                    goActivationList.Add(goData.ActiveSelf);
                }
            }

            for (int i = 0; i < goList.Count; ++i)
            {
                bool       activeSelf = goActivationList[i];
                GameObject go         = goList[i];
                if (go != null)
                {
                    go.SetActive(activeSelf);
                }
            }
        }
コード例 #9
0
 private void OnEnable()
 {
     manager = target as PersistentGameObject;
 }