Пример #1
0
 void OnEnable()
 {
     if (ocean == null)
     {
         ocean = GameObject.FindGameObjectWithTag("Ocean").GetComponent <Ocean>();
     }
 }
Пример #2
0
    public void Reanimate()
    {
        //NOTE : So, when unity recompiles shaders or scripts from editor while playing - quads not draws properly.
        //NOTE : Fixed. Buffers setted 1 time. Need to update when focus losted.
        //NOTE : Reinit [Reanimate] ocean stuff only after focus lost...

        if (Quads != null)
        {
            if (Quads.Count != 0)
            {
                for (int i = 0; i < Quads.Count; i++)
                {
                    Quads[i].Uniformed = false;

                    if (Atmosphere != null)
                    {
                        Atmosphere.InitUniforms(Quads[i].QuadMaterial);
                        Atmosphere.SetUniforms(Quads[i].QuadMaterial);
                    }
                }
            }
        }

        if (Ocean != null)
        {
            Ocean.Reanimate();
        }
        if (Atmosphere != null)
        {
            Atmosphere.Reanimate();
        }
    }
Пример #3
0
    public void ScorePointsPlanetTiles(Ocean tile)
    {
        if (tile != null)
        {
            if (ScoreManager.Instance != null)
            {
                // score points
                ScoreManager.Instance.AddScore(tile.scoreValue);

                // update the scoreStars in the Level Goal component
                m_levelGoal.UpdateScoreStars(ScoreManager.Instance.CurrentScore);

                if (UIManager.Instance != null && UIManager.Instance.scoreMeter != null)
                {
                    UIManager.Instance.scoreMeter.UpdateScoreMeter(ScoreManager.Instance.CurrentScore,
                                                                   m_levelGoal.scoreStars);
                }
            }

            // play scoring sound clip

            /* if (SoundManager.Instance != null && tile.clearSound != null)
             * {
             *   SoundManager.Instance.PlayClipAtPoint(piece.clearSound, Vector3.zero, SoundManager.Instance.fxVolume);
             * } */
        }
    }
        public static bool Prefix(HintSwimToSurface __instance, ref bool __result, int ___numShown)
        {
            Player main = Player.main;

            if (main == null)
            {
                __result = false;
                return(false);
            }
            if (___numShown >= __instance.maxNumToShow)
            {
                __result = false;
                return(false);
            }
            if (Ocean.main == null)
            {
                __result = false;
                return(false);
            }
            float   oxygenAvailable = main.GetOxygenAvailable();
            float   depthOf         = Ocean.GetDepthOf(main.gameObject);
            Vehicle vehicle         = main.GetVehicle();

            __result = (oxygenAvailable <__instance.oxygenThreshold && depthOf> 0f && main.IsSwimming()) || (vehicle != null && !vehicle.IsPowered());
            return(false);
        }
Пример #5
0
    void LateUpdate()
    {
        Ocean ocean    = Ocean.ocean;
        bool  spacehit = Vector3.Distance(spaceship.transform.position, transform.position) <= 0.2f + this.radius;

        if (spacehit)
        {
            Debug.Log("Spacehit!");
            vel = (transform.position - spaceship.transform.position).normalized * spaceship.vel.magnitude;
            Vector3 fromTo = (transform.position - spaceship.transform.position).normalized;
            transform.position = spaceship.transform.position + fromTo * (0.2f + radius) + fromTo * Time.deltaTime;
        }
        transform.position += vel * Time.deltaTime;
        if (Vector3.Distance(ocean.transform.position, transform.position) > ocean.radius - radius)
        {
            if (inside)
            {
                Vector3 fromTo = (transform.position - ocean.transform.position).normalized;
                transform.position = ocean.transform.position + fromTo * (ocean.radius - radius);
            }
        }
        else
        {
            inside = true;
        }
        if (split)
        {
            split = false;
            DoSplit();
        }
    }
Пример #6
0
 public Predator(Ocean AOcean, Coordinate offset, bool move,
                 int timeToReproduse = Constants.DEFAULT_TIME_TO_REPRODUCE,
                 int timeToFeed      = Constants.DEFAULT_TIME_TO_FEED)
     : base(AOcean, offset, move, timeToReproduse, (char)CellsSymbols.PredatorImage)
 {
     TimeToFeed = timeToFeed;
 }
Пример #7
0
 public void UpdateCollectionGoalsPlanet(Ocean ocean)
 {
     if (m_levelGoalCollected != null)
     {
         m_levelGoalCollected.UpdateGoalsPlanet(ocean);
     }
 }
        public void Move(Ocean playerBoard,
                         Ocean playerEmptyBoard,
                         Ocean enemyShipsBoard,
                         Dictionary <string, Ship> enemyShips)
        {
            int coordX = 0;
            int coordY = 0;

            if (PlaceShipsStage)
            {
                Place5Ships(playerBoard,
                            playerEmptyBoard,
                            ref coordX,
                            ref coordY);
                PlaceShipsStage = false;
            }
            else
            {
                ShootingMechanizm(playerBoard,
                                  playerEmptyBoard,
                                  enemyShipsBoard,
                                  enemyShips,
                                  ref coordX,
                                  ref coordY);
            }
        }
