Example #1
0
    protected override void Awake()
    {
        base.Awake();
        _controller = GetComponent<CharacterController>();

        _groundLayers = 1 << LayerMask.NameToLayer("Environment") | 1 << LayerMask.NameToLayer("StickingWall");
    }
Example #2
0
 void Start()
 {
     if (gameObject.layer == 8)
         mask = 1 << 9;
     else
         mask = 1 << 8;
 }
Example #3
0
 // Use this for initialization
 void Start()
 {
     drag = GetComponent<DragableBlock>();
     blocks = LayerMask.GetMask("Blocks");
     rotBy90 = Quaternion.Euler(0, 90, 0);
     rotByNeg90 = Quaternion.Euler(0, -90, 0);
 }
Example #4
0
	private void Setup(Vector2 heading, LayerMask layer)
	{
		Heading = heading;
		Layer = layer;

		StartCoroutine(Timer());
	}
Example #5
0
 // Use this for initialization
 void Start()
 {
     dst = new Vector3 (2.5f, transform.position.y, transform.position.z);
     cam = GetComponentInChildren<Camera> ();
     defaultMask = cam.cullingMask;
     init = false;
 }
Example #6
0
    public void launchMissile(MissileType type, GameObject T, Controller.Owner O, float d, float omm, bool hacked)
    {
        StopAllCoroutines();
        if (hacked)
            StartCoroutine(enableCollisions());
        switch (O)
        {
            case Controller.Owner.Enemy:
                gameObject.layer = LayerMask.NameToLayer("eMissiles");
                targetLayer = LayerMask.NameToLayer("Player");
                if(PS_Jammer.JammerEnabled)
                    StartCoroutine(checkJammer());
                break;
            case Controller.Owner.Player:
                gameObject.layer = LayerMask.NameToLayer("pMissiles");
                targetLayer = LayerMask.NameToLayer("Enemies");
                break;
        }

        assignedTarget = true;
        target = T;
        missileType = type;
        Modifier = omm;
        HP = 10;
        damage = d;
    }
Example #7
0
 void Start()
 {
     pathsMask = LayerMask.NameToLayer ("Paths");
     centerMask = LayerMask.NameToLayer ("CenterBlock");
     frontBlockMask = LayerMask.NameToLayer ("FrontBlock");
     oneBackMask = LayerMask.NameToLayer ("OneViewBack");
 }
 void Start()
 {
     navAgent = GetComponent<NavMeshAgent> ();
     myTransform = transform;
     raycastLayer = 1 << LayerMask.NameToLayer ("Player");
     StartCoroutine (DoCheck ());
 }
Example #9
0
	// Use this for initialization
	void Awake () {

        Random.seed = Seed;

        WayMask = ~(1 << LayerMask.NameToLayer("Way"));
        Generate();
	}
Example #10
0
	private LayerMask LayerMaskField( string label, LayerMask layerMask) {
		List<string> layers = new List<string>();
		List<int> layerNumbers = new List<int>();
		
		for (int i = 0; i < 32; i++) {
			string layerName = LayerMask.LayerToName(i);
			if (layerName != "") {
				layers.Add(layerName);
				layerNumbers.Add(i);
			}
		}
		int maskWithoutEmpty = 0;
		for (int i = 0; i < layerNumbers.Count; i++) {
			if (((1 << layerNumbers[i]) & layerMask.value) > 0)
				maskWithoutEmpty |= (1 << i);
		}
		maskWithoutEmpty = EditorGUILayout.MaskField( label, maskWithoutEmpty, layers.ToArray());
		int mask = 0;
		for (int i = 0; i < layerNumbers.Count; i++) {
			if ((maskWithoutEmpty & (1 << i)) > 0)
				mask |= (1 << layerNumbers[i]);
		}
		layerMask.value = mask;
		return layerMask;
	}
	void VerticalCollisions(ref Vector3 velocity, LayerMask cMask){
		float dirY 		= Mathf.Sign (velocity.y);																		        // direction of velocity in the y component
		float rayLength = Mathf.Abs(velocity.y) + skinWidth;															        // length of raycast ray, equal to velocity in the y component
		for (int i = 0; i < vertRayCount; i++) {
			Vector2 	 rayOrigin = (dirY == -1)?rayCastOrigins.botLeft:rayCastOrigins.topLeft;						        // checks direction of velocity in the y component and assigns an origin respectively 
			rayOrigin 	     	  += Vector2.right * (vertRaySpacing * i + velocity.x);									        // adds origin for each ray along boundry 
			RaycastHit2D hit 	   = Physics2D.Raycast(rayOrigin,Vector2.up * dirY,rayLength, cMask);			       		    // creates ray at each ray origin in the direction of velocity with the length of velocity while ignoring objects not in the layer mask collisionMask
			Debug.DrawRay(rayOrigin, Vector2.up * dirY * rayLength,Color.red);
			if (hit) {																									        // if ray collides with object in layer mask collisionMask
				velocity.y 	= (hit.distance - skinWidth) * dirY;												                // if hit assigns distance from boundry to object collided to velocity in the y component
				rayLength   = hit.distance;																	                    // assigns distance from boundry to object collided to rayLegth, as to not get confused if not all rays are colliding with same object distance
				if (collisionsInfo.climbingSlope){
					velocity.x = velocity.y / Mathf.Tan (collisionsInfo.slopeAngle * Mathf.Deg2Rad) * Mathf.Sign(velocity.x);   // more Trig!
				}
				collisionsInfo.below = dirY == -1;
				collisionsInfo.above = dirY == 1;
				if( timeStamp <= Time.time) {                                                                                   
					timeStamp = Time.time + jumpCoolDown;
				}
			}
		}
		if (collisionsInfo.climbingSlope){
			float directionX    = Mathf.Sign (velocity.x);
			rayLength           = Mathf.Abs (velocity.x) + skinWidth;
			Vector2 rayOrigin   = ((directionX == -1)?rayCastOrigins.botLeft:rayCastOrigins.botRight) + Vector2.up * velocity.y;
			RaycastHit2D hit    = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, cMask);
			if (hit) {
				float slopeAngle = Vector2.Angle (hit.normal, Vector2.up);
				if (slopeAngle  != collisionsInfo.slopeAngle){
					velocity.x   = (hit.distance - skinWidth) * directionX;
					collisionsInfo.slopeAngle = slopeAngle;
				}
			}			
		}
	}		
Example #12
0
 public NetBehaviour(GameObject gameObject, LayerMask interActable)
 {
     this.gameObject = gameObject;
     this.range = 2.5f;
     this.interActable = interActable;
     lastTimeFire = 0;
 }
 public void setHoming(float turn, float maxDist, float maxAngle, LayerMask voituresLayer)
 {
     this.turn = turn;
     this.maxDistance = maxDist;
     this.maxAngle = maxAngle;
     this.voituresLayer = voituresLayer;
 }
