Esempio n. 1
1
		protected override void SetPolygon ()
		{
			if (eyeShape == null)
				throw new System.ArgumentNullException ("The irises needs its eyes");

			Vector2 centerLeft = (eyeShape [1] + eyeShape [4]) * 0.5f;
			float widthLeft = Mathf.Min (Mathf.Min (eyeShape [0].x - eyeShape [2].x, eyeShape [5].x - eyeShape [3].x) * maxEyeHalfWidthIris,
				                  (eyeShape [4].y - eyeShape [1].y) * sougthAspectRatio);
			
			Vector2 centerRight = (eyeShape [11] + eyeShape [8]) * 0.5f;
			float widthRight = Mathf.Min (Mathf.Min (eyeShape [10].x - eyeShape [6].x, eyeShape[9].x - eyeShape [7].x) * maxEyeHalfWidthIris,
				(eyeShape [8].y - eyeShape [11].y) * sougthAspectRatio);

			polygon = new Vector2[8] {
				eyeShape [1],
				centerLeft + Vector2.left * widthLeft / 2f,
				eyeShape [4],
				centerLeft + Vector2.right * widthLeft / 2f,

				eyeShape [11],
				centerRight + Vector2.left * widthRight /2f,
				eyeShape [8],
				centerRight + Vector2.right * widthRight /2f
			};

			if (noise > 0)
				ApplyNoise ();
				
		}
Esempio n. 2
1
	void OnGUI()
	{
		if (!inited) Init();
		UniRPGEdGui.UseSkin();
		scroll = GUILayout.BeginScrollView(scroll);
		{
			sel = GUILayout.SelectionGrid(sel, keys, 6);
			if (sel != prev)
			{
				lostFocus = true;
				System.Array arr = System.Enum.GetValues(typeof(KeyCode));
				foreach (KeyCode k in arr)
				{
					if (k.ToString().Equals(keys[sel]))
					{
						if (forPrimary) def.primaryButton = k;
						else def.secondaryButton = k;
						break;
					}
				}
			}
		}
		GUILayout.EndScrollView();
		UniRPGEdGui.DrawHorizontalLine(1, UniRPGEdGui.DividerColor, 0, 10);

		EditorGUILayout.BeginHorizontal();
		{
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Cancel", UniRPGEdGui.ButtonStyle)) this.Close();
			GUILayout.FlexibleSpace();
		}
		EditorGUILayout.EndHorizontal();
		GUILayout.Space(10);
	}
Esempio n. 3
1
 public static Vector2 PointOnCircle(Vector2 midpoint, float radius, float angle)
 {
     return new Vector2(
         Mathf.Cos(angle),
         Mathf.Sin(angle)
     ) * radius + midpoint;
 }
Esempio n. 4
1
 public void Push(Vector2 value)
 {
     values.Add(new Value() {
     type  = "vector2",
     value = value.AsString()
     });
 }
				public State(RectTransform rect) {

					this.anchorMin = rect.anchorMin;
					this.anchorMax = rect.anchorMax;
					this.to = rect.anchoredPosition;

				}
Esempio n. 6
1
        public void OnMouseDown()
        {
            if (!IsInteractive) return;

            _objectScreenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
            _isDragging = true;
        }
 // Calculate the initial velocity for this PrincipalProjectile that results in
 // hitting the given target position (in principal space) at the given time.
 // Implements Equation 21 and 22 from the paper.
 public Vector2 GetInitialVelocityGivenRelativeTargetAndTime(
     Vector2 relativeTargetPosition, float timeToTarget)
 {
     Vector2 v0 = relativeTargetPosition * (k + 1 / timeToTarget);
     v0.y += k * vInfinity * timeToTarget;
     return v0;
 }
Esempio n. 8
1
        // Use this for initialization
        public static Mesh FileToMesh(string filePath)
        {
            meshStruct newMesh = createMeshStruct(filePath);
            populateMeshStruct(ref newMesh);

            Vector3[] newVerts = new Vector3[newMesh.faceData.Length];
            Vector2[] newUVs = new Vector2[newMesh.faceData.Length];
            Vector3[] newNormals = new Vector3[newMesh.faceData.Length];
            int i = 0;
            /* The following foreach loops through the facedata and assigns the appropriate vertex, uv, or normal
             * for the appropriate Unity mesh array.
             */
            foreach (Vector3 v in newMesh.faceData)
            {
                newVerts[i] = newMesh.vertices[(int)v.x - 1];
                if (v.y >= 1)
                    newUVs[i] = newMesh.uv[(int)v.y - 1];

                if (v.z >= 1)
                    newNormals[i] = newMesh.normals[(int)v.z - 1];
                i++;
            }

            Mesh mesh = new Mesh();

            mesh.vertices = newVerts;
            mesh.uv = newUVs;
            mesh.normals = newNormals;
            mesh.triangles = newMesh.triangles;

            mesh.RecalculateBounds();
            mesh.Optimize();

            return mesh;
        }
Esempio n. 9
1
            public ControlNode(Vector2i pos, float[,] map, Vector2 position, float size)
                : base(position)
            {
                Active = map[pos.x, pos.y];

                if (pos.x == map.GetLength(0))
                {
                    Right = new Node(position + Vector2.right * size * 0.5f);
                }
                else
                {
                    Right = new Node(position + Vector2.right * size * 0.5f);
                }

                if (pos.y == map.GetLength(1))
                {
                    Up = new Node(position + Vector2.up * size * 0.5f);
                }
                else
                {
                    Up = new Node(position + Vector2.up * size * 0.5f);
                }

                //float right = pos.x <  ? map[pos.x + 1, pos.y] : Active;
                //float up = map[pos.x, pos.y + 1];
            }
Esempio n. 10
1
		public float Get2D(Vector2 position)
		{
			MathS.Lerp(x0, x1, position.x);

			MathS.Lerp(y0, y1, position.y);
			return 0f;
		}
        /// <summary>
        /// Implementation of Besenham's line algorithm:
        /// http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Simplification
        /// </summary>
        public void DrawLine(Vector2 p1, Vector2 p2, Color color)
        {
            int dx = Mathf.Abs((int) (p1.x - p2.x));
            int dy = Mathf.Abs((int) (p1.y - p2.y));
            int sx = (p1.x < p2.x) ? 1 : -1;
            int sy = (p1.y < p2.y) ? 1 : -1;
            int err = dx - dy;
            int err2;

            while (true)
            {
              content.SetPixel((int) p1.x, (int) p1.y, color);
              if (p1.x == p2.x && p1.y == p2.y) break;
              err2 = err << 1;
              if (err2 > -dy)
              {
            err -= dy;
            p1.x += sx;
              }

              if (err2 < dx)
              {
            err += dx;
            p1.y += sy;
              }
            }
        }
        public void Render()
        {
            Sprite sprite = sourceSprite;
            Rect rect = sprite.textureRect;

            float iw = 1f / sprite.texture.width;
            float ih = 1f / sprite.texture.height;

            var srcPixel = new Vector2(iw, ih);
            var dstPixel = new Vector2(1f / texture.width, 1f / texture.height);

            material.SetVector("_SpriteUV",
                               new Vector4(rect.xMin * iw,
                                           rect.yMin * ih,
                                           rect.xMax * iw,
                                           rect.yMax * ih));

            material.SetVector("_DstPixel", dstPixel);
            material.SetVector("_SrcPixel", srcPixel);
            material.SetVector("_Scale", new Vector2(texture.width  / rect.width,
                                                     texture.height / rect.height));

            image.uvRect = Rect.MinMaxRect(0, 
                                           0, 
                                           (rect.width  + size * 2) / texture.width, 
                                           (rect.height + size * 2) / texture.height);
            image.SetNativeSize();

            Graphics.Blit(sprite.texture, texture, material);
        }
Esempio n. 13
1
		protected virtual void MultiPassBlur(RenderTexture source, RenderTexture destination)
		{
			int w = Mathf.FloorToInt((float)source.width / Downscaling);
			int h = Mathf.FloorToInt((float)source.height / Downscaling);
			Vector2 horizontal = new Vector2(1f / w, 0f);
			Vector2 vertical = new Vector2(0f, 1f / h);
			RenderTexture rt1 = RenderTexture.GetTemporary(w, h, 0, source.format);
			RenderTexture rt2 = RenderTexture.GetTemporary(w, h, 0, source.format);

			Material.SetVector("_Direction", horizontal);
			Graphics.Blit(source, rt1, Material);
			Material.SetVector("_Direction", vertical);
			Graphics.Blit(rt1, rt2, Material);

			for (int i = 1; i < Passes; i++)
			{
				Material.SetVector("_Direction", horizontal);
				Graphics.Blit(rt2, rt1, Material);
				Material.SetVector("_Direction", vertical);
				Graphics.Blit(rt1, rt2, Material);
			}

			Graphics.Blit(rt2, destination);

			RenderTexture.ReleaseTemporary(rt1);
			RenderTexture.ReleaseTemporary(rt2);
		}
