Exemplo n.º 1
0
        public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject spawned)
        {
            // Normal linear transforms
            transform.Rotation = Quaternion.Slerp(Origin.transform.rotation, Target.transform.rotation, curve.Value);
            transform.Scale    = Vector3.Lerp(Origin.transform.localScale, Target.transform.localScale, curve.Value);

            // Find new position by speed
            var direction = (Target.transform.position - spawned.GameObject.transform.position).normalized;
            var delta     = Speed * curve.Delta * direction;
            var output    = spawned.GameObject.transform.position + delta;

            // Force position to be on the correct path
            var correctGap       = (Target.transform.position - Origin.transform.position);
            var correctDirection = correctGap.normalized;
            var step             = (output - Origin.transform.position).magnitude;

            // If the movement moves past the target, halt at target
            if (step > correctGap.magnitude)
            {
                step             = correctGap.magnitude;
                transform.Active = false;
            }

            // Save output
            output             = Origin.transform.position + step * correctDirection;
            transform.Position = output;
        }
Exemplo n.º 2
0
    public SpawnedObject getSpawnedObjectInformation(Area area, Transform location)
    {
        SpawnedObject.Builder builder = SpawnedObject.CreateBuilder();

        string description = WorldMap.getDescriptionForStarAt(area.position.x, area.position.y);

        GlobalPosition.Builder pBuilder = GlobalPosition.CreateBuilder();
        pBuilder.SetAreaX(area.position.x);
        pBuilder.SetAreaY(area.position.y);
        pBuilder.SetLocalX((int)location.position.x);
        pBuilder.SetLocalY((int)location.position.z);
        builder.SetObjectPosition(pBuilder.Build());

        Weapon weaponAssociated = gameObject.GetComponent <Weapon> ();

        if (weaponAssociated != null)
        {
            builder.SetObjectData(getDirectObject().getDirectObjectAsProtobuf(weaponAssociated));
        }
        else
        {
            builder.SetObjectData(getDirectObject().getDirectObjectAsProtobuf());
        }

        builder.SetDescription(description);

        return(builder.Build());
    }
    public void test_arc_height()
    {
        var transform = new PathTransform();
        var instance  = fixture();
        var spawned   = new SpawnedObject()
        {
            GameObject = mobile
        };

        target.transform.position = new Vector3(0f, 0f, 10f);

        curve.elapsed = 0f;
        instance.Update(curve, transform, spawned);
        Assert(transform.position == new Vector3(0f, 0f, 0f));

        curve.elapsed = 2.5f;
        curve.Delta   = 2.5f;
        instance.Update(curve, transform, spawned);
        Assert((transform.position - new Vector3(0f, 7.071068f, 2.5f)).magnitude < 0.001f);

        curve.elapsed = 5f;
        curve.Delta   = 5f;
        instance.Update(curve, transform, spawned);
        Assert(transform.position == new Vector3(0f, 10f, 5f));

        curve.elapsed = 10.0f;
        curve.Delta   = 10.0f; // We never apply to the gameObject, so it doesn't step
        instance.Update(curve, transform, spawned);
        Assert((transform.position - new Vector3(0f, 0f, 10f)).magnitude < 0.001f);

        this.TearDown();
    }
    void Update()
    {
        var deltaTime = Debugger.instance.deltaTime;

        UpdateTransform(deltaTime);

        accumulatedTime += deltaTime;

        if (accumulatedTime >= timeToSpawn)
        {
            accumulatedTime -= timeToSpawn;

            spawnedObjects.Add(
                SpawnedObject.Create(
                    Instantiate(prefab,
                                transform.position, transform.rotation)));
        }

        for (int i = spawnedObjects.Length - 1; i >= 0; i--)
        {
            if (spawnedObjects.At(i).Update(deltaTime, timeToLive))
            {
                spawnedObjects.RemoveAtSwapBack(i);
            }
        }
    }
Exemplo n.º 5
0
    private void SpawnEnemy()
    {
        Vector3 randomPositionInSpawnArea = new Vector3(
            Random.Range(spawnAreaBoxCollider.bounds.min.x, spawnAreaBoxCollider.bounds.max.x),
            0,
            Random.Range(spawnAreaBoxCollider.bounds.min.z, spawnAreaBoxCollider.bounds.max.z));
        Enemy newEnemy = Instantiate(enemyPrefab, randomPositionInSpawnArea, Quaternion.identity).GetComponent <Enemy>();

        newEnemy.initEnemyTarget(goal, gameManager, idCounter++);
        newEnemy.transform.LookAt(goal.transform);
        spawnedEnemies.Add(newEnemy.id, newEnemy);

        int enemyLevel = DifficultySettings.singleton.getNewSpawnedEnemyLevel();

        initEnemyStats(newEnemy, enemyLevel);
        SpawnedObject visualAtributes = calculateVisualAtributes(newEnemy, enemyLevel);

        newEnemy.init(visualAtributes);

        SpawnEnemyMsg msg = new SpawnEnemyMsg()
        {
            type = EnemyType.Soldier, details = visualAtributes
        };

        NetworkServer.SendToAll((short)CustomProtocol.SpawnEnemyMsg, msg);
    }