Example #14
0
 void Start()
 {
     zeroMask = LayerMask.NameToLayer("ZeroView");
     oneMask = LayerMask.NameToLayer("OneView");
     zeroMaskBack = LayerMask.NameToLayer ("ZeroViewBack");
     oneMaskBack = LayerMask.NameToLayer ("OneViewBack");
 }
	 void HorizontalCollisions (ref Vector3 velocity, LayerMask cMask) {
		float dirX 		= Mathf.Sign (velocity.x);																		        // direction of velocity in the x component
		float rayLength = Mathf.Abs (velocity.x) + skinWidth;															        // length of raycast ray, equal to velocity in the x component
		for (int i = 0; i < horRayCount; i++) { 
			Vector2 	 rayOrigin	 = (dirX == -1)?rayCastOrigins.botLeft:rayCastOrigins.botRight;						        // checks direction of velocity in the x component and assigns an origin respectively
			rayOrigin 				+= Vector2.up * (horRaySpacing * i);												        // adds origin for each ray along boundry 
			RaycastHit2D hit		 = Physics2D.Raycast (rayOrigin, Vector2.right * dirX, rayLength, cMask);	        		// creates ray at each ray origin in the direction of velocity with the length of velocity while ignoring objects not in the layer mask collisionMask
			Debug.DrawRay(rayOrigin, Vector2.right * dirX * rayLength, Color.red);
			if (hit) {																									        // if ray collides with object in layer mask collisionMask
				float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
				if (i == 0 && slopeAngle <= maxClimbAngle){
					float distanceToSlopeStart = 0;                                                                             // temp variable for distance to slope
					if (slopeAngle != collisionsInfo.slopeAngleOld) {                                                           // checks change in slope
						distanceToSlopeStart = hit.distance - skinWidth;                                                        // assigns distance minus skin width to temp variable
						velocity.x 			-= distanceToSlopeStart * dirX;                                                     // subtracts temp value from velocity in the x axis with respect to direction
					}
					ClimbSlope (ref velocity, slopeAngle);                                                                      // calls ClimbSlope () method which checks collisions on slopes
					velocity.x += distanceToSlopeStart * dirX;                                                                  // adds temp value to velocity in the x axis with respect to direction
				}
				if (!collisionsInfo.climbingSlope || slopeAngle > maxClimbAngle){
				velocity.x  = (hit.distance - skinWidth) * dirX;												                // if hit assigns distance from boundry to object collided to velocity in the x component
				rayLength  	= hit.distance;																	                    // assigns distance from boundry to object collided to rayLegth, as to not get confused if not all rays are colliding with same object distance
				if (collisionsInfo.climbingSlope){
					velocity.y = Mathf.Tan (collisionsInfo.slopeAngle * Mathf.Deg2Rad) * Mathf.Abs(velocity.x);                 // Trig! 
				}
				collisionsInfo.left  = dirX == -1;                                                                      
				collisionsInfo.right = dirX == 1;
				} 
			}		
		}
	}
 void Awake()
 {
     playerController = GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerController> ();
     ShotSpawnPos = GameObject.FindGameObjectWithTag("ShotSpawn");
     ShootableMask = LayerMask.GetMask ("Shootable"); // get a reference to the shootable mask
     ShotLine = ShotSpawnPos.GetComponent<LineRenderer> ();   // get reference to the line AKA bullet
 }
  public void Reset()
    {
        Awake();

        // UnityChan2DController
        maxSpeed = 10f;
        jumpPower = 1000;
        backwardForce = new Vector2(-4.5f, 5.4f);
        whatIsGround = 1 << LayerMask.NameToLayer("Ground");

        // Transform
        transform.localScale = new Vector3(1, 1, 1);

        // Rigidbody2D
        m_rigidbody2D.gravityScale = 3.5f;
        m_rigidbody2D.fixedAngle = true;

        // BoxCollider2D
        m_boxcollier2D.size = new Vector2(1, 2.5f);
        m_boxcollier2D.offset = new Vector2(0, -0.25f);

        // Animator
        m_animator.applyRootMotion = false;

		speedlevel = 1;
		gameflg = true;
		bonusflg = false;
		jumpconstraint = 0;
		bonusJump = 0;
		GameSC = 0;
		Score.bonusgauge = 0;
		gamed = true;
    }
 void Awake()
 {
     pubbleLayerMask = 1 << (LayerMask.NameToLayer("PlayObject"));//实例化mask到cube这个自定义的层级之上。
     //此处手动修改layer ,因为NGUI的layer 默认初始化为UI,一定要写在Awake函数
     gameObject.layer = ConstantValue.PubbleMaskLayer;
     defaultLayer = 1 << (LayerMask.NameToLayer("Default"));
 }
 public void ChangeObjectLayermask(LayerMask newMask)
 {
     foreach (Transform trans in gameObject.GetComponentsInChildren<Transform>(true))
     {
         trans.gameObject.layer = (int)Mathf.Log(newMask.value, 2);
     }
 }
    //Initialize things on the global scale.
    void Awake()
    {
        //Setup singleton here.
        if (master == null)
        {
            master = this;
            DontDestroyOnLoad(this);
            DontDestroyOnLoad(this.gameObject);
        }
        else if (master != this)
        {
            Destroy(this);
        }

        //Raycasts ignore the ignoreRaycast, select character, and non-draggable area layers.
        regularCharacterMask = ~0 & ~((1 << 2) | (1 << 10) | (1 << 11) | (1 << 12));

        //Raycasts ignore the ignoreRaycast, selectCharacters, and other characters.
        draggedCharacterMask = ~0 & ~((1 << 2) | (1 << 10) | (1 << 8));

        //Ignore collision between characters and the selected characters.
        Physics2D.IgnoreLayerCollision(8, 10, true);

        Cursor.SetCursor(cursorTexture, new Vector2(13, 13), CursorMode.Auto);

        MusicLooper.loadAudioClips();
    }
Example #21
0
    public override float ChanceToHit(GameObject target)
    {
        if (Vector3.Distance(this.transform.position, target.transform.position) > range)
        {
            //out of range
            return 0;
        }

        Ray ray = new Ray(this.transform.position, target.transform.position - this.transform.position);
        RaycastHit hit;
        LayerMask layerMask = new LayerMask();
        layerMask = layerMask << LayerMask.NameToLayer("Avoid");

        if (Physics.Raycast(ray, out hit, range, layerMask))
        {
            if (hit.collider.gameObject != target)
            {
                //not aimed at target
                return 0;
            }
        }

        Vector3 direction = target.transform.position - this.transform.position;
        direction.Normalize();
        float chance = Vector3.Dot(this.transform.forward, direction);

        return chance;
    }
Example #22
0
	public void setLayerMask(){
		#if UNITY_EDITOR
		if(!Application.isPlaying && Layer.value <= 0){
			Layer = 1<< LayerMask.NameToLayer("ShadowLayer");
		}
		#endif
	}
Example #23
0
    // Use this for initialization
    void Start()
    {
        environmentLayerMask = 1 << LayerMask.NameToLayer("Environment");
        if(nodes == null) nodes = new List<Node>();

        for(int x = 0; x < width;x++) {

            for(int z = 0; z < length;z++) {
                Ray ray = new Ray(transform.position + new Vector3(x * gridSpacing, 0, z * gridSpacing),Vector3.down);
                RaycastHit hit;
                if(Physics.Raycast(ray,out hit, raycastRange, environmentLayerMask)) {
                    if(hit.transform.gameObject.layer == LayerMask.NameToLayer("Environment")) {
                        GameObject nodeGameObject;
                        if(debugMode) {
                            nodeGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                            Destroy(nodeGameObject.GetComponent<Collider>());
                            nodeGameObject.renderer.material.color = new Color(1, 1, 1);

                        } else {
                            nodeGameObject = new GameObject();
                        }

                        nodeGameObject.name = "Node";
                        Node newNode = nodeGameObject.AddComponent<Node>() as Node;
                        newNode.transform.position = hit.point;
                        newNode.transform.parent = hit.transform;
                        newNode.transform.localScale = newNode.transform.localScale * 0.2f + new Vector3(0.1f,0.1f,0.1f);
                        nodes.Add(newNode);
                    }

                }

            }
        }
    }
	void Awake ()
	{

		tipsBlockLayerMask = 1 << gameObject.layer;

		maskedLayer = 1 << ISSCLayerManager.blockLayer;
	}
Example #25
0
	public void CatchPlayer(Player me){
		holdingMe = me;
		childTransform.GetComponent<SpriteRenderer> ().enabled = false;
		transform.SetParent(holdingMe.transform);
		fightingMask = me.controller.fightingMask;
		held = true;
	}
Example #26
0
 //inform player move
 public override void onEnterState( StateMachine  prevState)
 {
     base.onEnterState(prevState);
     this.prevState = prevState;
     actionPoint = 1;
     this.targetLayer = GameController.instance.interactLayer;
 }
Example #27
0
 public static Transform WithinSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, LayerMask objectLayerMask)
 {
     Transform objectFound = null;
     var hitColliders = Physics.OverlapSphere(transform.position, viewDistance, objectLayerMask);
     if (hitColliders != null)
     {
         float minAngle = Mathf.Infinity;
         for (int i = 0; i < hitColliders.Length; ++i)
         {
             float angle;
             Transform obj;
             // Call the WithinSight function to determine if this specific object is within sight
             if ((obj = WithinSight(transform, positionOffset, fieldOfViewAngle, viewDistance, hitColliders[i].transform, false, out angle)) != null)
             {
                 // This object is within sight. Set it to the objectFound GameObject if the angle is less than any of the other objects
                 if (angle < minAngle)
                 {
                     minAngle = angle;
                     objectFound = obj;
                 }
             }
         }
     }
     return objectFound;
 }
	public void Initialize (LayerMask terrainMask, LayerMask objectMask, Transform foliageContainer, float newYearLength)
	{
		terrainLayerMask = terrainMask;
		objectLayerMask = objectMask;
		container = foliageContainer;
		yearLength = newYearLength;
	}