Esempio n. 14
1
        protected override void InstantiatePlayers()
        {
            // Hardcoded spawn metrics
            Vector2 spawnRange = new Vector2(-11, 9);
            float spawnLength = spawnRange.y - spawnRange.x;
            float spawnStep = spawnLength / (Manager.Player.Instance.Get().Count * 2);
            float lastSpawn = spawnRange.x;

            foreach (Player.Wrapper p  in Manager.Player.Instance.Get())
            {
                lastSpawn += spawnStep;

                int id = p.GetPuppet().GetIdentifier();

                // Instantiate player
                GameObject newPlayer = ( GameObject )Instantiate( m_puppetPrefabs[ id ] );
                newPlayer.AddComponent<SweetRain.PlayerController>();

                m_playerInstances.Add( newPlayer );

                // Set positoin
                newPlayer.transform.position = new Vector3(lastSpawn, 0, 0);

                // Add player as a child
                newPlayer.transform.parent = this.transform;

                // Subscribe to each player
                newPlayer.GetComponent<PlayerController>().Subscribe(this);
            }
        }
Esempio n. 15
1
        public override void AddPoint(Vector2 touchPos)
        {
            lineRendererPoints.Add(ConvertPointPos(touchPos));

            lineRenderer.SetVertexCount(lineRendererPoints.Count);
            lineRenderer.SetPositions(lineRendererPoints.ToArray());
        }
 private void SpawnFish(RepetitionTimer t)
 {
     Bounds b = GameManager.instance.field.GetComponent<Collider2D>().bounds;
     Vector2 pos = new Vector2(Random.Range(b.min.x, b.max.x), Random.Range(b.min.y, b.max.y));
     GameObject fish = (GameObject)Instantiate(fishPrefab, pos, Quaternion.identity);
     fish.GetComponent<Fish>().Game = this;
 }
Esempio n. 17
1
 public static Vector2 Rotate(Vector2 point, float angle)
 {
     var rad = angle*Mathf.Deg2Rad;
     var cos = Mathf.Cos(rad);
     var sin = Mathf.Sin(rad);
     return new Vector2(point.x * cos - point.y * sin, point.x * sin + point.y * cos);
 }
		public void LateUpdate() {

			if (this.duration <= 0f) return;

			var step = Vector2.zero;
			
			if (this.direction == Slider.Direction.BottomToTop) {
				
				step = Vector2.up;
				
			} else if (this.direction == Slider.Direction.TopToBottom) {
				
				step = -Vector2.up;
				
			} else if (this.direction == Slider.Direction.LeftToRight) {
				
				step = Vector2.right;
				
			} else if (this.direction == Slider.Direction.RightToLeft) {
				
				step = -Vector2.right;
				
			}

			this.offset += step * Time.deltaTime / this.duration;
			if (this.offset.x < 0f) this.offset.x += 1f;
			if (this.offset.x > 1f) this.offset.x -= 1f;
			if (this.offset.y < 0f) this.offset.y += 1f;
			if (this.offset.y > 1f) this.offset.y -= 1f;

			this.rectTransform.sizeDelta = new Vector2(this.size.x * Mathf.Abs(step.x) * 2f, this.size.y * Mathf.Abs(step.y) * 2f);
			this.rectTransform.anchoredPosition = new Vector2(this.offset.x * this.size.x, this.offset.y * this.size.y);

		}
Esempio n. 19
1
	public override void OnGUI(Object actionObj)
	{
		StateChangeAction action = actionObj as StateChangeAction;
		if (action == null) { GUILayout.Label("Error: Delete this Action."); return; }

		EditorGUILayout.BeginHorizontal();
		{
			action.setState = (0 == EditorGUILayout.Popup((action.setState ? 0 : 1), options));
			UniRPGEdGui.TargetTypeField(this.ed, "on", action.subject, TargetTypeHelp);
			GUILayout.FlexibleSpace();
		}
		EditorGUILayout.EndHorizontal();
		GUILayout.Space(15);

		scroll = UniRPGEdGui.BeginScrollView(scroll, UniRPGEdGui.ScrollViewNoTLMarginStyle, GUILayout.Height(200));
		for (int i = 0; i < UniRPGEditorGlobal.DB.states.Count; i++)
		{
			if (UniRPGEdGui.ToggleButton(UniRPGEditorGlobal.DB.states[i] == action.state, UniRPGEditorGlobal.DB.states[i].screenName, EditorStyles.miniButton, UniRPGEdGui.ButtonOnColor, GUILayout.Width(270)))
			{
				action.state = UniRPGEditorGlobal.DB.states[i];
			}
		}
		UniRPGEdGui.EndScrollView();
		showAcceptButton = (action.state != null);
	}
		void FixedUpdate () {
			float moveX = Input.GetAxis("Horizontal");
			float moveY = Input.GetAxis("Vertical");
			
			attacking = Input.GetButton("Fire1");
			animator.SetBool("Attack", attacking);

			var sprintPressed = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
			var targetSpeed = maxSpeed;
			if (attacking) {
				targetSpeed *= attackMoveSpeedMultiplier;
			}
			else if (sprintPressed) {
				targetSpeed *= sprintMultiplier;
			}
			var direction = new Vector2(moveX, moveY);
			var directionLength = direction.magnitude;
			if (directionLength > 1) {
				direction /= directionLength;
			}

			var currentSpeed = rigidBody2D.velocity.magnitude;
			var desiredSpeed = Mathf.Lerp(currentSpeed, targetSpeed, movementSensitivity);

			rigidBody2D.velocity = direction * desiredSpeed;
			
			if (moveX > 0 && !facingRight) {
				Flip();
			} else if (moveX < 0 && facingRight) {
				Flip ();
			}

			animator.SetFloat("Speed", rigidBody2D.velocity.magnitude);
		}
Esempio n. 21
1
        public override Vector2[] GetDimData(string dimX, string dimY)
        {
            if (!_dimensions.ContainsKey(dimX))
            {
                GenerateDimension(dimX);
            }

            if (!_dimensions.ContainsKey(dimY))
            {
                GenerateDimension(dimY);
            }

            var x = _dimensions[dimX];
            var y = _dimensions[dimY];

            Debug.Assert(x.Length == y.Length);
            var dimData = new Vector2[x.Length];
            for (int i = 0; i < dimData.Length; i++)
            {
                dimData[i].x = x[i];
                dimData[i].y = y[i];
            }

            return dimData;
        }
Esempio n. 22
1
        void Awake()
        {
            _resizedPanel = (ResizeParent ? transform.parent : transform) as RectTransform;

            var maximalSizeMargin = 10;
            _maximalSize = new Vector2(Screen.width - maximalSizeMargin, Screen.height - maximalSizeMargin);
        }
Esempio n. 23
0
 public PFCell(CellType type, int col, int row)
 {
     this.type = type;
     this.row = row;
     this.col = col;
     this.center = new Vector2((col + 0.5f) * GameConst.UNITS_PER_CELL, (row + 0.5f) * GameConst.UNITS_PER_CELL);
 }
Esempio n. 24
0
 //method used to convert hex grid coordinates to game world coordinates
 public Vector3 calcWorldCoord(Vector2 gridPos)
 {
     Vector3 initPos = calcInitPos();
     float x = initPos.x + gridPos.x * tileWidth;
     float z = initPos.z - gridPos.y * tileHeight;
     return new Vector3(x, 0, z);
 }
Esempio n. 25
0
File: Play.cs Progetto: gdgeek/fly
 public Vector3 touch(Vector2 position)
 {
     Ray ray = _camera.ScreenPointToRay (position);
     float dist = 0;
     sky_.Raycast (ray, out dist);
     return ray.GetPoint (dist);
 }
Esempio n. 26
0
 public Tap(Vector2 position, float startTime)
     : base(GestureType.TAP)
 {
     this.position = position;
     this.startTime = startTime;
     EndTime = startTime;
 }
Esempio n. 27
0
 public Vertex addVertex(Vector3 vert, Vector3 norm, Vector2 uv)
 {
     Vertex vertex = new Vertex(vert, norm, uv, vertexNumber);
     vertexNumber++;
     vertices.Add(vertex);
     return vertex;
 }
 public static Vector2 GetPushBackDirectionNormal(this Collision2D col)
 {
     var contactPoint = col.contacts[0].point;
       var center = col.collider.bounds.center;
       var normal = new Vector2(contactPoint.x - center.x, contactPoint.y - center.y).normalized;
       return normal;
 }
				public State(State source) {

					this.anchorMin = source.anchorMin;
					this.anchorMax = source.anchorMax;
					this.to = source.to;

				}