Пример #9
0
        /// <summary>
        /// Starts a new game.
        /// </summary>
        /// <param name="content">The content manager to load from.</param>
        private void StartGame(ContentManager content)
        {
            // create the game objects
            _scene = new Scene();
            _scene.LoadContent(content);

            _fishing = new FishingState(this, _scene);
            _fishing.LoadContent(content);

            _ocean = new Ocean(_fishing);
            _ocean.LoadContent(content);

            _money = new Money(_fishing);

            _timer = new Timer(_fishing);

            _store = new Store(_money, _fishing);
            _store.LoadContent(content);
            _store.Hit += OnStoreHit;

            BadgeContext badgeContext = new BadgeContext();

            badgeContext.Fishing = _fishing;
            badgeContext.Money   = _money;
            badgeContext.Store   = _store;
            badgeContext.Timer   = _timer;
            _badges.Context      = badgeContext;

            // create the views
            _sceneView = new SceneView(_scene, _camera);
            _sceneView.LoadContent(content);

            _oceanView = new OceanView(_ocean);

            _fishCaughtView = new FishCaughtView(_fishing);
            _fishEatenView  = new FishEatenView(_fishing);
            _fishingView    = new FishingView(_fishing, _context);
            _fishingView.LoadContent(content);

            _distanceView = new DistanceView(_scene, _fishing);
            _distanceView.LoadContent(content);

            _moneyView = new MoneyView(_money);
            _moneyView.LoadContent(content);

            _timerView = new TimerView(_timer);
            _timerView.LoadContent(content);

            _lureView = new LureView(_fishing, _store);
            _lureView.LoadContent(content);

            _storeView = new StoreView(_store);
            _storeView.LoadContent(content);

            _guideView = new GameGuideView();
            _guideView.LoadContent(content);
            _guide = new GameGuide(_guideView, _fishing, _store, _money);

            _cameraController = new CameraController(_camera, _scene, _fishing);
        }
Пример #10
0
        public override void process(Ocean ocean)
        {
            Coordinate toCoord;

            toCoord = LogicMove.getPreyNeighborCoord(ocean, offset);

            if (toCoord._x == offset._x && toCoord._y == offset._y)
            {
                --_timeToReproduce;
                toCoord = LogicMove.getEmptyNeighborCoord(ocean, offset);
                _swim.moveFrom(offset, toCoord, ocean, this);
            }
            else
            {
                if (_timeToReproduce == 0)
                {
                    _timeToReproduce = TIME_TO_REPRODUCE;
                    Coordinate tmpMove = LogicMove.getEmptyNeighborCoord(ocean, offset);
                    ocean.assignCellAt(tmpMove, (Prey)_swim.reproduce(tmpMove, ocean));
                    ++ocean.NumPrey;
                    ++ocean.NumReproduce;
                }
                else
                {
                    toCoord = LogicMove.getEmptyNeighborCoord(ocean, offset);
                    _swim.moveFrom(offset, toCoord, ocean, this);
                }
            }
        }
Пример #11
0
    // Update is called once per frame
    void Update()
    {
        Ocean ocean = Ocean.ocean;

        transform.position += transform.up * speed * Time.deltaTime;
        if (Vector3.Distance(ocean.transform.position, transform.position) > ocean.radius)
        {
            if (looped >= loops)
            {
                Destroy(this.gameObject);
            }
            else
            {
                Vector3 fromTo = ocean.transform.position - transform.position;
                transform.position += fromTo * 1.99f;
                looped++;
            }
        }
        for (int i = 0; i < Debris.all.Count; i++)
        {
            Debris deb = Debris.all[i];
            if (Vector3.Distance(transform.position, deb.transform.position) < deb.radius + radius)
            {
                if (!deb.CompareTag("plastic"))
                {
                    Score.record.Down();
                }
                deb.vel += transform.up * impactForce;
                Destroy(this.gameObject);
                deb.split = true;
            }
        }
    }
Пример #12
0
        public void FindStepWithPlayer_Traveler_Step()
        {
            int           peopleLimit   = 3;
            bool          decision      = true;
            EndStep       endStep       = new EndStep();
            Mountain      mountain      = new Mountain(peopleLimit, endStep);
            Ocean         ocean         = new Ocean(peopleLimit, mountain);
            ThermalWaters thermalWaters = new ThermalWaters(peopleLimit, ocean);
            Farm          farm          = new Farm(peopleLimit, thermalWaters);
            FirstStep     firstStep     = new FirstStep(farm);
            List <Step>   steps         = new List <Step>();

            steps.Add(farm);
            steps.Add(thermalWaters);
            steps.Add(ocean);
            steps.Add(mountain);
            Board           board     = new Board(steps, firstStep, endStep);
            List <Traveler> travelers = new List <Traveler>();

            travelers.Add(new Traveler());
            travelers.Add(new Traveler());
            GameData data     = new GameData(travelers, board);
            Movement movement = new Movement(data);

            movement.MakeMove(travelers[0], decision);
            Assert.AreEqual(movement.FindStepWithPlayer(travelers[0]), firstStep);
            Assert.AreEqual(movement.FindStepWithPlayer(travelers[1]), null);
        }