Example #29
0
 protected virtual void Awake()
 {
     boxCollider = GetComponent <BoxCollider2D> ();
     rgdBody = GetComponent <Rigidbody2D> ();
     speed = 10;
     Blocklayer = 1 << 8;
 }
 public void SetWallAvoidanceProperties(float strengthMultiplier, float avoidanceForce, float maxViewDistance, LayerMask obstacleLayer)
 {
     wallAvoidance.strengthMultiplier = strengthMultiplier;
     wallAvoidance.avoidanceForce = avoidanceForce;
     wallAvoidance.maxViewDistance = maxViewDistance;
     wallAvoidance.obstacleLayer = obstacleLayer;
 }
    public void Update()
    {
        Debug.DrawRay(transform.position, (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position), Color.red);

        if (Input.GetKey(KeyCode.D))
        {
            // va a droite
            m_MoveDir = transform.right;
        }
        else if (Input.GetKey(KeyCode.A))
        {
            // va a gauche
            m_MoveDir = -transform.right;
        }
        else
        {
            // va nul part
            m_MoveDir = Vector2.zero;
        }


        if (Input.GetKeyDown(KeyCode.W))
        {
            m_RB.AddForce(transform.up * m_JumpForce);
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (Physics2D.Raycast(transform.position, (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position), 3f, LayerMask.GetMask("Interractibles")))
            {
                GameObject m_BulletInstance = Instantiate(m_ProjectilePrefab, transform.position, Quaternion.identity);
                Projectile script           = m_BulletInstance.GetComponent <Projectile>();
                script.InitSpeed(m_BulletSpeed, (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position).normalized);
            }
        }
    }
Example #32
0
    private void Move()
    {
        if (isMovingDelayed)
        {
            return;
        }

        if (!isMoving)
        {
            Vector3 newDirection = Vector3.zero;

            if (horizontal_input == -1)
            {
                animator.Play("WalkLeft");
                newDirection = new Vector3(-1, 0, 0);
            }
            else if (horizontal_input == 1)
            {
                animator.Play("WalkRight");
                newDirection = new Vector3(1, 0, 0);
            }
            else if (vertical_input == 1)
            {
                animator.Play("WalkUp");
                newDirection = new Vector3(0, 1, 0);
            }
            else if (vertical_input == -1)
            {
                animator.Play("WalkDown");
                newDirection = new Vector3(0, -1, 0);
            }
            else
            {
                isNoInput = true;
                return;
            }

            if (!KeyHeldLongEnough())
            {
                return;
            }

            if (Grid.Instance.TileIsMoveable(transform.position + newDirection))
            {
                moveToLocation += newDirection;
            }

            isMoving = true;
        }

        transform.position = Vector2.MoveTowards(transform.position, moveToLocation, Time.deltaTime * MOVE_SPEED);

        if (Vector2.Distance(transform.position, moveToLocation) < 0.01f)
        {
            transform.position = moveToLocation;
            isMoving           = false;

            LayerMask layerMask = 1 << LayerMask.NameToLayer("teleports");

            RaycastHit2D hit = Physics2D.BoxCast(transform.position + new Vector3(0.5f, 0.5f, 0), new Vector2(0.5f, 0.5f), 0, Vector2.zero, 0, layerMask);

            if (hit.collider)
            {
                GameController.Instance.WarriorCollision(hit.collider);
            }

            float delayTime = Grid.Instance.GetMoveDelay(transform.position);
            if (delayTime > 0)
            {
                isMovingDelayed = true;
                Invoke("RemoveDelay", delayTime);
            }
        }
    }
Example #33
0
    void CheckUp()
    {
        RaycastHit hitUp;
        bool       isHitUp = Physics.BoxCast(transform.position, new Vector3(0.4f, 0.1f, 0.5f), Vector3.up, out hitUp, Quaternion.identity, 1, LayerMask.GetMask("ground"), QueryTriggerInteraction.Ignore);

        if (isHitUp && hitUp.distance < 0.4f)
        {
            moveToUp = false;
        }
        else
        {
            moveToUp = true;
        }
    }
Example #34
0
    void UnCross()
    {
        Vector3    origin = transform.position + new Vector3(0, 0.1f, 0);
        Vector3    size = new Vector3(0.01f, 0.3f, 1);
        RaycastHit hitLeft, hitRight;

        bool isHitLeft  = Physics.BoxCast(origin + new Vector3(0, 0, 0), size / 2, -body.right, out hitLeft, body.rotation, 0.5f, LayerMask.GetMask("ground"), QueryTriggerInteraction.Ignore);
        bool isHitRight = Physics.BoxCast(origin - new Vector3(0, 0, 0), size / 2, body.right, out hitRight, body.rotation, 0.5f, LayerMask.GetMask("ground"), QueryTriggerInteraction.Ignore);


        if (isHitLeft)
        {
            float dis = hitLeft.distance;
            if (dis < 0.5f)
            {
                float disTemp = (0.5f - dis) * unCrossSpeed;
                transform.position += new Vector3(disTemp, 0, 0);
            }
        }

        if (isHitRight)
        {
            float dis = hitRight.distance;
            if (dis < 0.5f)
            {
                float disTemp = (0.5f - dis) * unCrossSpeed;
                //print("反穿" + disTemp);
                transform.position -= new Vector3(disTemp, 0, 0);
            }
        }
    }
Example #35
0
    void CheckRight()
    {
        moveToRight = true;

        RaycastHit hitRight;
        bool       isHitRight = Physics.BoxCast(transform.position + new Vector3(0, 0.2f, 0), new Vector3(0.1f, 0.2f, 0.5f), body.right, out hitRight, body.rotation, 1, LayerMask.GetMask("ground"));

        rightDis = hitRight.distance;
        if (isHitRight && hitRight.distance < 0.6f)
        {
            moveToRight = false;
        }
        else
        {
            bool isClosedGround = groundDct.isClosedGround && groundDct.disGround < 0.2f;
            //判断斜率,超过最大则不能移动
            if (isClosedGround && groundDct.midNormal.x < 0 && groundDct.slope > GameManager.Instance.Player.maxFrictionSlope)
            {
                moveToRight = false;
            }
            //向左滑时不能向右移动
            if (role.slideProc.isSliding && groundDct.midNormal.x < 0)
            {
                moveToRight = false;
            }
        }
    }
 public static bool Contains(this LayerMask layers, GameObject gameObject)
 {
     return(0 != (layers.value & 1 << gameObject.layer));
 }
Example #37
0
    public static void CreatUIManager(Vector2 referenceResolution, CanvasScaler.ScreenMatchMode MatchMode, bool isOnlyUICamera, bool isVertical)
    {
        //UIManager
        GameObject UIManagerGo = new GameObject("UIManager");

        UIManagerGo.layer = LayerMask.NameToLayer("UI");
        //UIManager UIManager = UIManagerGo.AddComponent<UIManager>();
        UIManagerGo.AddComponent <UIManager>();

        //UIcamera
        GameObject cameraGo = new GameObject("UICamera");

        cameraGo.transform.SetParent(UIManagerGo.transform);
        cameraGo.transform.localPosition = new Vector3(0, 0, -1000);
        Camera camera = cameraGo.AddComponent <Camera>();

        camera.cullingMask  = LayerMask.GetMask("UI");
        camera.orthographic = true;
        if (!isOnlyUICamera)
        {
            camera.clearFlags = CameraClearFlags.Depth;
            camera.depth      = 1;
        }
        else
        {
            camera.clearFlags      = CameraClearFlags.SolidColor;
            camera.backgroundColor = Color.black;
        }

        //Canvas
        Canvas canvas = UIManagerGo.AddComponent <Canvas>();

        canvas.renderMode  = RenderMode.ScreenSpaceCamera;
        canvas.worldCamera = camera;

        //UI Raycaster
        //GraphicRaycaster Graphic = UIManagerGo.AddComponent<GraphicRaycaster>();
        UIManagerGo.AddComponent <GraphicRaycaster>();

        //CanvasScaler
        CanvasScaler scaler = UIManagerGo.AddComponent <CanvasScaler>();

        scaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
        scaler.referenceResolution = referenceResolution;
        scaler.screenMatchMode     = MatchMode;

        if (isVertical)
        {
            scaler.matchWidthOrHeight = 1;
        }
        else
        {
            scaler.matchWidthOrHeight = 0;
        }

        //挂载点
        GameObject     goTmp    = null;
        RectTransform  rtTmp    = null;
        UILayerManager layerTmp = UIManagerGo.GetComponent <UILayerManager>();

        goTmp       = new GameObject("GameUI");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                        = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax              = new Vector2(1, 1);
        rtTmp.anchorMin              = new Vector2(0, 0);
        rtTmp.anchoredPosition3D     = Vector3.zero;
        rtTmp.sizeDelta              = Vector2.zero;
        layerTmp.m_GameUILayerParent = goTmp.transform;

        goTmp       = new GameObject("Fixed");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                       = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax             = new Vector2(1, 1);
        rtTmp.anchorMin             = new Vector2(0, 0);
        rtTmp.anchoredPosition3D    = Vector3.zero;
        rtTmp.sizeDelta             = Vector2.zero;
        layerTmp.m_FixedLayerParent = goTmp.transform;

        goTmp       = new GameObject("Normal");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                        = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax              = new Vector2(1, 1);
        rtTmp.anchorMin              = new Vector2(0, 0);
        rtTmp.anchoredPosition3D     = Vector3.zero;
        rtTmp.sizeDelta              = Vector2.zero;
        layerTmp.m_NormalLayerParent = goTmp.transform;

        goTmp       = new GameObject("TopBar");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                        = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax              = new Vector2(1, 1);
        rtTmp.anchorMin              = new Vector2(0, 0);
        rtTmp.anchoredPosition3D     = Vector3.zero;
        rtTmp.sizeDelta              = Vector2.zero;
        layerTmp.m_TopbarLayerParent = goTmp.transform;

        goTmp       = new GameObject("PopUp");
        goTmp.layer = LayerMask.NameToLayer("UI");
        goTmp.transform.SetParent(UIManagerGo.transform);
        goTmp.transform.localScale = Vector3.one;
        rtTmp                       = goTmp.AddComponent <RectTransform>();
        rtTmp.anchorMax             = new Vector2(1, 1);
        rtTmp.anchorMin             = new Vector2(0, 0);
        rtTmp.anchoredPosition3D    = Vector3.zero;
        rtTmp.sizeDelta             = Vector2.zero;
        layerTmp.m_PopUpLayerParent = goTmp.transform;
        //m_UILayerManager = layerTmp;

        ProjectWindowUtil.ShowCreatedAsset(UIManagerGo);

        string Path = "Resources/UI/UIManager.prefab";

        FileTool.CreatFilePath(Application.dataPath + "/" + Path);
        PrefabUtility.CreatePrefab("Assets/" + Path, UIManagerGo, ReplacePrefabOptions.ConnectToPrefab);
    }