Esempio n. 30
0
        public void Draw(int id)
        {
            if (GUI.Button(closeButton, "Close"))
                showWindow = false;
            Rect r = new Rect(0, 0, usersRect.width, 25f * Users.Length);
            GUI.Box(usersRect, "");
            scrolpos = GUI.BeginScrollView(usersRect, scrolpos, r);
            int old = selectedUser;
            selectedUser = GUI.SelectionGrid(r, selectedUser, Users, 1);
            if (old != selectedUser)
            {
                OnMessageReceived(Users[selectedUser], "");
            }
            GUI.EndScrollView();

            if (GUI.Button(buttonRect, "Send"))
                if (this == null)
                    Msgs += "connect first" + "\r\n";
                else
                    this.onIrcSend(Input);

            Rect gr = new Rect(0, 0, msgRect.width, msgRect.height);
            GUI.BeginGroup(msgRect);
            GUI.Box(gr, "");
            GUI.TextArea(gr, Msgs, skin.FindStyle("msgs"));
            GUI.EndGroup();
            Input = GUI.TextField(inputRect, Input);
            GUI.DragWindow();
        }
Esempio n. 31
0
 public Unit(Vector2 pos, Player owner, float speed) :
     base(
         pos,
         owner,
         GameConstants.UnitHealth,
         GameConstants.UnitTurnsToAttack,
         GameConstants.UnitRange,
         GameConstants.UnitDamage
         )
 {
     this.speed = speed;
     OnDeath   += () =>
     {
         if (Game.UnitBlockedPositions.Contains(blockingPos - areaRangeDelta))
         {
             Game.UnitBlockedPositions.Remove(blockingPos - areaRangeDelta);
         }
         if (Game.UnitPositionQueues.ContainsKey(blockingPos) && Game.UnitPositionQueues[blockingPos].Contains(this))
         {
             Game.UnitPositionQueues[blockingPos] = new Queue <Unit>(Game.UnitPositionQueues[blockingPos].Except(new[] { this }));
         }
     };
 }
Esempio n. 32
0
    public static void makeSphere(int N, double jitter, int seed, out DualMesh mesh, out List <double> d)
    {
        var latlong = generateFibonacciSphere(N, jitter, seed);
        //DebugHelper.SaveArray("generateFibonacciSphere.txt", latlong);
        var r_xyz = new List <double>();

        for (var r = 0; r < latlong.Count / 2; r++)
        {
            pushCartesianFromSpherical(r_xyz, latlong[2 * r], latlong[2 * r + 1]);
        }

        var r_xy = stereographicProjection(r_xyz);
        //DebugHelper.SaveArray("stereographicProjection.txt", r_xy);
        var delaunay = new Delaunator(r_xy.ToArray());

        /* TODO: rotate an existing point into this spot instead of creating one */
        r_xyz.AddRange(new double[] { 0, 0, 1 });
        addSouthPoleToMesh(r_xyz.Count / 3 - 1, delaunay);

        var dummy_r_vertex = new Float2[N + 1];

        dummy_r_vertex[0] = new Float2(0, 0);
        for (var i = 1; i < N + 1; i++)
        {
            dummy_r_vertex[i] = dummy_r_vertex[0];
        }

        mesh = new DualMesh(new Graph()
        {
            numBoundaryRegions = 0,
            numSolidSides      = delaunay.triangles.Length,
            _r_vertex          = dummy_r_vertex,
            _triangles         = delaunay.triangles,
            _halfedges         = delaunay.halfedges,
        });
        d = r_xyz;
    }
    static int UguiSizeDelta(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 11);
            UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.GameObject));
            System.Nullable <UnityEngine.Vector2> arg1 = (System.Nullable <UnityEngine.Vector2>)ToLua.CheckVarObject(L, 2, typeof(System.Nullable <UnityEngine.Vector2>));
            UnityEngine.Vector2 arg2 = (UnityEngine.Vector2)ToLua.CheckObject(L, 3, typeof(UnityEngine.Vector2));
            float        arg3        = (float)LuaDLL.luaL_checknumber(L, 4);
            float        arg4        = (float)LuaDLL.luaL_checknumber(L, 5);
            InterpType   arg5        = (InterpType)ToLua.CheckObject(L, 6, typeof(InterpType));
            bool         arg6        = LuaDLL.luaL_checkboolean(L, 7);
            RepeatType   arg7        = (RepeatType)ToLua.CheckObject(L, 8, typeof(RepeatType));
            int          arg8        = (int)LuaDLL.luaL_checknumber(L, 9);
            AnimCallBack arg9        = null;
            LuaTypes     funcType10  = LuaDLL.lua_type(L, 10);

            if (funcType10 != LuaTypes.LUA_TFUNCTION)
            {
                arg9 = (AnimCallBack)ToLua.CheckObject(L, 10, typeof(AnimCallBack));
            }
            else
            {
                LuaFunction func = ToLua.ToLuaFunction(L, 10);
                arg9 = DelegateFactory.CreateDelegate(typeof(AnimCallBack), func) as AnimCallBack;
            }

            object[] arg10 = ToLua.CheckObjectArray(L, 11);
            AnimData o     = AnimSystem.UguiSizeDelta(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
            ToLua.PushObject(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    public void DefenceUpdate(SubsystemReferences subsystemReferences, TurretControls turretControls)
    {
        Vector2 ship = subsystemReferences.currentShipPositionWithinGalaxyMapNode;

        List <DetectedCloseObject> objs = subsystemReferences.Sensors.detectedCloseObjects;

        objs.Sort((a, b) => (int)((a.position - ship).sqrMagnitude - (b.position - ship).sqrMagnitude) * 1000);
        objs = objs.Where(a => shouldShot(a)).ToList();

        if (objs.Count < 1)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[0], ship);
        turretControls.FireTube0();

        if (objs.Count < 2)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[1], ship);
        turretControls.FireTube1();

        if (objs.Count < 3)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[2], ship);
        turretControls.FireTube2();

        if (objs.Count < 4)
        {
            return;
        }
        turretControls.aimTo = getAimTo(objs[3], ship);
        turretControls.FireTube3();
    }
Esempio n. 35
0
 void FinentEvent(UnityEngine.Vector2 start, bool active)
 {
     try
     {
         if (active)
         {
             if (isUp || isSkillWant)
             {
                 isUp    = false;
                 OKAlpha = false;
                 time    = 0.0f;
                 UISprite us = this.gameObject.GetComponent <UISprite>();
                 if (us != null)
                 {
                     UIManager.SkillDrectorColor = new UnityEngine.Color(255, 255, 255);
                     us.color = new UnityEngine.Color(255, 255, 255);
                 }
                 UnityEngine.Vector3 pos = UICamera.mainCamera.ScreenToWorldPoint(new UnityEngine.Vector3(start.x, start.y, 0));
                 this.transform.position = pos;
                 //NGUITools.SetActive(gameObject.transform.parent.gameObject, true);
                 UIManager.Instance.ShowWindowByName("TouchCircle");
             }
         }
         else
         {
             isUp    = true;
             OKAlpha = true;
             time    = 0.0f;
             //NGUITools.SetActive(gameObject, false);
         }
     }
     catch (Exception ex)
     {
         ArkCrossEngine.LogicSystem.LogFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace);
     }
 }
Esempio n. 36
0
            /** Gradient and value of the cost function of this VO.
             * The VO has a cost function which is 0 outside the VO
             * and increases inside it as the point moves further into
             * the VO.
             *
             * This is the negative gradient of that function as well as its
             * value (the weight). The negative gradient points in the direction
             * where the function decreases the fastest.
             *
             * The value of the function is the distance to the closest edge
             * of the VO and the gradient is normalized.
             */
            public Vector2 Gradient(Vector2 p, out float weight)
            {
                if (colliding)
                {
                    // Calculate double signed area of the triangle consisting of the points
                    // {line1, line1+dir1, p}
                    float l1 = SignedDistanceFromLine(line1, dir1, p);

                    // Serves as a check for which side of the line the point p is
                    if (l1 >= 0)
                    {
                        weight = l1;
                        return(new Vector2(-dir1.y, dir1.x));
                    }
                    else
                    {
                        weight = 0;
                        return(new Vector2(0, 0));
                    }
                }

                float det3 = SignedDistanceFromLine(cutoffLine, cutoffDir, p);

                if (det3 <= 0)
                {
                    weight = 0;
                    return(Vector2.zero);
                }
                else
                {
                    // Signed distances to the two edges along the sides of the VO
                    float det1 = SignedDistanceFromLine(line1, dir1, p);
                    float det2 = SignedDistanceFromLine(line2, dir2, p);
                    if (det1 >= 0 && det2 >= 0)
                    {
                        // We are inside both of the half planes
                        // (all three if we count the cutoff line)
                        // and thus inside the forbidden region in velocity space

                        // Actually the negative gradient because we want the
                        // direction where it slopes the most downwards, not upwards
                        Vector2 gradient;

                        // Check if we are in the semicircle region near the cap of the VO
                        if (Vector2.Dot(p - line1, dir1) > 0 && Vector2.Dot(p - line2, dir2) < 0)
                        {
                            if (segment)
                            {
                                // This part will only be reached for line obstacles (i.e not other agents)
                                if (det3 < radius)
                                {
                                    PF.Vector3 closestPointOnLine = VectorMath.ClosestPointOnSegment(segmentStart.ToPFV2(), segmentEnd.ToPFV2(), p.ToPFV2());
                                    var        dirFromCenter      = p.ToPFV2() - closestPointOnLine.ToV2();
                                    float      distToCenter;
                                    gradient = VectorMath.Normalize(dirFromCenter, out distToCenter);
                                    // The weight is the distance to the edge
                                    weight = radius - distToCenter;
                                    return(gradient);
                                }
                            }
                            else
                            {
                                var   dirFromCenter = p - circleCenter;
                                float distToCenter;
                                gradient = VectorMath.Normalize(dirFromCenter, out distToCenter);
                                // The weight is the distance to the edge
                                weight = radius - distToCenter;
                                return(gradient);
                            }
                        }

                        if (segment && det3 < det1 && det3 < det2)
                        {
                            weight   = det3;
                            gradient = new Vector2(-cutoffDir.y, cutoffDir.x);
                            return(gradient);
                        }

                        // Just move towards the closest edge
                        // The weight is the distance to the edge
                        if (det1 < det2)
                        {
                            weight   = det1;
                            gradient = new Vector2(-dir1.y, dir1.x);
                        }
                        else
                        {
                            weight   = det2;
                            gradient = new Vector2(-dir2.y, dir2.x);
                        }

                        return(gradient);
                    }

                    weight = 0;
                    return(Vector2.zero);
                }
            }