Пример #13
0
    public List<Cube> CreateCubeField(Vector3 offset, Vector3 diagonal, float scale, float density)
    {
        List<Cube> cubes = new List<Cube>();

        for (int i = 0; i < diagonal.x; i++)
        {
            for (int j = 0; j < diagonal.y; j++)
            {
                for (int k = 0; k < diagonal.z; k++)
                {
                    if (Random.value < density)
                    {
                        Vector3 position = new Vector3(i*scale, j*scale, k*scale);
                        Vector3 size = new Vector3(scale, scale, scale);
                        Ocean cube = new Ocean(position, size);
                        Color color = Util.RainbowColor();
                        cube.Color(color);
                        cube.fluid.nutrients = Random.Range(10f, 100f);
                        cubes.Add(cube);
                    }
                }
            }
        }

        return cubes;
    }
Пример #14
0
        public void GameDataConstructor_TravelerAndBoard_TravelerNullException()
        {
            void Excecute()
            {
                int           peopleLimit   = 3;
                EndStep       endStep       = new EndStep();
                Mountain      mountain      = new Mountain(peopleLimit, endStep);
                Ocean         ocean         = new Ocean(peopleLimit, mountain);
                ThermalWaters thermalWaters = new ThermalWaters(peopleLimit, ocean);
                Farm          farm          = new Farm(peopleLimit, thermalWaters);
                FirstStep     firstStep     = new FirstStep(farm);
                List <Step>   steps         = new List <Step>();

                steps.Add(farm);
                steps.Add(thermalWaters);
                steps.Add(ocean);
                steps.Add(mountain);
                Board           board     = new Board(steps, firstStep, endStep);
                List <Traveler> travelers = new List <Traveler>();

                travelers.Add(null);
                travelers.Add(null);
                GameData data = new GameData(travelers, board);
            }

            Assert.Throws(typeof(TravelerNullException), Excecute);
        }
Пример #15
0
 public MCLQ(byte[] chunkBytes, MCNK parentChunk) : base(chunkBytes)
 {
     MinHeight = ReadSingle();
     MaxHeight = ReadSingle();
     for (int i = 0; i < 81; i++)
     {
         if (parentChunk.Flags.HasFlag(MCNKFlags.LiquidMagma))
         {
             Vertices[i] = new Magma();
         }
         else if (parentChunk.Flags.HasFlag(MCNKFlags.LiquidOcean))
         {
             Vertices[i] = new Ocean();
         }
         else
         {
             Vertices[i] = new Water();
         }
         Vertices[i].Read(this);
     }
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             Tiles[i, j] = ReadByte();
         }
     }
     NumberFlowvs = ReadUInt32();
     for (int i = 0; i < 3; i++)
     {
         Flowvs[i].Read(this);
     }
     Close();
 }
Пример #16
0
        public static void AddOceans()
        {
            var db = new AquariumDetailsContext();
            // *** Add Oceans ***
            var newOcean = new Ocean
            {
                Name    = "Atlantic",
                AvgTemp = 85
            };

            db.Oceans.Add(newOcean);
            db.SaveChanges();

            newOcean.Name    = "Pacific";
            newOcean.AvgTemp = 70;
            db.Oceans.Add(newOcean);
            db.SaveChanges();

            newOcean.Name    = "Indian";
            newOcean.AvgTemp = 75;
            db.Oceans.Add(newOcean);
            db.SaveChanges();

            newOcean.Name    = "Arctic";
            newOcean.AvgTemp = 75;
            db.Oceans.Add(newOcean);

            db.SaveChanges();
        }
Пример #17
0
        // Use this for initialization
        void Start()
        {
            Light l = GameObject.FindObjectOfType <Light>();
            Ocean o = GetComponent <Ocean>();

            o.m_sun = l.gameObject;
        }
 private void Place5Ships(Ocean playerBoard,
                          Ocean playerEmptyBoard,
                          ref int coordX,
                          ref int coordY)
 {
     for (int i = 0; i < 5; i++)
     {
         bool shipPlaced;
         do
         {
             ChooseShipTypeAndPlacement(playerEmptyBoard,
                                        out coordX,
                                        out coordY,
                                        out Ship newShip,
                                        out bool horizontal);
             shipPlaced = Ship.PlaceShip(coordX,
                                         coordY,
                                         horizontal,
                                         playerBoard.ArrayOfSquares,
                                         newShip);
             if (shipPlaced)
             {
                 UpdatePlayerShipList(newShip);
             }
         } while (!shipPlaced);
         Console.Clear();
         UTILS.AsciiArt.Battleship();
         Console.WriteLine($"This is {Name} turn.");
         if (Name != "AI")
         {
             Ocean.PrintBoard(playerBoard, playerEmptyBoard);
         }
     }
 }
Пример #19
0
 public Player()
 {
     radar   = new Radar();
     ocean   = new Ocean();
     Content = GetContent();
     //System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\WriteText.txt", text);
     //string[] stringArray = System.IO.File.ReadAllLines(@"C:\\words.txt");
 }
