예제 #1
0
        public void SaveGame(IGameState gameState)
        {
            int     currentSaveIndex = 0;
            Vector3 currCorr         = EJRConsts.Instance["useEndlessMap"] == "true" ? EndlessWorld.EndlessWorldModuleManager.Instance.GetRootCorrection() : Vector3.zero;

            foreach (int id in _activeObjects.Keys)
            {
                AOInfo info = _activeObjects[id];
                gameState.SetKey("sm_uid_" + currentSaveIndex, info.UniqueID);
                gameState.SetKey("sm_pr_" + currentSaveIndex, info.PrefabName);
                if (info.CreatedObject != null)
                {
                    gameState.SetKey("sm_px_" + currentSaveIndex, info.CreatedObject.transform.position.x - currCorr.x);
                    gameState.SetKey("sm_py_" + currentSaveIndex, info.CreatedObject.transform.position.y - currCorr.y);
                    gameState.SetKey("sm_pz_" + currentSaveIndex, info.CreatedObject.transform.position.z - currCorr.z);
                }
                else
                {
                    gameState.SetKey("sm_px_" + currentSaveIndex, info.LastPosX - currCorr.x);
                    gameState.SetKey("sm_py_" + currentSaveIndex, info.LastPosY - currCorr.y);
                    gameState.SetKey("sm_pz_" + currentSaveIndex, info.LastPosZ - currCorr.z);
                }
                currentSaveIndex++;
            }
            gameState.SetKey("sm_recs", currentSaveIndex);
            gameState.SetKey("sm_ukey", _nextUniqueID);
        }
예제 #2
0
 private void HideActiveObject(AOInfo aoi)
 {
     aoi.LastPosX = aoi.CreatedObject.transform.position.x;
     aoi.LastPosY = aoi.CreatedObject.transform.position.y;
     aoi.LastPosZ = aoi.CreatedObject.transform.position.z;
     PrefabPool.Instance.ReleasePrefab(aoi.CreatedObject);
     aoi.CreatedObject = null;
 }
예제 #3
0
        //rejestruje przedmiot utworzony przez inną klasę
        public void AddActiveObject(ActiveObject ao)
        {
            ao.UniqueID = GetNextUniqueID();
            AOInfo aoi = new AOInfo {
                UniqueID = ao.UniqueID, PrefabName = ao.name, LastPosX = ao.transform.position.x, LastPosY = ao.transform.position.y, LastPosZ = ao.transform.position.z, CreatedObject = ao.gameObject
            };

            _activeObjects.Add(ao.UniqueID, aoi);
        }
예제 #4
0
        //użyj tej funkcji gdy aktywny przedmiot jest pierwszy raz tworzony, np. przez generator
        public GameObject CreateAvtiveObject(string prefabName, Vector3 newPosition)
        {
            GameObject   createdGO = InternalSpawn(prefabName, newPosition);
            ActiveObject createdAO = createdGO.GetComponent <ActiveObject>();

            if (createdAO == null)
            {
                Debug.LogError(prefabName + "nie posiada komponentu AktywnyObiekt");
            }
            else
            {
                createdAO.UniqueID = GetNextUniqueID();
                AOInfo aoi = new AOInfo {
                    UniqueID = createdAO.UniqueID, PrefabName = prefabName, LastPosX = 0, LastPosY = 0, LastPosZ = 0, CreatedObject = createdGO
                };
                _activeObjects.Add(createdAO.UniqueID, aoi);
                createdGO.SetActive(true);
                return(createdGO);
            }
            return(null);
        }
예제 #5
0
        public void LoadGame(IGameState gameState)
        {
            _nextUniqueID = gameState.GetIntKey("sm_ukey");
            int liczbaRekordow = gameState.GetIntKey("sm_recs");

            for (int i = 0; i < liczbaRekordow; i++)
            {
                int    id      = gameState.GetIntKey("sm_uid_" + i);
                string aPrefab = gameState.GetStringKey("sm_pr_" + i);
                float  posX    = gameState.GetFloatKey("sm_px_" + i);
                float  posY    = gameState.GetFloatKey("sm_py_" + i);
                float  posZ    = gameState.GetFloatKey("sm_pz_" + i);
                AOInfo ai      = new AOInfo()
                {
                    UniqueID = id, PrefabName = aPrefab, LastPosX = posX, LastPosY = posY, LastPosZ = posZ, CreatedObject = null
                };
                if (!_activeObjects.ContainsKey(id))
                {
                    _activeObjects.Add(id, ai);
                }
            }
        }
예제 #6
0
        private void ShowActiveObject(AOInfo aoi)
        {
            Vector3 newPosition = new Vector3(aoi.LastPosX, aoi.LastPosY, aoi.LastPosZ);

            if (aoi.PrefabName == null || aoi.PrefabName == "")
            {
                Debug.LogError("aoi.prefabName is null");
            }
            else
            {
                GameObject   createdObject = InternalSpawn(aoi.PrefabName, newPosition);
                ActiveObject ao            = createdObject.GetComponent <ActiveObject>();
                if (ao == null)
                {
                    Debug.LogError(aoi.PrefabName + " nie posiada AktywnyObiekt");
                }
                else
                {
                    ao.UniqueID       = aoi.UniqueID;
                    aoi.CreatedObject = createdObject;
                }
            }
        }