예제 #1
0
    private void SpawnObject(int index)
    {
        SpawnableObject currSpawnableObject = spawnableObjects[index];
        Vector3         positionToSpawn     = spawnPoint.position + new Vector3(0, currSpawnableObject.spawnPosition, 0);

        Instantiate(currSpawnableObject.gameObject, positionToSpawn, Quaternion.identity, transform);
    }
예제 #2
0
    public void Cull(SpawnableObject o, int amount)
    {
        if (o.isWater)
        {
            return;
        }
        //Debug.Log(amount.ToString("0 ") + o.name + " to cull");
        //Debug.Log(GameCore.CreationLookup[o.name].Count);
        if (GameCore.CreationLookup[o.name].Count > amount)
        {
            for (int i = 0; i < amount; i++)
            {
                int      randomIndex = Random.Range(0, GameCore.CreationLookup[o.name].Count);
                Creation c           = GameCore.CreationLookup[o.name][randomIndex];
                //Debug.Log(c.name);
                Destroy(c.gameObject);
                GameCore.CreationLookup[o.name].RemoveAt(randomIndex);
            }
        }
        else
        {
            for (int i = 0; i < GameCore.CreationLookup[o.name].Count; i++)
            {
                Creation c = GameCore.CreationLookup[o.name][i];
                Destroy(c.gameObject);
            }
            GameCore.CreationLookup[o.name] = new List <Creation>();
        }

        uiController.UpdatePopulationDetails();
    }
예제 #3
0
파일: GUI.cs 프로젝트: Hengle/LD43
    void DoDropping(UnityEngine.Object droppedObject)
    {
        if (droppedObject.GetType() == typeof(GameObject) || droppedObject.GetType() == typeof(Transform))
        {
            GameObject obj = null;
            if (droppedObject.GetType() == typeof(GameObject))
            {
                obj = (GameObject)droppedObject;
            }
            else
            {
                obj = ((Transform)droppedObject).gameObject;
            }
            //Check if prefab was already put here
            int result = spawnableObjects.FindIndex(
                delegate(SpawnableObject s)
            {
                return(s.prefab == obj || (s.prefab.name == obj.name && s.prefab != obj));
            }
                );


            if (result == -1)
            {
                SpawnableObject so = new SpawnableObject();
                so.prefab   = obj;
                so.spawn    = true;
                so.isPrefab = PrefabUtility.GetPrefabType(obj) == PrefabType.Prefab ? true : false;

                spawnableObjects.Add(so);
            }
        }
    }
예제 #4
0
    public void SpawnObject(SpawnableObject obj)
    {
        if (obj.cache && obj.cached)
        {
            obj.Object.SetActive(true);
        }
        else
        {
            Transform parent = InkWriter.main.transform;
            if (obj.parentPath != "")
            {
                Transform childParent = parent.transform.Find(obj.parentPath);
                if (childParent != null)
                {
                    parent = childParent;
                }
            }
            ;
            GameObject newObj = Instantiate(obj.Object, parent);

            if (obj.cache)
            {
                obj.Object = newObj;
                obj.cached = true;
            }
            else
            {
                obj.spawnedObject = newObj;
            }
        }
    }
예제 #5
0
 public void init(int _x, int _y)
 {
     fieldRenderer = GetComponent <SpriteRenderer>();
     content       = null;
     x             = _x;
     y             = _y;
 }
예제 #6
0
    private void Start()
    {
        float totalWeights = 0;

        foreach (SpawnableObject o in spawnableObjects)
        {
            totalWeights += o.weight;
        }

        float random = Random.Range(0f, totalWeights);

        SpawnableObject s      = new SpawnableObject();
        float           weight = 0;

        foreach (SpawnableObject o in spawnableObjects)
        {
            if (random > weight && random < weight + o.weight)
            {
                s = o;
            }
        }

        if (s.prefab == null)
        {
            return;
        }

        Instantiate(s.prefab, transform.position, Quaternion.identity, transform.parent);

        Destroy(gameObject);
    }