Esempio n. 37
0
        void GenerateNeighbourAgentVOs(VOBuffer vos)
        {
            float inverseAgentTimeHorizon = 1.0f / agentTimeHorizon;

            // The RVO algorithm assumes we will continue to
            // move in roughly the same direction
            Vector2 optimalVelocity = currentVelocity;

            for (int o = 0; o < neighbours.Count; o++)
            {
                Agent other = neighbours[o];

                // Don't avoid ourselves
                if (other == this)
                {
                    continue;
                }

                // Interval along the y axis in which the agents overlap
                float maxY = System.Math.Min(elevationCoordinate + height, other.elevationCoordinate + other.height);
                float minY = System.Math.Max(elevationCoordinate, other.elevationCoordinate);

                // The agents cannot collide since they are on different y-levels
                if (maxY - minY < 0)
                {
                    continue;
                }

                float totalRadius = radius + other.radius;

                // Describes a circle on the border of the VO
                Vector2 voBoundingOrigin = other.position - position;

                float avoidanceStrength;
                if (other.locked || other.manuallyControlled)
                {
                    avoidanceStrength = 1;
                }
                else if (other.Priority > 0.00001f || Priority > 0.00001f)
                {
                    avoidanceStrength = other.Priority / (Priority + other.Priority);
                }
                else
                {
                    // Both this agent's priority and the other agent's priority is zero or negative
                    // Assume they have the same priority
                    avoidanceStrength = 0.5f;
                }

                // We assume that the other agent will continue to move with roughly the same velocity if the priorities for the agents are similar.
                // If the other agent has a higher priority than this agent (avoidanceStrength > 0.5) then we will assume it will move more along its
                // desired velocity. This will have the effect of other agents trying to clear a path for where a high priority agent wants to go.
                // If this is not done then even high priority agents can get stuck when it is really crowded and they have had to slow down.
                Vector2 otherOptimalVelocity = Vector2.Lerp(other.currentVelocity, other.desiredVelocity, 2 * avoidanceStrength - 1);

                var voCenter = Vector2.Lerp(optimalVelocity, otherOptimalVelocity, avoidanceStrength);

                vos.Add(new VO(voBoundingOrigin, voCenter, totalRadius, inverseAgentTimeHorizon, 1 / simulator.DeltaTime));
                if (DebugDraw)
                {
                    DrawVO(position + voBoundingOrigin * inverseAgentTimeHorizon + voCenter, totalRadius * inverseAgentTimeHorizon, position + voCenter);
                }
            }
        }
