Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            ActionOnDestroy c = (ActionOnDestroy)target;

            GUILayout.Space(8);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("enable"), true);
            if (c.enable)
            {
                GUILayout.Space(8);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("onDestroy"), true);
            }

            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 2
0
        // Original Spawn Function
        public GameObject SpawnAndSelect(Vector3 position)
        {
            var obj = SelectSpawnObject();

            if (obj == null)
            {
                throw new System.ArgumentNullException("Spawner: Cant find a Gameobject prefab to spawn");
            }



            // Revisa si puede hacer el spawn o no puede
            GameObject clone = null;

            if (spawnMode == SpawnMode.Infinite)
            {
                //Debug.Log("Spawn by Infinite");
                clone = Instantiate(obj, position, Quaternion.identity);
            }
            else if ((spawnMode == SpawnMode.Count || spawnMode == SpawnMode.RandomCount) && spawned < totalSpawns)
            {
                //Debug.Log("Spawn by Count, current: " + spawned + " max: " + totalSpawns);
                clone = Instantiate(obj, position, Quaternion.identity);
            }
            else if ((spawnMode == SpawnMode.Track || spawnMode == SpawnMode.RandomTrack) && spawnedInScene < totalSpawns)
            {
                //Debug.Log("Spawn by Track, current: " + spawnedInScene + " max: " + totalSpawns);
                clone = Instantiate(obj, position, Quaternion.identity);
            }


            if (clone == null)
            {
                return(null);
            }


            spawned++;
            spawnedInScene++;

            var tracker = ActionOnDestroy.AddComponent(clone, new ActionOnDestroy.Properties
            {
                onDestroy = () => spawnedInScene = Umath.Min(spawnedInScene - 1, 0)
            });

            // Revisa si debe ser hijo de alguno
            if (setAsChildOf != null)
            {
                clone.transform.SetParent(setAsChildOf);
            }

            // Ejecuta los delegates en el objeto
            try
            {
                onSpawn?.Invoke(clone);
            }
            catch (Exception e)
            {
                Debug.LogError("Spawner: Error in delegate applied to objects, " + e);
            }

            return(clone);
        }