Пример #1
0
        /// *******************************************************
        /// <summary>初期処理</summary>
        /// *******************************************************
        protected override void OnStart()
        {
            CharType = CharacterTyep.ENEMY;
            if (TargetPosition == null)
            {
                TargetPosition = new Vector2();
            }
            ScriptMain = new EnemyScriptMain(this, Initial, SpawnKey);

            if (Initial != null)
            {
                SetInitial(Initial);
            }

            if (StageManager.Instance != null)
            {
                StageManager.Instance.AddEnemyList(this);
            }

            base.OnStart();

            if (Script != null)
            {
                ScriptMain.ReadScriptText(Script.text);
            }
            SpawnSide = (Position.x < 0) ? SpawnPosition.LEFT : SpawnPosition.RIGHT;
        }
Пример #2
0
        private void PlaceObject(LevelObjectPrefab prefab, SpawnPosition spawnPosition, Level level)
        {
            float rotation = 0.0f;

            if (prefab.AlignWithSurface && spawnPosition.Normal.LengthSquared() > 0.001f && spawnPosition != null)
            {
                rotation = MathUtils.VectorToAngle(new Vector2(spawnPosition.Normal.Y, spawnPosition.Normal.X));
            }
            rotation += Rand.Range(prefab.RandomRotationRad.X, prefab.RandomRotationRad.Y, Rand.RandSync.Server);

            Vector2 position = Vector2.Zero;
            Vector2 edgeDir  = Vector2.UnitX;

            if (spawnPosition == null)
            {
                position = new Vector2(
                    Rand.Range(0.0f, level.Size.X, Rand.RandSync.Server),
                    Rand.Range(0.0f, level.Size.Y, Rand.RandSync.Server));
            }
            else
            {
                edgeDir  = (spawnPosition.GraphEdge.Point1 - spawnPosition.GraphEdge.Point2) / spawnPosition.Length;
                position = spawnPosition.GraphEdge.Point2 + edgeDir * Rand.Range(prefab.MinSurfaceWidth / 2.0f, spawnPosition.Length - prefab.MinSurfaceWidth / 2.0f, Rand.RandSync.Server);
            }

            if (!MathUtils.NearlyEqual(prefab.RandomOffset.X, 0.0f) || !MathUtils.NearlyEqual(prefab.RandomOffset.Y, 0.0f))
            {
                Vector2 offsetDir = spawnPosition.Normal.LengthSquared() > 0.001f ? spawnPosition.Normal : Rand.Vector(1.0f, Rand.RandSync.Server);
                position += offsetDir * Rand.Range(prefab.RandomOffset.X, prefab.RandomOffset.Y, Rand.RandSync.Server);
            }

            var newObject = new LevelObject(prefab,
                                            new Vector3(position, Rand.Range(prefab.DepthRange.X, prefab.DepthRange.Y, Rand.RandSync.Server)), Rand.Range(prefab.MinSize, prefab.MaxSize, Rand.RandSync.Server), rotation);

            AddObject(newObject, level);

            foreach (LevelObjectPrefab.ChildObject child in prefab.ChildObjects)
            {
                int childCount = Rand.Range(child.MinCount, child.MaxCount, Rand.RandSync.Server);
                for (int j = 0; j < childCount; j++)
                {
                    var matchingPrefabs = LevelObjectPrefab.List.Where(p => child.AllowedNames.Contains(p.Name));
                    int prefabCount     = matchingPrefabs.Count();
                    var childPrefab     = prefabCount == 0 ? null : matchingPrefabs.ElementAt(Rand.Range(0, prefabCount, Rand.RandSync.Server));
                    if (childPrefab == null)
                    {
                        continue;
                    }

                    Vector2 childPos = position + edgeDir * Rand.Range(-0.5f, 0.5f, Rand.RandSync.Server) * prefab.MinSurfaceWidth;

                    var childObject = new LevelObject(childPrefab,
                                                      new Vector3(childPos, Rand.Range(childPrefab.DepthRange.X, childPrefab.DepthRange.Y, Rand.RandSync.Server)),
                                                      Rand.Range(childPrefab.MinSize, childPrefab.MaxSize, Rand.RandSync.Server),
                                                      rotation + Rand.Range(childPrefab.RandomRotationRad.X, childPrefab.RandomRotationRad.Y, Rand.RandSync.Server));

                    AddObject(childObject, level);
                }
            }
        }
