예제 #1
0
    public void initializeWalker(int pathIndex, int spriteIndex)
    {
        WalkerScript walker = Instantiate(walkerPrefab, Vector3.zero, Quaternion.identity) as WalkerScript;

        if (walker != null)
        {
            walker.transform.parent = this.transform;
        }
        if (walker != null)
        {
            walker.Initialisation();
        }
        if (walker != null)
        {
            walker.setSprite(_spriteArray[spriteIndex]);
        }
        if (walker != null)
        {
            walker.startWalking(_pathArray[pathIndex]);
        }
        if (walker != null)
        {
            walkerList.Add(walker);
        }
    }
 public void Add(WalkerScript _Walkers)
 {
     m_Walkers.Add(_Walkers);
 }
예제 #3
0
 public CmdAllTransform(WalkerScript walker)
 {
     this.walker = walker;
     worldData   = MMW.GetAsset <WorldData>();
 }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        _timer -= Time.deltaTime;
        while (currentWalker != _maxWalker && _timer <= 0)
        {
            initializeWalker(Random.Range(0, _pathArray.Length), Random.Range(0, _spriteArray.Length));
            _timer = _timeBetweenSpawn;
            currentWalker++;
        }

        if (Input.GetButtonDown("Fire1") && _GUImanager.active == true)
        {
            Ray        ray = new Ray(Camera.main.transform.position, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1000)) - Camera.main.transform.position);
            RaycastHit hit;
            Physics.Raycast(ray, out hit, 1000);


            from = Camera.main.transform.position;
            to   = (Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1000)) - Camera.main.transform.position) * 100;

            if (hit.collider != null && hit.collider.gameObject.GetComponent <WalkerScript>() != null)
            {
                dragWalker = hit.collider.gameObject.GetComponent <WalkerScript>();
                dragWalker.grab();
                oldMousePosition     = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, dragWalker.transform.position.z));
                dragWalker.isWalking = false;
            }

            /*for (int i = 0; i < walkerList.Count; i++ )
             * {
             *  if (walkerList[i] != null && walkerList[i].GetComponent<Collider2D>().overlapMouse())
             *  {
             *      dragWalker = walkerList[i];
             *                          dragWalker.grab();
             *      oldMousePosition = Camera.main.ScreenToWorldPoint ( new Vector3 (Input.mousePosition.x, Input.mousePosition.y, dragWalker.transform.position.z));
             *      dragWalker.isWalking = false;
             *      break;
             *  }
             * }*/
        }

        if (Input.GetButtonUp("Fire1") && dragWalker != null)
        {
            //dragWalker.isWalking = true;
            Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, dragWalker.transform.position.z));
            Vector3 temp   = newPos - oldMousePosition;
            dragWalker.throwAway(temp * throwForce);
            dragWalker = null;
            currentWalker--;
        }

        if (dragWalker != null)
        {
            Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, dragWalker.transform.position.z));

            dragWalker.transform.position += newPos - oldMousePosition;
            if (dragWalker.transform.position.y < -1.4f)
            {
                dragWalker.transform.position = new Vector3(dragWalker.transform.position.x, -1.4f, dragWalker.transform.position.z);
            }
            oldMousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, dragWalker.transform.position.z));
        }
    }
예제 #5
0
    //===========================================================
    //  Main update loop
    //===========================================================

    void Update()
    {
        // Reset simulation with 'r'
        if (Input.GetKeyDown("r"))
        {
            Reset();
        }

        // Toggle pause using Space
        if (Input.GetKeyDown(KeyCode.Space))
        {
            isPaused = !isPaused;
        }

        // Number keys to change mode
        if (Input.GetKeyDown("1"))
        {
            currentMode = Modes.Point; spawnInterval = 2;
        }
        if (Input.GetKeyDown("2"))
        {
            currentMode = Modes.Rings; spawnInterval = 20;
        }
        if (Input.GetKeyDown("3"))
        {
            currentMode = Modes.Circles; spawnInterval = 20;
        }
        if (Input.GetKeyDown("4"))
        {
            currentMode = Modes.Spheres; spawnInterval = 20;
        }
        if (Input.GetKeyDown("5"))
        {
            currentMode = Modes.Blanket; spawnInterval = 100;
        }
        if (Input.GetKeyDown("6"))
        {
            currentMode = Modes.Line;
        }
        if (Input.GetKeyDown("7"))
        {
            currentMode = Modes.Wave;
        }

        if (!isPaused)
        {
            // Spawn walkers at the point where the laser pointer ray meets the active meshes
            if (isSpawning && laserIsHovering)
            {
                if (Time.frameCount >= lastSpawnTime + spawnInterval)
                {
                    RaycastHit hit;
                    Ray        ray  = new Ray(laserPointer.transform.position, laserPointer.transform.forward);
                    bool       bHit = Physics.Raycast(ray, out hit);

                    if (bHit)
                    {
                        SpawnWalkersAbove(hit.point);
                    }

                    lastSpawnTime = Time.frameCount;
                }
            }

            walkersToRemove = new List <GameObject>();

            foreach (GameObject walker in activeWalkers)
            {
                // Handle movement of all active walkers
                if (walker.layer == LayerMask.NameToLayer("Walkers"))
                {
                    WalkerScript ws = walker.GetComponent <WalkerScript>();

                    // Flag for removal any walkers that are too old or too far away from the mesh
                    if (ws.age > maxWalkerAge || Vector3.Distance(walker.transform.position, meshContainer.transform.position) > maxWalkerDistance)
                    {
                        walkersToRemove.Add(walker);

                        // Move all active walkers
                    }
                    else
                    {
                        // Move towards origin of mesh
                        // walker.transform.position = Vector3.MoveTowards(walker.transform.position, meshContainer.transform.position + targetOffset + Random.insideUnitSphere * 10f, 1.0f *  Time.deltaTime);

                        // Move walkers forward
                        // walker.transform.position += new Vector3(0,0,walkerSpeed);

                        // Move walkers downward
                        walker.transform.position += new Vector3(0, -walkerSpeed, 0);

                        // Add motion jitter
                        walker.transform.position += Random.insideUnitSphere * jitterAmount;
                    }
                }
                else if (walker.layer == LayerMask.NameToLayer("Aggregated"))
                {
                    walker.GetComponent <Renderer>().material = aggregateMaterial;
                }
            }

            // Remove walkers that have been flagged for removal
            foreach (GameObject walker in walkersToRemove)
            {
                inactiveWalkers.Add(walker);
                activeWalkers.Remove(walker);
            }
        }
    }