Esempio n. 38
0
    static int _CreateSingleField(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                SingleField obj = new SingleField();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Color)))
            {
                UnityEngine.Color arg0 = (UnityEngine.Color)ToLua.CheckObject(L, 1, typeof(UnityEngine.Color));
                SingleField       obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector3)))
            {
                UnityEngine.Vector3 arg0 = (UnityEngine.Vector3)ToLua.CheckObject(L, 1, typeof(UnityEngine.Vector3));
                SingleField         obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(System.Enum)))
            {
                System.Enum arg0 = (System.Enum)ToLua.CheckObject(L, 1, typeof(System.Enum));
                SingleField obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(System.Collections.Generic.List <string>)))
            {
                System.Collections.Generic.List <string> arg0 = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <string>));
                SingleField obj = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Vector2)))
            {
                UnityEngine.Vector2 arg0 = (UnityEngine.Vector2)ToLua.CheckObject(L, 1, typeof(UnityEngine.Vector2));
                SingleField         obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(string)))
            {
                string      arg0 = ToLua.CheckString(L, 1);
                SingleField obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(float)))
            {
                float       arg0 = (float)LuaDLL.luaL_checknumber(L, 1);
                SingleField obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(bool)))
            {
                bool        arg0 = LuaDLL.luaL_checkboolean(L, 1);
                SingleField obj  = new SingleField(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(FieldType), typeof(string), typeof(string)))
            {
                FieldType   arg0 = (FieldType)ToLua.CheckObject(L, 1, typeof(FieldType));
                string      arg1 = ToLua.CheckString(L, 2);
                string      arg2 = ToLua.CheckString(L, 3);
                SingleField obj  = new SingleField(arg0, arg1, arg2);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: SingleField.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 39
0
 private Map(Bounds2D bounds, Vector2 tileSize, HashSet <Vector2> roadNodes)
 {
     Bounds    = bounds;
     TileSize  = tileSize;
     RoadNodes = roadNodes;
 }
Esempio n. 40
0
    static int To(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Vector4, UnityEngine.Vector4, float>(L, 1))
            {
                UnityEngine.Vector4 arg0 = ToLua.ToVector4(L, 1);
                UnityEngine.Vector4 arg1 = ToLua.ToVector4(L, 2);
                float             arg2   = (float)LuaDLL.lua_tonumber(L, 3);
                FairyGUI.GTweener o      = FairyGUI.GTween.To(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Color, UnityEngine.Color, float>(L, 1))
            {
                UnityEngine.Color arg0 = ToLua.ToColor(L, 1);
                UnityEngine.Color arg1 = ToLua.ToColor(L, 2);
                float             arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                FairyGUI.GTweener o    = FairyGUI.GTween.To(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Vector3, UnityEngine.Vector3, float>(L, 1))
            {
                UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 1);
                UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 2);
                float             arg2   = (float)LuaDLL.lua_tonumber(L, 3);
                FairyGUI.GTweener o      = FairyGUI.GTween.To(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <float, float, float>(L, 1))
            {
                float             arg0 = (float)LuaDLL.lua_tonumber(L, 1);
                float             arg1 = (float)LuaDLL.lua_tonumber(L, 2);
                float             arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                FairyGUI.GTweener o    = FairyGUI.GTween.To(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Vector2, UnityEngine.Vector2, float>(L, 1))
            {
                UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 1);
                UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 2);
                float             arg2   = (float)LuaDLL.lua_tonumber(L, 3);
                FairyGUI.GTweener o      = FairyGUI.GTween.To(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: FairyGUI.GTween.To"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 41
0
    static int Create(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Texture2D), typeof(UnityEngine.Rect), typeof(UnityEngine.Vector2)))
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.ToObject(L, 1);
                UnityEngine.Rect      arg1 = (UnityEngine.Rect)ToLua.ToObject(L, 2);
                UnityEngine.Vector2   arg2 = ToLua.ToVector2(L, 3);
                UnityEngine.Sprite    o    = UnityEngine.Sprite.Create(arg0, arg1, arg2);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Texture2D), typeof(UnityEngine.Rect), typeof(UnityEngine.Vector2), typeof(float)))
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.ToObject(L, 1);
                UnityEngine.Rect      arg1 = (UnityEngine.Rect)ToLua.ToObject(L, 2);
                UnityEngine.Vector2   arg2 = ToLua.ToVector2(L, 3);
                float arg3           = (float)LuaDLL.lua_tonumber(L, 4);
                UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Texture2D), typeof(UnityEngine.Rect), typeof(UnityEngine.Vector2), typeof(float), typeof(uint)))
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.ToObject(L, 1);
                UnityEngine.Rect      arg1 = (UnityEngine.Rect)ToLua.ToObject(L, 2);
                UnityEngine.Vector2   arg2 = ToLua.ToVector2(L, 3);
                float arg3           = (float)LuaDLL.lua_tonumber(L, 4);
                uint  arg4           = (uint)LuaDLL.lua_tonumber(L, 5);
                UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Texture2D), typeof(UnityEngine.Rect), typeof(UnityEngine.Vector2), typeof(float), typeof(uint), typeof(UnityEngine.SpriteMeshType)))
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.ToObject(L, 1);
                UnityEngine.Rect      arg1 = (UnityEngine.Rect)ToLua.ToObject(L, 2);
                UnityEngine.Vector2   arg2 = ToLua.ToVector2(L, 3);
                float arg3 = (float)LuaDLL.lua_tonumber(L, 4);
                uint  arg4 = (uint)LuaDLL.lua_tonumber(L, 5);
                UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.ToObject(L, 6);
                UnityEngine.Sprite         o    = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 7 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Texture2D), typeof(UnityEngine.Rect), typeof(UnityEngine.Vector2), typeof(float), typeof(uint), typeof(UnityEngine.SpriteMeshType), typeof(UnityEngine.Vector4)))
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.ToObject(L, 1);
                UnityEngine.Rect      arg1 = (UnityEngine.Rect)ToLua.ToObject(L, 2);
                UnityEngine.Vector2   arg2 = ToLua.ToVector2(L, 3);
                float arg3 = (float)LuaDLL.lua_tonumber(L, 4);
                uint  arg4 = (uint)LuaDLL.lua_tonumber(L, 5);
                UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.ToObject(L, 6);
                UnityEngine.Vector4        arg6 = ToLua.ToVector4(L, 7);
                UnityEngine.Sprite         o    = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Sprite.Create"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int DOShakeAnchorPos(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Vector2>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
                DG.Tweening.Tweener o    = obj.DOShakeAnchorPos(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <float>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1            = (float)LuaDLL.lua_tonumber(L, 3);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.Vector2, int>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
                int arg2 = (int)LuaDLL.lua_tonumber(L, 4);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <float, int>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1            = (float)LuaDLL.lua_tonumber(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <UnityEngine.Vector2, int, float>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                float arg3            = (float)LuaDLL.lua_tonumber(L, 5);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <float, int, float>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1            = (float)LuaDLL.lua_tonumber(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                float arg3            = (float)LuaDLL.lua_tonumber(L, 5);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2, arg3);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes <UnityEngine.Vector2, int, float, bool>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                float arg3            = (float)LuaDLL.lua_tonumber(L, 5);
                bool  arg4            = LuaDLL.lua_toboolean(L, 6);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2, arg3, arg4);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes <float, int, float, bool>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1            = (float)LuaDLL.lua_tonumber(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                float arg3            = (float)LuaDLL.lua_tonumber(L, 5);
                bool  arg4            = LuaDLL.lua_toboolean(L, 6);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2, arg3, arg4);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 7 && TypeChecker.CheckTypes <UnityEngine.Vector2, int, float, bool, bool>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
                UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                float arg3            = (float)LuaDLL.lua_tonumber(L, 5);
                bool  arg4            = LuaDLL.lua_toboolean(L, 6);
                bool  arg5            = LuaDLL.lua_toboolean(L, 7);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 7 && TypeChecker.CheckTypes <float, int, float, bool, bool>(L, 3))
            {
                UnityEngine.RectTransform obj = (UnityEngine.RectTransform)ToLua.CheckObject(L, 1, typeof(UnityEngine.RectTransform));
                float arg0            = (float)LuaDLL.luaL_checknumber(L, 2);
                float arg1            = (float)LuaDLL.lua_tonumber(L, 3);
                int   arg2            = (int)LuaDLL.lua_tonumber(L, 4);
                float arg3            = (float)LuaDLL.lua_tonumber(L, 5);
                bool  arg4            = LuaDLL.lua_toboolean(L, 6);
                bool  arg5            = LuaDLL.lua_toboolean(L, 7);
                DG.Tweening.Tweener o = obj.DOShakeAnchorPos(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.PushObject(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.RectTransform.DOShakeAnchorPos"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
    static int GetRecord(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string)))
            {
                RecordTable obj  = (RecordTable)ToLua.ToObject(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                SingleField o    = obj.GetRecord(arg0);
                ToLua.PushObject(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string), typeof(UnityEngine.Vector2)))
            {
                RecordTable         obj  = (RecordTable)ToLua.ToObject(L, 1);
                string              arg0 = ToLua.ToString(L, 2);
                UnityEngine.Vector2 arg1 = (UnityEngine.Vector2)ToLua.ToObject(L, 3);
                UnityEngine.Vector2 o    = obj.GetRecord(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string), typeof(UnityEngine.Vector3)))
            {
                RecordTable         obj  = (RecordTable)ToLua.ToObject(L, 1);
                string              arg0 = ToLua.ToString(L, 2);
                UnityEngine.Vector3 arg1 = (UnityEngine.Vector3)ToLua.ToObject(L, 3);
                UnityEngine.Vector3 o    = obj.GetRecord(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string), typeof(UnityEngine.Color)))
            {
                RecordTable       obj  = (RecordTable)ToLua.ToObject(L, 1);
                string            arg0 = ToLua.ToString(L, 2);
                UnityEngine.Color arg1 = (UnityEngine.Color)ToLua.ToObject(L, 3);
                UnityEngine.Color o    = obj.GetRecord(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string), typeof(string)))
            {
                RecordTable obj  = (RecordTable)ToLua.ToObject(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                string      arg1 = ToLua.ToString(L, 3);
                string      o    = obj.GetRecord(arg0, arg1);
                LuaDLL.lua_pushstring(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string), typeof(bool)))
            {
                RecordTable obj  = (RecordTable)ToLua.ToObject(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                bool        arg1 = LuaDLL.lua_toboolean(L, 3);
                bool        o    = obj.GetRecord(arg0, arg1);
                LuaDLL.lua_pushboolean(L, o);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(RecordTable), typeof(string), typeof(float)))
            {
                RecordTable obj  = (RecordTable)ToLua.ToObject(L, 1);
                string      arg0 = ToLua.ToString(L, 2);
                float       arg1 = (float)LuaDLL.lua_tonumber(L, 3);
                float       o    = obj.GetRecord(arg0, arg1);
                LuaDLL.lua_pushnumber(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: RecordTable.GetRecord"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 44
0
    static int Raycast(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckStructArray <UnityEngine.RaycastHit2D>(L, 3);
                int o = obj.Raycast(arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.ContactFilter2D, UnityEngine.RaycastHit2D[]>(L, 3))
            {
                UnityEngine.Collider2D      obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2         arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.ContactFilter2D arg1 = StackTraits <UnityEngine.ContactFilter2D> .To(L, 3);

                UnityEngine.RaycastHit2D[] arg2 = ToLua.ToStructArray <UnityEngine.RaycastHit2D>(L, 4);
                int o = obj.Raycast(arg0, arg1, arg2);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.RaycastHit2D[], float>(L, 3))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.ToStructArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                int   o    = obj.Raycast(arg0, arg1, arg2);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <UnityEngine.ContactFilter2D, UnityEngine.RaycastHit2D[], float>(L, 3))
            {
                UnityEngine.Collider2D      obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2         arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.ContactFilter2D arg1 = StackTraits <UnityEngine.ContactFilter2D> .To(L, 3);

                UnityEngine.RaycastHit2D[] arg2 = ToLua.ToStructArray <UnityEngine.RaycastHit2D>(L, 4);
                float arg3 = (float)LuaDLL.lua_tonumber(L, 5);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes <UnityEngine.RaycastHit2D[], float, int>(L, 3))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.ToStructArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                int   arg3 = (int)LuaDLL.lua_tonumber(L, 5);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 6)
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckStructArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                int   arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
                float arg4 = (float)LuaDLL.luaL_checknumber(L, 6);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3, arg4);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 7)
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.CheckObject <UnityEngine.Collider2D>(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckStructArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.luaL_checknumber(L, 4);
                int   arg3 = (int)LuaDLL.luaL_checknumber(L, 5);
                float arg4 = (float)LuaDLL.luaL_checknumber(L, 6);
                float arg5 = (float)LuaDLL.luaL_checknumber(L, 7);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3, arg4, arg5);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Collider2D.Raycast"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 45
