Inheritance: MonoBehaviour
コード例 #1
0
        void ForceControlls()
        {
            float dist = 100.0f;

            Ray raycast = new Ray(holder.transform.position, holder.transform.forward * dist);

            RaycastHit hit;
            bool       bHit = Physics.Raycast(raycast, out hit);

            if (bHit)
            {
                int id = hit.collider.GetInstanceID();

                if (hit.collider.gameObject.tag.Contains("grabblable") && currentId != id)
                {
                    if (currentId != 0)
                    {
                        ResetCurrObj();
                    }

                    MoveAlongPath moveAlong = hit.collider.gameObject.GetComponent <MoveAlongPath>();
                    if (moveAlong)
                    {
                        if (moveAlong.GetIsMoving())
                        {
                            return;
                        }
                    }

                    currentId        = id;
                    currentObj       = hit.collider.gameObject;
                    originalPosition = currentObj.transform.position;
                    halfWayPosition  = currentObj.transform.position;
                    originalRotation = currentObj.transform.rotation;

                    SetObjUseGravity(false, true);
                    float flyDist = currObjUseGravity ? flyDistVal : 0f;

                    SetHighlight(true, currentObj);

                    currentObj.transform.position = new Vector3(originalPosition.x, originalPosition.y + flyDist, originalPosition.z);
                }
                else if (!hit.collider.gameObject.tag.Contains("grabblable") && currentId != 0)
                {
                    SetCounter();
                }
                else if (currentId == id)
                {
                    startCleanCount = false;
                }
            }
            else if (currentId != 0)
            {
                SetCounter();
            }
            if (startCleanCount)
            {
                CounterToClean();
            }
        }
コード例 #2
0
ファイル: TunnelGameManager.cs プロジェクト: shldn/mdons
    void StartExperiment(bool playerVis, UserControl uControl)
    {
        Debug.LogError("Starting experiment: " + expCount);
        GameManager.Inst.LocalPlayer.Visible = playerVis;

        MoveAlongPath moveScript = (MoveAlongPath)FindObjectOfType(typeof(MoveAlongPath));

        GameManager.Inst.playerManager.SetLocalPlayerTransform(GameManager.Inst.playerManager.GetLocalSpawnTransform());
        moveScript.Reset();
        TunnelEnvironmentManager.Inst.Reset();

        switch (uControl)
        {
        case UserControl.NONE:
            allowUserControls = false;
            moveScript.AutoStart();
            break;

        case UserControl.PARTIAL:
            allowUserControls = true;
            break;

        default:
            Debug.LogError("UserControl: " + uControl + " not yet handled");
            break;
        }

        ++expCount;
    }
コード例 #3
0
    void Start () {

        if (toSet == null)
            toSet = transform;
        if (!ladder)
            pathMovementScript = GetComponent<PathNodeJumper>();
        else
            ladderPath = GetComponent<MoveAlongPath>();
        referenceTransform = new GameObject().transform;
        referenceTransform.transform.name = "PathRotationReferenceTransform";
        if (alignToPath)
            StartingLookPosition(true);
        else if (lookAtTarget)
            StartingLookPosition(false);
    }
コード例 #4
0
 public void TriggerEntered(int whichTrigger, Transform other)
 {
     inLadderZone = true;
     pathMovement = other.GetComponent<MoveAlongPath>();
     pathMovement.pathName = pathScript.pathName;
     if (whichTrigger == 0)
     {
         pathMovement.pathPercentage = upperPercentage;
         playerLadderScript.pathControlScript.pathName = upperPath;
         playerLadderScript.pathControlScript.distanceMargin = upperPathDistMargin;
         playerLadderScript.pathControlScript.objectPathPosition = upperPathStartingPercentage;
         playerLadderScript.pathControlScript.smootheTime= upperSmoothingTime;
     }
     else
     {
         pathMovement.pathPercentage = lowerPercentage;
         playerLadderScript.pathControlScript.pathName = lowerPath;
         playerLadderScript.pathControlScript.distanceMargin = lowerPathDistMargin;
         playerLadderScript.pathControlScript.objectPathPosition = lowerPathStartingPercentage;
         playerLadderScript.pathControlScript.smootheTime = lowerSmoothingTime;
     }
 }