Пример #3
0
//	bool ValidNextSpawningEnemy()
//	{
//		nextSpawningEnemyId = RandomEnemyId();
//		if (nextSpawningEnemyId > -1)
//		{
//			if (enemyPrefabs[nextSpawningEnemyId] != null)
//				return true;
//			else
//			{
//				Debug.LogError ("EnemyID: " + nextSpawningEnemyId + " is not valid");
//				return false;
//			}
//		}
//		return false;
//	}

// TOTAL RANDOM
//	void Spawn()
//	{
////		if (ValidNextSpawningEnemy())
////		{
////			nextEnemySpawnTimestamp = Time.time + RandomNextSpawnTimestamp();
//			spawnCount++;
//			int randomSpawn = Random.Range (0, spawnPositions.Count);
//			SpawnPosition randomSpawnPosition = spawnPositions[randomSpawn];
//			WaveEnemy randomWaveEnemy = CrystalQuestWaveManager.Instance.GetCurrentWave ().GetRandomWaveEnemy ();
//			GameObject newEnemy = InstantiateEnemy (randomWaveEnemy, randomSpawnPosition);
//			if (newEnemy != null)
//			{
//				newEnemy.SetActive (true);
//				newEnemy.GetComponent<HealthManager>().Revive ();
//				//			newEnemy.GetComponent<PooledObject>().Reuse ();		// TODO
//				//			EnemyObjectScript enemyScript = newEnemy.GetComponent<EnemyObjectScript>();
//				if (audioSource != null && spawnClip != null)
//					audioSource.PlayOneShot (spawnClip);
//				else
//					Debug.LogError ("AudioSource or SpawnClip not set");
//			}
////		}
//	}

    /// <summary>
    /// Spawn Enemy with considering frequency.
    /// </summary>
    void Spawn()
    {
        //		if (ValidNextSpawningEnemy())
        //		{
        //			nextEnemySpawnTimestamp = Time.time + RandomNextSpawnTimestamp();
        spawnCount++;
        int           randomSpawn         = Random.Range(0, spawnPositions.Count);
        SpawnPosition randomSpawnPosition = spawnPositions[randomSpawn];
//		WaveEnemy randomWaveEnemy = CrystalQuestWaveManager.Instance.GetCurrentWave ().GetRandomWaveEnemy ();
        int        randomConsideringFrequency = RandomEnemyId();
        GameObject enemyPrefab = currentWaveEnemyFrequency[randomConsideringFrequency];
        GameObject newEnemy    = InstantiateEnemy(enemyPrefab, randomSpawnPosition);

        if (newEnemy != null)
        {
            newEnemy.SetActive(true);
            newEnemy.GetComponent <HealthManager>().Revive();
            //			newEnemy.GetComponent<PooledObject>().Reuse ();		// TODO
            //			EnemyObjectScript enemyScript = newEnemy.GetComponent<EnemyObjectScript>();
            if (audioSource != null && spawnClip != null)
            {
                audioSource.PlayOneShot(spawnClip);
            }
            else
            {
                Debug.LogError("AudioSource or SpawnClip not set");
            }
        }
        //		}
    }
Пример #4
0
    private void _randomSpawn()
    {
        int           nRandom = Random.Range(0, m_nCntLst);
        SpawnPosition _pos    = ArraySpawnPos[nRandom];

        _generate(_pos, PrefabCar);
    }