0
    private static bool IsCrossLine(float ptX, float ptZ, IList <TV2> ptList, int nIndex)
    {
        int nNumLine = ptList.Count;

        TV2 ptLine1 = ptList[nIndex];                  // 线段顶点1
        TV2 ptLine2 = ptList[(nIndex + 1) % nNumLine]; // 线段顶点2

        if (ptLine1.x < ptX && ptLine2.x < ptX)        // 如果线段在射线左边
        {
            return(false);
        }

        if (ptLine1.y < ptZ && ptLine2.y < ptZ)// 如果线段在射线上边
        {
            return(false);
        }

        if (ptLine1.y > ptZ && ptLine2.y > ptZ)// 如果线段在射线下边
        {
            return(false);
        }

        if (ptLine1.y == ptLine2.y)// 如果线段与射线在同一水平线上
        {
            return(false);
        }

        if (ptZ == ptLine1.y)// 如果射线穿过线段顶点1
        {
            // 找到顶点1之前最近且与射线不在同一水平线上的点
            ptLinePreV2 = default(TV2);   // 顶点1之前的点
            bool bFind = false;
            for (int i = 1; i < nNumLine; i++)
            {
                ptLinePreV2 = ptList[(nIndex + nNumLine - i) % nNumLine];
                if (ptLinePreV2.y != ptZ)// 不在扫描线上
                {
                    bFind = true;
                    break;
                }
            }
            if (!bFind)// 没找到符合条件的点(多边形所有点在同一水平线上)
            {
                return(false);
            }

            if ((ptLinePreV2.y < ptZ && ptLine2.y > ptZ) ||
                (ptLinePreV2.y > ptZ && ptLine2.y < ptZ))   // 如果顶点1之前点与顶点2在射线两侧
            {
                return(false);
            }
        }

        // 计算射线与边的交点
        float fSlope  = (ptLine2.x - ptLine1.x) / (ptLine2.y - ptLine1.y);
        float fCrossX = (ptZ - ptLine1.y) * fSlope + ptLine1.x;

        if (fCrossX <= ptX)//交点在测试点左侧
        {
            return(false);
        }

        return(true);
    }
Esempio n. 46
0
    private AABB Fatten(ref AABB aabb)
    {
        Vector2 r = new Vector2(Settings.AABBExtension, Settings.AABBExtension);

        return(new AABB(aabb.LowerBound - r, aabb.UpperBound + r));
    }
 public WarpStruct(Vector2 vect, GravitySignature signature, String dest)
 {
     this.warpDest  = dest;
     this.vector    = vect;
     finalSignature = signature;
 }
    public void SensorsUpdate(SubsystemReferences subsysRef, ShipSensors Data)
    {
        double EMSangle;
        float  signalStrength;
        int    EMSsignature;

        float  EMSdistance;
        double EMSposX, EMSposY;

        Vector2 pos;
        Vector2 vel;

        bool water  = false;
        bool common = false;
        bool metal  = false;

        //empty lists
        GWIWarpData.RemoveAll();
        EMSData.RemoveAll();

        for (int i = 0; i < Data.EMSensor.Count; i++)
        {
            EMSangle       = (double)Data.EMSensor[i].angle;
            signalStrength = Data.EMSensor[i].signalStrength;
            EMSsignature   = Data.EMSensor[i].materialSignature;

            EMSdistance = ShipSensors.EMConstant / signalStrength;

            EMSposX = EMSdistance * Math.Cos(EMSangle);
            EMSposY = EMSdistance * Math.Sin(EMSangle);

            vel = Data.EMSensor[i].velocity;

            pos = new Vector2((float)EMSposX, (float)EMSposY);

            if (Data.CheckSignatureForSpaceMaterial(EMSsignature, SpaceMaterial.Water))
            {
                water = true;
            }
            if (Data.CheckSignatureForSpaceMaterial(EMSsignature, SpaceMaterial.Common))
            {
                common = true;
            }
            if (Data.CheckSignatureForSpaceMaterial(EMSsignature, SpaceMaterial.Metal))
            {
                metal = true;
            }

            EMSData.Add(new EMSDetection(pos, vel, EMSsignature, water, common, metal));
        }


        String           warpgateDest;
        double           angle;
        float            waveAmplitude;
        GravitySignature signature;

        SpaceMaterial[] material = { };

        //Good data
        float   distance;
        double  distX, distY;
        Vector2 vector;


        for (int i = 0; i < Data.GWInterferometer.Count; i++)
        {
            //get data
            warpgateDest  = Data.GWInterferometer[i].warpGateDestination;
            angle         = (double)Data.GWInterferometer[i].angle;
            waveAmplitude = Data.GWInterferometer[i].waveAmplitude;
            signature     = Data.GWInterferometer[i].signature;

            //distance = G / waveAmp
            distance = ShipSensors.GConstant / waveAmplitude;

            //distance for vectors
            distX = distance * Math.Cos(angle);
            distY = distance * Math.Sin(angle);

            vector = new Vector2((float)distX, (float)distY);

            if (signature == GravitySignature.WarpGate)
            {
                GWIWarpData.Add(new WarpStruct(vector, signature, warpgateDest));
            }
        }
    }