Exemplo n.º 6
0
            } //===============================================================================================================================

            public void AddObject(SpawnedObject obj)
            {
                if (bounds.Contains(obj.position))
                {
                    AddObjectInternal(obj);
                }
            }
        public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject spawned)
        {
            // Normal linear transforms
              transform.Rotation = Quaternion.Slerp(Origin.transform.rotation, Target.transform.rotation, curve.Value);
              transform.Scale = Vector3.Lerp(Origin.transform.localScale, Target.transform.localScale, curve.Value);

              // Find new position by speed
              var direction = (Target.transform.position - spawned.GameObject.transform.position).normalized;
              var delta = Speed * curve.Delta * direction;
              var output = spawned.GameObject.transform.position + delta;

              // Force position to be on the correct path
              var correctGap = (Target.transform.position - Origin.transform.position);
              var correctDirection = correctGap.normalized;
              var step = (output - Origin.transform.position).magnitude;

              // If the movement moves past the target, halt at target
              if (step > correctGap.magnitude)
              {
            step = correctGap.magnitude;
            transform.Active = false;
              }

              // Save output
              output = Origin.transform.position + step * correctDirection;
              transform.Position = output;
        }
Exemplo n.º 8
0
    private void GameSetup()
    {
        NetworkManager = GameObject.Find("NetworkManager").GetComponent <NetworkManagerParty>();

        int        counter = 0;
        GameObject SpawnedObject;
        GameObject SpawndObject;

        foreach (var Player in NetworkManager.PartyPlayers)
        {
            SpawndObject = Instantiate(GameBoardPlayer);
            SpawndObject.GetComponent <GamePlayerInformation>().PlayerNetworkClone = Player;
            PlayerList.Add(SpawndObject);

            SpawnedObject = Instantiate(BoardObject);
            SpawnedObject.transform.parent        = StartingLocations[counter].transform;
            SpawnedObject.transform.localPosition = new Vector3(0, 0, 0);
            SpawnedObject.GetComponent <PlayerObjectMovmentScript>().ConnectedPlayer = SpawndObject.GetComponent <GamePlayerInformation>();
            SpawndObject.GetComponent <GamePlayerInformation>().BoardObject          = SpawnedObject.GetComponent <PlayerObjectMovmentScript>();
            SpawnedObject.GetComponent <PlayerObjectMovmentScript>().NextTile        = FirstTile;
            counter++;
        }
        StartCoroutine("DecideTurnOrder");
        // Decide the order in what players go
    }
Exemplo n.º 9
0
        public void DecaySpawns()
        {
            if (m_Decay == TimeSpan.Zero)
            {
                return;
            }

            for (int i = 0; i < m_Spawned.Count; ++i)
            {
                if (m_Spawned[i] is SpawnedObject)
                {
                    m_Object = (SpawnedObject)m_Spawned[i];

                    if (DateTime.UtcNow <= m_Object.Time + m_Decay)
                    {
                        return;
                    }

                    object o = m_Object.Spawned;

                    if (o != null && o is Item && !((Item)o).Deleted)
                    {
                        ((Item)o).Delete();
                    }
                    else if (o != null && o is Mobile && !((Mobile)o).Deleted)
                    {
                        ((Mobile)o).Delete();
                    }
                }
            }

            Defrag();
        }