Пример #5
0
        public void Save()
        {
            var path = Path.Combine(Application.RootFolder, "Routes", Name + ".route");

            if (!File.Exists(path))
            {
                File.Delete(path);
            }

            List <string> lines = new List <string>();

            lines.Add(PreviewCameraPosition.ConvertToString());
            lines.Add(PreviewCameraDirection.ConvertToString());
            lines.Add("");
            lines.Add(SpawnPosition.ConvertToString());
            lines.Add(SpawnRotation.ConvertToString());
            lines.Add("");

            Application.Console.WriteLine("[Route.Save]: Saving route " + Name + " with " + Barriers.Count + " barriers");
            foreach (var b in Barriers)
            {
                Application.Console.WriteLine("[Route.Save]: Writing barrier with midpoint " + b.Midpoint.X + " | " + b.Midpoint.Y);
                for (int j = 0; j < b.Coordinates.Count; j++)
                {
                    lines.Add(b.Coordinates[j].ConvertToString());
                    Application.Console.WriteLine(b.Coordinates[j].ConvertToString());
                }
                lines.Add("");
            }

            File.WriteAllLines(path, lines);
        }
Пример #6
0
    public void CreateHorde(SpawnPosition position, float count)
    {
        Horde newHorde = Instantiate(hordePrefab, transform);

        newHorde.name = "Horde " + hordeCounter;
        hordeCounter++;
        hordes.Add(newHorde);
        switch (position)
        {
        case SpawnPosition.LEFT:
            newHorde.Spawn(-10f, -1f, 0f, 62f, count);
            break;

        case SpawnPosition.TOP:
            newHorde.Spawn(0f, 64f, 62f, 71f, count);
            break;

        case SpawnPosition.RIGHT:
            newHorde.Spawn(64f, 73f, 0f, 62f, count);
            break;

        case SpawnPosition.BOTTOM:
            newHorde.Spawn(0f, 64f, -10f, -1f, count);
            break;
        }
    }
Пример #7
0
 public virtual void PoolAdquire(SpawnPosition spawnerTransform, string objType, BasePool pool)
 {
     _inPool            = false;
     ownerPool          = pool;
     shootType          = objType;
     transform.position = spawnerTransform.spawnPoint;
     transform.rotation = spawnerTransform.rotation;
 }
Пример #8
0
 public BattalionSpawnEffect(BattalionIdentifier spawnSource,
                             BattalionState spawnedUnit,
                             SpawnPosition position)
 {
     SpawnSource = spawnSource;
     SpawnedUnit = spawnedUnit;
     Position    = position;
 }
Пример #9
0
 public static Tuple <float, float, float, float> GetPositionHeading(this SpawnPosition position)
 {
     return(new Tuple <float, float, float, float>(
                position.Y / 8f,
                position.Z / 8f,
                position.X / 8f,
                position.Heading / 8f / 255f
                ));
 }
Пример #10
0
    void Update()
    {
        if (WaitingToReconnect)
        {
            Debug.LogError("waiting to reconnect...");
            return;
        }
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = AR_Camera.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit))
                {
                    try
                    {
                        SpawnPosition p = new SpawnPosition
                        {
                            X = hit.point.x,
                            Y = hit.point.y,
                            Z = hit.point.z
                        };

                        var reply = client.SpawnSphere(p);
                    }
                    catch (Exception e)
                    {
                        //  StartCoroutine(TimeoutCount());
                        //  Debug.LogError(Time.time + ": " + e.Message);
                    }
                }
            }


            try
            {
                CameraOrientation o = new CameraOrientation
                {
                    X  = AR_Camera.position.x,
                    Y  = AR_Camera.position.y,
                    Z  = AR_Camera.position.z,
                    Rx = AR_Camera.eulerAngles.x,
                    Ry = AR_Camera.eulerAngles.y,
                    Rz = AR_Camera.eulerAngles.z
                };

                var reply = client.SetCameraPosition(o);
            }
            catch (Exception e)
            {
                //  StartCoroutine(TimeoutCount());
                //  Debug.LogError(Time.time + ": " + e.Message);
            }
        }
    }
        protected virtual SpawnPosition GetSpawnPosition(UInt32 p1, UInt32 p2, UInt32 p3, UInt32 p4, UInt32 p5)
        {
            var posn = new SpawnPosition();

            posn.X       = Utils.EQ19ToFloat((Int32)(p5 >> 12) & 0x7FFFF);   //!
            posn.Y       = Utils.EQ19ToFloat((Int32)(p4) & 0x7FFFF);         //!
            posn.Z       = Utils.EQ19ToFloat((Int32)((p1 >> 12) & 0x7FFFF)); //!
            posn.Heading = Utils.EQ19ToFloat((Int32)(p5) & 0xFFF);
            return(posn);
        }