Example #38
0
    public static void CreateGuideWindow()
    {
        string UIWindowName = "GuideWindow";
        UIType UIType       = UIType.TopBar;

        GameObject uiGo = new GameObject(UIWindowName);

        Type            type         = EditorTool.GetType(UIWindowName);
        GuideWindowBase guideBaseTmp = uiGo.AddComponent(type) as GuideWindowBase;

        uiGo.layer = LayerMask.NameToLayer("UI");

        guideBaseTmp.m_UIType = UIType;

        Canvas can = uiGo.AddComponent <Canvas>();

        uiGo.AddComponent <GraphicRaycaster>();

        can.overrideSorting  = true;
        can.sortingLayerName = "Guide";

        RectTransform ui = uiGo.GetComponent <RectTransform>();

        ui.sizeDelta = Vector2.zero;
        ui.anchorMin = Vector2.zero;
        ui.anchorMax = Vector2.one;

        GameObject BgGo = new GameObject("BG");

        BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform Bg = BgGo.AddComponent <RectTransform>();

        Bg.SetParent(ui);
        Bg.sizeDelta = Vector2.zero;
        Bg.anchorMin = Vector2.zero;
        Bg.anchorMax = Vector2.one;

        GameObject rootGo = new GameObject("root");

        rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform root = rootGo.AddComponent <RectTransform>();

        root.SetParent(ui);
        root.sizeDelta = Vector2.zero;
        root.anchorMin = Vector2.zero;
        root.anchorMax = Vector2.one;

        GameObject mask = new GameObject("mask");

        mask.layer = LayerMask.NameToLayer("UI");
        RectTransform maskrt = mask.AddComponent <RectTransform>();
        Image         img    = mask.AddComponent <Image>();

        img.color = new Color(0, 0, 0, 0.75f);
        maskrt.SetParent(root);
        maskrt.sizeDelta = Vector2.zero;
        maskrt.anchorMin = Vector2.zero;
        maskrt.anchorMax = Vector2.one;

        guideBaseTmp.m_mask = img;

        guideBaseTmp.m_bgMask = BgGo;
        guideBaseTmp.m_uiRoot = rootGo;

        string Path = "Resources/UI/" + UIWindowName + "/" + UIWindowName + ".prefab";

        FileTool.CreatFilePath(Application.dataPath + "/" + Path);
        PrefabUtility.CreatePrefab("Assets/" + Path, uiGo, ReplacePrefabOptions.ConnectToPrefab);

        ProjectWindowUtil.ShowCreatedAsset(uiGo);
    }
    void Update()
    {
        RotateWeaponForEnemy();

        //Vector2 positionOfPlayer = player.position;
        float distanceFromEnemyToPlayer = (transform.position - player.position).sqrMagnitude;

        if (distanceFromEnemyToPlayer < fireDistance)
        {
            //射线检测
            bool notFire = Physics2D.Raycast(transform.position, player.position - transform.position, Mathf.Sqrt(distanceFromEnemyToPlayer), 1 << LayerMask.NameToLayer("Wall"));
            if (!notFire)
            {
                //开火
                totalTime -= Time.deltaTime;
                if (totalTime <= 0)
                {
                    Shoot();
                    Invoke("Shoot", 0.5f);
                    //todo:计时结束
                    totalTime = 2f;
                }
            }
        }
    }
Example #40
0
        private void LateUpdate()
        {
            if (runUpdate)
            {
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    PointerEventData pointer = new PointerEventData(EventSystem.current);
                    pointer.position = Input.mousePosition;
                    List <RaycastResult> raycastResults = new List <RaycastResult>();
                    EventSystem.current.RaycastAll(pointer, raycastResults);

                    if (raycastResults.Count > 0 && raycastResults[0].gameObject.layer == LayerMask.NameToLayer("UI"))
                    {
                        return;
                    }
                }
                //Calculate Mouse World Position

                if (Input.GetMouseButtonDown(0))
                {
                    initialMouseScreenPosition = Input.mousePosition;
                    RecordInitialPosition();
                }
                else if (Input.GetMouseButton(0))
                {
                    RecordInitialPosition();
                    //Generate mesh wires
                    CalculateCurrentPosition();
                    UpdateMesh();
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    RecordInitialPosition();

                    RecordFinalPosition();
                    //RECTANGLE CALCULUS
                    Vector3 Vertex1 = new Vector3(FinalMousePosition.x, initialMouseWorldPosition.y, FinalMousePosition.z);

                    Vector3 Vertex3 = new Vector3(initialMouseWorldPosition.x, FinalMousePosition.y, FinalMousePosition.z);;



                    Matrix4x4 world_to_local = data.gameObject.transform.worldToLocalMatrix;

                    Vector3 LocalVertex0 = world_to_local.MultiplyPoint3x4(initialMouseWorldPosition);
                    Vector3 LocalVertex1 = world_to_local.MultiplyPoint3x4(Vertex1);
                    Vector3 LocalVertex2 = world_to_local.MultiplyPoint3x4(FinalMousePosition);
                    Vector3 LocalVertex3 = world_to_local.MultiplyPoint3x4(Vertex3);

                    float MaxX = Mathf.Max(LocalVertex2.x, LocalVertex0.x);
                    float MinX = Mathf.Min(LocalVertex2.x, LocalVertex0.x);
                    float MaxY = Mathf.Max(LocalVertex2.y, LocalVertex0.y);
                    float MinY = Mathf.Min(LocalVertex2.y, LocalVertex0.y);

                    foreach (var kvp in data.pointDataTable)
                    {
                        Vector3 localpos = kvp.Value.normed_position;
                        if (localpos.x >= MinX && localpos.x <= MaxX && localpos.y >= MinY && localpos.y <= MaxY)
                        {
                            data.globalMetaData.FreeSelectionIDList.Add(kvp.Key);
                        }
                    }
                    MeshObject.GetComponent <MeshFilter>().mesh = null;
                    CloudUpdater.instance.UpdatePointSelection();
                    //Find last mouse position and calculate the area selected
                }
                //ERASE SELECTION
                else if (Input.GetMouseButtonDown(1))
                {
                    initialMouseScreenPosition = Input.mousePosition;
                    RecordInitialPosition();
                }
                else if (Input.GetMouseButton(1))
                {
                    RecordInitialPosition();
                    //Generate mesh wires
                    CalculateCurrentPosition();
                    UpdateMesh();
                }
                else if (Input.GetMouseButtonUp(1))
                {
                    RecordInitialPosition();

                    RecordFinalPosition();
                    //RECTANGLE CALCULUS
                    Vector3 Vertex1 = new Vector3(FinalMousePosition.x, initialMouseWorldPosition.y, FinalMousePosition.z);

                    Vector3 Vertex3 = new Vector3(initialMouseWorldPosition.x, FinalMousePosition.y, FinalMousePosition.z);;



                    Matrix4x4 world_to_local = data.gameObject.transform.worldToLocalMatrix;

                    Vector3 LocalVertex0 = world_to_local.MultiplyPoint3x4(initialMouseWorldPosition);
                    Vector3 LocalVertex1 = world_to_local.MultiplyPoint3x4(Vertex1);
                    Vector3 LocalVertex2 = world_to_local.MultiplyPoint3x4(FinalMousePosition);
                    Vector3 LocalVertex3 = world_to_local.MultiplyPoint3x4(Vertex3);

                    float MaxX = Mathf.Max(LocalVertex2.x, LocalVertex0.x);
                    float MinX = Mathf.Min(LocalVertex2.x, LocalVertex0.x);
                    float MaxY = Mathf.Max(LocalVertex2.y, LocalVertex0.y);
                    float MinY = Mathf.Min(LocalVertex2.y, LocalVertex0.y);

                    foreach (var kvp in data.pointDataTable)
                    {
                        Vector3 localpos = kvp.Value.normed_position;
                        if (localpos.x >= MinX && localpos.x <= MaxX && localpos.y >= MinY && localpos.y <= MaxY)
                        {
                            data.globalMetaData.FreeSelectionIDList.Remove(kvp.Key);
                        }
                    }
                    CloudUpdater.instance.UpdatePointSelection();
                    MeshObject.GetComponent <MeshFilter>().mesh = null;
                }
            }
        }