Exemplo n.º 10
0
        public override void Deserialize(GenericReader reader)
        {
            DateTime time;

            base.Deserialize(reader);

            int version = reader.ReadInt();

            if (version < 3)
            {
                Old_Deserialize(reader, version);
                return;
            }

            switch (version)
            {
            case 3:
            {
                TimeSpan.TryParse(reader.ReadString(), out m_Decay);
                m_Level = (AccessLevel)reader.ReadInt();
                goto case 2;
            }

            case 2:
            {
                //case 2
                m_Sound = reader.ReadInt();
                //case 1
                m_Chance = reader.ReadDouble();
                //case 0
                m_Active    = reader.ReadBool();
                m_Creature  = reader.ReadString();
                m_Message   = reader.ReadString();
                m_Location  = reader.ReadPoint3D();
                m_HomeRange = reader.ReadInt();
                m_Team      = reader.ReadInt();
                m_Limit     = reader.ReadInt();
                DateTime.TryParse(reader.ReadString(), out m_NextSpawn);
                m_Delay = reader.ReadTimeSpan();

                int size = reader.ReadInt();
                m_Spawned = new ArrayList(size);

                for (int i = 0; i < size; ++i)
                {
                    //IEntity e = World.FindEntity(reader.ReadInt());
                    IEntity e = reader.ReadEntity();
                    DateTime.TryParse(reader.ReadString(), out time);

                    if (e != null)
                    {
                        m_Object = new SpawnedObject(e, time);
                        m_Spawned.Add(m_Object);
                    }
                }

                break;
            }
            }
        }
    public void SpawnPlayerObject(GameObject givenPrefab, InvItem originInvSlot)
    {
        // Don't spawn in an object if the player is already dragging one
        if (!dragScript.draggedObject)
        {
            originInvSlot.startingAmount--;
            originInvSlot.UpdateAmountCounter();

            // Spawn the object, and capture a reference to it in order to add it to spawnedObjects
            GameObject gameObjectInstance = (GameObject)Instantiate(givenPrefab);

            InteractiveObject intObj = gameObjectInstance.GetComponent <InteractiveObject>();
            if (intObj != null)
            {
                intObj.draggable = true;
            }
            else
            {
                Debug.LogError("Spawned object has no interactive object script");
            }

            // Add it to the list of spawnedObjects | m_position is set 0,0,0 since it doesnt
            // really matter as we'll grab the objects final position when the game actually starts
            SpawnedObject newSpawnedObject = new SpawnedObject(gameObjectInstance, originInvSlot.uniqueName, new Vector3(0, 0, 0), givenPrefab, Quaternion.identity, -1);
            spawnedObjects.Add(newSpawnedObject);

            dragScript.forceDraggedObject = true;
            dragScript.SetNewDraggedObject(gameObjectInstance, new Vector2(0, 0));
        }
    }
    public void test_arc_height()
    {
        var transform = new PathTransform();
        var instance = fixture();
        var spawned = new SpawnedObject() {GameObject = mobile};
        target.transform.position = new Vector3(0f, 0f, 10f);

        curve.elapsed = 0f;
        instance.Update(curve, transform, spawned);
        Assert(transform.position == new Vector3(0f, 0f, 0f));

        curve.elapsed = 2.5f;
        curve.Delta = 2.5f;
        instance.Update(curve, transform, spawned);
        Assert((transform.position - new Vector3(0f, 7.071068f, 2.5f)).magnitude < 0.001f);

        curve.elapsed = 5f;
        curve.Delta = 5f;
        instance.Update(curve, transform, spawned);
        Assert(transform.position == new Vector3(0f, 10f, 5f));

        curve.elapsed = 10.0f;
        curve.Delta = 10.0f; // We never apply to the gameObject, so it doesn't step
        instance.Update(curve, transform, spawned);
        Assert((transform.position - new Vector3(0f, 0f, 10f)).magnitude < 0.001f);

        this.TearDown();
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        SpawnedObject so = collision.gameObject.GetComponent <SpawnedObject>();

        if (so && so.objectSpawner == this)
        {
            so.destroy();
        }
    }
Exemplo n.º 14
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            SpawnedObject SO = collision.GetComponent <SpawnedObject>();

            if (SO != null)
            {
                SO.EnteringScene();
            }
        }
    // Update is called once per frame
    void Update()
    {
        if (Time.time > lastSpawnTime + spawnDelay)
        {
            lastSpawnTime = Time.time;
            GameObject spawnPrefab = spawnPrefabPool[Random.Range(0, spawnPrefabPool.Count)];
            GameObject spawn       = Instantiate(spawnPrefab);
            Transform  spawnPoint  = spawnPoints[0];
            if (spawnPoints.Count == 1)
            {
                spawnPoint     = spawnPoints[0];
                lastSpawnIndex = 0;
            }
            else
            {
                switch (spawnSelectionMode)
                {
                case SpawnSelectionMode.RANDOM:
                    int randIndex = Random.Range(0, spawnPoints.Count);
                    lastSpawnIndex = randIndex;
                    spawnPoint     = spawnPoints[randIndex];
                    break;

                case SpawnSelectionMode.ORDERED:
                    int index = (lastSpawnIndex + 1) % spawnPoints.Count;
                    lastSpawnIndex = index;
                    spawnPoint     = spawnPoints[index];
                    break;
                }
            }
            spawn.transform.position = spawnPoint.position;
            SpawnedObject so = spawn.GetComponent <SpawnedObject>();
            if (so == null)
            {
                so = spawn.AddComponent <SpawnedObject>();
                so.initialDirection = defaultInitialDirection;
            }
            so.objectSpawner = this;
            if (so.initialDirection == Vector2.zero)
            {
                so.initialDirection = defaultInitialDirection;
            }
            if (so.destroyDelay == 0)
            {
                so.destroyDelay = defaultDestroyDelay;
            }
            if (so.destroySpeed == 0)
            {
                so.destroySpeed = defaultDestroySpeed;
            }
            Rigidbody2D spawnRB2D = spawn.GetComponent <Rigidbody2D>();
            spawnRB2D.velocity = so.initialDirection;
        }
    }
 public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject origin)
 {
     var distance = (Target.transform.position - origin.GameObject.transform.position).magnitude;
       if (distance < Offset)
       {
     var total = 1f - (distance - Offset) / Offset;
     byte alpha = (byte) (255 - (byte) Math.Ceiling(255 * total));
     alpha = transform.Active ? alpha : (byte) 255;
     transform.Color = new Color32(Color.r, Color.g, Color.b, alpha);
       }
 }