コード例 #5
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (cameraIdleCursor.gameObject.activeInHierarchy)
        {
            gameState.Camera = GameState.CameraState.Disarm;
        }
        else if (cameraCursor.gameObject.activeInHierarchy)
        {
            if (camFlash > 0)
            {
                // Debug.Log("Camera cooldown");
                return;
            }
            // Debug.Log("Taking a picture");

            // camera flash
            FireCameraFlash();

            // camera sound
            FindObjectOfType <ambientSoundController>()?.PlayCamera();

            // Find out which window we are taking a pic from
            RectTransform camTarget    = null;
            Rect          newRect      = new Rect();
            Vector3[]     worldCorners = new Vector3[4];
            foreach (var ct in cameraTargets)
            {
                ct.GetWorldCorners(worldCorners);
                newRect = new Rect(worldCorners[0], worldCorners[2] - worldCorners[0]);
                if (newRect.Contains(Input.mousePosition))
                {
                    camTarget = ct;
                    break;
                }
            }
            if (camTarget == null)
            {
                return;
            }

            // Find the ray parameters
            Vector2 mousePos = eventData.position;
            Vector2 rectPos  = new Vector2(newRect.x, newRect.y);
            Vector2 rectSize = new Vector2(newRect.width, newRect.height);

            //Debug.Log(mousePos);
            //Debug.Log(rectPos);
            //Debug.Log(rectSize);

            var    texture      = camTarget.GetComponent <UnityEngine.UI.RawImage>().texture;
            Camera activeCamera = null;
            if (cameraFront.targetTexture == texture)
            {
                activeCamera = cameraFront;
            }
            else if (cameraLeft.targetTexture == texture)
            {
                activeCamera = cameraLeft;
            }
            else if (cameraRight.targetTexture == texture)
            {
                activeCamera = cameraRight;
            }
            if (activeCamera == null)
            {
                return;
            }

            //Debug.Log(activeCamera.pixelRect);
            Vector2 camRectSize = new Vector2(activeCamera.pixelWidth, activeCamera.pixelHeight);
            Vector2 localPos    = (mousePos - rectPos) / rectSize * camRectSize;
            //Debug.Log(localPos);

            // Annihilate the fishes with a barrage of deadly raytraces
            int fishcount = 0;
            for (int i = -320; i <= 320; i += 64)
            {
                for (int j = -192; j <= 192; j += 64)
                {
                    var rayScreenPos = localPos + new Vector2(i, j);

                    if (activeCamera.pixelRect.Contains(rayScreenPos))
                    {
                        //Debug.Log(rayScreenPos);
                        var ray = activeCamera.ScreenPointToRay(rayScreenPos);

                        //var ray = new Ray(activeCamera.transform.position, activeCamera.transform.forward*5+activeCamera.transform.localToWorldMatrix.MultiplyVector(new Vector3(i/2, j/2, 0)));
                        //Debug.DrawRay(ray.origin, ray.direction*20, Color.magenta, 20f);
                        //Debug.Log(ray);
                        var hits = Physics.RaycastAll(ray.origin, ray.direction, 500);
                        foreach (var hit in hits)
                        {
//                            print(hit.transform.gameObject.name);

                            FishAI fish = hit.transform.GetComponent <FishAI>();
                            if (fish != null)
                            {
                                bool newCatch = fish.Catch();  // TODO: sound if something is catched?
                                fishcount++;
                                if (newCatch)
                                {
                                    FindObjectOfType <ambientSoundController>()?.PlaySuccess();
                                }
                            }

                            MoveAlongPath monsterPath = hit.transform.GetComponent <MoveAlongPath>();
                            if (monsterPath != null && !gameState.tookFotoOfMonster)
                            {
                                print("You took a picture of the monster! Ending game...");
                                gameState.tookFotoOfMonster = true;
                                gameState.Camera            = GameState.CameraState.Disarm;
                            }
                        }
                    }
                }
            }
            // Debug.Log("Hit fish " + fishcount + " times while taking a picture");
        }
    }