예제 #7
0
    List <SpawnableObject[]> CheckSpawnableObjects(int[] newAmountOfEnemiesPerWave)
    {
        List <SpawnableObject[]> newSpawnOb = new List <SpawnableObject[]>();

        for (int i = 0; i < size; i++)
        {
            if (i < spawnOb.Count)
            {
                SpawnableObject[] spawnableObjects = new SpawnableObject[newAmountOfEnemiesPerWave[i]];
                for (int io = 0; io < newAmountOfEnemiesPerWave[i]; io++)
                {
                    if (io < spawnOb[i].Length)
                    {
                        spawnableObjects[io] = spawnOb[i][io];
                    }
                    else
                    {
                        spawnableObjects[io] = new SpawnableObject(((SpawnManager)(target)).gameObject, 0);
                    }
                }
                newSpawnOb.Add(spawnableObjects);
            }
            else
            {
                SpawnableObject[] spawnableObjects = new SpawnableObject[newAmountOfEnemiesPerWave[i]];
                for (int io = 0; io < newAmountOfEnemiesPerWave[i]; io++)
                {
                    spawnableObjects[io] = new SpawnableObject(((SpawnManager)(target)).gameObject, 0);
                }
                newSpawnOb.Add(spawnableObjects);
            }
        }
        return(newSpawnOb);
    }
예제 #8
0
        internal override void CustomizeObject(GameObject go, SpawnableObject spawnerDefinition)
        {
            SpawnableDancer def = spawnerDefinition as SpawnableDancer;

            var dancer = go.GetComponent <Puppet.Dancer>();

            dancer.footDistance *= Random.Range(0.8f, 2.0f);
            dancer.stepFrequency = Random.Range(def.minTempo, def.maxTempo);
            dancer.stepHeight   *= 0.1f + Random.Range(def.minEnergy, def.maxEnergy);
            dancer.stepAngle    *= Random.Range(def.minEnergy, def.maxEnergy);

            dancer.hipHeight        *= Random.Range(0.75f, 1.25f);
            dancer.hipPositionNoise *= Random.Range(def.minEnergy, def.maxEnergy);
            dancer.hipRotationNoise *= Random.Range(def.minEnergy, def.maxEnergy);

            dancer.spineBend           = Random.Range(def.minEnergy * 5, -def.maxEnergy * 12);
            dancer.spineRotationNoise *= Random.Range(0.75f, 1.25f);

            dancer.handPositionNoise *= Random.Range(0.5f, 2.0f);
            dancer.handPosition      += Random.insideUnitSphere * 0.25f;

            dancer.headMove       *= Random.Range(def.minEnergy / 2, def.maxEnergy * 2);
            dancer.noiseFrequency *= Random.Range(0.4f, 1.8f);
            dancer.randomSeed      = Random.Range(0, 0xffffff);

            var renderer = dancer.GetComponentInChildren <Renderer>();

            renderer.material.color = Random.ColorHSV(0, 1, 0.6f, 0.8f, 0.8f, 1.0f);
        }
예제 #9
0
    public static void ApplyRandomFactors(SpawnableObject obj, Transform objTransform)
    {
        // Random Scale
        if (obj.isScale)
        {
            float scale = UnityEngine.Random.Range(obj.minScale, obj.maxScale);
            objTransform.localScale = new Vector3(scale, scale, scale);
        }

        // Random Rotation
        if (obj.isRotationX || obj.isRotationY || obj.isRotationZ)
        {
            Vector3 rotation = objTransform.eulerAngles;
            if (obj.isRotationX)
            {
                rotation.x = UnityEngine.Random.Range(obj.xMinRot, obj.xMaxRot);
            }
            if (obj.isRotationY)
            {
                rotation.y = UnityEngine.Random.Range(obj.yMinRot, obj.yMaxRot);
            }
            if (obj.isRotationZ)
            {
                rotation.z = UnityEngine.Random.Range(obj.zMinRot, obj.zMaxRot);
            }
            objTransform.eulerAngles = rotation;
        }
    }