Пример #20
0
 public Prey(Ocean AOcean, Coordinate aCoord, bool move,
             int timeToReproduce = Constants.DEFAULT_TIME_TO_REPRODUCE,
             char image          = (char)CellsSymbols.PreyImage)
     : base(AOcean, aCoord, image)
 {
     Move            = move;
     TimeToReproduce = timeToReproduce;
 }
Пример #21
0
        private float GetOceanLevel()
        {
#if SUBNAUTICA
            return(Ocean.main.GetOceanLevel());
#elif BELOWZERO
            return(Ocean.GetOceanLevel());
#endif
        }
Пример #22
0
        static void Main()
        {
            IRunnable ocean1 = new Ocean(new ConsoleWriter(0, 0));

            ocean1.Run(100);

            System.Console.ReadKey();
        }
        internal float GetDepth()
        {
#if SUBNAUTICA
            return(gameObject == null ? 0f : Ocean.main.GetDepthOf(gameObject));
#elif BELOWZERO
            return(gameObject == null ? 0f : Ocean.GetDepthOf(gameObject));
#endif
        }
Пример #24
0
 public static Coordinate getEmptyNeighborCoord(Ocean ocean, Coordinate coo)
 {
     if (coo._y < Ocean.ROW && coo._x < Ocean.COL)
     {
         return(getNeighborWithImage(ocean, coo, (char)ValueOcean.Sea));
     }
     return(new Coordinate());
 }
Пример #25
0
 public static bool loadPreset(Ocean o, string preset, bool runtime = false, bool useFixedGaussianRandTable = false)
 {
             #if !UNITY_WEBGL && !UNITY_WEBPLAYER && !(UNITY_WSA_8_1 || UNITY_WP_8_1 || UNITY_WINRT_8_1) || UNITY_EDITOR
     return(readPreset(o, preset, runtime, useFixedGaussianRandTable));
             #else
     return(false);
             #endif
 }
Пример #26
0
        /// <summary>
        /// Creates a new ocean view.
        /// </summary>
        /// <param name="ocean">The ocean to draw.</param>
        public OceanView(Ocean ocean)
        {
            _ocean              = ocean;
            _ocean.FishAdded   += (o, e) => _fishes.Add(e.Fish, new FishView(e.Fish));
            _ocean.FishRemoved += (o, e) => _fishes.Remove(e.Fish);

            _fishes = new Dictionary <Fish, FishView>();
            _ocean.Fish.ForEach(fish => _fishes.Add(fish, new FishView(fish)));
        }
Пример #27
0
 void Start()
 {
     ocean = Ocean.Singleton;
     if (ocean.choppy_scale > 0)
     {
         hasChoppy = true;
     }
     oldPos = transform.position;
 }
        public static bool Prefix(SeaTruckMotor __instance, bool ____piloting)
        {
            /*
             * foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
             * {
             *  if (Input.GetKeyDown(kcode))
             *      Logger.Log("KeyCode down: " + kcode);
             * }
             */

            bool isThisOurTruck    = Vector3.Distance(Player.main.transform.position, __instance.transform.position) < 2;
            bool isAutoMoveClicked = (Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.JoystickButton8));

            if (!isThisOurTruck)
            {
                return(true);
            }

            if (FreeReadPatcher.isInPDA && isAutoMoveClicked)
            {
                Logger.Log("Toggling cruise");
                FreeReadPatcher.isCruising = !FreeReadPatcher.isCruising;
            }

            if (FreeReadPatcher.isCruising)
            {
                Logger.Log("...cruising...");

                // if keyboard, allow translation ( f and b cancel auto-move )

                // if controller, allow rotation



                //=====================================
                // the rest of this is base game code
                //=====================================
                bool myIsPowered       = !__instance.requiresPower || (__instance.relay && __instance.relay.IsPowered());
                bool myIsBusyAnimating = __instance.waitForAnimation && __instance.seatruckanimation != null && __instance.seatruckanimation.currentAnimation > SeaTruckAnimation.Animation.Idle;
                if (Player.main.transform.position.y < Ocean.GetOceanLevel() && __instance.useRigidbody != null && myIsPowered && !myIsBusyAnimating)
                {
                    // "vector" as described by GameInput.UpdateMoveDirection
                    Vector3 vector      = new Vector3(0, 0, 1);
                    Vector3 a           = MainCameraControl.main.rotation * vector;
                    float   myGetWeight = __instance.truckSegment.GetWeight() + __instance.truckSegment.GetAttachedWeight() * (__instance.horsePowerUpgrade ? 0.65f : 0.8f);
                    float   num         = 1f / Mathf.Max(1f, myGetWeight * 0.35f) * __instance.acceleration;
                    __instance.useRigidbody.AddForce(num * a, ForceMode.Acceleration);
                    if (__instance.relay)
                    {
                        float num2;
                        __instance.relay.ConsumeEnergy(Time.deltaTime * __instance.powerEfficiencyFactor * 0.12f, out num2);
                    }
                    return(false);
                }
            }
            return(true);
        }