Esempio n. 49
0
    private static void DrawFaceEditor(ref int face, OCAtlas atlas, ref UnityEngine.Matrix4x4 matrix)
    {
        UnityEngine.GUILayout.BeginVertical(UnityEngine.GUI.skin.box);
        UnityEngine.Texture texture = atlas.Texture;
        UnityEngine.Rect    rect    = UnityEngine.GUILayoutUtility.GetAspectRect((float)texture.width / texture.height);
        UnityEngine.GUILayout.EndVertical();

        UnityEngine.Matrix4x4 rectMatrix    = UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(rect.width, rect.height, 0)) * matrix;
        UnityEngine.Matrix4x4 invRectMatrix = matrix.inverse * UnityEngine.Matrix4x4.Scale(new UnityEngine.Vector3(1 / rect.width, 1 / rect.height, 0));
        UnityEngine.Matrix4x4 invertY       = UnityEngine.Matrix4x4.TRS(new UnityEngine.Vector2(0, 1), UnityEngine.Quaternion.identity, new UnityEngine.Vector2(1, -1));

        bool mouseInRect = rect.Contains(UnityEngine.Event.current.mousePosition);

        UnityEngine.GUI.BeginGroup(rect);
        {
            UnityEngine.Vector2 mouse = invRectMatrix.MultiplyPoint(UnityEngine.Event.current.mousePosition);             // local mouse [0..1]

            if (UnityEngine.Event.current.type == UnityEngine.EventType.Repaint)
            {
                UnityEngine.Rect texturePosition = Mul(new UnityEngine.Rect(0, 0, 1, 1), rectMatrix);
                UnityEngine.Rect faceRet         = atlas.ToRect(face);
                faceRet = Mul(faceRet, rectMatrix * invertY);
                UnityEngine.GUI.DrawTexture(texturePosition, texture);
                BlockEditorUtils.DrawRect(faceRet, UnityEngine.Color.green);
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDown && UnityEngine.Event.current.button == 0 && mouseInRect)
            {
                UnityEngine.Vector2 invMouse = invertY.MultiplyPoint(mouse);
                if (invMouse.x >= 0 && invMouse.x <= 1 && invMouse.y >= 0 && invMouse.y <= 1)
                {
                    int posX = UnityEngine.Mathf.FloorToInt(invMouse.x * atlas.Width);
                    int posY = UnityEngine.Mathf.FloorToInt(invMouse.y * atlas.Height);
                    face = posY * atlas.Width + posX;

                    UnityEngine.GUI.changed = true;
                    UnityEngine.Event.current.Use();
                }
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDrag && UnityEngine.Event.current.button == 1 && mouseInRect)
            {
                UnityEngine.Vector3 delta = UnityEngine.Event.current.delta;
                delta.x /= rect.width;
                delta.y /= rect.height;

                UnityEngine.Matrix4x4 offsetMatrix = UnityEngine.Matrix4x4.TRS(delta, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix = offsetMatrix * matrix;

                UnityEngine.GUI.changed = true;
                UnityEngine.Event.current.Use();
            }

            if (UnityEngine.Event.current.type == UnityEngine.EventType.ScrollWheel && mouseInRect)
            {
                float s = 0.95f;
                if (UnityEngine.Event.current.delta.y < 0)
                {
                    s = 1.0f / s;
                }

                UnityEngine.Matrix4x4 offsetMatrix = UnityEngine.Matrix4x4.TRS(mouse, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix *= offsetMatrix;

                UnityEngine.Matrix4x4 scaleMatrix = UnityEngine.Matrix4x4.Scale(UnityEngine.Vector3.one * s);
                matrix *= scaleMatrix;

                offsetMatrix = UnityEngine.Matrix4x4.TRS(-mouse, UnityEngine.Quaternion.identity, UnityEngine.Vector3.one);
                matrix      *= offsetMatrix;

                UnityEngine.GUI.changed = true;
                UnityEngine.Event.current.Use();
            }
        }
        UnityEngine.GUI.EndGroup();
    }
Esempio n. 50
0
    static int Create(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      arg1 = StackTraits <UnityEngine.Rect> .Check(L, 2);

                UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
                UnityEngine.Sprite  o    = UnityEngine.Sprite.Create(arg0, arg1, arg2);
                ToLua.PushSealed(L, o);
                return(1);
            }
            else if (count == 4)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      arg1 = StackTraits <UnityEngine.Rect> .Check(L, 2);

                UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
                float arg3           = (float)LuaDLL.luaL_checknumber(L, 4);
                UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3);
                ToLua.PushSealed(L, o);
                return(1);
            }
            else if (count == 5)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      arg1 = StackTraits <UnityEngine.Rect> .Check(L, 2);

                UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
                float arg3           = (float)LuaDLL.luaL_checknumber(L, 4);
                uint  arg4           = (uint)LuaDLL.luaL_checknumber(L, 5);
                UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4);
                ToLua.PushSealed(L, o);
                return(1);
            }
            else if (count == 6)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      arg1 = StackTraits <UnityEngine.Rect> .Check(L, 2);

                UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
                float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
                uint  arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
                UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
                UnityEngine.Sprite         o    = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5);
                ToLua.PushSealed(L, o);
                return(1);
            }
            else if (count == 7)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      arg1 = StackTraits <UnityEngine.Rect> .Check(L, 2);

                UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
                float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
                uint  arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
                UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
                UnityEngine.Vector4        arg6 = ToLua.ToVector4(L, 7);
                UnityEngine.Sprite         o    = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
                ToLua.PushSealed(L, o);
                return(1);
            }
            else if (count == 8)
            {
                UnityEngine.Texture2D arg0 = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
                UnityEngine.Rect      arg1 = StackTraits <UnityEngine.Rect> .Check(L, 2);

                UnityEngine.Vector2 arg2 = ToLua.ToVector2(L, 3);
                float arg3 = (float)LuaDLL.luaL_checknumber(L, 4);
                uint  arg4 = (uint)LuaDLL.luaL_checknumber(L, 5);
                UnityEngine.SpriteMeshType arg5 = (UnityEngine.SpriteMeshType)ToLua.CheckObject(L, 6, typeof(UnityEngine.SpriteMeshType));
                UnityEngine.Vector4        arg6 = ToLua.ToVector4(L, 7);
                bool arg7            = LuaDLL.luaL_checkboolean(L, 8);
                UnityEngine.Sprite o = UnityEngine.Sprite.Create(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
                ToLua.PushSealed(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Sprite.Create"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 51
0
 /** Returns a negative number of if \a p lies on the left side of a line which with one point in \a a and has a tangent in the direction of \a dir.
  * The number can be seen as the double signed area of the triangle {a, a+dir, p} multiplied by the length of \a dir.
  * If dir.magnitude=1 this is also the distance from p to the line {a, a+dir}.
  */
 public static float SignedDistanceFromLine(Vector2 a, Vector2 dir, Vector2 p)
 {
     return((p.x - a.x) * (dir.y) - (dir.x) * (p.y - a.y));
 }
    static int Raycast(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Collider2D), typeof(UnityEngine.Vector2), typeof(UnityEngine.RaycastHit2D[])))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.ToObject(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckObjectArray <UnityEngine.RaycastHit2D>(L, 3);
                int o = obj.Raycast(arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Collider2D), typeof(UnityEngine.Vector2), typeof(UnityEngine.RaycastHit2D[]), typeof(float)))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.ToObject(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckObjectArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                int   o    = obj.Raycast(arg0, arg1, arg2);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Collider2D), typeof(UnityEngine.Vector2), typeof(UnityEngine.RaycastHit2D[]), typeof(float), typeof(int)))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.ToObject(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckObjectArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                int   arg3 = (int)LuaDLL.lua_tonumber(L, 5);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Collider2D), typeof(UnityEngine.Vector2), typeof(UnityEngine.RaycastHit2D[]), typeof(float), typeof(int), typeof(float)))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.ToObject(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckObjectArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                int   arg3 = (int)LuaDLL.lua_tonumber(L, 5);
                float arg4 = (float)LuaDLL.lua_tonumber(L, 6);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3, arg4);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 7 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.Collider2D), typeof(UnityEngine.Vector2), typeof(UnityEngine.RaycastHit2D[]), typeof(float), typeof(int), typeof(float), typeof(float)))
            {
                UnityEngine.Collider2D     obj  = (UnityEngine.Collider2D)ToLua.ToObject(L, 1);
                UnityEngine.Vector2        arg0 = ToLua.ToVector2(L, 2);
                UnityEngine.RaycastHit2D[] arg1 = ToLua.CheckObjectArray <UnityEngine.RaycastHit2D>(L, 3);
                float arg2 = (float)LuaDLL.lua_tonumber(L, 4);
                int   arg3 = (int)LuaDLL.lua_tonumber(L, 5);
                float arg4 = (float)LuaDLL.lua_tonumber(L, 6);
                float arg5 = (float)LuaDLL.lua_tonumber(L, 7);
                int   o    = obj.Raycast(arg0, arg1, arg2, arg3, arg4, arg5);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Collider2D.Raycast"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 53
0
            /** Creates a VO for avoiding another agent.
             * Note that the segment is directed, the agent will want to be on the left side of the segment.
             */
            public static VO SegmentObstacle(Vector2 segmentStart, Vector2 segmentEnd, Vector2 offset, float radius, float inverseDt, float inverseDeltaTime)
            {
                var vo = new VO();

                // Adjusted so that a parameter weightFactor of 1 will be the default ("natural") weight factor
                vo.weightFactor = 1;
                // Just higher than anything else
                vo.weightBonus = Mathf.Max(radius, 1) * 40;

                var closestOnSegment = VectorMath.ClosestPointOnSegment(segmentStart.ToPFV2(), segmentEnd.ToPFV2(), Vector2.zero.ToPFV2());

                // Collision?
                if (closestOnSegment.magnitude <= radius)
                {
                    vo.colliding = true;

                    vo.line1  = closestOnSegment.normalized.ToUnityV3() * (closestOnSegment.magnitude - radius) * 0.3f * inverseDeltaTime;
                    vo.dir1   = new Vector2(vo.line1.y, -vo.line1.x).normalized;
                    vo.line1 += offset;

                    vo.cutoffDir  = Vector2.zero;
                    vo.cutoffLine = Vector2.zero;
                    vo.dir2       = Vector2.zero;
                    vo.line2      = Vector2.zero;
                    vo.radius     = 0;

                    vo.segmentStart = Vector2.zero;
                    vo.segmentEnd   = Vector2.zero;
                    vo.segment      = false;
                }
                else
                {
                    vo.colliding = false;

                    segmentStart *= inverseDt;
                    segmentEnd   *= inverseDt;
                    radius       *= inverseDt;

                    var cutoffTangent = (segmentEnd - segmentStart).normalized;
                    vo.cutoffDir   = cutoffTangent;
                    vo.cutoffLine  = segmentStart + new Vector2(-cutoffTangent.y, cutoffTangent.x) * radius;
                    vo.cutoffLine += offset;

                    // See documentation for details
                    // The call to Max is just to prevent floating point errors causing NaNs to appear
                    var startSqrMagnitude = segmentStart.sqrMagnitude;
                    var normal1           = -VectorMath.ComplexMultiply(segmentStart, new Vector2(radius, Mathf.Sqrt(Mathf.Max(0, startSqrMagnitude - radius * radius)))) / startSqrMagnitude;
                    var endSqrMagnitude   = segmentEnd.sqrMagnitude;
                    var normal2           = -VectorMath.ComplexMultiply(segmentEnd, new Vector2(radius, -Mathf.Sqrt(Mathf.Max(0, endSqrMagnitude - radius * radius)))) / endSqrMagnitude;

                    vo.line1 = segmentStart + normal1.ToUnityV2() * radius + offset;
                    vo.line2 = segmentEnd + normal2.ToUnityV2() * radius + offset;

                    // Note that the normals are already normalized
                    vo.dir1 = new Vector2(normal1.y, -normal1.x);
                    vo.dir2 = new Vector2(normal2.y, -normal2.x);

                    vo.segmentStart = segmentStart;
                    vo.segmentEnd   = segmentEnd;
                    vo.radius       = radius;
                    vo.segment      = true;
                }

                return(vo);
            }
 public Connection(Direction d, UnityEngine.Vector2 v)
 {
     Dir   = d;
     Point = v;
 }
Esempio n. 55
0
            /** Creates a VO for avoiding another agent.
             * \param center The position of the other agent relative to this agent.
             * \param offset Offset of the velocity obstacle. For example to account for the agents' relative velocities.
             * \param radius Combined radius of the two agents (radius1 + radius2).
             * \param inverseDt 1 divided by the local avoidance time horizon (e.g avoid agents that we will hit within the next 2 seconds).
             * \param inverseDeltaTime 1 divided by the time step length.
             */
            public VO(Vector2 center, Vector2 offset, float radius, float inverseDt, float inverseDeltaTime)
            {
                // Adjusted so that a parameter weightFactor of 1 will be the default ("natural") weight factor
                this.weightFactor = 1;
                weightBonus       = 0;

                //this.radius = radius;
                Vector2 globalCenter;

                circleCenter = center * inverseDt + offset;

                this.weightFactor = 4 * Mathf.Exp(-Sqr(center.sqrMagnitude / (radius * radius))) + 1;
                // Collision?
                if (center.magnitude < radius)
                {
                    colliding = true;

                    // 0.001 is there to make sure lin1.magnitude is not so small that the normalization
                    // below will return Vector2.zero as that will make the VO invalid and it will be ignored.
                    line1  = center.normalized * (center.magnitude - radius - 0.001f) * 0.3f * inverseDeltaTime;
                    dir1   = new Vector2(line1.y, -line1.x).normalized;
                    line1 += offset;

                    cutoffDir   = Vector2.zero;
                    cutoffLine  = Vector2.zero;
                    dir2        = Vector2.zero;
                    line2       = Vector2.zero;
                    this.radius = 0;
                }
                else
                {
                    colliding = false;

                    center      *= inverseDt;
                    radius      *= inverseDt;
                    globalCenter = center + offset;

                    // 0.001 is there to make sure cutoffDistance is not so small that the normalization
                    // below will return Vector2.zero as that will make the VO invalid and it will be ignored.
                    var cutoffDistance = center.magnitude - radius + 0.001f;

                    cutoffLine  = center.normalized * cutoffDistance;
                    cutoffDir   = new Vector2(-cutoffLine.y, cutoffLine.x).normalized;
                    cutoffLine += offset;

                    float alpha = Mathf.Atan2(-center.y, -center.x);

                    float delta = Mathf.Abs(Mathf.Acos(radius / center.magnitude));

                    this.radius = radius;

                    // Bounding Lines

                    // Point on circle
                    line1 = new Vector2(Mathf.Cos(alpha + delta), Mathf.Sin(alpha + delta));
                    // Vector tangent to circle which is the correct line tangent
                    // Note that this vector is normalized
                    dir1 = new Vector2(line1.y, -line1.x);

                    // Point on circle
                    line2 = new Vector2(Mathf.Cos(alpha - delta), Mathf.Sin(alpha - delta));
                    // Vector tangent to circle which is the correct line tangent
                    // Note that this vector is normalized
                    dir2 = new Vector2(line2.y, -line2.x);

                    line1 = line1 * radius + globalCenter;
                    line2 = line2 * radius + globalCenter;
                }

                segmentStart = Vector2.zero;
                segmentEnd   = Vector2.zero;
                segment      = false;
            }
Esempio n. 56
0
 public Vector2(UnityEngine.Vector2 v)
 {
     this.x = v.x;
     this.y = v.y;
 }
Esempio n. 57
0
    static int SaveRecord(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(string), typeof(UnityEngine.Vector2)))
            {
                string arg0 = ToLua.ToString(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                UnityEngine.Vector2 arg2 = (UnityEngine.Vector2)ToLua.ToObject(L, 3);
                RecordManager.SaveRecord(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(string), typeof(UnityEngine.Vector3)))
            {
                string arg0 = ToLua.ToString(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                UnityEngine.Vector3 arg2 = (UnityEngine.Vector3)ToLua.ToObject(L, 3);
                RecordManager.SaveRecord(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(string), typeof(UnityEngine.Color)))
            {
                string            arg0 = ToLua.ToString(L, 1);
                string            arg1 = ToLua.ToString(L, 2);
                UnityEngine.Color arg2 = (UnityEngine.Color)ToLua.ToObject(L, 3);
                RecordManager.SaveRecord(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(string), typeof(string)))
            {
                string arg0 = ToLua.ToString(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                string arg2 = ToLua.ToString(L, 3);
                RecordManager.SaveRecord(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(string), typeof(bool)))
            {
                string arg0 = ToLua.ToString(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                bool   arg2 = LuaDLL.lua_toboolean(L, 3);
                RecordManager.SaveRecord(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(string), typeof(float)))
            {
                string arg0 = ToLua.ToString(L, 1);
                string arg1 = ToLua.ToString(L, 2);
                float  arg2 = (float)LuaDLL.lua_tonumber(L, 3);
                RecordManager.SaveRecord(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: RecordManager.SaveRecord"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 58
0
    // Update is called once per frame
    void FixedUpdate()
    {
        _animator.speed = _rgd2d.velocity.magnitude < 0.05f ? 0 : 1;
        if (ladder_mode)
        {
            ladderMode();
            return;
        }

        var contactsCount = _rgd2d.GetContacts(contact_list);

        is_grounded = (contact_list.Take(contactsCount).Any(contact => contact.normal.y > 0.9f));

        if (is_grounded && pressed_fall)
        {
            _animator.SetTrigger("Jump");
            _rgd2d.velocity = Vector2.zero;
            Debug.Log("FREEFALLING");
            _boxCollider2D.isTrigger = true;
            is_dropping = true;
        }
        else if (is_grounded)
        {
            _animator.SetTrigger("Contact");
        }

        Vector2 velocity;
        var     newSpeed    = is_dropping ? 0 : currentSpeed;
        var     newVelocity = new Vector2(Input.GetAxisRaw("Horizontal") * newSpeed, (velocity = this._rgd2d.velocity).y);

        _rgd2d.velocity = Vector2.SmoothDamp(velocity, newVelocity, ref cur_velo, m_smooth_time);

        var absX = Math.Abs(velocity.x);

        if (absX > .1f)
        {
            _spriteRenderer.flipX = velocity.x > 0;
        }

        if (!ladder_mode)
        {
            _animator.SetBool("Moving", !is_dropping && absX > 0.1f);
        }

        if (is_dropping)
        {
            return;
        }

        if (is_grounded && pressed_jump)
        {
            _animator.SetTrigger("Jump");
            is_grounded = false;
            _rgd2d.AddForce(new Vector2(0f, m_jump_velocity * 50));
            Debug.Log("PRESSED JUMP");
        }


        if (pressed_repair)
        {
            StartCoroutine(PlayerIsFixing());
        }

        pressed_jump = false;
        pressed_fall = false;
        animTrigger  = null;

        // ShowArrow();
    }
Esempio n. 59
0
    //public SerializedProperty property;

    public MapSelectionDropdown(AdvancedDropdownState state) : base(state)
    {
        minimumSize = new UnityEngine.Vector2(50, 400f);
    }
Esempio n. 60
0
    public static void TickBullets(World model)
    {
        foreach (var bullet in model.bullets.Values)
        {
            bullet.dir += model.wind;
            bullet.pos += bullet.dir * bullet.speed;

            UnityEngine.Camera  cam = UnityEngine.Camera.main;
            UnityEngine.Vector2 bulletViewportPos = cam.WorldToViewportPoint(bullet.pos.Vector3());
            UnityEngine.Vector3 bulletWorldPos    = bullet.pos.Vector3();

            if (bulletViewportPos.x < 0 || bulletViewportPos.x > 1)
            {
                bullet.dir = new Position(-bullet.dir.x, bullet.dir.y).Normalize();
                bullet.pos = new Position(
                    cam.ViewportToWorldPoint(
                        new UnityEngine.Vector2(UnityEngine.Mathf.Clamp01(bulletViewportPos.x), bulletViewportPos.y)
                        )
                    );
                bullet.ricochetLifeHits--;

                AudioController.Instance.PlaySound(AudioController.Sound.Ricoshet);
            }
            if (bulletViewportPos.y < 0 || bulletViewportPos.y > 1)
            {
                bullet.dir = new Position(bullet.dir.x, -bullet.dir.y).Normalize();
                bullet.pos = new Position(
                    cam.ViewportToWorldPoint(
                        new UnityEngine.Vector2(bulletViewportPos.x, UnityEngine.Mathf.Clamp01(bulletViewportPos.y))
                        )
                    );
                bullet.ricochetLifeHits--;
                AudioController.Instance.PlaySound(AudioController.Sound.Ricoshet);
            }

            foreach (var bandit in model.bandits.Values)
            {
                Circle bulletCircle = CollisionService.CreateCircle(bullet.pos, bullet.dir * bullet.radius, bullet.radius);
                Circle banditCircle = CollisionService.CreateCircle(bandit.pos, new Position(), bandit.radius);

                Position hitPoint;
                if (CollisionService.DynamicToStaticCircleCollision(bulletCircle, banditCircle, out hitPoint))
                {
                    model.gizmos.Add(hitPoint);

                    Position delta  = hitPoint - bandit.pos;
                    Position normal = delta.Normalize();

                    Position pushDir = (bullet.dir * 0.5f + normal * 0.75f).Normalize();


                    bullet.pos = hitPoint;
                    bullet.dir = pushDir;
                    bullet.ricochetLifeHits--;
                    bullet.hits++;

                    bandit.pos += pushDir * -2f;
                    bandit.hp--;

                    if (bandit.hp <= 0)
                    {
                        bandit.isActive = false;
                    }
                    else if (bandit.hp > 0)
                    {
                        model.events.Enqueue(new BanditDamagedEvent(bandit.id));
                    }
                }
            }

            if (bullet.ricochetLifeHits <= 0)
            {
                bullet.isActive = false;
            }
        }
    }