예제 #10
0
 public void HoldForChair(SpawnableObject sObj)
 {
     if (sObj.gameObject.name.Contains("tableDinner") || sObj.gameObject.name.Contains("DeskWithDrawers")) {
         _boxcond = BoxCondition.ChairSpot;
         _furniture = sObj.gameObject;
         //ChangeColor(_furniture);
     }
 }
예제 #11
0
 void SpawnObjects()
 {
     for (int i = 0; i < _SpawnableObjects.Length; i++)
     {
         SpawnableObject _Object = _SpawnableObjects[i];
         SetUpObject(_Object._ObjectTotalGroups, _Object.ObjectPos, _Object._ObjectPrefab, _Object._ObjectsPerPoint, _Object._ObjectRangeFromPoint, _Object._ObjectParent);
     }
 }
예제 #12
0
 private void SetupObject(SpawnableObject obj, GameObject go)
 {
     go.transform.SetParent(Map);
     if (obj.SpawnOnPlanet)
     {
         go.transform.Rotate(Vector3.forward, GetRotationOfSpawn(go.transform.position));
     }
 }
예제 #13
0
    // If you are cloning a Component then the GameObject it is attached to will also be cloned, again with an optional position and rotation.
    public SpawnableObject SpawnObject(SpawnableObject obj, Vector3 pos, Quaternion rot)
    {
        var instantiatedObject = Instantiate(obj, pos, rot, transform);

        instantiatedObject.SetSpawner(this);
        instantiatedObjects.Add(instantiatedObject);
        return(instantiatedObject);
    }
예제 #14
0
    protected override void InitializeObject(SpawnableObject obj)
    {
        base.InitializeObject(obj);
        var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        pos.z = -8;
        obj.transform.position = pos;
        obj.transform.rotation = Quaternion.identity;
    }
    public void SelectObjectToSpawn(SpawnableObject obj)
    {
        GameObject toSpawn = spawnableObjectToGameObject[obj];

        if (toSpawn != null)
        {
            selectedObjectToSpawn = toSpawn;
        }
    }
예제 #16
0
    void OnCollisionEnter(Collision collider)
    {
        SpawnableObject obj = collider.gameObject.GetComponent <SpawnableObject>();

        if (obj != null)
        {
            obj.CheckProjectileType(type);
        }
    }
예제 #17
0
    public void SpawnRare(float minSpawnRange, float maxSpawnRange)
    {
        Vector3    pos = (Random.Range(0, minSpawnRange - maxSpawnRange) + maxSpawnRange) * (Vector3)Random.insideUnitCircle.normalized + generateAround.position;
        Quaternion rot = Quaternion.Euler(0, 0, Random.Range(0, 360));

        pos.z = Random.Range(zMin, zMax);
        SpawnableObject spawned = SpawnRandomObject(pos, rot);

        spawned.gameObject.GetComponent <SpriteRenderer> ().sortingOrder = (int)pos.z;
    }
예제 #18
0
 void SpawnEnemies(SpawnableObject enemy)
 {
     for (
         var numberOfEnemiesSpawned = 0;
         numberOfEnemiesSpawned < enemy.Quantity;
         numberOfEnemiesSpawned += 1)
     {
         SpawnEnemy(enemy.Prefab);
     }
 }
예제 #19
0
    public void RpcUpdateChar(string key, char vel)
    {
        if (!dict.ContainsKey(key))
        {
            return;
        }
        SpawnableObject comp = dict[key];

        comp.SetValue(key, vel);
    }
예제 #20
0
파일: Grid.cs 프로젝트: disas69/Bubble-Pops
        private void OnRowDeactivated(SpawnableObject spawnableObject)
        {
            var row = spawnableObject as Row;

            if (row != null)
            {
                row.Deactivated -= OnRowDeactivated;
                _activeRows.Remove(row);
            }
        }
예제 #21
0
 public void DeSpawnObject(SpawnableObject obj)
 {
     if (obj.cache && obj.cached)
     {
         obj.Object.SetActive(false);
     }
     else
     {
         GameObject.Destroy(obj?.spawnedObject);
     }
 }