Пример #29
0
    private void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(gameObject);
            return;
        }

        instance = this;
    }
Пример #30
0
        public static void Logic()
        {
            AsciiArt();
            string playerName = Player.GetTheInput("PLAYER 1 - Type in your name");

            (var player1, var player1Board, var emptyPlayer1Board) = Player.CreateNewPlayer(playerName);
            MainPlayer = player1;
            playerName = Player.GetTheInput("PLAYER 2 - Type in your name or hit ENTER to play with computer");
            (var player2, var player2Board, var emptyPlayer2Board) = Player.CreateNewPlayer(playerName);
            EnemyPlayer = player2;
            Console.Clear();
            bool firstRound = true;

            while (IsPlaying() || firstRound)
            {
                AsciiArt();
                Console.WriteLine($"This is {player1.Name} turn.");
                Ocean.PrintBoard(player1Board, emptyPlayer2Board);
                player1.Move(player1Board,
                             emptyPlayer2Board,
                             player2Board, player2.PlayerShips);
                Console.WriteLine("Press any button to switch players.");
                Console.ReadKey();
                Console.Clear();
                AsciiArt();
                Console.WriteLine($"This is {player2.Name} turn.");
                if (player2.Name != "AI")
                {
                    Ocean.PrintBoard(player2Board, emptyPlayer1Board);
                }
                player2.Move(player2Board,
                             emptyPlayer1Board,
                             player1Board, player1.PlayerShips);
                firstRound = false;
                if (player2.Name != "AI")
                {
                    Console.WriteLine("Press any button to switch players.");
                    Console.ReadKey();
                }
                Console.Clear();
            }

            AsciiArt();
            if (EnemyPlayer.PlayerShips.Count == 0)
            {
                Console.WriteLine($"\n{player1.Name} wins!\n");
            }
            else
            {
                Console.WriteLine($"\n{player2.Name} wins!\n");
            }
            Console.WriteLine("Press any button to exit.");
            Console.ReadKey();
            Environment.Exit(1);
        }
 /// <summary>
 ///     Handles the Tick event of the dispatcherTimer control.
 /// </summary>
 /// <param name="_sender">The source of the event.</param>
 /// <param name="_e">The <see cref="EventArgs" /> instance containing the event data.</param>
 private void dispatcherTimer_Tick(object _sender, EventArgs _e)
 {
     myOcean.UpdateEnvironnement();
     LapinPresent.Content  = myOcean.lapinList.Count;
     RenardPresent.Content = myOcean.renardList.Count;
     EatBar.Content        = Ocean.getTimeEat();
     LifeBar.Content       = Ocean.getTimeLife();
     VisibilityFox.Content = Ocean.getVisionRenard();
     //this.RenardPresent.Content = this.myOcean.renardList.Count;
     TikLapinApparition.Content = myOcean.timeToAppear;
 }
Пример #32
0
	IEnumerator Start() {
		ocean = gameObject.GetComponent<Ocean>();
		
		while (true) {
			yield return new WaitForEndOfFrame();
			
			if(forceStorm)
	            humidity = 1f;
		    else
    		    humidity = GetHumidity();
			
			if(ocean != null)
			    ocean.SetWaves(Mathf.Lerp(0, waveScale, humidity));
		}
	}
