public RuneObject(int x, int y, int z, int type, object mainClass, int bX, int bY, int id, GameObject objects, GameObject animatedObjects) { localX = x / 128f; height = y / 128f; localY = z / 128f; if (mainClass is InteractiveObject) { if ((mainClass as InteractiveObject).renderable is Projectile) { isGfx = true; } } shouldMove = true; objectType = type; if (type == 1) { wallObj = (WallObject)mainClass; } if (type == 2) { obj2 = (WallDecoration)mainClass; } if (type == 3) { obj3 = (GroundDecoration)mainClass; } if (type == 4) { obj4 = (Object4)mainClass; } if (type == 5) { obj5 = (InteractiveObject)mainClass; } baseX = bX; baseY = bY; modelId = id; if (id > 0) { def = ObjectDef.forID(id); if (def != null) { if (def.animId != -1) { isAnimated = true; } } } myRuneMesh = new RuneMesh(); this.objectRoot = objects; this.animatedObjectsRoot = animatedObjects; }
public void UpdateObjConf(int newConf) { objConf = newConf; int mId = objConf >> 14 & 0x7fff; if (modelId != mId) { modelId = mId; if (modelId > 0) { def = ObjectDef.forID(modelId); if (def != null) { if (def.animId != -1) { isAnimated = true; } } } } }
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; } } } }