Наследование: MonoBehaviour
Пример #1
0
 void Awake()
 {
     if (isSheepFlock)
     {
         sheepFlock = this;
     }
 }
Пример #2
0
 void Start()
 {
     body    = GetComponent <Rigidbody2D>();
     manager = GameObject.Find("Boid Manager").GetComponent <BoidManager>();
     liner   = gameObject.AddComponent <LineRenderer>();
     //velocity = Vector3.zero;
 }
Пример #3
0
    private PointAttractDriver _pointAttractDriver; // makes boids chase the cursor (or whatever)

    private void Awake()
    {
        gameUI.onCoherenceValueChange  += HandleCoherenceValueChange;
        gameUI.onSeperationValueChange += HandleSeperationValueChange;
        gameUI.onAlignmentValueChange  += HandleAlignmentValueChange;

        _boidManager = new BoidManager();
        boidViewManager.boidManager = _boidManager;

        _boidManager.count = 50;

        _flockDriver    = new FlockDriver();
        _alignDriver    = new AlignDriver();
        _seperateDriver = new SeperateDriver();

        _pointAttractDriver = new PointAttractDriver(); // To make the boids follow a coursor or whatnot, See: Update()

        foreach (Boid boid in _boidManager.Boids)
        {
            boid.drivers.Add(_flockDriver);
            boid.drivers.Add(_alignDriver);
            boid.drivers.Add(_seperateDriver);
            boid.drivers.Add(_pointAttractDriver);
        }

        // set initial values
        HandleCoherenceValueChange(gameUI.slider_Coherence.value);
        HandleSeperationValueChange(gameUI.slider_Seperation.value);
        HandleAlignmentValueChange(gameUI.slider_Alignment.value);
    }
Пример #4
0
 //For dependency injection.
 public void SetManager(BoidManager tank, int d, int num, Texture2D tex)
 {
     manager         = tank;
     id              = d;
     _numBoids       = num;
     _relativeValues = tex;
 }
Пример #5
0
    /* MY CODE */
    void Update()
    {
        // generate boids while the space key is held and the mouse cursor is on a collider of the level
        if (Input.GetKey("space"))
        {
            // create a ray from the camera in the direction fo the mouse cursor
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // cast the ray and check if it hits a collider
            if (Physics.Raycast(ray, out hit))
            {
                // instantiate a boid at the hit position + a little vertical offset
                Boid    boid = Instantiate(prefab);
                Vector3 pos  = new Vector3(hit.point.x, hit.point.y + 2, hit.point.z);
                boid.transform.position = pos;
                boid.transform.forward  = Random.insideUnitSphere;
                boid.SetColour(Random.ColorHSV());

                // add the new boid to the BoidManager
                BoidManager manager = FindObjectOfType <BoidManager>();
                manager.AddBoid(boid);
                boidsCount++;
            }
        }
    }
Пример #6
0
 void Awake()
 {
     Instance      = this;
     BoidList      = new List <BoidUtil>();
     MenaceList    = new List <GameObject>();
     FoodList      = new List <GameObject>();
     WaypointsList = new List <Vector3>();
 }
Пример #7
0
 void Update()
 {
     time -= Time.deltaTime;
     if (time <= 0)
     {
         BoidManager.Get().FoodList.Remove(this.gameObject);
         Destroy(this.gameObject);
     }
 }
Пример #8
0
    //******************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************

    /// <summary>
    //  Called when the object is created, before Start().
    /// </summary>
    private void Awake()
    {
        // Initialize singleton
        if (Instance != null && Instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
        Instance = this;
    }
Пример #9
0
    private void GetBoidsGameObject()
    {
        boidGameObject = GameObject.Find("Boid Manager");

        if (boidGameObject)
        {
            boidManager = boidGameObject.GetComponent <BoidManager>();
            SetupBoidsActions();
        }
    }
Пример #10
0
    void Start()
    {
        this.boidManager = new BoidManager {
            BoidPrefab = this.BoidPrefab
        };
        this.Reset();

        // TODO: Remove
        this.SetBoidBrush();
        this.SetSphereBrush();
    }
    public void Initialize(CellGrid cellGrid)
    {
        this.cellGrid = cellGrid;

        if (Instance == null)
        {
            Instance = this;
        }

        seekTimer = timeTillSeekTargetChange;
    }
Пример #12
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
Пример #13
0
    private void TransformIntoMenace()
    {
        GameObject menace = Instantiate(MenacePrefab);

        menace.transform.position = transform.position;
        BoidManager boidGet = BoidManager.Get();

        boidGet.MenaceList.Add(menace);
        boidGet.BoidList.Remove(this);
        Destroy(this.gameObject);
    }
Пример #14
0
    protected override void Init()
    {
        base.Init();

        fishSettings = (FishSettings)consumerSettings;

        if (DoesSchool)
        {
            Environment.Instance.AddBoidManagerToFishContainters(this);
            boidManager = GetComponentInParent <BoidManager>();
        }
    }
Пример #15
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
         return;
     }
 }
Пример #16
0
        static void Main(string[] args)
        {
            var engine = new RenderEngine(1080, 1920, "Boids");

            engine.UseShaders(@"./Shaders");
            engine.ShaderManager.OnLoad();

            var boidManager = new BoidManager(engine.ShaderManager.Shaders.FirstOrDefault(x => x.Name.ToLower() == "boid") as IShader, 10);

            boidManager.OnLoad();

            engine.Run();
        }