Пример #12
0
 public void SetPositionIsTaken(SpawnPosition spawnPos, bool b)
 {
     foreach (SpawnPosition spawnPosition in spawnPositions)
     {
         if (spawnPosition == spawnPos)
         {
             spawnPosition.IsTaken = b;
         }
     }
 }
Пример #13
0
 public void SeenByGuard()
 {
     if (AbleToMove())
     {
         _seen         = true;
         spawnPosition = levelManager.levelManager.GetNearestAvailablePosition(this);
         HideToPlace(spawnPosition);
         OnSeen?.Invoke(ID);
     }
 }
Пример #14
0
        public void SpawnEntity(EntityStackPool pool)
        {
            var entity = pool.Pull();

            SpawnPosition spawnPos = pool.SpawnPosition;
            Vector3       pos      = spawnPos == SpawnPosition.Any ? Random.value > 0.5f ? upSpawn.position : downSpawn.position
                                                        : spawnPos == SpawnPosition.Up ? upSpawn.position : downSpawn.position;

            entity.transform.SetParent(entitiesParent);
            entity.Setup(pos, settings);
        }
Пример #15
0
 public override void PoolAdquire(SpawnPosition spawnerTransform, string objType, BasePool pool)
 {
     base.PoolAdquire(spawnerTransform, objType, pool);
     if (trails.Length > 0)
     {
         foreach (TrailRenderer t in trails)
         {
             t.enabled = true;
         }
     }
 }
Пример #16
0
 // Use this for initialization
 void Start()
 {
     m_rigidBody     = GetComponent <Rigidbody2D>();
     m_spawnPosition = FindObjectOfType <SpawnPosition>();
     if (m_spawnPosition == null)
     {
         Debug.Log("SpawnPostion Not Found");
     }
     NotUpdateExecution = false;
     m_bCanJump         = true;
 }
Пример #17
0
 private void SpawnFirstCards()
 {
     for (int c = 1; c <= _initialCardsCount; c++)
     {
         var spawnPos      = new Vector3(transform.position.x + _spawnInterval * c, transform.position.y, -6f);
         var randomCard    = Instantiate(_normalCards[Random.Range(0, _normalCards.Count)], spawnPos, Quaternion.identity);
         var spawnPosition = new SpawnPosition(spawnPos);
         randomCard.GetComponent <CardBehaviour>().spawnPosition = spawnPosition;
         _spawnPositions.Add(spawnPosition);
     }
 }
Пример #18
0
    private void _generate(SpawnPosition _pos, GameObject _objPrefab)
    {
        GameObject _objCar = Instantiate(_objPrefab, Vector3.zero, Quaternion.identity);

        _objCar.transform.SetParent(_pos.transform);
        _objCar.transform.localPosition = Vector3.zero;
        CarMovement _carMovement = _objCar.GetComponent <CarMovement>();

        _carMovement.Registe(chgSpeedMgr);
        _carMovement.SetStartData(_pos.MoveDir, _pos.Dir);
    }
Пример #19
0
//	GameObject InstantiateEnemy (WaveEnemy waveEnemy, SpawnPosition spawnPos)
//	{
//		GameObject enemy = GetObject (waveEnemy);
//		if (enemy != null)
//		{
//			enemy.transform.position = spawnPos.Position;
//		}
//
//		return enemy;
//	}

    GameObject InstantiateEnemy(GameObject enemyPrefab, SpawnPosition spawnPos)
    {
        GameObject enemy = GetObject(enemyPrefab);

        if (enemy != null)
        {
            enemy.transform.position = spawnPos.Position;
        }

        return(enemy);
    }
Пример #20
0
    public void AddPlayer(PlayerController _newPlayer, int _newID)
    {
        _audioSource.Play();

        ID     = _newID;
        Player = _newPlayer;
        StartInteraction();
        transform.position = new Vector3(transform.position.x, _newPlayer.gameObject.transform.position.y, transform.position.z);

        levelManager.levelManager.SetPositionIsTaken(spawnPosition, false);
        spawnPosition = null;
    }