Пример #33
0
    void Start()
    {
        GameObject ocean = GameObject.Find("Ocean");

        if(ocean == null)
        {
            Debug.Log("AddBuoyancy::Start - Could not find ocean game object");
            return;
        }

        m_ocean = ocean.GetComponent<Ocean>();

        if(m_ocean == null)
            Debug.Log("AddBuoyancy::Start - Could not find ocean script");
    }
    protected virtual void Start ()
	{
        ocean = Ocean.Singleton;
		
		GetComponent<Rigidbody>().centerOfMass = new Vector3 (0.0f, -1f, 0.0f);
	
		Vector3 bounds = GetComponent<BoxCollider> ().size;
		float length = bounds.z;
		float width = bounds.x;

		blobs = new List<Vector3> ();

		int i = 0;
		float xstep = 1.0f / (ax - 1f);
		float ystep = 1.0f / (ay - 1f);
	
		sinkForces = new List<float>();
		
		float totalSink = 0;

		for (int x=0; x<ax; x++) {
			for (int y=0; y<ay; y++) {		
				blobs.Add (new Vector3 ((-0.5f + x * xstep) * width, 0.0f, (-0.5f + y * ystep) * length) + Vector3.up * ypos);
				
				float force =  Random.Range(0f,1f);
				
				force = force * force;
				
				totalSink += force;
				
				sinkForces.Add(force);
				i++;
			}		
		}
		
		// normalize the sink forces
		for (int j=0; j< sinkForces.Count; j++)
		{
			sinkForces[j] = sinkForces[j] / totalSink * sinkForce;
		}
		
	}
	void checkPdir(Ocean ocean) {
		if(Directory.Exists(presetPath)){
			string[] dp = Directory.GetFiles(presetPath);
			int k=0;
			for(int i=0; i<dp.Length; i++) {
				if(!dp[i].Contains(".meta")&& dp[i].Contains(".preset")) {k++;}
			}

			presets=null; presetpaths=null;
			System.Array.Resize(ref presets, k+2);
			System.Array.Resize(ref presetpaths, k+1);
			k=0;
			presets[0] = "Select Preset";
			for(int i=0; i<dp.Length; i++) {
				if(!dp[i].Contains(".meta") && dp[i].Contains(".preset")) {
					k++;
					presetpaths[k] = dp[i];
					presets[k+1] = Path.GetFileName(dp[i]).Replace(".preset","");
					if (presets[k+1] == ocean._name) {  currentPreset = k+1; oldpreset = currentPreset;}
				}
			}
			dp=null;
		}
	}
	public static void savePreset(Ocean ocean) {
		if (!Directory.Exists(presetPath)) Directory.CreateDirectory(presetPath);
		string preset = EditorUtility.SaveFilePanel("Save Ocean preset", presetPath,"","preset");

		if (preset != null) {
			if (preset.Length > 0) {
				title = Path.GetFileName(preset).Replace(".preset", ""); ocean._name = title;
				updcurPreset();
				using (BinaryWriter swr = new BinaryWriter(File.Open(preset, FileMode.Create))) {
					swr.Write(ocean.followMainCamera);//bool
					swr.Write(ocean.ifoamStrength);//float
					swr.Write(ocean.farLodOffset);//float
					swr.Write(ocean.tiles);//int
					swr.Write(ocean.size.x);//float
					swr.Write(ocean.size.y);//float
					swr.Write(ocean.size.z);//float
					swr.Write(ocean.width);//int
					swr.Write(ocean.height);//int
					swr.Write(ocean.fixedTiles);//bool
					swr.Write(0);//int removed
					swr.Write(0);//intremoved
					swr.Write(ocean.scale);//float
					swr.Write(ocean.choppy_scale);//float
					swr.Write(ocean.speed);//float
					swr.Write(0f);//float ocean.waveSpeed removed
					swr.Write(ocean.wakeDistance);//float
					swr.Write(ocean.renderReflection);//bool
					swr.Write(ocean.renderRefraction);//bool
					swr.Write(ocean.renderTexWidth);//int
					swr.Write(ocean.renderTexHeight);//int
					swr.Write(ocean.m_ClipPlaneOffset);//float
					swr.Write(LayerMaskField(ocean.renderLayers));//int
					swr.Write(ocean.specularity);//float
					swr.Write(ocean.mistEnabled);//bool
					swr.Write(ocean.dynamicWaves);//bool
					swr.Write(ocean.humidity);//float
					swr.Write(ocean.pWindx);//float
					swr.Write(ocean.pWindy);//float
					swr.Write(ocean.waterColor.r);//float
					swr.Write(ocean.waterColor.g);//float
					swr.Write(ocean.waterColor.b);//float
					swr.Write(ocean.waterColor.a);//float
					swr.Write(ocean.surfaceColor.r);//float
					swr.Write(ocean.surfaceColor.g);//float
					swr.Write(ocean.surfaceColor.b);//float
					swr.Write(ocean.surfaceColor.a);//float
					swr.Write(ocean.foamFactor);//float
					swr.Write(ocean.spreadAlongFrames);//bool
					swr.Write(ocean.shaderLod);//bool
					swr.Write(ocean.everyXframe);//int
					swr.Write(ocean.useShaderLods);//bool
					swr.Write(ocean.numberLods);//int
					swr.Write(ocean.fakeWaterColor.r);//float
					swr.Write(ocean.fakeWaterColor.g);//float
					swr.Write(ocean.fakeWaterColor.b);//float
					swr.Write(ocean.fakeWaterColor.a);//float
					swr.Write(ocean.defaultLOD);//int

					swr.Write(ocean.reflrefrXframe);//int
					swr.Write(ocean.foamUV);//float
					swr.Write(ocean.sun.transform.localRotation.eulerAngles.x);//float
					swr.Write(ocean.sun.transform.localRotation.eulerAngles.y);//float
					swr.Write(ocean.sun.transform.localRotation.eulerAngles.z);//float
					swr.Write(ocean.bumpUV);//float
					swr.Write(ocean.ifoamWidth);//float
					swr.Write(ocean.lodSkipFrames);//int
					if(ocean.material) swr.Write(ocean.material.name);else swr.Write("");//string
					if(ocean.material1) swr.Write(ocean.material1.name);else swr.Write("");//string
					if(ocean.material2) swr.Write(ocean.material2.name);else swr.Write("");//string
					swr.Write(ocean.shaderAlpha);//float
					swr.Write(ocean.reflectivity);//float
					swr.Write(ocean.translucency);//float
					swr.Write(ocean.shoreDistance);//float
					swr.Write(ocean.shoreStrength);//float
					swr.Write(ocean.specPower);//float
					if(ocean.oceanShader) swr.Write(ocean.oceanShader.name);else swr.Write("");//string
					swr.Write(ocean.hasShore);//bool
					swr.Write(ocean.hasShore1);//bool
					swr.Write(ocean.hasFog);//bool
					swr.Write(ocean.hasFog1);//bool
					swr.Write(ocean.hasFog2);//bool
					swr.Write(ocean.distCan1);//bool
					swr.Write(ocean.distCan2);//bool
					swr.Write(ocean.cancellationDistance);//float
					swr.Write(ocean.foamDuration);//float
					swr.Write(ocean.sTilesLod);//int
					swr.Write(ocean.discSize);//int
					swr.Write(ocean.lowShaderLod);//int
					swr.Write(ocean.forceDepth);//bool
				}

			}
		}
	}
	public static void checkOceanWidth(Ocean ocean) {
		switch (ocean.width) {
			case 8:
			ocW = 0; ocean.width = ocean.height = 8; break;
			case 16:
			ocW = 1 ;ocean.width = ocean.height = 16; break;
			case 32:
			ocW = 2; ocean.width = ocean.height = 32; break;
			case 64:
			ocW = 3; ocean.width = ocean.height = 64; break;
			case 128:
			ocW = 4; ocean.width = ocean.height = 128; break;
		}
		oldocW = ocW;
	}
 void OnEnable()
 {
     if (ocean == null)
         ocean = GameObject.FindGameObjectWithTag ("Ocean").GetComponent<Ocean>();
 }
