protected override void Update() { bool done = true; if (m_startTime > 0.0f) { m_startTime -= Time.deltaTime; return; } update_positions(); for (int i = 0; i < m_number; i++) { AttachPoint at = m_members[i]; if (at.pointState == AttachPoint.PointState.inField) { if (at.shipState == AttachPoint.ShipState.preSpawn) { //Debug.Log("spawn " + i.ToString ()); CBaseEnemy be; at.obj = (GameObject)Instantiate(def_shipType0, new Vector3(at.loc.x, at.loc.y, transform.position.z), new Quaternion()); be = at.obj.GetComponent <CBaseEnemy>(); be.m_formation = at; // if having null-exception here, then the def does not contain Component 'CBaseEnemy'. It should. m_spawnCount++; at.shipState = AttachPoint.ShipState.spawned; } else if (at.obj == null) { // killed at.obj = null; at.shipState = AttachPoint.ShipState.killed; } } else if (at.pointState == AttachPoint.PointState.left) { if (at.obj != null) { // leave area Destroy(at.obj); at.obj = null; at.shipState = AttachPoint.ShipState.left; } } if (at.shipState == AttachPoint.ShipState.preSpawn) { done = false; } if (at.shipState == AttachPoint.ShipState.spawned) { done = false; } } if (done && !m_done) { // this wave was completed. m_done = true; } base.Update(); }
public void SetAttached(AttachPoint point) { attachedTo = point; this.transform.parent = point.transform.parent; StartCoroutine(SmoothAttach()); Destroy(this.GetComponent <Rigidbody>()); Destroy(this.GetComponent <Grabbable>()); }
void OnTriggerEnter(Collider other) { if (other.GetComponent <AttachPoint>() != null) { otherAttachPoint = other.GetComponent <AttachPoint>(); otherAttachPoint.halo.enabled = true; } }
public void ForceDrop() { grabbed = false; pointAttachedTo = null; sprite.sortingOrder++; gameObject.layer -= 1; FailDrop(); }
public void OnLetGo(Container from) { if (!hoverObject) { return; } AttachPoint point = hoverObject.GetComponent <AttachPoint>(); point.InteractWith(this); }
public void AttachToPoint(GameObject point) { dj.connectedBody = point.GetComponent <Rigidbody2D>(); dj.enabled = true; currentAttachedPoint = point.GetComponent <AttachPoint>(); dj.distance = currentAttachedPoint.defaultDistance; swingDirection = currentAttachedPoint.swingDirection; LastAttachedPoint = point; isAttached = true; }
void OnTriggerExit(Collider other) { if (other.GetComponent <AttachPoint>() != null) { if (otherAttachPoint != null) { otherAttachPoint.halo.enabled = false; otherAttachPoint = null; } } }
void OnDestroy() { for (int i = 0; i < m_number; i++) { AttachPoint at = m_members[i]; if (at.obj != null) { Destroy(at.obj); } at.obj = null; } }
public void SelectAttachPoint(AttachPoint newPoint) { if (selectedAttachPoint != null) { selectedAttachPoint.SetSelected(false); } selectedAttachPoint = newPoint; selectedAttachPoint.SetSelected(true); UpdateValidPartCheck(); }
protected override void Awake() { base.Awake(); m_startTime = def_startTime; m_spawnCount = 0; for (int i = 0; i < m_number; i++) { AttachPoint at = m_members[i]; if (at.obj != null) { Destroy(at.obj); } at.obj = null; at.pointState = AttachPoint.PointState.preEnter; at.shipState = AttachPoint.ShipState.preSpawn; } }
void OnEnable() { mCam = cameraAttach != null ? cameraAttach : Camera.main; var attachPoint = AttachPoint.Get(attachPointName); if (attachPoint) { mAttachPoint = attachPoint.transform.position; } else { Debug.LogWarning("Unable to find attach point: " + attachPointName); mAttachPoint = Vector2.zero; } Update(); }
public IEnumerator AttachToPlayer(AttachPoint attachPoint) { float lerpTime = 0.15f; float timer = 0; float perc; Vector2 endPos = attachPoint.FreeAttachPoint(this); yAttachModifier = endPos.y - attachPoint.transform.position.y; Vector2 startPos = transform.position; sprite.sortingOrder--; while (timer <= lerpTime) { timer += Time.deltaTime; perc = timer / lerpTime; transform.position = Vector2.Lerp(startPos, endPos, perc); yield return(null); } pointAttachedTo = attachPoint; yield return(null); }
public void CopyFrom(AttachPoint src) { name = src.name; position = src.position; angle = src.angle; }
public bool CompareTo(AttachPoint src) { return(name == src.name && src.position == position && src.angle == angle); }
//this method attempts to load the image as well as a corrosponding json file, and create a matching FrameInfo object based off of those private FrameInfo LoadSingleFrame(string path, GaeAnimationInfo animationInfo) { path = System.IO.Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)); string pngPath = path + ".png"; string jsonPath = path + ".json"; if (!File.Exists(pngPath)) { return(null); } byte[] bytes = File.ReadAllBytes(pngPath); Texture2D tex = new Texture2D(2, 2); tex.LoadImage(bytes); tex.filterMode = FilterMode.Point; Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), 1); if (File.Exists(jsonPath)) { try { string jsonInfo = File.ReadAllText(jsonPath); FrameJsonInfo frameJsonInfo = JsonConvert.DeserializeObject <FrameJsonInfo>(jsonInfo); for (int i = 1; i < frameJsonInfo.attachPoints.Length; i++) { //this bit of code relies on conversion exceptions to make sure the data type is right. this only happens to class members are marked as [JsonRequiredAttribute] //this is probably really bad practice. especially since it relies on loaded objects to be of " Newtonsoft.Json.Linq.JObject" type but i dont know any better as of writing this try { frameJsonInfo.attachPoints[i] = (frameJsonInfo.attachPoints[i] as Newtonsoft.Json.Linq.JObject).ToObject <ArrayTypeUnkownAndSize>(); } catch (Exception) {} try { frameJsonInfo.attachPoints[i] = (frameJsonInfo.attachPoints[i] as Newtonsoft.Json.Linq.JObject).ToObject <AttachPoint>(); } catch (Exception) {} } float convertedX1 = 0; float convertedX2 = 0; float convertedY1 = 0; float convertedY2 = 0; bool isTwoHanded = false; for (int i = 0; i < frameJsonInfo.attachPoints.Length; i++) { if (frameJsonInfo.attachPoints[i] is AttachPoint) { if ((frameJsonInfo.attachPoints[i] as AttachPoint).name == "PrimaryHand") { AttachPoint hand1 = frameJsonInfo.attachPoints[i] as AttachPoint; convertedX1 = hand1.position.x * 16 - frameJsonInfo.x; convertedY1 = hand1.position.y * 16 - frameJsonInfo.y; } else if ((frameJsonInfo.attachPoints[i] as AttachPoint).name == "SecondaryHand") { AttachPoint hand2 = frameJsonInfo.attachPoints[i] as AttachPoint; convertedX2 = hand2.position.x * 16 - frameJsonInfo.x; convertedY2 = hand2.position.y * 16 - frameJsonInfo.y; isTwoHanded = true; } } } return(new FrameInfo(tex, sprite, convertedX1, convertedY1, convertedX2, convertedY2, frameJsonInfo.x, frameJsonInfo.y, isTwoHanded, path, animationInfo)); } catch (Exception) { throw new Exception("json seems to be invalid! or i dont know how to read jsons (prob the second one ;) )!"); } } return(new FrameInfo(tex, sprite, pngPath, animationInfo)); }
public ControlPoint(IObject Object, AttachPoint attachPoint) { this.Object = Object; this.attachPoint = attachPoint; }
void Start() { up = new AttachPoint(new Vector3(transform.position.x, transform.position.y + transform.localScale.y / 2), this, "up"); down = new AttachPoint(new Vector3(transform.position.x, transform.position.y - transform.localScale.y / 2), this, "down"); }
public IEnumerator Loader() { if (savedSpaceShip.shipName != "") { savedSpaceShip.partIndex = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".savedSpaceShip.partIndex"); myAPoints = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".myAPoints"); targetAPoints = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".targetAPoints"); int[] serialID = new int[savedSpaceShip.partIndex.Length]; thisPartAttachPoint = null; otherPartAttachPoint = null; thisParts = new ShipPart[savedSpaceShip.partIndex.Length]; otherParts = new ShipPart[savedSpaceShip.partIndex.Length]; ShipPart thisPart = null; ShipPart otherPart = null; int value; for (int i = 0; i < savedSpaceShip.partIndex.Length; i++) { thisPart = (ShipPart)Instantiate(partInstantiator.GetComponent <PartInstantiator>().partList[savedSpaceShip.partIndex[i]], (Vector2)(Camera.main.transform.position), Quaternion.Euler(-90, 180, 0)); int.TryParse(thisPart.name, out value); thisPart.name = (i + 100 + value).ToString(); int.TryParse(thisPart.name, out value); serialID [i] = value; otherPart = GameObject.Find(serialID[thisPart.attachedToIndex].ToString()).GetComponent <ShipPart>(); thisParts[i] = thisPart; otherParts[i] = otherPart; if (i == 0) { loadedShip = thisPart.gameObject; } shipScaleVertical += thisPart.GetComponent <BoxCollider>().size.y; } yield return(new WaitForEndOfFrame()); for (int i = 0; i < myAPoints.Length; i++) { Transform[] children = thisParts[i + 1].GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if ((child.name == "attachPoint(up)" && myAPoints[i] == 1) || (child.name == "attachPoint(down)" && myAPoints[i] == 2)) { thisPartAttachPoint = child.GetComponent <AttachPoint>(); } } children = otherParts[i + 1].GetComponentsInChildren <Transform>(); foreach (Transform child in children) { if ((child.name == "attachPoint(up)" && targetAPoints[i] == 1) || (child.name == "attachPoint(down)" && targetAPoints[i] == 2)) { otherPartAttachPoint = child.GetComponent <AttachPoint>(); } } thisPartAttachPoint.otherAttachPoint = otherPartAttachPoint; thisPartAttachPoint.Attach(); } } else { Debug.Log("Load failed."); } }
void OnTriggerEnter(Collider other) { if (other.GetComponent<AttachPoint>() != null) { otherAttachPoint = other.GetComponent<AttachPoint>(); otherAttachPoint.halo.enabled = true; } }
// Update is called once per frame void Update() { int currentLayerMask = allRaycastLayers; if (heldMovableObject != null && heldMovableObject is Limb) { //Debug.Log("USING holdingLimbRaycastLayers"); currentLayerMask = holdingLimbRaycastLayers; } bool shouldRaycast = true; if (heldMovableObject != null && heldMovableObject is Draggable) { shouldRaycast = false; } Ray inputRay = mainCamera.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(inputRay.origin, inputRay.direction, Color.blue, 1f); RaycastHit hit; if (shouldRaycast && Physics.Raycast(inputRay, out hit, 40, currentLayerMask)) { if (hit.collider.gameObject.layer == 8 || hit.collider.gameObject.layer == 9 || hit.collider.gameObject.layer == 10) { IHightlightableObject highlightableObject = hit.collider.gameObject.GetComponent <IHightlightableObject>(); if (highlightableObject != null && highlightableObject != currentHightlightedObject) { if (currentHightlightedObject != null) { currentHightlightedObject.HightlightEnd(); } currentHightlightedObject = highlightableObject; currentHightlightedObject.HightlightStart(); } } else { if (currentHightlightedObject != null) { currentHightlightedObject.HightlightEnd(); currentHightlightedObject = null; } } } else { if (currentHightlightedObject != null) { currentHightlightedObject.HightlightEnd(); currentHightlightedObject = null; } } if (Input.GetMouseButtonDown(0)) { if (currentHightlightedObject != null) { MovableObject moveableObject = currentHightlightedObject.GetGameObject().GetComponent <MovableObject>(); if (moveableObject != null) { heldMovableObject = moveableObject; heldMovableObject.OnMoveStart(); //currentZOffsetFromCamera = (heldMovableObject.gameObject.transform.position - mainCamera.transform.position).z; playerRigidbody.MovePosition(heldMovableObject.transform.position); //Limb move offset is from -1 to 1 in localspace. Turn it into normal -0.5 to 0.5 to use it as an anchor playerHingeJoint.connectedAnchor = heldMovableObject.GetMoveOffset() * 0.5f; //heldMovableObject.transform. playerHingeJoint.connectedBody = heldMovableObject.GetComponent <Rigidbody>(); } } } else if (Input.GetMouseButtonUp(0)) { if (heldMovableObject != null) { playerHingeJoint.connectedBody = null; heldMovableObject.OnMoveStop(); if (currentHightlightedObject != null && currentHightlightedObject is AttachPoint && heldMovableObject is Limb) { AttachPoint attachPoint = currentHightlightedObject as AttachPoint; if (!attachPoint.HasLimb()) { SoundEffects.PlayAudioAtLocation("critch", transform.position); attachPoint.AttachLimb(heldMovableObject as Limb, true); } } heldMovableObject = null; } } else if (Input.GetMouseButton(0)) { if (heldMovableObject != null) { Vector2 mouseDelta = (Vector2)Input.mousePosition - previousMousePosition; if (heldMovableObject is Limb) { //heldMovableObject.OnMoveInDirection(((Vector2)Input.mousePosition - previousMousePosition) * Time.deltaTime); //currentZOffsetFromCamera = (heldMovableObject.gameObject.transform.position - mainCamera.transform.position).z; playerRigidbody.MovePosition(mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, zOffsetFromCamera)) - Vector3.up * 0.35f); } else if (heldMovableObject is Draggable && mouseDelta.magnitude > Vector2.zero.magnitude) { heldMovableObject.OnMoveInDirection(mouseDelta); } } } previousMousePosition = Input.mousePosition; }
void Start() { up = new AttachPoint(new Vector3(transform.position.x,transform.position.y + transform.localScale.y / 2),this,"up"); down = new AttachPoint(new Vector3(transform.position.x,transform.position.y - transform.localScale.y / 2),this,"down"); }
void OnTriggerExit(Collider other) { if (other.GetComponent<AttachPoint>() != null) { if(otherAttachPoint != null) { otherAttachPoint.halo.enabled = false; otherAttachPoint = null; } } }
IEnumerator DoVictory() { //wait for player to land while (!mMoveCtrl.isGrounded) { yield return(null); } yield return(null); DisablePhysics(); float curT = 0f; //wait a bit while (curT < victoryToPortalWait) { //rotate Vector3 euler = transform.localEulerAngles; euler.z += victoryRotatePerSecond * Time.deltaTime; transform.eulerAngles = euler; curT += Time.deltaTime; yield return(null); } LoLManager.instance.PlaySound(soundExitPath, false, false); //move towards victory var destAttachPt = AttachPoint.Get(victoryAttachPoint); Vector2 start = transform.position; Vector2 end = destAttachPt.transform.position; curT = 0f; float dist = (end - start).magnitude; if (dist > 0f) { float moveDelay = dist / victoryToPortalSpeed; while (curT < moveDelay) { //rotate Vector3 euler = transform.localEulerAngles; euler.z += victoryRotatePerSecond * Time.deltaTime; transform.eulerAngles = euler; //move transform.position = Vector2.Lerp(start, end, Mathf.Clamp01(curT / moveDelay)); curT += Time.deltaTime; yield return(null); } transform.position = end; } //shrink curT = 0f; while (curT < victoryScaleOutDelay) { //rotate Vector3 euler = transform.localEulerAngles; euler.z += victoryRotatePerSecond * Time.deltaTime; transform.eulerAngles = euler; //scale transform.localScale = Vector3.Lerp(Vector3.one, Vector3.zero, Mathf.Clamp01(curT / victoryScaleOutDelay)); curT += Time.deltaTime; yield return(null); } transform.localScale = Vector3.zero; }
public IEnumerator Loader() { if (savedSpaceShip.shipName != "") { savedSpaceShip.partIndex = PlayerPrefsX.GetIntArray (savedSpaceShip.shipName + ".savedSpaceShip.partIndex"); myAPoints = PlayerPrefsX.GetIntArray (savedSpaceShip.shipName + ".myAPoints"); targetAPoints = PlayerPrefsX.GetIntArray(savedSpaceShip.shipName + ".targetAPoints"); int[] serialID = new int[savedSpaceShip.partIndex.Length]; thisPartAttachPoint = null; otherPartAttachPoint = null; thisParts = new ShipPart[savedSpaceShip.partIndex.Length]; otherParts = new ShipPart[savedSpaceShip.partIndex.Length]; ShipPart thisPart = null; ShipPart otherPart = null; int value; for (int i = 0; i < savedSpaceShip.partIndex.Length; i++) { thisPart = (ShipPart)Instantiate(partInstantiator.GetComponent<PartInstantiator>().partList[savedSpaceShip.partIndex[i]], (Vector2)(Camera.main.transform.position), Quaternion.Euler(-90,180,0)); int.TryParse (thisPart.name, out value); thisPart.name = (i + 100 + value).ToString(); int.TryParse (thisPart.name, out value); serialID [i] = value; otherPart = GameObject.Find(serialID[thisPart.attachedToIndex].ToString()).GetComponent<ShipPart>(); thisParts[i] = thisPart; otherParts[i] = otherPart; if (i == 0) { loadedShip = thisPart.gameObject; } shipScaleVertical += thisPart.GetComponent<BoxCollider>().size.y; } yield return new WaitForEndOfFrame(); for (int i = 0; i < myAPoints.Length; i++) { Transform[] children = thisParts[i+1].GetComponentsInChildren<Transform>(); foreach(Transform child in children) { if ((child.name == "attachPoint(up)" && myAPoints[i] == 1) || (child.name == "attachPoint(down)" && myAPoints[i] == 2)) { thisPartAttachPoint = child.GetComponent<AttachPoint>(); } } children = otherParts[i+1].GetComponentsInChildren<Transform>(); foreach(Transform child in children) { if ((child.name == "attachPoint(up)" && targetAPoints[i] == 1) || (child.name == "attachPoint(down)" && targetAPoints[i] == 2)) { otherPartAttachPoint = child.GetComponent<AttachPoint>(); } } thisPartAttachPoint.otherAttachPoint = otherPartAttachPoint; thisPartAttachPoint.Attach (); } } else { Debug.Log("Load failed."); } }
public void CopyFrom( AttachPoint src ) { name = src.name; position = src.position; angle = src.angle; }
// 添加一个模型到绑点上,如武器 翅膀 public void AttachModel(int modelId, AttachPoint ap) { }
public void AddPart(int displayIndex, int anchorIndex) { if (selectedAttachPoint == null) { return; } if (page * partDisplays.Count + displayIndex > partsList.Count) { return; } GameObject obj = GameObject.Instantiate(partsList[page * partDisplays.Count + displayIndex], selectedAttachPoint.transform); DronePart part = obj.GetComponent <DronePart>(); Transform anchor = part.GetAnchorPoint(anchorIndex); obj.transform.localEulerAngles = (Vector3.up * 180) - anchor.localEulerAngles; obj.transform.localPosition = -(anchor.localRotation * anchor.localPosition); obj.transform.SetParent(selectedAttachPoint.transform.parent, true); part.AttachToAnchor(anchorIndex); part.SetParentAttachPoint(selectedAttachPoint); selectedAttachPoint.SetSelected(false); selectedAttachPoint.gameObject.SetActive(false); selectedAttachPoint = null; SerializableDictionary <RESOURCE, float> costsIncurred = part.GetResourceCost(); if (costsIncurred.ContainsKey(RESOURCE.IRON)) { currentResourceCost.Iron += costsIncurred[RESOURCE.IRON]; } if (costsIncurred.ContainsKey(RESOURCE.COPPER)) { currentResourceCost.Copper += costsIncurred[RESOURCE.COPPER]; } if (costsIncurred.ContainsKey(RESOURCE.URANIUM)) { currentResourceCost.Uranium += costsIncurred[RESOURCE.URANIUM]; } SerializableDictionary <DroneStatFields, float> statsAdded = part.GetStatFields(); if (statsAdded.ContainsKey(DroneStatFields.HEALTH)) { currentDroneStats.Health += statsAdded[DroneStatFields.HEALTH]; } if (statsAdded.ContainsKey(DroneStatFields.POWER)) { currentDroneStats.Power += statsAdded[DroneStatFields.POWER]; } if (statsAdded.ContainsKey(DroneStatFields.FUEL)) { currentDroneStats.Fuel += statsAdded[DroneStatFields.FUEL]; } if (statsAdded.ContainsKey(DroneStatFields.STORAGE)) { currentDroneStats.Storage += statsAdded[DroneStatFields.STORAGE]; } UpdateCostDisplay(); UpdateAttachDistLimit(); }
public void SetParentAttachPoint(AttachPoint newParentPoint) { parentPoint = newParentPoint; attachType = parentPoint.attachType & attachType; UpdateAttachType(); }
public bool CompareTo( AttachPoint src ) { return (name == src.name && src.position == position && src.angle == angle); }
public void SetAttachPoint(AttachPoint attachPoint) { currentAttachPoint = attachPoint; }