Example #41
0
 public static bool ContainLayer(this LayerMask layerMask, int layer)
 {
     return(layerMask.ContainSameLayer(1 << layer));
 }
 protected override void Start()
 {
     Vines = GetComponent<Animator>();
     Vines.SetTrigger("VineAttack");
     playerMask = LayerMask.NameToLayer("ObjectWithLives");
 }
Example #43
0
 public bool RaycastCheck(float offset)
 {
     return(Physics2D.Raycast(new Vector2(transform.position.x + offset, transform.position.y), Vector2.down, deployHeight, LayerMask.GetMask("Deployer", "Conveyor")));
 }
Example #44
0
 public override void Process(AGE.Action _action, Track _track)
 {
     if (!MonoSingleton<Reconnection>.GetInstance().isProcessingRelayRecover)
     {
         SkillUseContext refParamObject = null;
         Vector3 bindPosOffset = this.bindPosOffset;
         Quaternion bindRotOffset = this.bindRotOffset;
         GameObject gameObject = _action.GetGameObject(this.targetId);
         GameObject obj3 = _action.GetGameObject(this.objectSpaceId);
         Transform transform = null;
         Transform transform2 = null;
         if (this.bindPointName.Length == 0)
         {
             if (gameObject != null)
             {
                 transform = gameObject.transform;
             }
             else if (obj3 != null)
             {
                 transform2 = obj3.transform;
             }
         }
         else
         {
             GameObject obj4 = null;
             Transform transform3 = null;
             if (gameObject != null)
             {
                 obj4 = SubObject.FindSubObject(gameObject, this.bindPointName);
                 if (obj4 != null)
                 {
                     transform3 = obj4.transform;
                 }
                 if (transform3 != null)
                 {
                     transform = transform3;
                 }
                 else if (gameObject != null)
                 {
                     transform = gameObject.transform;
                 }
             }
             else if (obj3 != null)
             {
                 obj4 = SubObject.FindSubObject(obj3, this.bindPointName);
                 if (obj4 != null)
                 {
                     transform3 = obj4.transform;
                 }
                 if (transform3 != null)
                 {
                     transform2 = transform3;
                 }
                 else if (gameObject != null)
                 {
                     transform2 = obj3.transform;
                 }
             }
         }
         if (this.bBulletPos)
         {
             VInt3 zero = VInt3.zero;
             _action.refParams.GetRefParam("_BulletPos", ref zero);
             bindPosOffset = (Vector3) zero;
             bindRotOffset = Quaternion.identity;
             if (this.bBulletDir)
             {
                 VInt3 num2 = VInt3.zero;
                 if (_action.refParams.GetRefParam("_BulletDir", ref num2))
                 {
                     bindRotOffset = Quaternion.LookRotation((Vector3) num2);
                 }
             }
         }
         else if (transform != null)
         {
             bindPosOffset = transform.localToWorldMatrix.MultiplyPoint(this.bindPosOffset);
             bindRotOffset = transform.rotation * this.bindRotOffset;
         }
         else if (transform2 != null)
         {
             if (obj3 != null)
             {
                 PoolObjHandle<ActorRoot> actorHandle = _action.GetActorHandle(this.objectSpaceId);
                 if (actorHandle != 0)
                 {
                     bindPosOffset = (Vector3) IntMath.Transform((VInt3) this.bindPosOffset, actorHandle.handle.forward, (VInt3) obj3.transform.position);
                     bindRotOffset = Quaternion.LookRotation((Vector3) actorHandle.handle.forward) * this.bindRotOffset;
                 }
             }
             else
             {
                 bindPosOffset = transform2.localToWorldMatrix.MultiplyPoint(this.bindPosOffset);
                 bindRotOffset = transform2.rotation * this.bindRotOffset;
             }
             if (this.bBulletDir)
             {
                 VInt3 num3 = VInt3.zero;
                 if (_action.refParams.GetRefParam("_BulletDir", ref num3))
                 {
                     bindRotOffset = Quaternion.LookRotation((Vector3) num3) * this.bindRotOffset;
                 }
             }
             else if (this.bBullerPosDir)
             {
                 refParamObject = _action.refParams.GetRefParamObject<SkillUseContext>("SkillContext");
                 if (refParamObject != null)
                 {
                     PoolObjHandle<ActorRoot> originator = refParamObject.Originator;
                     if ((originator != 0) && (originator.handle.gameObject != null))
                     {
                         Vector3 forward = transform2.position - originator.handle.gameObject.transform.position;
                         bindRotOffset = Quaternion.LookRotation(forward) * this.bindRotOffset;
                     }
                 }
             }
         }
         if (((!this.bEnableOptCull || (transform2 == null)) || (transform2.gameObject.layer != LayerMask.NameToLayer("Hide"))) && ((!this.bEnableOptCull || !MonoSingleton<GlobalConfig>.instance.bEnableParticleCullOptimize) || MonoSingleton<CameraSystem>.instance.CheckVisiblity(new Bounds(bindPosOffset, new Vector3((float) this.extend, (float) this.extend, (float) this.extend)))))
         {
             string resourceName;
             bool isInit = false;
             if (this.bUseSkin)
             {
                 resourceName = SkinResourceHelper.GetResourceName(_action, this.resourceName, this.bUseSkinAdvance);
             }
             else
             {
                 resourceName = this.resourceName;
             }
             if (refParamObject == null)
             {
                 refParamObject = _action.refParams.GetRefParamObject<SkillUseContext>("SkillContext");
             }
             bool flag2 = true;
             int particleLOD = GameSettings.ParticleLOD;
             if (GameSettings.DynamicParticleLOD)
             {
                 if (((refParamObject != null) && (refParamObject.Originator != 0)) && (refParamObject.Originator.handle.TheActorMeta.PlayerId == Singleton<GamePlayerCenter>.GetInstance().GetHostPlayer().PlayerId))
                 {
                     flag2 = false;
                 }
                 if (!flag2 && (particleLOD > 1))
                 {
                     GameSettings.ParticleLOD = 1;
                 }
                 MonoSingleton<SceneMgr>.GetInstance().m_dynamicLOD = flag2;
             }
             this.particleObject = MonoSingleton<SceneMgr>.GetInstance().GetPooledGameObjLOD(resourceName, true, SceneObjType.ActionRes, bindPosOffset, bindRotOffset, out isInit);
             if (GameSettings.DynamicParticleLOD)
             {
                 MonoSingleton<SceneMgr>.GetInstance().m_dynamicLOD = false;
             }
             if (this.particleObject == null)
             {
                 if (GameSettings.DynamicParticleLOD)
                 {
                     MonoSingleton<SceneMgr>.GetInstance().m_dynamicLOD = flag2;
                 }
                 this.particleObject = MonoSingleton<SceneMgr>.GetInstance().GetPooledGameObjLOD(this.resourceName, true, SceneObjType.ActionRes, bindPosOffset, bindRotOffset, out isInit);
                 if (GameSettings.DynamicParticleLOD)
                 {
                     MonoSingleton<SceneMgr>.GetInstance().m_dynamicLOD = false;
                 }
                 if (this.particleObject == null)
                 {
                     if (GameSettings.DynamicParticleLOD)
                     {
                         GameSettings.ParticleLOD = particleLOD;
                     }
                     return;
                 }
             }
             if (GameSettings.DynamicParticleLOD)
             {
                 GameSettings.ParticleLOD = particleLOD;
             }
             if (this.particleObject != null)
             {
                 ParticleHelper.IncParticleActiveNumber();
                 if (transform != null)
                 {
                     PoolObjHandle<ActorRoot> handle3 = (transform.gameObject != gameObject) ? ActorHelper.GetActorRoot(transform.gameObject) : _action.GetActorHandle(this.targetId);
                     if ((handle3 != 0) && (handle3.handle.ActorMesh != null))
                     {
                         this.particleObject.transform.parent = handle3.handle.ActorMesh.transform;
                     }
                     else
                     {
                         this.particleObject.transform.parent = transform.parent;
                     }
                 }
                 string layerName = "Particles";
                 if ((transform != null) && (transform.gameObject.layer == LayerMask.NameToLayer("Hide")))
                 {
                     layerName = "Hide";
                 }
                 this.particleObject.SetLayer(layerName, false);
                 if (isInit)
                 {
                     ParticleHelper.Init(this.particleObject, this.scaling);
                 }
                 if (!isInit)
                 {
                 }
                 Singleton<CGameObjectPool>.GetInstance().RecycleGameObjectDelay(this.particleObject, Mathf.Max(_action.length, (int) (this.lifeTime * 1000f)), new CGameObjectPool.OnDelayRecycleDelegate(TriggerParticleTick.OnRecycleTickObj));
                 if (this.applyActionSpeedToParticle && (this.particleObject != null))
                 {
                     _action.AddTempObject(AGE.Action.PlaySpeedAffectedType.ePSAT_Fx, this.particleObject);
                 }
             }
         }
     }
 }
    void Update()
    {
        if (GameManager.playerControls)
        {
            playerLocation = rb2d.transform;
            h = Input.GetAxis("Horizontal");
            anim.SetFloat("Speed", Mathf.Abs(h));
            grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));


            if (grounded && !inHitStun)
            {
                anim.SetTrigger("Grounded");
            }
            if (!grounded && !attacking && !inHitStun)
            {
                anim.SetTrigger("Jump");
            }
            if (h > 0 && !inHitStun && !isDead && !dashing && !crouching)
            {
                if (!facingRight)
                {
                    flip();
                }
                playerMoveRight();
            }

            if (h < 0 && !inHitStun && !isDead && !dashing && !crouching)
            {
                if (facingRight)
                {
                    flip();
                }
                playerMoveLeft();
            }

            if (h == 0 && !inHitStun && !isDead)
            {
                anim.SetTrigger("Idle");
                rb2d.velocity = new Vector2(0, rb2d.velocity.y);
            }

            if (Input.GetButtonDown("Jump") && grounded && !inHitStun && !isDead)
            {
                playerJump();
            }

            /* if (Input.GetButton ("Jump") && !grounded &&!inHitStun) {
             * if (boostMeter > 0) {
             *      boostMeter -= 10;
             *      rb2d.AddForce (new Vector2 (rb2d.velocity.x, 20f));
             * }
             * } */

            if (Input.GetKeyDown(KeyCode.J) && !inHitStun && grounded && !dashing && !attacking)
            {
                attacking = true;
                anim.SetTrigger("Attack");
                FindObjectOfType <SoundManagerScript> ().PlaySound("attack");
                StartCoroutine(Attack());
            }
            if (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A))
            {
                anim.SetBool("Dash", false);
                dashing = false;
                dashFlame.SetActive(false);
            }
            if (dashing && Input.GetKeyDown(KeyCode.J) && !inHitStun && !attacking && !isDead && grounded)
            {
                anim.SetTrigger("DashAttack");
                dashing = false;
                float d = getDirection(facingRight);
                rb2d.velocity = new Vector2(5 * d, 0);
                StartCoroutine(Attack());
            }
            if (!grounded && Input.GetKeyDown(KeyCode.J) && !inHitStun && !attacking && !isDead && !dashing)
            {
                attacking = true;
                anim.SetTrigger("Jump Attack");
                FindObjectOfType <SoundManagerScript> ().PlaySound("attack");
                StartCoroutine(Attack());
            }

            /*
             * if (grounded && !inHitStun && Input.GetKeyDown (KeyCode.U)) {
             * anim.SetTrigger ("Punch");
             * SoundManagerScript.PlaySound("attack");
             * }
             * if (grounded && !inHitStun && Input.GetKeyDown (KeyCode.K)) {
             * anim.SetTrigger ("Launcher");
             * SoundManagerScript.PlaySound("attack");
             * }
             * if (grounded && !inHitStun && Input.GetKeyDown (KeyCode.L)) {
             * anim.SetTrigger ("Stab");
             * SoundManagerScript.PlaySound("attack");
             * } */
            if (grounded && !inHitStun && Input.GetKeyDown(KeyCode.S) && !dashing)
            {
                crouching = true;
                anim.SetBool("Crouch", true);
                bc2d.size = new Vector2(0.33f, 0.55f);
            }
            if (!inHitStun && Input.GetKeyUp(KeyCode.S))
            {
                anim.SetBool("Crouch", false);
                crouching = false;
                bc2d.size = pvSize;
            }
            if (!inHitStun && Input.GetKeyUp(KeyCode.O) && energySlider.value > 1)
            {
                anim.SetTrigger("Shoot");
                FindObjectOfType <SoundManagerScript> ().PlaySound("rangeAttack");
                fire();
            }
            if (healthSlider.value <= 0 && !isDead)
            {
                StartCoroutine(death());
            }
            if (Input.GetKeyDown(KeyCode.Q) && GameManager.rKits > 0)
            {
                GameManager.rKits -= 1;
                FindObjectOfType <SoundManagerScript> ().PlaySound("repair");
                healthSlider.value = 100;
            }

            StartCoroutine(doubleDashRight());
            StartCoroutine(doubleDashLeft());
            StartCoroutine(backDash());
            StartCoroutine(comboAttack());
        }
    }