Пример #17
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.transform.tag == "Food")
     {
         BoidManager.Get().FoodList.Remove(other.gameObject);
         Destroy(other.gameObject);
         foodCount++;
         if (foodCount >= MaxFood)
         {
             TransformIntoMenace();
         }
     }
 }
Пример #18
0
    public void Initialize(BoidSettings settings, List <Target> targets, BoidManager manager)
    {
        // this.target = target;
        this.targets  = targets;
        this.settings = settings;

        position = cachedTransform.position;
        forward  = cachedTransform.forward;

        float startSpeed = (settings.minSpeed + settings.maxSpeed) / 2;

        velocity = transform.forward * startSpeed;

        this.manager = manager;
        SetColour(manager.color);
    }
Пример #19
0
    void Awake()
    {
        // The following code makes the game manager a singleton. I.e. there can only be one instance in the game at any given time.
        // This is a good thing as the game manager keeps track of score etc. and therefor there shouldnt be more than one
        if (instance == null)
        {
            instance = this;                            //If no game managers exists, this game object becomes the game manager.
        }
        //If instance already exists and it's not this:
        else if (instance != this)
        {
            Destroy(gameObject);                 //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
        }

        DontDestroyOnLoad(gameObject);         //when changing scenes Unity normally destorys all gameobject. However sincethe game manager keeps track of score it should not be destoyed when new scenes are loaded
    }
Пример #20
0
    void Spawn(GameObject prefab, string tipo)
    {
        GameObject obj  = Instantiate(prefab);
        float      xPos = Random.Range(BoxBounds.min.x, BoxBounds.max.x);
        float      zPos = Random.Range(BoxBounds.min.z, BoxBounds.max.z);
        float      yPos = Random.Range(BoxBounds.min.y, BoxBounds.max.y);

        obj.transform.position = new Vector3(xPos, yPos, zPos);

        if (tipo == "Food")
        {
            BoidManager.Get().FoodList.Add(obj);
        }
        else if (tipo == "Menace")
        {
            BoidManager.Get().MenaceList.Add(obj);
        }
    }
Пример #21
0
 internal void SetController(BoidManager boidManager)
 {
     manager = boidManager;
 }
Пример #22
0
 void Awake() {
     spawners = GetComponentsInChildren<PlantManager>();
     boidManager = FindObjectOfType<BoidManager>();
     //miniBoidManager = FindObjectOfType<MiniBoidManager>();
     player = FindObjectOfType<PlayerPhysicsBehaviour>();
 }
Пример #23
0
    void Start()
    {
        Instance = this;
        if ( !useInteractions )
        {
            for ( int i = 0; i < numOfBoids; i++ )
            {
                GameObject.Instantiate(boidPrefab, Random.insideUnitSphere * spawnRadius, Quaternion.identity);
            }
        }
        else
        {
            for ( int i = 0; i < blueNum; i++ )
            {
                GameObject.Instantiate(blueBoid, Random.insideUnitSphere * spawnRadius, Quaternion.identity);
            }
            for ( int i = 0; i < blackNum; i++ )
            {
                GameObject.Instantiate(blackBoid, Random.insideUnitSphere * spawnRadius, Quaternion.identity);
            }
            for ( int i = 0; i < greenNum; i++ )
            {
                GameObject.Instantiate(greenBoid, Random.insideUnitSphere * spawnRadius, Quaternion.identity);
            }
            for ( int i = 0; i < redNum; i++ )
            {
                GameObject.Instantiate(redBoid, Random.insideUnitSphere * spawnRadius, Quaternion.identity);
            }
        }

        foreach ( GameObject obj in GameObject.FindGameObjectsWithTag("Boid"))
        {
            Boid boid = obj.GetComponent<Boid>();
            if (boid != null)
            {
                boid.canCollide = true;
            }
        }

        StartCoroutine(BoidInteraction());
    }
Пример #24
0
 private void Awake()
 {
     S      = this;
     target = transform;
 }
Пример #25
0
 // Start is called before the first frame update
 void Start()
 {
     boidManager    = FindObjectOfType <BoidManager>();
     spriteRenderer = GetComponent <SpriteRenderer>();
 }
 private void Awake()
 {
     manager = BoidManager.instance;
 }
Пример #27
0
 // Use this for initialization
 void Start()
 {
     manager    = GetComponent <BoidManager>();
     avgPosDist = new List <Sample>();
 }
Пример #28
0
 // Use this for initialization
 void Start()
 {
     noBoids             = BoidManager.getBoids();
     displayNoBoids.text = noBoids.ToString();
 }
Пример #29
0
 public void updateBoids()
 {
     noBoids             = BoidManager.getBoids();
     displayNoBoids.text = noBoids.ToString();
 }
Пример #30
0
 public void setBoidManager(GameObject manager)
 {
     boidManager = manager.GetComponent <BoidManager>();
 }
Пример #31
0
 private void Awake()
 {
     boidManager = GetComponentInParent <BoidManager>();
     sprite      = GetComponentInChildren <SpriteRenderer>();
 }
Пример #32
0
 /// <summary>
 /// Manage boid count and stepping.
 /// </summary>
 /// <param name="mngr">The (flock) manager. Contains utils for driver functions.</param>
 /// <param name="pos">Initial position</param>
 /// <param name="vel">Initial velocity</param>
 public Boid(BoidManager mngr, Vector2 pos, Vector2 vel)
 {
     Manager  = mngr;
     Position = pos;
     Velocity = vel;
 }