Exemplo n.º 17
0
        public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject origin)
        {
            var distance = (Target.transform.position - origin.GameObject.transform.position).magnitude;

            if (distance < Offset)
            {
                var  total = 1f - (distance - Offset) / Offset;
                byte alpha = (byte)(255 - (byte)Math.Ceiling(255 * total));
                alpha           = transform.Active ? alpha : (byte)255;
                transform.Color = new Color32(Color.r, Color.g, Color.b, alpha);
            }
        }
Exemplo n.º 18
0
        public void Old_Deserialize(GenericReader reader, int version)
        {
            switch (version)
            {
            case 2:
            {
                m_Sound = reader.ReadInt();
                goto case 1;
            }

            case 1:
            {
                m_Chance = reader.ReadDouble();
                goto case 0;
            }

            case 0:
            {
                m_Active    = reader.ReadBool();
                m_Creature  = reader.ReadString();
                m_Message   = reader.ReadString();
                m_Location  = reader.ReadPoint3D();
                m_HomeRange = reader.ReadInt();
                m_Team      = reader.ReadInt();
                m_Limit     = reader.ReadInt();
                DateTime.TryParse(reader.ReadString(), out m_NextSpawn);
                m_Delay = reader.ReadTimeSpan();

                int size = reader.ReadInt();
                m_Spawned = new ArrayList(size);

                for (int i = 0; i < size; ++i)
                {
                    //IEntity e = World.FindEntity(reader.ReadInt());
                    IEntity e = reader.ReadEntity();

                    if (e != null)
                    {
                        m_Object = new SpawnedObject(e);
                        m_Spawned.Add(m_Object);
                    }
                }

                break;
            }
            }

            if (version == 0)
            {
                m_Chance = 1;
            }
        }
 public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject target)
 {
     var delta = (target.GameObject.transform.position - target.Origin.Position).magnitude;
       if (Distance > 0)
       {
     if (delta <= Distance)
     {
       var total = delta / Distance;
       byte alpha = (byte) Math.Ceiling(255 * total);
       transform.Color.a = alpha;
     }
       }
 }
Exemplo n.º 20
0
 public void CreatePool(int objectCount, SpawnedObject objectToBeSpawned)
 {
     for (int i = 0; i < objectCount; i++)
     {
         GameObject obj = Instantiate(objectToBeSpawned.gameObject);
         obj.SetActive(false);
         if (obj.GetComponent <SpawnedObject>() == null)
         {
             obj.AddComponent <SpawnedObject>();
         }
         spawnedObjects.Add(obj.GetComponent <SpawnedObject>());
     }
 }
Exemplo n.º 21
0
    public virtual void init(SpawnedObject details)
    {
        this.speed            = details.speed; this.id = details.id;
        transform.position    = details.pos;
        transform.localScale  = details.scale;
        transform.eulerAngles = details.rot;


        if (theSprite != null && details.color.a > 0)
        {
            theSprite.color = details.color;
        }
    }
Exemplo n.º 22
0
        private void SpawnNewDecoration()
        {
            Vector3 pos = _lastChain.Position;

            pos.x += _lastChain.Collider.bounds.size.x;

            // TODO: Переделать на пул объектов
            SpawnedObject nextChain = Instantiate(_prefab, pos, Quaternion.identity);

            _lastChain = nextChain;

            _lastChain.OnEnteringScene += SpawnNewDecoration;
        }
Exemplo n.º 23
0
    void CmdSpawnObject()
    {
        float   distance  = Random.Range(0f, Radius);
        Vector2 position  = transform.position + transform.rotation * (Quaternion.Euler(0, 0, Random.Range(0, Angle)) * Vector2.right) * distance;
        int     objectIdx = Random.Range(0, objectList.Length);

        if (objectList[objectIdx] != null)
        {
            SpawnedObject obj = Instantiate(objectList[objectIdx], position, Quaternion.Euler(0, 0, Random.Range(0, 360f)));
            NetworkServer.Spawn(obj.gameObject);
            obj.SetMovementDirection(transform.rotation * (Quaternion.Euler(0, 0, Random.Range(0, Angle)) * Vector2.right));
        }
    }
Exemplo n.º 24
0
 public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject target)
 {
     if (curve.Value > Offset)
       {
     var total = 1.0f - Offset;
     if (total >= 0)
     {
       var value = (curve.Value - Offset) / total;
       byte alpha = (byte) (255 - (byte) Math.Ceiling(255 * value));
       alpha = transform.Active ? alpha : (byte) 255;
       transform.Color.a = alpha;
     }
       }
 }
Exemplo n.º 25
0
        public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject target)
        {
            var delta = (target.GameObject.transform.position - target.Origin.Position).magnitude;

            if (Distance > 0)
            {
                if (delta <= Distance)
                {
                    var  total = delta / Distance;
                    byte alpha = (byte)Math.Ceiling(255 * total);
                    transform.Color.a = alpha;
                }
            }
        }