Example #46
0
 public static bool ContainSameLayer(this LayerMask layerMask, LayerMask another)
 {
     return((layerMask & another) != 0);
 }
    //player Controls
    private void PlayerControls()
    {
        if (Input.GetKey("d") || Input.GetKey("right"))
        {
            rb.velocity = new Vector2(fwdMvSpeed, rb.velocity.y);


            //Debug.Log("forward");
        }
        else if (Input.GetKey("a") || Input.GetKey("left"))
        {
            rb.velocity = new Vector2(bckMvSpeed, rb.velocity.y);


            //Debug.Log("Backward");
        }
        else
        {
            rb.velocity = new Vector2(0, rb.velocity.y); //stops character //find a new way to slow down character instead
        }

        //Rotate Player

        if (Input.GetKeyDown("d") && !facingRight || Input.GetKeyDown("right") && !facingRight)
        {
            FlipPlayer();
            //Debug.Log("Player Flipped Forward");
        }
        if (Input.GetKeyDown("a") && facingRight || Input.GetKeyDown("left") && facingRight)
        {
            FlipPlayer();
            //Debug.Log("Player Flipped Backward");
        }


        //jump


        if (Input.GetKeyDown("space") && isGrounded)
        {
            isJumping       = true;
            jumpTimeCounter = jumpTime;

            rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
        }

        if (jumpTimeCounter > 0 && isJumping == true)
        {
            rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
            Debug.Log("jump");
            jumpTimeCounter -= Time.deltaTime;
        }
        else
        {
            isJumping = false;
        }

        if (Input.GetKeyUp("space"))
        {
            isJumping = false;
        }

        if (rb.velocity.y > 0)
        {
            GetComponent <Rigidbody>().AddForce(Physics.gravity * addedGravity, ForceMode.Acceleration);
        }



        if (Physics.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")))
        {
            isGrounded = true;
        }
        else
        {
            isGrounded = false;
        }
    }
Example #48
0
        static public RayCastResult RayCast(Vector3 from, Vector3 dir, float distance, LayerMask layerMask)
        {
            var ray = new Ray();

            ray.origin    = from;
            ray.direction = dir;
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, distance, layerMask))
            {
                var collider = hit.collider;
                var texture  =
                    collider.GetComponent <UwcWindowTexture>() ??
                    collider.GetComponentInChildren <UwcWindowTexture>();
                if (texture)
                {
                    var window     = texture.window;
                    var meshFilter = texture.GetComponent <MeshFilter>();
                    if (window != null && meshFilter && meshFilter.sharedMesh)
                    {
                        var localPos     = texture.transform.InverseTransformPoint(hit.point);
                        var meshScale    = 2f * meshFilter.sharedMesh.bounds.extents;
                        var windowLocalX = (int)((localPos.x / meshScale.x + 0.5f) * window.width);
                        var windowLocalY = (int)((0.5f - localPos.y / meshScale.y) * window.height);
                        var desktopX     = window.x + windowLocalX;
                        var desktopY     = window.y + windowLocalY;
                        return(new RayCastResult {
                            hit = true,
                            texture = texture,
                            position = hit.point,
                            normal = hit.normal,
                            windowCoord = new Vector2(windowLocalX, windowLocalY),
                            desktopCoord = new Vector2(desktopX, desktopY),
                        });
                    }
                }
            }

            return(new RayCastResult()
            {
                hit = false,
            });
        }