예제 #22
0
    public void CmdAcknowledge(string key, string value)
    {
        if (!dict.ContainsKey(key))
        {
            return;
        }
        SpawnableObject comp = dict[key];

        comp.SetValue(key, value);
        Debug.Log("Cmd ACK of message " + value);
    }
예제 #23
0
    public void RpcUpdateQuaternion(string key, Quaternion value)
    {
        if (!dict.ContainsKey(key))
        {
            return;
        }
        SpawnableObject comp = dict[key];

        comp.SetValue(key, value);
        Debug.Log("Cmd ACK of message " + value.ToString());
    }
예제 #24
0
    void Awake()
    {
        if (spawnable == null)
        {
            spawnable = GetComponent <SpawnableObject>();
        }

        if (autoDestroyEffect == null)
        {
            autoDestroyEffect = GetComponent <AutoDestroyEffect>();
        }
    }
예제 #25
0
    /// <summary>
    /// Adds a new Instantiated object to the spawnpool list
    /// </summary>
    /// <param name="obj"></param>
    private void AddNewObjectToSpawnPool(SpawnableObject obj)
    {
        int             hash    = obj.name.GetHashCode();
        SpawnableObject newMono = Instantiate <SpawnableObject>(obj);

        newMono.name = newMono.name.Substring(0, obj.name.Length);//Removes the word clone from the instantiated object
        newMono.transform.SetParent(this.transform);
        newMono.gameObject.SetActive(false);
        newMono.isInSpawnPool = true;

        spawnPoolDictionary[hash].Enqueue(newMono);
    }
예제 #26
0
    public void AddToSyncDictionary(ref string key, SpawnableObject obj)
    {
        int offset = -1;

        while (dict.ContainsKey(key))
        {
            offset++;
            key = key + offset;
            Debug.Log("The dictionary already contains a key with this value. Name got changed to " + key + " and is checked again.");
        }
        dict.Add(key, obj);
    }
예제 #27
0
    void spawnTile(int tile, int spawner)
    {
        int        rand = 0;
        GameObject obs  = null;

        switch (tile)
        {
        case 0:
            if (powerUpCounter <= 0)
            {
                rand = bs.randomInfluencedIndex(difficulty.powerUpObjects);
                obs  = (GameObject)Instantiate(difficulty.powerUpObjects[rand].gameObject, spawnPoints[spawner].transform.position, spawnPoints[spawner].transform.rotation);
                obs.transform.parent = spawnPoints[spawner].transform;
                powerUpCounter       = 30;
            }
            break;

        case 1:
            if (!isDouble)
            {
                rand = bs.randomInfluencedIndex(difficulty.staticObjects);
                obs  = (GameObject)Instantiate(difficulty.staticObjects[rand].gameObject, spawnPoints[spawner].transform.position, spawnPoints[spawner].transform.rotation);
                obs.transform.parent = spawnPoints[spawner].transform;
            }
            else
            {
                rand = bs.randomInfluencedIndex(difficulty.doubleObjects);
                obs  = (GameObject)Instantiate(difficulty.doubleObjects[rand].gameObject, spawnPoints[spawner].transform.position, spawnPoints[spawner].transform.rotation);
                obs.transform.parent = spawnPoints[spawner].transform;
                isDouble             = false;
            }
            break;

        case 2:
            rand = bs.randomInfluencedIndex(difficulty.movableObjects);
            obs  = (GameObject)Instantiate(difficulty.movableObjects[rand].gameObject, spawnPoints[spawner].transform.position, spawnPoints[spawner].transform.rotation);
            obs.transform.parent = spawnPoints[spawner].transform;
            SpawnableObject so = obs.GetComponent <SpawnableObject>();
            so.lanes     = spawnPoints;
            so.spawnLane = spawner;
            break;

        case 3:
            rand = bs.randomInfluencedIndex(difficulty.enthusiasmObjects);
            obs  = (GameObject)Instantiate(difficulty.enthusiasmObjects[rand].gameObject, spawnPoints[spawner].transform.position, spawnPoints[spawner].transform.rotation);
            obs.transform.parent = spawnPoints[spawner].transform;
            break;

        default:
            break;
        }
    }