Exemplo n.º 26
0
 void AddObjectInternal(SpawnedObject obj)
 {
     if (level == maxLevels)
     {
         obj.cell = (MaxCell)this;
         obj.cell.objects.Add(obj);
         obj.listIndex = obj.cell.objects.Count - 1;
     }
     else
     {
         int index = AddCell(obj.position);
         cells[index].AddObjectInternal(obj);
     }
 }
Exemplo n.º 27
0
 public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject target)
 {
     if (curve.Value > Offset)
     {
         var total = 1.0f - Offset;
         if (total >= 0)
         {
             var  value = (curve.Value - Offset) / total;
             byte alpha = (byte)(255 - (byte)Math.Ceiling(255 * value));
             alpha             = transform.Active ? alpha : (byte)255;
             transform.Color.a = alpha;
         }
     }
 }
Exemplo n.º 28
0
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)3); // version

            writer.Write((string)m_Decay.ToString());
            writer.Write((int)m_Level);

            writer.Write(m_Sound);
            writer.Write(m_Chance);
            writer.Write(m_Active);
            writer.Write(m_Creature);
            writer.Write(m_Message);
            writer.Write(m_Location);
            writer.Write(m_HomeRange);
            writer.Write(m_Team);
            writer.Write(m_Limit);
            writer.Write((string)m_NextSpawn.ToString());
            writer.Write(m_Delay);

            Defrag();
            writer.Write(m_Spawned.Count);

            for (int i = 0; i < m_Spawned.Count; ++i)
            {
                if (m_Spawned[i] is SpawnedObject)
                {
                    m_Object = (SpawnedObject)m_Spawned[i];
                    object o = m_Object.Spawned;

                    if (o is Item)
                    {
                        writer.Write((Item)o);
                    }
                    else if (o is Mobile)
                    {
                        writer.Write((Mobile)o);
                    }
                    else
                    {
                        writer.Write(Serial.MinusOne);
                    }

                    writer.Write((m_Object.Time).ToString());
                }
            }
        }
Exemplo n.º 29
0
    // Use this for initialization
    void Start()
    {
        GMScript = GM.GetComponent <GameManagerScript>();
        int ChildCount = SpawningPoints.transform.GetChildCount();

        for (int i = 0; i < ChildCount; i++)
        {
            GameObject ChildGO;
            ChildGO = SpawningPoints.transform.GetChild(i).gameObject;
            GameObject SpawnedObject;
            SpawnedObject = Instantiate(SphereSpawning, ChildGO.transform.position, ChildGO.transform.rotation);
            int randomMat = Random.Range(0, 3);
            SpawnedObject.GetComponent <SphereSpawningScript>().SetMat = randomMat;
            SpawnedObject.GetComponent <SphereSpawningScript>().GM     = GM;
        }
    }
    public void Fetch()
    {
        string[]             allObjects = AssetDatabase.FindAssets("t:Prefab", Folders);
        SpawnedObjectManager manager    = GetComponent <PixelCrushers.SpawnedObjectManager>();

        manager.spawnedObjectPrefabs.Clear();
        foreach (string obj in allObjects)
        {
            string        assetPath = AssetDatabase.GUIDToAssetPath(obj);
            SpawnedObject asset     = (SpawnedObject)AssetDatabase.LoadAssetAtPath(assetPath, typeof(SpawnedObject));
            if (asset != null)
            {
                manager.spawnedObjectPrefabs.Add(asset);
            }
        }
    }
    void instantiateAfterTimeMethod()
    {
        int index = firstNullIndex();

        spawnedObjects[index]            = new SpawnedObject();
        spawnedObjects[index].gameObject = Instantiate(objectToSpawn);
        spawnedObjects[index].spawnTime  = Time.time;

        spawnedObjects[index].spriteRenderers = spawnedObjects[index].gameObject.GetComponentsInChildren <SpriteRenderer>();

        //setto la posizione corretta
        spawnedObjects[index].gameObject.transform.parent        = transform;
        spawnedObjects[index].gameObject.transform.localPosition = Vector3.zero;

        lastIstantiatedTime = Time.time;
    }
Exemplo n.º 32
0
        GameObject SpawnAsset(Pose pose)
        {
            var spawnedObject = new SpawnedObject {
                time = Time.time
            };
            var obj = Instantiate(m_Assets[Random.Range(0, m_Assets.Length)]);

            spawnedObject.obj = obj;
            var newTransform = obj.transform;

            newTransform.parent   = transform.parent;
            newTransform.position = pose.position;
            newTransform.rotation = pose.rotation;
            m_SpawnedObjects.Enqueue(spawnedObject);

            return(obj);
        }
    public void test_fixed_path_with_moving_target()
    {
        var transform = new PathTransform();
        var instance = fixture();
        var spawned = new SpawnedObject() {GameObject = mobile};
        target.transform.position = new Vector3(0f, 0f, 10f);
        curve.elapsed = 0f;
        instance.Update(curve, transform, spawned);

        Assert(transform.position == new Vector3(0f, 0f, 0f));

        curve.elapsed = 5f;
        curve.Delta = 5f;
        instance.Update(curve, transform, spawned);
        Assert(transform.position == new Vector3(0f, 0f, 5f));

        this.TearDown();
    }