Example #49
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag.Equals("Minion")) //나중에챔피언일때도적일때도조건에추가
        {                               //미니언의 경우 트리거 켜진건 공격 추-적 반경이라 디스턴스를 추가
         //if (Vector3.Distance(other.transform.position, transform.position) <= skillRange)
         //{
            MinionBehavior mB = other.GetComponent <MinionBehavior>();
            if (!other.gameObject.name.Contains(mySkill.TheChampionBehaviour.Team))
            {
                mB.minAtk.PauseAtk(1f, true);
                //other.GetComponent<Rigidbody>().AddForce(0, upPower, 0);
                //s = other.transform.DOJump(other.transform.position, 3, 1, 1f).OnUpdate(() => { if (mB.isDead) if (s != null) s.Kill(); });
                float damage = mySkill.skillData.qDamage[mySkill.TheChampionData.skill_Q - 1]
                               + mySkill.Acalculate(mySkill.skillData.qAstat, mySkill.skillData.qAvalue);
                //공격 코드(데미지 등) 삽입'
                //float damage = mySkill.QSkillInfo.myskill.Damage[mySkill.QSkillInfo.myskill.skillLevel]
                //    + mySkill.QSkillInfo.Acalculate(mySkill.QSkillInfo.myskill.Astat, mySkill.QSkillInfo.myskill.Avalue);

                if (mB != null)
                {
                    int viewID = mB.GetComponent <PhotonView>().viewID;
                    //mySkill.HitRPC(viewID, damage, "AP", "Jump");
                    if (mB.HitMe(damage, "AP", mySkill.gameObject))
                    {
                        //여기에는 나중에 평타 만들면 플레이어의 현재 공격 타겟이 죽었을 시 초기화해주는 것을 넣자.
                        mySkill.TheChampionAtk.ResetTarget();

                        // 스킬쏜애 주인이 나면 킬올리자
                        if (mySkill.GetComponent <PhotonView>().owner.Equals(PhotonNetwork.player))
                        {
                            mySkill.TheChampionData.Kill_CS_Gold_Exp(other.gameObject.name, 1, other.transform.position);
                        }
                    }
                }
            }
        }
        //else if (other.tag.Equals("Player"))
        else if (other.gameObject.layer.Equals(LayerMask.NameToLayer("Champion")))
        {
            ChampionBehavior cB = other.GetComponent <ChampionBehavior>();
            if (cB.Team != mySkill.TheChampionBehaviour.Team)
            {
                cB.myChampAtk.PauseAtk(1f, true);
                float damage = mySkill.skillData.qDamage[mySkill.TheChampionData.skill_Q - 1]
                               + mySkill.Acalculate(mySkill.skillData.qAstat, mySkill.skillData.qAvalue);
                if (cB != null)
                {
                    int viewID = cB.GetComponent <PhotonView>().viewID;
                    //mySkill.HitRPC(viewID, damage, "AP", "Jump");
                    if (cB.HitMe(damage, "AP", mySkill.gameObject, mySkill.name))
                    {
                        mySkill.TheChampionAtk.ResetTarget();
                        if (!sysmsg)
                        {
                            sysmsg = GameObject.FindGameObjectWithTag("SystemMsg").GetComponent <SystemMessage>();
                        }
                        sysmsg.sendKillmsg("alistar", other.GetComponent <ChampionData>().ChampionName, mySkill.TheChampionBehaviour.Team.ToString());
                        // 스킬쏜애 주인이 나면 킬올리자
                        if (mySkill.GetComponent <PhotonView>().owner.Equals(PhotonNetwork.player))
                        {
                            mySkill.TheChampionData.Kill_CS_Gold_Exp(other.gameObject.name, 0, other.transform.position);
                        }
                    }
                }
                //s = other.transform.DOJump(other.transform.position, 3, 1, 1f).OnUpdate(() =>
                //{
                //    if (cB.myChampionData.totalstat.Hp - ((damage * 100f) / (100f + cB.myChampionData.totalstat.Ability_Def)) <= 1)
                //    {
                //        if (s != null)
                //            s.Kill();
                //    }
                //});
            }
        }
        else if (other.gameObject.layer.Equals(LayerMask.NameToLayer("Monster")))
        {
            MonsterBehaviour mB = other.GetComponent <MonsterBehaviour>();
            mB.monAtk.PauseAtk(1f, true);
            //s = other.transform.DOJump(other.transform.position, 3, 1, 1f).OnUpdate(() => { if (mB.isDead) if (s != null) s.Kill(); });
            float damage = mySkill.skillData.qDamage[mySkill.TheChampionData.skill_Q - 1]
                           + mySkill.Acalculate(mySkill.skillData.qAstat, mySkill.skillData.qAvalue);
            if (mB != null)
            {
                int viewID = mB.GetComponent <PhotonView>().viewID;
                //mySkill.HitRPC(viewID, damage, "AP", "Jump");
                if (mB.HitMe(damage, "AP", mySkill.gameObject))
                {
                    mySkill.TheChampionAtk.ResetTarget();

                    //// 스킬쏜애 주인이 나면 킬올리자
                    //if (mySkill.GetComponent<PhotonView>().owner.Equals(PhotonNetwork.player))
                    //{
                    //    mySkill.TheChampionData.Kill_CS_Gold_Exp(other.gameObject.name, 3, other.transform.position);
                    //}
                }
            }
        }
    }
Example #50
0
    void Movimentacao()
    {
        verificaChao = Physics2D.Linecast(transform.position, chaoVerificador.position, 1 << LayerMask.NameToLayer("Chao"));
        if (Input.GetAxisRaw("Horizontal") > 0)
        {
            transform.Translate(Vector2.right * velocidade * Time.deltaTime);
            transform.eulerAngles = new Vector2(0, 0);
        }

        if (Input.GetAxisRaw("Horizontal") < 0)
        {
            transform.Translate(Vector2.right * velocidade * Time.deltaTime);
            transform.eulerAngles = new Vector2(0, 180);
        }

        if (Input.GetButtonDown("Jump") && verificaChao)
        {
            GetComponent <Rigidbody2D>().AddForce(transform.up * forcaPulo);
        }
    }
Example #51
0
    void Update()
    {
        if (RunnerHealth.isInSwitch())
        {
            return;
        }

        runner.layer = powerUpState ["Shield"] ? LayerMask.NameToLayer("Invincible") :  LayerMask.NameToLayer("Default");

        if (powerUpState ["SlowDown"])
        {
            currentRunner.speed = defaultRunnerSpeed * 0.5f;
        }
        else if (powerUpState ["SpeedUp"])
        {
            currentRunner.speed = defaultRunnerSpeed * 2.0f;
        }
        else
        {
            currentRunner.speed = defaultRunnerSpeed;
        }

        if (powerUpState ["JumpHigh"])
        {
            currentRunner.jumpPower = defaultJumpPower * 2;
        }
        else
        {
            currentRunner.jumpPower = defaultJumpPower;
        }


        CannonControl.freeze = powerUpState ["FreezeCannon"];
    }
Example #52
0
 private void Start()
 {
     rb              = GetComponent <Rigidbody>();
     enemyGun        = FindObjectOfType <EnemyGun>();
     playerLayerMask = LayerMask.GetMask("Player");
 }
Example #53
0
    void Update()
    {
        //Casts a line between our ground checker gameobject and our player
        //If the floor is between us and the groundchecker, this makes "isGrounded" true
        if (Physics2D.Linecast(transform.position, groundChecker.position, 1 << LayerMask.NameToLayer("Platform")) || Physics2D.Linecast(transform.position, groundChecker.position, 1 << LayerMask.NameToLayer("PlayerWall")))
        {
            isGrounded = true;
        }
        else
        {
            isGrounded = false;
        }

        if (flungInAir && gameManager.GetComponent <GameManager>().playerFlung)
        {
            StartCoroutine(waitForFling());
        }
        if (isGrounded && !flungInAir && gameManager.GetComponent <GameManager>().playerFlung)
        {
            inControl = true;
            gameManager.GetComponent <GameManager>().playerFlung = false;
        }
        //If our player hit the jump key, then it's true that we jumped!
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            playerJumped  = true;      //Our player jumped!
            playerJumping = true;      //Our player is jumping!
            jumpTimer     = Time.time; //Set the time at which we jumped
        }

        //If our player lets go of the Jump button OR if our jump was held down to the maximum amount...
        if (Input.GetButtonUp("Jump") || Time.time - jumpTimer > maxExtraJumpTime)
        {
            playerJumping = false; //... then set PlayerJumping to false
        }

        //If our player hit a horizontal key...
        if (Input.GetButtonDown("Horizontal"))
        {
            sprintTimer        = Time.time; //.. reset the sprintTimer variable
            jumpedDuringSprint = false;     //... change Jumped During Sprint to false, as we lost momentum
        }
    }
 public static bool GetGroundInfo(Vector3 startPos, out RaycastHit hit, Transform ignoreTransform = null)
 {
     return(TransformUtil.GetGroundInfo(startPos, out hit, 100f, LayerMask.op_Implicit(-1), ignoreTransform));
 }
