void OnTriggerExit2D(Collider2D other) { worldObject w = other.gameObject.GetComponent <worldObject>(); if (w != null) { if (triggerOnBodyExit && w.objectName == "mainBody") { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",BX\n"); //Debug.Log("hi"); } else if (triggerOnLeftHandExit && w.objectName == "leftHand") { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",LX\n"); } else if (triggerOnRightHandExit && w.objectName == "rightHand") { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",RX\n"); } else if (triggerOnOtherObjectsExit) { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",OX\n"); } } }
worldObject loadProtoFromXML(XmlTextReader reader, worldObject parentObj) { string type = null; string baseType = null; float moveRate = 1.0f; int width = 1; // placeholder int height = 1; if (parentObj == null) { type = xmlHelperManager.getStringRequired("type", reader); baseType = xmlHelperManager.getStringRequired("baseType", reader); moveRate = xmlHelperManager.getFloatRequired("moveRate", reader); width = xmlHelperManager.getIntDefault("w", 1, reader); height = xmlHelperManager.getIntDefault("h", 1, reader); } else { type = xmlHelperManager.getStringRequired("type", reader); baseType = parentObj.baseType; moveRate = xmlHelperManager.getFloatDefault("moveRate", parentObj.movementCost, reader); width = xmlHelperManager.getIntDefault("w", parentObj.width, reader); height = xmlHelperManager.getIntDefault("h", parentObj.height, reader); } worldObject obj = worldObject.createPrototype(type, moveRate, width, height, baseType); return(obj); }
void OnTriggerEnter2D(Collider2D other) { //List<string> doNotRemove = new List<string>() { "leftHand", "rightHand", "mainBody" }; //Debug.Log("trigger hit " + other.gameObject); worldObject w = other.gameObject.GetComponent <worldObject>(); if (w != null) { if (triggerOnBodyEnter && w.objectName == "mainBody") { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",BE\n"); } else if (triggerOnLeftHandEnter && w.objectName == "leftHand") { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",LE\n"); } else if (triggerOnRightHandEnter && w.objectName == "rightHand") { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",RE\n"); } else if (triggerOnOtherObjectsEnter) { GlobalVariables.outgoingMessages.Add("TB," + objectName + ",OE\n"); } } }
public Node(worldObject _thing, terrainType _walk, Vector3Int _worldPos, orientation _dir) { placedThing = _thing; walkable = _walk; worldSpacePosition = _worldPos; texture = 1; direction = _dir; }
public worldObjectSavedToFile(worldObject w) { //store the world object's relevant details prefabID = w.prefabID; positionX = w.rigidbody2D.transform.position.x; positionY = w.rigidbody2D.transform.position.y; rotation = w.rigidbody2D.transform.rotation.z; objName = w.objectName; specialValues = w.valuesToSave; }
public void onWorldObjectDestroyed(worldObject obj) { if (obj != null) { if (this.worldObjects.ContainsKey(obj)) { this.worldObjects[obj].transform.SetParent(null); Destroy(this.worldObjects[obj]); } } }
public static worldObject createPrototype(string objectType, float movementCost, int width, int height, string baseType) // TODO implement w & h && locName { worldObject obj = new worldObject(); obj.objectType = objectType; obj.movementCost = movementCost; obj.width = width; obj.height = height; obj.baseType = baseType; return(obj); }
void loadToCurrentTask() { //place all world objects foreach (worldObjectSavedToFile wo in worldObjects) { //find the asset path of the object with this prefab id, search through all prefabs bool loaded = false; foreach (worldObject s in Resources.LoadAll <worldObject>("Prefabs")) { if (s.prefabID == wo.prefabID) { worldObject newObj = MonoBehaviour.Instantiate(s, //Resources.Load<GameObject>(wo.assetPath) new Vector3(wo.positionX, wo.positionY), new Quaternion(0, 0, wo.rotation, 0)) as worldObject; newObj.valuesToSave = wo.specialValues; newObj.loadVals(); loaded = true; break; } } if (!loaded) { Debug.Log("Couldn't load item " + wo.objName); } } //"Prefabs/food_and_pain/bacon" //set position/rotation of body, hands mainBody.rigidbody2D.transform.position = new Vector2(bodyX, bodyY); mainBody.rigidbody2D.velocity = Vector2.zero; //Debug.Log("x " + bodyX + " Y " + bodyY); mainBody.rigidbody2D.transform.rotation = new Quaternion(0, 0, bodyRotation, 0); rightHand.transform.position = new Vector2(rightHandX, rightHandY); leftHand.transform.position = new Vector2(leftHandX, leftHandY); rightHand.rigidbody2D.transform.rotation = mainBody.rigidbody2D.transform.rotation; leftHand.rigidbody2D.transform.rotation = mainBody.rigidbody2D.transform.rotation; mainBody.rigidbody2D.AddForce(new Vector2(0, 0)); //this forces the screen to update his rotation //load environment variables like gravity, game speed, etc. Physics2D.gravity = new Vector2(gravityX, gravityY); Time.timeScale = gameSpeed; GlobalVariables.centerCamera = centerCamera; GlobalVariables.showDetailedVisionMarkers = showDetailedVisionMarkers; GlobalVariables.showPeripheralVisionMarkers = showPeripheralVisionMarkers; mainBody.customItems = new Dictionary <string, worldObject>(); mainBody.indexCustomItems(); }
void loadProto(XmlTextReader reader) { worldObject parentProto = loadProtoFromXML(reader, null); // loads the first proto encountered worldObjectProtos.Add(parentProto.objectType, parentProto); if (reader.ReadToDescendant("variant")) // loads its variants { worldObject childProto = loadProtoFromXML(reader, parentProto); worldObjectProtos.Add(childProto.objectType, childProto); while (reader.ReadToNextSibling("variant")) { childProto = loadProtoFromXML(reader, parentProto); worldObjectProtos.Add(childProto.objectType, childProto); } } }
//?+ callbacks public void onWorldObjectCreated(worldObject obj) { // create a GO for the obj GameObject objGO = new GameObject(); worldObjects.Add(obj, objGO); // add it to the list objGO.name = obj.objectType + "_" + obj.baseTile.position.x + "_" + obj.baseTile.position.y; objGO.transform.SetParent(this.transform); objGO.transform.position = new Vector3(obj.baseTile.position.x, obj.baseTile.position.y, 0); SpriteRenderer tileSR = objGO.AddComponent <SpriteRenderer>(); tileSR.sprite = spriteManager.instance.getSprite(obj.baseType, obj.objectType + "_0"); objGO.AddComponent <BoxCollider>(); obj.registerOnChangedCB(onWorldObjectChanged); }
void loadObjs() { worldObject[] goArray = UnityEngine.MonoBehaviour.FindObjectsOfType(typeof(worldObject)) as worldObject[]; foreach (worldObject obj in goArray) { if (obj.objectName == "mainBody") { mainBody = (bodyController)obj; } else if (obj.objectName == "leftHand") { leftHand = obj; } else if (obj.objectName == "rightHand") { rightHand = obj; } } }
public static worldObject placeInstance(worldObject proto, tile baseTile) { worldObject obj = new worldObject(); obj.objectType = proto.objectType; obj.movementCost = proto.movementCost; obj.width = proto.width; obj.height = proto.height; obj.baseType = proto.baseType; obj.baseTile = baseTile; obj.flags = 0; // TODO maybe we can have multiple tile objects? if (!baseTile.placeObject(obj)) { // the placement failed return(null); } return(obj); }
public void placeWorldObject(string objectType, tile t) { // TODO make it use rotation and big objects if (objectXMLManager.instance.worldObjectProtos.ContainsKey(objectType)) { worldObject obj = worldObject.placeInstance(objectXMLManager.instance.worldObjectProtos[objectType], t); //Debug.Log("Placed object"); if (obj != null) { if (onWorldObjectCreatedCB != null) { onWorldObjectCreatedCB(obj); } } } else { Debug.LogError("world::placeWorldOject: No object of type " + objectType); } this.updateAdjacentTiles(t); // update the adjacent tiles }
public bool placeObject(worldObject objInstance) { if (objInstance == null) { this.childObject = null; return(false); } else if (this.childObject == null) { this.childObject = objInstance; return(true); } else if (this.childObject != null) { //Debug.Log("Tile_" + this.position.x + "_" + this.position.y + " already has a world object"); return(false); } else { return(false); } }
public override void updateSensor() { Vector2 pos = getPosition(); objectTouched = getObjectAt(pos); temp = objectTouched.temperature; if (objectTouched.GetType()==typeof(rewardOrPunishmentController)) endorphins = ((rewardOrPunishmentController)objectTouched).endorphins; else endorphins = 0f; texture = new float[objectTouched.texture.Length]; for (int i=0; i<texture.Length; i++) texture[i] = objectTouched.texture[i]; }
protected worldObject getObjectAt(Vector2 pos) { //close hand, grip whatever //find all objects it might possibly grip //int layerNum = 8; //Normal objects layer List<int> validLayers = new List<int>(); validLayers.Add (LayerMask.NameToLayer("Default")); validLayers.Add (LayerMask.NameToLayer("Normal Objects")); validLayers.Add (LayerMask.NameToLayer("VisibleButNonreactive")); //int[] validLayers = new int[]{0,8}; worldObject[] goArray = UnityEngine.MonoBehaviour.FindObjectsOfType(typeof(worldObject)) as worldObject[]; List<System.Object> goList = new List<System.Object>(); for (int i = 0; i < goArray.Length; i++) { if (validLayers.Contains(goArray[i].gameObject.layer)) { //Debug.Log("found: " + goArray[i]); goList.Add(goArray[i]); //does it have a collider? if (goArray[i].collider2D != null) { if (goArray[i].collider2D.OverlapPoint(pos)) {//connect it at that point worldObject obj = goArray[i]; //Debug.Log("connecting hand to " + obj + " at " + rightHandRigidBody.position); //assuming the object is a rigidbody, you can get the position of pos relative to obj with obj.rigidbody2D.GetVector(pos) if (obj.objectName!="rightHand" && obj.objectName!="leftHand") return obj; } } } } //create background object to return worldObject BG = new worldObject(); BG.objectName = "Background"; return BG; }
public void onWorldObjectChanged(worldObject obj) { worldObjects[obj].GetComponent <SpriteRenderer>().sprite = spriteManager.instance.getSprite( obj.baseType, obj.objectType + "_" + obj.flags); }
// Use this for initialization void Start() { p = GetComponentInParent <worldObject>(); }
void loadObjs() { worldObject[] goArray = UnityEngine.MonoBehaviour.FindObjectsOfType(typeof(worldObject)) as worldObject[]; foreach (worldObject obj in goArray) { if (obj.objectName == "mainBody") mainBody = (bodyController)obj; else if (obj.objectName == "leftHand") leftHand = obj; else if (obj.objectName == "rightHand") rightHand = obj; } }