Exemplo n.º 34
0
        public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject spawned)
        {
            // Normal linear transforms
            transform.Scale = Vector3.Lerp(Origin.transform.localScale, Target.transform.localScale, curve.Value);

            // Find new position by speed
            var direction = (Target.transform.position - spawned.GameObject.transform.position).normalized;
            var delta     = Speed * curve.Delta * direction;
            var output    = spawned.GameObject.transform.position + delta;

            if (Math.Abs(direction.magnitude) < DirectionTolerance)
            {
                transform.Active = false;
                return;
            }

            // Force position to be on the correct path
            var correctDirection = (Origin.transform.position - Target.transform.position).normalized;
            var offset           = output - spawned.Origin.Position;
            var pathLength       = (correctDirection * Vector3.Dot(offset, correctDirection) / correctDirection.magnitude);
            var projected        = Origin.transform.position + pathLength;

            // Distance from here to origin
            var left      = (projected - Target.transform.position).magnitude;
            var total     = (spawned.Origin.Position - Target.transform.position).magnitude;
            var increment = 1f - left / total;

            // Apply arc
            // NB. f(x)  -> (x, sin(x)) ie. f'(x) -> (1, cos(x))
            var currentHeight    = Mathf.Sin(increment * 180f * Mathf.Deg2Rad) * this.Height;
            var right            = Vector3.Cross(Up, direction);
            var tangentDirection = Mathf.Cos(increment * 180f * Mathf.Deg2Rad) * Up - correctDirection;
            var normal           = Vector3.Cross(right, -tangentDirection);

            transform.Rotation      = Quaternion.LookRotation(tangentDirection, normal);
            transform.Position      = projected + Up * currentHeight;
            spawned.Origin.Position = Origin.transform.position;

            // Halt?
            if ((transform.Position - Target.transform.position).magnitude < ArcFixedPath.CutoffDistance)
            {
                transform.Active = false;
            }
        }
Exemplo n.º 35
0
        public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject spawned)
        {
            // Normal linear transforms
              transform.Scale = Vector3.Lerp(Origin.transform.localScale, Target.transform.localScale, curve.Value);

              // Find new position by speed
              var direction = (Target.transform.position - spawned.GameObject.transform.position).normalized;
              var delta = Speed * curve.Delta * direction;
              var output = spawned.GameObject.transform.position + delta;
              if (Math.Abs(direction.magnitude) < DirectionTolerance)
              {
            transform.Active = false;
            return;
              }

              // Force position to be on the correct path
              var correctDirection = (Origin.transform.position - Target.transform.position).normalized;
              var offset = output - spawned.Origin.Position;
              var pathLength = (correctDirection * Vector3.Dot(offset, correctDirection) / correctDirection.magnitude);
              var projected = Origin.transform.position + pathLength;

              // Distance from here to origin
              var left = (projected - Target.transform.position).magnitude;
              var total = (spawned.Origin.Position - Target.transform.position).magnitude;
              var increment = 1f - left / total;

              // Apply arc
              // NB. f(x)  -> (x, sin(x)) ie. f'(x) -> (1, cos(x))
              var currentHeight = Mathf.Sin(increment * 180f * Mathf.Deg2Rad) * this.Height;
              var right = Vector3.Cross(Up, direction);
              var tangentDirection = Mathf.Cos(increment * 180f * Mathf.Deg2Rad) * Up - correctDirection;
              var normal = Vector3.Cross(right, -tangentDirection);
              transform.Rotation = Quaternion.LookRotation(tangentDirection, normal);
              transform.Position = projected + Up * currentHeight;
              spawned.Origin.Position = Origin.transform.position;

              // Halt?
              if ((transform.Position - Target.transform.position).magnitude < ArcFixedPath.CutoffDistance)
              {
            transform.Active = false;
              }
        }
Exemplo n.º 36
0
    public void Click()
    {
        Ray ray = Camera.main.ScreenPointToRay(GameManager.Instance.PlayerInput.PointerPosition);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            SpawnedObject spawnedobj = hit.transform.GetComponent <SpawnedObject>();

            if (spawnedobj == null)
            {
                Spawn(hit.point, Quaternion.identity);
            }
            else
            {
                ClickOnObject(spawnedobj);
            }
        }
    }
Exemplo n.º 37
0
        public virtual async UniTask SpawnAsync(string path, CancellationToken cancellationToken = default, params string[] parameters)
        {
            if (IsObjectSpawned(path))
            {
                Debug.LogWarning($"Object `{path}` is already spawned and can't be spawned again before it's destroyed.");
                return;
            }

            var resourcePath   = SpawnConfiguration.ProcessInputPath(path, out _);
            var prefabResource = await loader.LoadAndHoldAsync(resourcePath, this);

            if (cancellationToken.CancelASAP)
            {
                return;
            }
            if (!prefabResource.Valid)
            {
                Debug.LogWarning($"Failed to spawn `{resourcePath}`: resource is not valid.");
                return;
            }

            var obj = Engine.Instantiate(prefabResource.Object, path);

            var spawnedObj = new SpawnedObject {
                Object = obj, State = new SpawnedObjectState(path, parameters)
            };

            spawnedObjects.Add(spawnedObj);

            var parameterized = obj.GetComponent <Commands.Spawn.IParameterized>();

            parameterized?.SetSpawnParameters(parameters);

            var awaitable = obj.GetComponent <Commands.Spawn.IAwaitable>();

            if (awaitable != null)
            {
                await awaitable.AwaitSpawnAsync(cancellationToken);
            }
        }