예제 #28
0
    public void AttemptToSpawnObject(GameObject room, Transform spawnTransform)
    {
        SpawnableObject spawmedObjectPrefab = SpawnableObject.ChooseRandomSpawnable(SpawnableObjects);

        if (spawmedObjectPrefab == null || spawmedObjectPrefab.spawnableObject == null || !spawnTransform)
        {
            return;
        }

        GameObject newSpawnable = Instantiate(spawmedObjectPrefab.spawnableObject, spawnTransform.position, spawnTransform.rotation);

        newSpawnable.transform.SetParent(room.transform);
    }
예제 #29
0
    protected override void InitializeObject(SpawnableObject obj)
    {
        if (area != null)
        {
            (obj as Enemy).TargetPosition = area.GetRandomPoint();
        }
        else
        {
            (obj as Enemy).TargetPosition = transform.position;
        }

        obj.transform.position   = transform.position;
        (obj as Enemy).FromFront = IsFront;
    }
예제 #30
0
    public virtual void SpawnBackgrounds(float minSpawnRange, float maxSpawnRange)
    {
        var backgroundCount = instantiatedObjects.Count;

        for (var i = 0; backgroundCount < maxCount && i < maxCount; i++)
        {
            Vector3    pos = (Random.Range(0, minSpawnRange - maxSpawnRange) + maxSpawnRange) * (Vector3)Random.insideUnitCircle.normalized + generateAround.position;
            Quaternion rot = Quaternion.Euler(0, 0, Random.Range(0, 360));
            pos.z = Random.Range(zMin, zMax);
            SpawnableObject spawned = SpawnRandomObject(pos, rot);
            spawned.gameObject.GetComponent <SpriteRenderer> ().sortingOrder = (int)pos.z;
            backgroundCount++;
        }
    }
예제 #31
0
    public SpawnGenerator(IEnumerable <T> objects, int seed)
    {
        r = new Random(seed);
        var totalProbability = 0;

        spawnableObjects = new List <SpawnableObject>();
        foreach (var o in objects)
        {
            var spawnable = new SpawnableObject(o, totalProbability);
            totalProbability += o.ThousandInOneProbability;
            spawnableObjects.Add(spawnable);
        }
        Debug.Assert(totalProbability <= 1000);
    }
예제 #32
0
    private void Start()
    {
        if (SceneManager.GetActiveScene().name != "PCG") {
            gameObject.SetActive(false);
            _placed = true;
            return;
        }

        if (parentOfParent)
            _papa = gameObject.transform.parent.transform.parent.GetComponent<SpawnableObject>();
        else
            _papa = gameObject.transform.parent.GetComponent<SpawnableObject>();

        //int objSum = 0;

        //foreach (var item in MiniObjectsToPlace) {
        //    objSum += item.maxPlacementNum;
        //}

        //if (_totalAmountOfMiniObjects > objSum) {
        //    Debug.LogWarning("Sum of mini objects lower than the number asked to place. Exiting. " + gameObject.name);
        //    _placed = true;
        //    return;
        //}
    }
예제 #33
0
 public void SetCarpet(SpawnableObject sObj)
 {
     if (_carpet == null) {
         _carpet = sObj.gameObject;
         //ChangeColor(_carpet);
     }
 }
예제 #34
0
    public void SetFurniture(SpawnableObject sObj)
    {
        if (_boxcond == BoxCondition.Occupied)
            return;

        if (_furniture == null) {
            if (sObj.localTag == SpawnableObject.Tag.Short)
                _boxcond = BoxCondition.Short;
            else if (sObj.localTag == SpawnableObject.Tag.Tall)
                _boxcond = BoxCondition.Tall;

            _furniture = sObj.gameObject;
            //ChangeColor(_furniture);
        }
    }