Example #55
0
    // Update is called once per frame
    void Update()
    {
        if (alvo == null)
        {
            alvo = GameObject.Find("Player");
            return;
        }
        else
        {
            rdbp = alvo.transform.GetComponentsInParent <Rigidbody2D>()[0];
            rdba = alvo.transform.GetComponent <Rigidbody2D>();
        }
        Ray2D[] rays     = new Ray2D[4];
        Vector2 position = transform.position;

        /*Ray down*/
        rays[0] = new Ray2D(position, Vector2.down);
        /*Ray up*/
        rays[1] = new Ray2D(position, Vector2.up);
        /*Ray left*/
        rays[2] = new Ray2D(position, Vector2.left);
        /*Ray right*/
        rays[3] = new Ray2D(position, Vector2.right);

        /* for (int i = 0; i < 4; i++) {
         *   RaycastHit2D hit = Physics2D.Raycast(rays[i].origin, rays[i].origin,xMaxDistance);
         *   if (hit.collider != null && !hit.collider.gameObject.name.Contains("Player")) {
         *       Debug.Log("Colidiu: "+hit.collider.gameObject.name);
         *   }
         * }*/
        //maxdown = maxup = maxleft = maxright = false;

        int mask = LayerMask.GetMask("Camera");


        //Debug.Log("Layer: "+ LayerMask.NameToLayer("Camera"));
        RaycastHit2D hit = Physics2D.Raycast(rays[0].origin, rays[0].direction, yMaxDistance, mask);

        if (hit.collider != null && hit.collider.gameObject.tag.Equals("CameraLimit"))
        {
            maxdown = true;
            Debug.DrawRay(rays[0].origin, rays[0].direction, Color.blue, yMaxDistance);
        }
        else
        {
            maxdown = false;
        }

        RaycastHit2D hit1 = Physics2D.Raycast(rays[1].origin, rays[1].direction, yMaxDistance, mask);

        if (hit1.collider != null && hit1.collider.gameObject.tag.Equals("CameraLimit"))
        {
            maxup = true;
            Debug.DrawRay(rays[1].origin, rays[1].direction, Color.yellow, yMaxDistance);
        }
        else
        {
            maxup = false;
        }

        RaycastHit2D hit2 = Physics2D.Raycast(rays[2].origin, rays[2].direction, xMaxDistance, mask);

        if (hit2.collider != null && hit2.collider.gameObject.tag.Equals("CameraLimit"))
        {
            maxleft = true;
            Debug.DrawRay(rays[2].origin, rays[2].direction, Color.red, -xMaxDistance);
        }
        else
        {
            maxleft = false;
        }

        RaycastHit2D hit3 = Physics2D.Raycast(rays[3].origin, rays[3].direction, xMaxDistance, mask);

        if (hit3.collider != null && hit3.collider.gameObject.tag.Equals("CameraLimit"))
        {
            maxright = true;

            Debug.DrawRay(rays[3].origin, rays[3].direction, Color.green, xMaxDistance);
        }
        else
        {
            maxright = false;
        }



        rdb        = rdbp != null?rdbp:rdba;
        posJogador = alvo.transform.position;

        float osx = transform.position.x; // = offsetX * (rdb.velocity.y >= 0 ? 0.3f : -0.3f);
        float osy = transform.position.y;
        float x;                          //=transform.position.x;

        //Debug.Log(rdb.velocity.y);

        if (rdb.velocity.x > 0.01f && rdb.position.x > transform.position.x && !maxright)
        {
            osx = Mathf.Lerp(transform.position.x, posJogador.x, Time.deltaTime * .5f);
            //osx = rdb.position.x;
        }
        if (rdb.velocity.x < -0.01f && rdb.position.x < transform.position.x && !maxleft)
        {
            osx = Mathf.Lerp(transform.position.x, posJogador.x, Time.deltaTime * .5f);
            //osx = rdb.position.x;
        }
        if (rdb.velocity.y < -0.01f && rdb.position.y < transform.position.y && !maxdown)
        {
            osy = Mathf.Lerp(transform.position.y, posJogador.y, Time.deltaTime * .5f);
            //osy = rdb.position.y;
        }
        if (rdb.velocity.y > 0.01f && rdb.position.y > transform.position.y && !maxup)
        {
            osy = Mathf.Lerp(transform.position.y, posJogador.y, Time.deltaTime * .5f);
            //osy = rdb.position.y;
        }

        float   y    = Mathf.Lerp(transform.position.y, posJogador.y + offsetY, Time.deltaTime * 10);
        float   z    = Mathf.Lerp(transform.position.z, transform.position.z, Time.deltaTime * 10);
        Vector3 fpos = new Vector3(osx, osy, z);

        transform.position = fpos;        //marcadorCamera [indice].transform.position;
        if (canCloseUp)
        {
            //Debug.Log (CameraSize+" : "+targetSize);
            Camera.main.orthographicSize = Mathf.Lerp(CameraSize, targetSize, Time.time * .02f);
            //Debug.Log (Camera.main.orthographicSize);
            if (Camera.main.orthographicSize < targetSize + .30f)
            {
                canCloseUp = false;
            }
        }
    }
Example #56
0
    public RaycastHit GetRaycastHit()
    {
        RaycastHit hit;

        Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f, LayerMask.GetMask("Raycastable"));
        return(hit);
    }
    public void AttackTarget()
    {
        if (!Stats.alive)
        {
            return;
        }

        PlayAttackSound();

        if (Attack is HandCombat)
        {
            ((HandCombat)Attack).ExecuteAttack(this, Target);
        }
        else if (Attack is MagicSpell)
        {
            ((MagicSpell)Attack).Cast(this, SpellHotspot.position, Target.transform.position, LayerMask.NameToLayer("Magic"));
        }
        else if (Attack is MagicStomp)
        {
            ((MagicStomp)Attack).Execute(this, gameObject.transform.position, LayerMask.NameToLayer("Magic"));
        }
    }
Example #58
0
    void CheckLeft()
    {
        moveToLeft = true;

        RaycastHit hitLeft;
        bool       isHitLeft = Physics.BoxCast(transform.position + new Vector3(0, 0.2f, 0), new Vector3(0.1f, 0.2f, 0.5f), -body.right, out hitLeft, body.rotation, 1, LayerMask.GetMask("ground"));

        leftDis = hitLeft.distance;
        if (isHitLeft && hitLeft.distance < 0.6f)
        {
            moveToLeft = false;
        }
        else
        {
            bool isClosedGround = groundDct.isClosedGround && groundDct.disGround < 0.2f;
            //判断斜率,超过最大则不能移动
            if (isClosedGround && groundDct.midNormal.x > 0 && groundDct.slope > GameManager.Instance.Player.maxFrictionSlope)
            {
                moveToLeft = false;
            }
            //向右滑时不能向左移动
            if (role.slideProc.isSliding && groundDct.midNormal.x > 0)
            {
                moveToLeft = false;
            }
        }


        if (isDebug && isHitLeft)
        {
            Debug.DrawLine(transform.position + new Vector3(0, 0.1f, 0), hitLeft.point, Color.yellow);
        }
    }
Example #59
0
    protected override void MultiSelect()
    {
        DeselectAll();
        SelectBox.Disable();
        Vector3 groundClickedPosition = WorldTouchPoint(Camera.main.ScreenToWorldPoint(clickedPosition));
        Vector3 groundMousePosition   = WorldTouchPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
        float   distance = Mathf.Abs(groundMousePosition.x - groundClickedPosition.x);
        float   xMin     = Mathf.Min(groundMousePosition.x, groundClickedPosition.x);
        float   zMin     = Mathf.Min(groundMousePosition.z, groundClickedPosition.z);
        float   zMax     = Mathf.Max(groundMousePosition.z, groundClickedPosition.z);

        RaycastHit[] hits = Physics.CapsuleCastAll(new Vector3(xMin, 0f, zMin), new Vector3(xMin, 0f, zMax), 0.1f, Vector3.right, distance, LayerMask.GetMask(new string[] { player.species.ToString() }));
        foreach (RaycastHit hit in hits)
        {
            Unit unit = hit.collider.gameObject.GetComponent <Unit> ();
            if (unit)
            {
                SelectWorldOject(unit as WorldObject);
            }
        }
    }
Example #60
0
 private void Start()
 {
     buttonMask = LayerMask.GetMask("BUTTON");
     hand       = GameObject.Find("Controller (left)").GetComponent <SteamVR_Behaviour_Pose>();
     StartCoroutine(UIButtonCheck());
 }