コード例 #6
0
	void Start () {
        pathMovementScript = GetComponent<MoveAlongPath>();
        FindPathNames();
	}
コード例 #7
0
 private void Awake()
 {
     _move = GetComponent <MoveAlongPath>();
     _unit = GetComponent <Unit.Unit>();
 }
コード例 #8
0
        private void PullAction()
        {
            MoveAlongPath objMovePath = null;

            if (currentObj != null)
            {
                objMovePath = currentObj.GetComponent <MoveAlongPath>();

                if (objMovePath != null && objMovePath.GetIsMoving())
                {
                    halfWayPosition = currentObj.transform.position;
                }

                //teste  angle
                //Vector3[] path = projectileCalc.CalculatePath(transform.position, currentObj.transform.position);
                //projectileCalc.Show();
                //projectileCalc.SetLineColor(Color.yellow);
                //projectileCalc.DrawLine();
            }

            if (Vector3.Distance(transform.position, currentObj.transform.position) <= 0.2f)
            {
                hasObject       = true;
                backOriginalPos = false;
                currentObj.transform.position = transform.position;
                if (objMovePath != null && objMovePath.GetIsMoving())
                {
                    objMovePath.Stop();
                }
            }

            if (gettingObject)
            {
                time += Time.deltaTime;
                float speed = curve.Evaluate(time);

                //Vector3[] path = projectileCalc.CalculatePath(transform.position, currentObj.transform.position);
                //projectileCalc.Show();
                //projectileCalc.SetLineColor(Color.yellow);
                //projectileCalc.DrawLine();

                if (objMovePath != null && objMovePath.GetIsMoving())
                {
                    objMovePath.SetSight(true);
                    //System.Array.Reverse(path);
                    Vector3[] Simplepath = { transform.position, currentObj.transform.position };
                    // objMovePath.SetMoveParams(path, curve.Evaluate(0.0f), MoveAlongPath.MoveType.Speed);
                    objMovePath.SetMoveParams(Simplepath, speed, MoveAlongPath.MoveType.Speed, null, null);
                }
            }

            if (Input.GetAxis("SecondaryTrigger") > 0.4f)//SteamVR_Input.GetState("forcePull", "pull", SteamVR_Input_Sources.LeftHand)
            {
                if (!gettingObject && !hasObject)
                {
                    gettingObject = true;
                    time          = 0.0f;
                    //StartCoroutine(MoveObject());

                    if (currentObj != null && Vector3.Distance(transform.position, currentObj.transform.position) > 0.2f)
                    {
                        //Vector3[] path = projectileCalc.CalculatePath(transform.position, currentObj.transform.position);
                        //projectileCalc.Show();
                        //projectileCalc.SetLineColor(Color.yellow);
                        //projectileCalc.DrawLine();

                        //  objMovePath = currentObj.GetComponent<MoveAlongPath>();

                        if (objMovePath != null && !objMovePath.GetIsMoving())
                        {
                            objMovePath.SetSight(true);
                            //System.Array.Reverse(path);
                            Vector3[] Simplepath = { transform.position, currentObj.transform.position };
                            // objMovePath.SetMoveParams(path, curve.Evaluate(0.0f), MoveAlongPath.MoveType.Speed);
                            objMovePath.SetMoveParams(Simplepath, curve.Evaluate(0.0f), MoveAlongPath.MoveType.Speed, null, null);
                        }
                    }
                }
            }
            else if ((Input.GetAxis("SecondaryTrigger") < 0.4f && gettingObject))//SteamVR_Input.GetStateUp("forcePull", "pull", SteamVR_Input_Sources.LeftHand) ||
            {
                projectileCalc.HideLine();
                gettingObject = false;
                time          = 0.0f;
                if (currentObj != null)
                {
                    if (objMovePath != null)
                    {
                        objMovePath.Stop();
                    }
                }
            }
        }