Exemplo n.º 38
0
 public void ResetManager()
 {
     manager = transform.root.gameObject.GetComponent<SpawnedObject>();
 }
Exemplo n.º 39
0
        public void Defrag()
        {
            if (m_DoingDefragNow)
                return;

            m_DoingDefragNow = true;
            bool removed = false;

            for (int i = 0; i < m_Spawned.Count; ++i)
            {
                if (m_Spawned[i] is SpawnedObject)
                {
                    m_Object = (SpawnedObject)m_Spawned[i];
                    object o = m_Object.Spawned;

                    if (o != null && o is Item)
                    {
                        Item item = (Item)o;

                        if (item.Deleted || (m_ForgetOnAcquire && item.Parent != null))
                        {
                            m_Spawned.RemoveAt(i);
                            --i;
                            removed = true;
                        }
                    }

                    else if (o != null && o is Mobile)
                    {
                        if (((Mobile)o).Deleted)
                        {
                            m_Spawned.RemoveAt(i);
                            --i;
                            removed = true;
                        }
                        else if (o is BaseCreature)
                        {
                            if (m_ForgetOnAcquire && (((BaseCreature)o).Controlled || ((BaseCreature)o).IsStabled))
                            {
                                m_Spawned.RemoveAt(i);
                                --i;
                                removed = true;
                            }
                        }
                    }
                    else
                    {
                        m_Spawned.RemoveAt(i);
                        --i;
                        removed = true;
                    }
                }
                else
                {
                    m_Spawned.RemoveAt(i);
                    --i;
                    removed = true;
                }
            }
            if (removed)
                InvalidateProperties();

            m_DoingDefragNow = false;
        }
Exemplo n.º 40
0
 public void Update(IAnimationCurve curve, PathTransform transform, SpawnedObject spawned)
 {
     transform.Position = Vector3.Lerp(Origin.transform.position, Target.transform.position, curve.Value);
       transform.Rotation = Quaternion.Slerp(Origin.transform.rotation, Target.transform.rotation, curve.Value);
       transform.Scale = Vector3.Lerp(Origin.transform.localScale, Target.transform.localScale, curve.Value);
 }
Exemplo n.º 41
0
 public void RegisterObject(SpawnedObject so, char index)
 {
     _droppingKeys.Add(index, so);
     so.SetActivationTime(_timeTillActivation[_timeIndex.IndexOf(index)]);
 }
Exemplo n.º 42
0
        public void Spawn()
        {
            Map map = Map;

            if (map == null || map == Map.Internal || m_Location == Point3D.Zero || m_Creature == null || m_Creature == "-invalid-")
                return;

            Type type = SpawnerType.GetType((string)m_Creature);

            if (type != null)
            {
                m_NextSpawn = DateTime.UtcNow + m_Delay;

                try
                {
                    object o = Activator.CreateInstance(type);

                    if (o is Mobile)
                    {
                        Mobile m = (Mobile)o;

                        m_Object = new SpawnedObject(m);
                        m_Spawned.Add(m_Object);
                        InvalidateProperties();

                        m.Map = map;
                        m.Location = m_Location;

                        if (m_Message != null)
                            m.PublicOverheadMessage(MessageType.Regular, 0x76C, false, m_Message);

                        if (m_Sound > 0)
                            Effects.PlaySound(m.Location, m.Map, m_Sound);

                        if (m is BaseCreature)
                        {
                            BaseCreature c = (BaseCreature)m;

                            c.RangeHome = m_HomeRange;

                            if (m_Team > 0)
                                c.Team = m_Team;

                            c.Home = m_Location;
                        }
                    }
                    else if (o is Item)
                    {
                        Item item = (Item)o;

                        m_Object = new SpawnedObject(item);
                        m_Spawned.Add(m_Object);
                        InvalidateProperties();

                        item.MoveToWorld(m_Location, map);

                        if (m_Message != null)
                            item.PublicOverheadMessage(MessageType.Regular, 0x76C, false, m_Message);

                        if (m_Sound > 0)
                            Effects.PlaySound(item.Location, item.Map, m_Sound);
                    }
                }
                catch
                {
                    PublicOverheadMessage(MessageType.Regular, 0x3BD, false, string.Format("Exception Caught!")); // debugging
                }
            }
        }