Пример #39
0
        private void Analyze()
        {
            // Build the ocean
            //	- an ocean (set) of islands (set)
            //	- also a hash for TopicAnalysis (topic->{island set,refcount}) for quick check if already present
            _referenceMap = _namespaceManager.GetReferenceMap(ExistencePolicy.ExistingOnly);

            foreach (string outerTopic in _referenceMap.Keys)
            {
                Ocean islands = new Ocean();
                QualifiedTopicRevisionCollection linkedTopics = _referenceMap[outerTopic];

                QualifiedTopicRevision outerRevision = new QualifiedTopicRevision(outerTopic, _namespaceManager.Namespace);
                TopicAnalysis outerTopicAnalysis = null;
                if (!_topicToTopicAnalysis.ContainsKey(outerRevision))
                {
                    outerTopicAnalysis = new TopicAnalysis();
                    _topicToTopicAnalysis[outerRevision] = outerTopicAnalysis;
                }
                else
                {
                    outerTopicAnalysis = _topicToTopicAnalysis[outerRevision];
                }

                if (outerTopicAnalysis.Island != null)
                {
                    islands.Add(outerTopicAnalysis.Island);
                }

                //	- foreach outer topic
                //		islands = new set
                //		foreach linked topic
                //			increment refcount for linked topic
                //			if (linkedtopic is on an island)
                //				islands add that island
                Island inNamespaceLinks = new Island();
                foreach (QualifiedTopicRevision linkedTopic in linkedTopics)
                {
                    // Only analyze in this namespace
                    if (linkedTopic.Namespace != _namespaceManager.Namespace)
                    {
                        // Response.Write("Skiping linked topic (" + linkedTopic.Name + ") because namespace doesn't match<br>");
                        continue;
                    }
                    // Only do each topic once; have we seen this one?
                    if (inNamespaceLinks.Contains(linkedTopic))
                    {
                        // Response.Write("Skiping linked topic (" + linkedTopic.Name + ") because seen before<br>");
                        continue;
                    }
                    // Skip self-references
                    if (linkedTopic.Equals(outerTopic))
                    {
                        continue;
                    }

                    inNamespaceLinks.Add(linkedTopic);
                    TopicAnalysis linkedTopicAnalysis = null;
                    if (!_topicToTopicAnalysis.ContainsKey(linkedTopic))
                    {
                        linkedTopicAnalysis = new TopicAnalysis();
                        _topicToTopicAnalysis[linkedTopic] = linkedTopicAnalysis;
                    }
                    else
                    {
                        linkedTopicAnalysis = _topicToTopicAnalysis[linkedTopic];
                    }
                    linkedTopicAnalysis.RefCount++;
                    if (linkedTopicAnalysis.Island != null)
                    {
                        islands.Add(linkedTopicAnalysis.Island);
                    }
                }

                //		if (islands is empty)
                //			create new island
                //			add outer topic and all linked topics
                //		else if (islands size == 1)
                //			add all links and the outer topic to that islands
                //		else
                //			// need to merge islands
                //			newset = merged set of all islands
                //			TopicAnalysiss and replace and of the old islands with the new island

                Island newIsland;
                if (islands.Count == 1)
                {
                    newIsland = islands.First;	// if there's only one, we can just use that one
                }
                else
                {
                    newIsland = new Island();
                    _ocean.Add(newIsland);
                }
                // Add the island and the linkedTopics
                newIsland.Add(new QualifiedTopicRevision(outerTopic, _namespaceManager.Namespace));
                outerTopicAnalysis.Island = newIsland;
                foreach (QualifiedTopicRevision linkedTopic in inNamespaceLinks)
                {
                    newIsland.Add(linkedTopic);
                    _topicToTopicAnalysis[linkedTopic].Island = newIsland;
                    // Response.Write("Placing " + linkedTopic.Name + "<br>");
                }
                // Now merge if there was originally more than one
                if (islands.Count > 1)
                {
                    foreach (Island eachIsland in islands)
                    {
                        foreach (QualifiedTopicRevision revision in eachIsland)
                        {
                            newIsland.Add(revision);
                        }
                        _ocean.Remove(eachIsland);
                        // Now update all the pointers from the TopicAnalysiss
                        foreach (QualifiedTopicRevision eachTopic in eachIsland)
                        {
                            _topicToTopicAnalysis[eachTopic].Island = newIsland;
                        }
                    }
                }
            }
        }
