static int AttachToCollider(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 2) { InteractiveCloth obj = LuaScriptMgr.GetNetObject <InteractiveCloth>(L, 1); Collider arg0 = LuaScriptMgr.GetNetObject <Collider>(L, 2); obj.AttachToCollider(arg0); return(0); } else if (count == 3) { InteractiveCloth obj = LuaScriptMgr.GetNetObject <InteractiveCloth>(L, 1); Collider arg0 = LuaScriptMgr.GetNetObject <Collider>(L, 2); bool arg1 = LuaScriptMgr.GetBoolean(L, 3); obj.AttachToCollider(arg0, arg1); return(0); } else if (count == 4) { InteractiveCloth obj = LuaScriptMgr.GetNetObject <InteractiveCloth>(L, 1); Collider arg0 = LuaScriptMgr.GetNetObject <Collider>(L, 2); bool arg1 = LuaScriptMgr.GetBoolean(L, 3); bool arg2 = LuaScriptMgr.GetBoolean(L, 4); obj.AttachToCollider(arg0, arg1, arg2); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: InteractiveCloth.AttachToCollider"); } return(0); }
static int AddForceAtPosition(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 4) { InteractiveCloth obj = LuaScriptMgr.GetNetObject <InteractiveCloth>(L, 1); Vector3 arg0 = LuaScriptMgr.GetNetObject <Vector3>(L, 2); Vector3 arg1 = LuaScriptMgr.GetNetObject <Vector3>(L, 3); float arg2 = (float)LuaScriptMgr.GetNumber(L, 4); obj.AddForceAtPosition(arg0, arg1, arg2); return(0); } else if (count == 5) { InteractiveCloth obj = LuaScriptMgr.GetNetObject <InteractiveCloth>(L, 1); Vector3 arg0 = LuaScriptMgr.GetNetObject <Vector3>(L, 2); Vector3 arg1 = LuaScriptMgr.GetNetObject <Vector3>(L, 3); float arg2 = (float)LuaScriptMgr.GetNumber(L, 4); ForceMode arg3 = LuaScriptMgr.GetNetObject <ForceMode>(L, 5); obj.AddForceAtPosition(arg0, arg1, arg2, arg3); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: InteractiveCloth.AddForceAtPosition"); } return(0); }
public void OnInitializeMesh() { rope.GenerateJointObjects(); if (tube == null) { tube = new RopeTubeRenderer(gameObject, true); } mRender = gameObject.GetComponent <ClothRenderer>(); if (mRender == null) { mRender = gameObject.AddComponent <ClothRenderer>(); } mFilter = gameObject.GetComponent <InteractiveCloth>(); if (mFilter == null) { mFilter = gameObject.AddComponent <InteractiveCloth>(); } GenerateMesh(); //if (useAutoTextureTiling) // gameObject.GetComponent<ClothRenderer>().sharedMaterial.mainTextureScale = new Vector2(rope.Joints.Count / 2f, 1); if (gameObject.GetComponent <ClothRenderer>().sharedMaterial == null) { gameObject.GetComponent <ClothRenderer>().sharedMaterial = (Material)Resources.Load("Materials/Rope", typeof(Material)); } }
internal override void OnInitialize() { Vector3[] vectorArray2; int[] numArray2; base.OnInitialize(); this.m_cloth = base.m_obj.GetComponent <InteractiveCloth>(); int vertexCount = this.m_cloth.mesh.vertexCount; Vector3[] vertices = this.m_cloth.mesh.vertices; int[] triangles = this.m_cloth.mesh.triangles; if (this.m_cloth.vertices.Length == this.m_cloth.mesh.vertices.Length) { vectorArray2 = vertices; numArray2 = triangles; } else { Dictionary <Vector3, int> dictionary = new Dictionary <Vector3, int>(); int[] numArray3 = new int[vertexCount]; int num3 = 0; for (int i = 0; i < vertexCount; i++) { int num2; if (dictionary.TryGetValue(vertices[i], out num2)) { numArray3[i] = num2; } else { numArray3[i] = num3; dictionary.Add(vertices[i], num3++); } } vectorArray2 = new Vector3[num3]; dictionary.Keys.CopyTo(vectorArray2, 0); int length = triangles.Length; numArray2 = new int[length]; for (int j = 0; j < length; j++) { numArray2[j] = numArray3[triangles[j]]; } } this.m_vertexCount = vectorArray2.Length; this.m_prevCenters = new Vector3[this.m_vertexCount]; this.m_currCenters = new Vector3[this.m_vertexCount]; this.m_motions = new Vector2[this.m_vertexCount]; this.m_clonedMesh = new Mesh(); this.m_clonedMesh.vertices = vectorArray2; this.m_clonedMesh.uv = this.m_motions; this.m_clonedMesh.triangles = numArray2; string name = "Hidden/Easyflow/ClothVectors"; if (base.m_owner.Instance.QualityLevel == Easyflow.Quality.Mobile) { name = name + "Mobile"; } this.m_clonedMat = new Material(Shader.Find(name)); this.m_clonedMat.SetFloat("_EFLOW_OBJID", ((float)base.m_obj.ObjectId) / 255f); this.UpdateMesh(true); }
public ClothState(AmplifyMotionCamera owner, AmplifyMotionObjectBase obj) : base(owner, obj) { #if UNITY_4 m_cloth = m_obj.GetComponent <InteractiveCloth>(); #else m_cloth = m_obj.GetComponent <Cloth>(); #endif }
static int DetachFromCollider(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); InteractiveCloth obj = LuaScriptMgr.GetNetObject <InteractiveCloth>(L, 1); Collider arg0 = LuaScriptMgr.GetNetObject <Collider>(L, 2); obj.DetachFromCollider(arg0); return(0); }
// Update is called once per frame void Update() { InteractiveCloth ic = GetComponent <InteractiveCloth>(); float f = ac1.Evaluate((((st.SequenceNo + Time.time) / tm.Text.Length) % period) / period); if (((int)(Time.time / 10)) % tm.Text.Length == st.SequenceNo) { ic.pressure = Mathf.Max(0f, f); } }
static int _CreateInteractiveCloth(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (count == 0) { InteractiveCloth obj = new InteractiveCloth(); LuaScriptMgr.Push(L, obj); return(1); } else { LuaDLL.luaL_error(L, "invalid arguments to method: InteractiveCloth.New"); } return(0); }
void HandleInput() { for (var i = 0; i < Input.touchCount; i++) { Touch touch = Input.GetTouch(i); if (touch.phase == TouchPhase.Began) { ((InteractiveCloth)this.GetComponent <InteractiveCloth>()).AddForceAtPosition(new Vector3(0, 0, 20), new Vector3(touch.position.x, touch.position.y, 0), 0.1f); } } if (Input.GetMouseButtonDown(0)) { Debug.Log(SackBehavior.Kicks); ((InteractiveCloth)GetComponent <InteractiveCloth>()).AddForceAtPosition(new Vector3(0, 0, -5), new Vector3(2, 2, 0), 1.0f); Debug.Log(GetComponent <InteractiveCloth>()); } if (Input.GetMouseButtonDown(0)) { Debug.Log("Mouse down"); Ray ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Debug.Log("hit some object"); if (hit.collider == gameObject.collider) { Debug.Log("Hit this object: " + hit.point); InteractiveCloth cloth = GetComponent <InteractiveCloth>(); Debug.Log("Cloth = " + cloth); // Gets here, and cloth variable is a valid InteractiveCloth (there is only one in the scene) // hit.point looks to be exactly where the ray should intercept the cloth cloth.AddForceAtPosition(new Vector3(0, 0, 20), hit.point, 5); Debug.Log("Done applying force."); } } } }
public void EnableRope(bool enable) { if (cloth != null) { Destroy(cloth.gameObject); } enabled = enable; rigidbody.isKinematic = false; attached = false; rigidbody.useGravity = enable; rigidbody.velocity = Vector3.zero; if (enable) { cloth = ((GameObject)Instantiate(clothPrefab, pl.pos, Quaternion.identity)); Cloth = cloth.GetComponentInChildren <InteractiveCloth>(); oldpos = pos = cloth.transform.Find("s2").position; Cloth.AttachToCollider(pl.RopeColl, false, false); Cloth.AttachToCollider(this.collider, false, true); } }
static int get_friction(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name friction"); } else { LuaDLL.luaL_error(L, "attempt to index friction on a nil value"); } } InteractiveCloth obj = (InteractiveCloth)o; LuaScriptMgr.Push(L, obj.friction); return(1); }
static int set_mesh(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name mesh"); } else { LuaDLL.luaL_error(L, "attempt to index mesh on a nil value"); } } InteractiveCloth obj = (InteractiveCloth)o; obj.mesh = LuaScriptMgr.GetNetObject <Mesh>(L, 3); return(0); }
static int set_attachmentResponse(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name attachmentResponse"); } else { LuaDLL.luaL_error(L, "attempt to index attachmentResponse on a nil value"); } } InteractiveCloth obj = (InteractiveCloth)o; obj.attachmentResponse = (float)LuaScriptMgr.GetNumber(L, 3); return(0); }
void OnCollisionEnter(Collision collision) { //Debug.Log("OnCollisionEnter -> colName ================== " + collision.gameObject.name + ", CountOnHit == " + CountOnHit); InteractiveCloth cloth = collision.gameObject.GetComponent <InteractiveCloth>(); SSTriggerScore triScore = collision.gameObject.GetComponent <SSTriggerScore>(); if (triScore == null && cloth == null && !IsDeFenQiu) { //没有碰上分数触发器和篮网的布料碰撞器. CountOnHit++; } if (CountOnHit == 0) { //空心球不去打开篮球的物理碰撞. //Debug.Log("OnCollisionEnter -> player get a kongXinQiu*********************"); } else { IsInitMoveBall = false; if (m_Rigidbody != null) { if (m_HitLanKuangAudio != null) { //播放篮球碰撞的音效. m_HitLanKuangAudio.Play(); } if (!m_Rigidbody.useGravity) { m_Rigidbody.useGravity = true; } Vector3 hitPos = collision.transform.position; Vector3 ballPos = transform.position; hitPos.z = ballPos.z = 0f; Vector3 vecHB = Vector3.Normalize(ballPos - hitPos); #if USE_PULL_BALL_TYPE02 //采用模式2篮球碰撞逻辑. if (m_BallAni != null) { Transform trLanKuang = SSGameDataCtrl.GetInstance().m_LanKuang[(int)m_BallAni.IndexPlayer].transform; Vector3 lanKuangPos = trLanKuang.position; Vector3 ballPosTmp = transform.position; if (lanKuangPos.x > ballPosTmp.x) { vecHB.x = 1f; } else { vecHB.x = -1f; } } else { if (vecHB.x > 0f) { vecHB.x = 1f; } else { vecHB.x = -1f; } } vecHB.y = -1f; float randForceOffset = Random.Range(0.01f, 0.04f); m_Rigidbody.AddForce(vecHB * m_ForceBall * randForceOffset, ForceMode.Impulse); #endif #if USE_PULL_BALL_TYPE01 //采用模式1篮球碰撞逻辑. m_Rigidbody.AddForce(vecHB * m_ForceBall, ForceMode.Force); m_Rigidbody.AddTorque(transform.right * m_TorqueBall); #endif if (m_ForceBall > m_MinForceBall) { m_ForceBall -= m_SubForceBall; if (m_ForceBall < m_MinForceBall) { m_ForceBall = m_MinForceBall; } } } } }
public ClothState(AmplifyMotionCamera owner, AmplifyMotionObjectBase obj) : base(owner, obj) { m_cloth = m_obj.GetComponent <InteractiveCloth>(); }
private static void INTERNAL_CALL_AddForceAtPosition(InteractiveCloth self, ref Vector3 force, ref Vector3 position, float radius, ForceMode mode){}
// Use this for initialization void Start() { cloth = GetComponent <InteractiveCloth> (); }