Пример #21
0
    void Awake()
    {
        SerializedObject = target as SpawnPosition;

        GroundDetectionHeight = this.serializedObject.FindProperty("GroundDetectionHeight");
        ObjectsToSpawn        = this.serializedObject.FindProperty("Objects_to_Spawn");
        ObjectsToIgnore       = this.serializedObject.FindProperty("IgnoredSpawnObject");

        ButtonLayout    = new GUILayoutOption[2];
        ButtonLayout[0] = GUILayout.Height(15);
        ButtonLayout[1] = GUILayout.Width(100);
    }
Пример #22
0
 /// <summary>
 /// A custom hash code algorithm that takes into account the values of each property of the <see cref="SpawnInfo"/> instance,
 /// and attempts to reduce diagonal collisions.
 /// </summary>
 /// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
 public override int GetHashCode()
 {
     unchecked // overflow is fine, just wrap around
     {
         int hash = 13;
         hash = (hash * 7) + TechType.GetHashCode();
         hash = (hash * 7) + ClassId.GetHashCode();
         hash = (hash * 7) + SpawnPosition.GetHashCode();
         hash = (hash * 7) + Rotation.GetHashCode();
         hash = (hash * 7) + Type.GetHashCode();
         return(hash);
     }
 }
Пример #23
0
    // Start is called before the first frame update
    void Awake()
    {
        //set up ref to spawnPos
        spawnPos = StarDatabase.starDatabase.starsInfo[starNumber - 1].starSpawnPosition;

        //calculate random
        xOrigin = Random.Range(spawnPos.xOrigin_min, spawnPos.xOrigin_max);
        yOrigin = Random.Range(spawnPos.yOrigin_min, spawnPos.yOrigin_max);
        zOrigin = Random.Range(spawnPos.zOrigin_min, zOrigin_max);

        //set position of Star
        transform.position = new Vector3(xOrigin, yOrigin, zOrigin);
    }
Пример #24
0
    void OnTriggerExit(Collider other)
    {
        SpawnPosition spawnPos = other.gameObject.GetComponent <SpawnPosition>();

        if (spawnPos)
        {
            other.gameObject.transform.position = spawnPos.spawnPosition;
            other.gameObject.transform.rotation = Quaternion.Euler(spawnPos.spawnRotation);
            Rigidbody rb = other.gameObject.GetComponent <Rigidbody>();
            rb.velocity        = Vector3.zero;
            rb.angularVelocity = Vector3.zero;
        }
    }
Пример #25
0
    public void Spawn()
    {
        hittingBall   = GameObject.FindObjectOfType <HittingBall>();
        spawnPosition = GameObject.FindObjectOfType <SpawnPosition>();
        Vector3 position = spawnPosition.pos;

        float   random   = Random.Range(-spawnX, spawnX);
        Vector3 spawnPos = position + new Vector3(random, -3.65f, 0f);

        Instantiate(objectHole, spawnPos, Quaternion.identity);

        hittingBall.Update();
    }
    IEnumerator DestroyBoss()
    {
        yield return(new WaitForSeconds(1f));

        SpawnPosition spawnerPosition = new SpawnPosition();

        spawnerPosition.spawnPoint = transform.position;
        spawnerPosition.rotation   = transform.rotation;

        ReleaseCoins();
        ReleasePowerUp();

        Destroy(this.gameObject);
    }
Пример #27
0
        public override void HandleMcpeRespawn(McpeRespawn mcpeRespawn)
        {
            PlayerLocation oldSpawnPosition = SpawnPosition.Clone() as PlayerLocation;

            PlayerRespawnEventArgs respawnEvent = new PlayerRespawnEventArgs(this, null);

            respawnEvent.OnCallEvent();

            SpawnPosition = respawnEvent.GetRespawnLocation() ?? SpawnPosition;

            base.HandleMcpeRespawn(mcpeRespawn);

            SpawnPosition = oldSpawnPosition;
        }