Пример #40
0
	private static void createTiles(Ocean ocean) {

	//	int width=ocean.width;
	//	int height=ocean.height;
		Vector3 size=ocean.size;
		int tiles=ocean.tiles;

		if (ocean.parentTile!=null) {
			DestroyImmediate(ocean.parentTile);
			ocean.parentTile=null;
		}
		GameObject parentTile=new GameObject("ParentTile");
		GameObject tile;
		//int chDist; // Chebychev distance	
		for (int y=0; y<tiles; y++) {
			for (int x=0; x<tiles; x++) {
				//chDist = System.Math.Max (System.Math.Abs (tiles_y / 2 - y), System.Math.Abs (tiles_x / 2 - x));
				//chDist = chDist > 0 ? chDist - 1 : 0;
				float cy = y - Mathf.Floor(tiles * 0.5f);
				float cx = x - Mathf.Floor(tiles * 0.5f);
				tile = new GameObject ("WaterTile");
				Vector3 pos=tile.transform.position;
				pos.x = cx * size.x;
				pos.y = 0f;
				pos.z = cy * size.z;
				tile.transform.position=pos;
				MeshFilter m=tile.AddComponent<MeshFilter>();
				m.mesh=CreateMesh(size.x,size.z);

				tile.AddComponent ("MeshRenderer");
				tile.renderer.material = ocean.material;
				
				//Make child of this object, so we don't clutter up the
				//scene hierarchy more than necessary.
				tile.transform.parent = parentTile.transform;
				
				//Also we don't want these to be drawn while doing refraction/reflection passes,
				//so we'll add the to the water layer for easy filtering.
				tile.layer = LayerMask.NameToLayer ("Water");
			}
		}

		parentTile.transform.parent=ocean.transform;
		parentTile.transform.localPosition=Vector3.zero;
		ocean.parentTile=parentTile;
	}
    void Start () {

		if(!_renderer) {
			_renderer = GetComponent<Renderer>();
			if(!_renderer) {
				_renderer = GetComponentInChildren<Renderer>();
			}
		}

		if(_renderer && renderQueue>0) _renderer.material.renderQueue = renderQueue;

		if(!_renderer) {
			if(cvisible) { Debug.Log("Renderer to check visibility not assigned."); cvisible = false; }
			if(wvisible) { Debug.Log("Renderer to check visibility not assigned."); wvisible = false; }
			if(svisible) { Debug.Log("Renderer to check visibility not assigned."); svisible = false; }
		}

		if(dampCoeff<0) dampCoeff = Mathf.Abs(dampCoeff);

		rrigidbody =  GetComponent<Rigidbody>();

		useGravity = rrigidbody.useGravity;

		if(interpolation>0) {
			interpolate = true;
			iF = 1/(float)interpolation;
			intplt = interpolation;
		}

		if(SlicesX<2) SlicesX=2;
		if(SlicesZ<2) SlicesZ=2;

        ocean = Ocean.Singleton;
		
		rrigidbody.centerOfMass = new Vector3 (0.0f, CenterOfMassOffset, 0.0f);
	
		Vector3 bounds = GetComponent<BoxCollider> ().size;

		float length = bounds.z;
		float width = bounds.x;

		blobs = new List<Vector3> ();
		prevBoya = new List<float[]>();

		int i = 0;
		float xstep = 1.0f / ((float)SlicesX - 1f);
		float ystep = 1.0f / ((float)SlicesZ - 1f);
	
		sinkForces = new List<float>();
		
		float totalSink = 0;

		for (int x=0; x<SlicesX; x++) {
			for (int y=0; y<SlicesX; y++) {		
				blobs.Add (new Vector3 ((-0.5f + x * xstep) * width, 0.0f, (-0.5f + y * ystep) * length) + Vector3.up * ypos);

				if(interpolate) { prevBoya.Add(new float[interpolation]); }
				
				float force =  Random.Range(0f,1f);
				force = force * force;
				totalSink += force;
				sinkForces.Add(force);
				i++;
			}		
		}
		
		// normalize the sink forces
		for (int j=0; j< sinkForces.Count; j++)	{
			sinkForces[j] = sinkForces[j] / totalSink * sinkForce;
		}

	}
	void Start () {
		ocean = Ocean.Singleton;
		if(ocean.choppy_scale>0) hasChoppy = true;
		oldPos = transform.position;
	}
Пример #43
0
 void Start()
 {
     ocean = (Ocean)GameObject.FindObjectOfType(typeof(Ocean));
     thisBody = GetComponent<Rigidbody>();
 }