Exemplo n.º 43
0
        public void Old_Deserialize(GenericReader reader, int version)
        {
            switch (version)
            {
                case 2:
                    {
                        m_Sound = reader.ReadInt();
                        goto case 1;
                    }
                case 1:
                    {
                        m_Chance = reader.ReadDouble();
                        goto case 0;
                    }
                case 0:
                    {
                        m_Active = reader.ReadBool();
                        m_Creature = reader.ReadString();
                        m_Message = reader.ReadString();
                        m_Location = reader.ReadPoint3D();
                        m_HomeRange = reader.ReadInt();
                        m_Team = reader.ReadInt();
                        m_Limit = reader.ReadInt();
                        DateTime.TryParse(reader.ReadString(), out m_NextSpawn);
                        m_Delay = reader.ReadTimeSpan();

                        int size = reader.ReadInt();
                        m_Spawned = new ArrayList(size);

                        for (int i = 0; i < size; ++i)
                        {
                            IEntity e = World.FindEntity(reader.ReadInt());

                            if (e != null)
                            {
                                m_Object = new SpawnedObject(e);
                                m_Spawned.Add(m_Object);
                            }
                        }

                        break;
                    }
            }
            if (version == 0)
                m_Chance = 1;
        }
Exemplo n.º 44
0
        public override void Deserialize(GenericReader reader)
        {
            DateTime time;
            base.Deserialize(reader);

            int version = reader.ReadInt();
            if (version < 3)
            {
                Old_Deserialize(reader, version);
                return;
            }

            switch (version)
            {
                case 3:
                    {
                        TimeSpan.TryParse(reader.ReadString(), out m_Decay);
                        m_Level = (AccessLevel)reader.ReadInt();
                        goto case 2;
                    }
                case 2:
                    {
                        //case 2
                        m_Sound = reader.ReadInt();
                        //case 1
                        m_Chance = reader.ReadDouble();
                        //case 0
                        m_Active = reader.ReadBool();
                        m_Creature = reader.ReadString();
                        m_Message = reader.ReadString();
                        m_Location = reader.ReadPoint3D();
                        m_HomeRange = reader.ReadInt();
                        m_Team = reader.ReadInt();
                        m_Limit = reader.ReadInt();
                        DateTime.TryParse(reader.ReadString(), out m_NextSpawn);
                        m_Delay = reader.ReadTimeSpan();

                        int size = reader.ReadInt();
                        m_Spawned = new ArrayList(size);

                        for (int i = 0; i < size; ++i)
                        {
                            IEntity e = World.FindEntity(reader.ReadInt());
                            DateTime.TryParse(reader.ReadString(), out time);

                            if (e != null)
                            {
                                m_Object = new SpawnedObject(e, time);
                                m_Spawned.Add(m_Object);
                            }
                        }

                        break;
                    }
            }
        }
Exemplo n.º 45
0
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            writer.Write((int)3); // version

            writer.Write((string)m_Decay.ToString());
            writer.Write((int)m_Level);

            writer.Write(m_Sound);
            writer.Write(m_Chance);
            writer.Write(m_Active);
            writer.Write(m_Creature);
            writer.Write(m_Message);
            writer.Write(m_Location);
            writer.Write(m_HomeRange);
            writer.Write(m_Team);
            writer.Write(m_Limit);
            writer.Write((string)m_NextSpawn.ToString());
            writer.Write(m_Delay);

            Defrag();
            writer.Write(m_Spawned.Count);

            for (int i = 0; i < m_Spawned.Count; ++i)
            {
                if (m_Spawned[i] is SpawnedObject)
                {
                    m_Object = (SpawnedObject)m_Spawned[i];
                    object o = m_Object.Spawned;

                    if (o is Item)
                        writer.Write((Item)o);
                    else if (o is Mobile)
                        writer.Write((Mobile)o);
                    else
                        writer.Write(Serial.MinusOne);

                    writer.Write((m_Object.Time).ToString());
                }
            }
        }
Exemplo n.º 46
0
        public void DecaySpawns()
        {
            if (m_Decay == TimeSpan.Zero)
                return;

            for (int i = 0; i < m_Spawned.Count; ++i)
            {
                if (m_Spawned[i] is SpawnedObject)
                {
                    m_Object = (SpawnedObject)m_Spawned[i];

                    if (DateTime.UtcNow <= m_Object.Time + m_Decay)
                        return;

                    object o = m_Object.Spawned;

                    if (o != null && o is Item && !((Item)o).Deleted)
                        ((Item)o).Delete();
                    else if (o != null && o is Mobile && !((Mobile)o).Deleted)
                        ((Mobile)o).Delete();
                }
            }

            Defrag();
        }
Exemplo n.º 47
0
        public void DeSpawn()
        {
            for (int i = 0; i < m_Spawned.Count; ++i)
            {
                if (m_Spawned[i] is SpawnedObject)
                {
                    m_Object = (SpawnedObject)m_Spawned[i];
                    object o = m_Object.Spawned;

                    if (o != null && o is Item && !((Item)o).Deleted)
                        ((Item)o).Delete();
                    else if (o != null && o is Mobile && !((Mobile)o).Deleted)
                        ((Mobile)o).Delete();
                }
            }

            Defrag();
        }