Пример #28
0
    public void SpawnRandomCustomer(SpawnPosition seletcedSpawner)
    {
        if (seletcedSpawner == null)
        {
            return;
        }

        CustomerData customerData = GetNextSpawningCustomer(CustomerSpawnStrategy.Random);
        Vector3      pos;
        Quaternion   rot;

        seletcedSpawner.GetSpawnPosAndRot(out pos, out rot);
        SpawnCustomer(customerData, pos, rot);
    }
    // Use this for initialization
    void Start()
    {
        if (isLocalPlayer)
        {
            SpawnPosition sp = GameObject.Find("SpawnPoints").GetComponent <SpawnPosition>();

            int ran = Random.Range(0, sp.spawnPos.Length - 1);

            myTransform.position = sp.spawnPos[ran].position;
            GetComponent <PlayerMove>().enabled          = true;
            GetComponent <CharacterController>().enabled = true;
            cam.enabled = true;
        }
    }
Пример #30
0
    public SpawnPosition GetNearestAvailablePosition(PickUpItem item)
    {
        SpawnPosition nearestPos = null;
        Vector3       itemPos    = item.transform.position;

        foreach (SpawnPosition spawnPosition in spawnPositions)
        {
            if (!spawnPosition.IsTaken && (nearestPos == null || Vector3.Distance(itemPos, spawnPosition.transform.position) < Vector3.Distance(itemPos, nearestPos.transform.position)))
            {
                nearestPos = spawnPosition;
            }
        }

        return(nearestPos);
    }
        /**
         * Sets camera position and identity vector.
         * The identity vector defined the center point of our universe (e.g. X = Y = Z = 0)
         */
        private void SetSpawnPosition(SpawnPosition position)
        {
            switch (defaultSpawnPosition) {
                case SpawnPosition.ZERO:
                    identityVector = IntVector3.zero;
                    break;

                case SpawnPosition.CENTER:
                    identityVector = new IntVector3(Region.REGION_SIZE / 2);
                    break;
            }
        }
Пример #32
0
	private IEnumerator WaitForPosition()
	{
		while(transform.position == Vector3.zero)
		{
			yield return null;
		}

		//set position it will change forward direction
		Vector2 pos = (Vector2)transform.position;
		center = Camera.main.ViewportToWorldPoint (new Vector3 (0.5f, 0.5f));
		
		float angle = (float)Math.Atan2 (center.y - pos.y, center.x - pos.x);

		center.x = 0.5f + (float)(Math.Cos (angle) * centerRadius);
		center.y = 0.5f + (float)(Math.Sin (angle) * centerRadius);;

		center = Camera.main.ViewportToWorldPoint (center);

		float totalTime = (Vector2.Distance (pos, center) * 2) / vel;
		float sideVel = 0f;

		//set side position where it will land
		pos = Camera.main.WorldToViewportPoint (pos);

		if (pos.x < 0)
			spawnPosition = SpawnPosition.Left;
		else if (pos.x > 1)
			spawnPosition = SpawnPosition.Right;
		else if (pos.y < 0)
			spawnPosition = SpawnPosition.Down;
		else if (pos.y > 1)
			spawnPosition = SpawnPosition.Up;

		//move Y
		if(spawnPosition == SpawnPosition.Left || spawnPosition == SpawnPosition.Right)
		{
			float landPosition = 0f;
			if(pos.y > 0.5f)//UP
				landPosition = 0.2f;
			else//DOWN
				landPosition = 0.8f;

			pos = Camera.main.ViewportToWorldPoint(new Vector2(pos.x, landPosition));

			sideVel = (pos.y - transform.position.y) / totalTime;

			forceSideway = transform.up * sideVel;

			//invert direction on RIGHT
			if(spawnPosition == SpawnPosition.Right)
				forceSideway *= -1;
		}
		else//move X
		{
			float landPosition = 0f;
			if(pos.x > 0.5f)//RIGHT
				landPosition = 0.2f;
			else//LEFT
				landPosition = 0.8f;
			
			pos = Camera.main.ViewportToWorldPoint(new Vector2(landPosition, pos.y));
			
			sideVel = (pos.x - transform.position.x) / totalTime;
			
			forceSideway = transform.up * sideVel;

			//invert direction on DOWN
			if(spawnPosition == SpawnPosition.Down)
				forceSideway *= -1;
		}

		myRigidbody2D.velocity = (forceForward + forceSideway).normalized * vel;
	}