void DrawLine(Vector3 start, Vector3 end, Material m) { var mesh = CjLib.PrimitiveMeshFactory.Line(start, end); var meshAndMat = new MeshAndMat(); meshAndMat.m_mesh = mesh; meshAndMat.m_material = m; m_drawThese.Add(meshAndMat); }
public void FixedUpdate() { if (runeScript.shouldRender) { runeScript.shouldRender = false; if (!runeScript.initialRendered) { runeScript.initialRendered = true; runeScript.myObject.transform.localPosition = new Vector3((runeScript.localX) + (runeScript.player != null ? runeScript.baseX : 0), (-runeScript.height) + 0.075f, (runeScript.localY) + (runeScript.player != null ? runeScript.baseY : 0)); runeScript.objPos = runeScript.myObject.transform.localPosition; runeScript.myMesh = runeScript.myObject.GetComponent <MeshFilter> ().sharedMesh; if (runeScript.myMesh == null) { runeScript.myMesh = UnityClient.GetMesh(); } runeScript.myObject.GetComponent <MeshFilter> ().sharedMesh = runeScript.myMesh; runeScript.myRenderer = runeScript.myObject.GetComponent <MeshRenderer> (); MeshAndMat meshAndMaterial = null; //new RuneMesh(); try { meshAndMaterial = runeScript.myRuneMesh.Render(runeScript.myMesh, false); } catch (Exception ex) { //Debug.Log ("Model ex " + ex.Message + " " + ex.StackTrace); // GameObject.Destroy (myObject); goto end; } runeScript.myMesh = meshAndMaterial.mesh; //if(runeScript.myMesh == null || runeScript.myMesh.vertexCount = 0) GameObject.Destroy(gameObject); runeScript.myObject.GetComponent <MeshRenderer> ().sharedMaterials = meshAndMaterial.materials; if (!runeScript.isAnimated && !runeScript.isGfx) { runeScript.SetParent(runeScript.objectRoot); } runeScript.myObject.AddComponent <BoxCollider> (); UnityClient.objectsSinceLastBatch++; } else { if ((runeScript.isAnimated || runeScript.isGfx) && runeScript.myMesh != null) { //myObject.transform.position = new Vector3 ((localX/128f) + baseX, -height/128f, (localY/128f) + baseY); MeshAndMat meshAndMaterial = null; //new RuneMesh(); try { meshAndMaterial = runeScript.myRuneMesh.Render(runeScript.myMesh, true); } catch (Exception ex) { //Debug.Log ("Model ex" + ex.Message + " " + ex.StackTrace); //GameObject.Destroy (myObject); goto end; } runeScript.myMesh = meshAndMaterial.mesh; //myObject.GetComponent<MeshRenderer> ().sharedMaterials = meshAndMaterial.materials; } } } end: if (runeScript.shouldMove) { runeScript.shouldMove = false; runeScript.myObject.transform.localPosition = new Vector3((runeScript.localX) + (runeScript.player != null ? runeScript.baseX : 0), (-runeScript.height) + 0.075f, (runeScript.localY) + (runeScript.player != null ? runeScript.baseY : 0)); runeScript.objPos = runeScript.myObject.transform.localPosition; } //transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed); if (runeScript.player != null) { transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(new Vector3(0, (runeScript.player.turnDirection / 2048f) * 360f, 0)), Time.deltaTime * UnityClient.rotationLerpSpeed); } //if(!runeScript.isAnimated) GameObject.Destroy(gameObject.GetComponent<RuneLiveObject>()); // if (runeScript.myObject != null) { // bool isDead = runeScript.isDead; // if (timeAlive >= UnityClient.gfxTimeout) // isDead = true; // Vector3 objPos = runeScript.objPos; // if (UnityClient.playerPos != Vector3.zero && !runeScript.isMainPlayer) // if ((objPos.x < (UnityClient.playerPos.x - UnityClient.disposeDistance)) || (objPos.x > (UnityClient.playerPos.x + UnityClient.disposeDistance)) || (objPos.z < (UnityClient.playerPos.z - UnityClient.disposeDistance)) || (objPos.z > (UnityClient.playerPos.z + UnityClient.disposeDistance)) || isDead) { // if (!UnityClient.objectsToDispose.Contains (runeScript.myObject) && !runeScript.isGrassObj && !runeScript.isTreeObj) // UnityClient.objectsToDispose.Add (runeScript.myObject); // } // } if (runeScript.isGfx) { timeAlive += 1; } }
public void RenderMesh() { //if(!active) active = true; if (myObject == null) { //modelId = myModel.objId; try { if (player == null) { def = ObjectDef.forID(modelId); } } catch (Exception ex) { } //Loom.DispatchToMainThread (() => { //myRuneMesh.Fill (myModel,true); int treeType = isTree(); if (!isGrass() && treeType == 0) { if (!initialRendered) { myObject = UnityClient.GetRuneObject(); myObject.name = player != null ? (player is Player ? "Player : " + (player as Player).name : "Npc : " + (player as NPC).desc.name) : (def != null ? "Object : " + (def.name) + " : " + modelId : "Object" + " : " + modelId); if (isAnimated || player != null || isGfx) { myObject.AddComponent <RuneLiveObjectUpdate> (); myObject.GetComponent <RuneLiveObjectUpdate> ().runeScript = this; SetParent(animatedObjectsRoot); } else { myObject.AddComponent <RuneLiveObject> (); myObject.GetComponent <RuneLiveObject> ().runeScript = this; UnityClient.allRuneObjects.Add(myObject.GetComponent <RuneLiveObject> ()); SetParent(objectRoot); } shouldRender = true; } } else if (isGrass()) { myObject = GameObject.Instantiate(UnityClient.grassObjStatic); myObject.name = "Grass : " + (def.name) + " : " + modelId; myObject.layer = LayerMask.NameToLayer("Objects"); myObject.AddComponent <RuneLiveObject> (); myObject.GetComponent <RuneLiveObject> ().runeScript = this; isGrassObj = true; UnityClient.allRuneObjects.Add(myObject.GetComponent <RuneLiveObject> ()); shouldRender = false; isAnimated = false; initialRendered = true; myRenderer = myObject.GetComponent <MeshRenderer> (); SetParent(animatedObjectsRoot); } else if (treeType > 0) { if (treeType == 1) { myObject = GameObject.Instantiate(UnityClient.standardTreeStatic); } else if (treeType == 2) { myObject = GameObject.Instantiate(UnityClient.oakTreeStatic); } else if (treeType == 3) { myObject = GameObject.Instantiate(UnityClient.yewTreeStatic); } else if (treeType == 4) { myObject = GameObject.Instantiate(UnityClient.mapleTreeStatic); } else if (treeType == 5) { myObject = GameObject.Instantiate(UnityClient.deadTreeStatic); } else if (treeType == 6) { myObject = GameObject.Instantiate(UnityClient.willowTreeStatic); } myObject.name = "Tree : " + (def.name) + " : " + modelId; myObject.layer = LayerMask.NameToLayer("Objects"); myObject.AddComponent <RuneLiveObject> (); myObject.GetComponent <RuneLiveObject> ().runeScript = this; UnityClient.allRuneObjects.Add(myObject.GetComponent <RuneLiveObject> ()); myRenderer = myObject.GetComponent <MeshRenderer> (); shouldRender = false; isAnimated = false; isTreeObj = true; initialRendered = true; SetParent(animatedObjectsRoot); } //}, true, true); } //myObject.SetActive(true); if (myObject != null) { if (isAnimated || player != null || isGfx) { //myRuneMesh.Fill (myModel,myRuneMesh.numVertices == myModel.numVertices ? false : true); shouldRender = true; } else { if (shouldRender) { shouldRender = false; if (!initialRendered) { initialRendered = true; myObject.transform.localPosition = new Vector3((localX + (player != null ? baseX : 0)), (-height) + 0.075f, (localY + (player != null ? baseY : 0))); objPos = myObject.transform.localPosition; myMesh = myObject.GetComponent <MeshFilter> ().sharedMesh; if (myMesh == null) { myMesh = UnityClient.GetMesh(); } myObject.GetComponent <MeshFilter> ().sharedMesh = myMesh; myRenderer = myObject.GetComponent <MeshRenderer> (); MeshAndMat meshAndMaterial = null; //new RuneMesh(); try { meshAndMaterial = myRuneMesh.Render(myMesh, false); if (meshAndMaterial.mesh != null && meshAndMaterial.mesh.vertexCount < 4) { meshAndMaterial.mesh = null; } } catch (Exception ex) { Debug.Log("Model ex " + ex.Message + " " + ex.StackTrace); myObject.name = "Model EX"; // GameObject.Destroy (myObject); goto end; } myMesh = meshAndMaterial.mesh; //if(myMesh == null || myMesh.vertexCount = 0) GameObject.Destroy(gameObject); myObject.GetComponent <MeshRenderer> ().sharedMaterials = meshAndMaterial.materials; myObject.AddComponent <BoxCollider> (); UnityClient.objectsSinceLastBatch++; } else { // if (isAnimated && myMesh != null) { // //myObject.transform.localPosition = new Vector3 ((localX/128f) + baseX, -height/128f, (localY/128f) + baseY); // MeshAndMat meshAndMaterial = null;//new RuneMesh(); // try { // meshAndMaterial = myRuneMesh.Render (myMesh, true); // } catch (Exception ex) { // //Debug.Log ("Model ex" + ex.Message + " " + ex.StackTrace); // //GameObject.Destroy (myObject); // goto end; // } // myMesh = meshAndMaterial.mesh; // //myObject.GetComponent<MeshRenderer> ().sharedMaterials = meshAndMaterial.materials; // } } } end: if (shouldMove) { shouldMove = false; myObject.transform.localPosition = new Vector3((localX + (player != null ? baseX : 0)), (-height) + 0.075f, (localY + (player != null ? baseY : 0))); objPos = myObject.transform.localPosition; } } } }