void Awake() { rd = GetComponentInChildren <ResourceDrop>(); cm = GetComponentInChildren <UEO_ColorCycler>(); oc = GetComponentInChildren <UEO_ObjectCycler>(); cs = GetComponentInChildren <UEO_ScaleManipulator>(); }
public virtual void SetProperties(SimpleJSON.JSONClass N) { // return; // Debug.Log("set prop:"+N.ToString()); if (N.GetKeys().Contains(uuidKey)) { SetUuid("setprop", N[uuidKey].AsInt); // Debug.Log("just set my uuid key:"+N[uuidKey].AsInt); } ResourceDrop rd = GetComponentInChildren <ResourceDrop>(); if (rd && N.GetKeys().Contains(ResourceDrop.key)) { // Debug.Log("set prop resource:"+N.ToString()); rd.SetProperties(N); } if (N.GetKeys().Contains(JsonUtil.scaleKey)) { // Debug.Log("set scale on: "+myName+", "+N[JsonUtil.scaleKey].AsInt); // name += " scaled."; transform.localScale = JsonUtil.GetScaleFromInt(N[JsonUtil.scaleKey].AsInt); scaleSetFromInstanceLoad = true; } UEO_ScaleManipulator cs = GetComponentInChildren <UEO_ScaleManipulator>(); if (cs && N.GetKeys().Contains(UEO_ScaleManipulator.key)) { int x = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyX].Value); int y = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyY].Value); int z = MathUtils.IntParse(N[UEO_ScaleManipulator.key][UEO_ScaleManipulator.keyZ].Value); cs.transform.localScale = new Vector3(x, y, z); cs.UpdateSize(x, y, z); // if (cloneObject) cloneObject.transform.localScale = transform.localScale; } if (N.GetKeys().Contains(UEO_ColorCycler.colorManipulatorKey)) { UEO_ColorCycler cc = GetComponentInChildren <UEO_ColorCycler>(); if (cc) { cc.SetProperties(N); } } if (N.GetKeys().Contains(UEO_ObjectCycler.objectIndexKey)) { UEO_ObjectCycler cc = GetComponentInChildren <UEO_ObjectCycler>(); if (cc) { cc.SetProperties(N); } } if (N.GetKeys().Contains(tagsKey)) { if (N[tagsKey].Value.Length > 0) { myTags.AddRange(N[tagsKey].Value.Split(',')); // Debug.Log("<color=#f0f>addtag:</color>"+N[tagsKey].Value); } // Debug.Log("tags!:"+tags+", json val:"+N[tagsKey].ToString()); } else { // print("no tagskey on:"+myName); } PickUppableObject pip = GetComponent <PickUppableObject>(); if (pip) { // Vadim todo add Interface IMySetProperties? pip.SetProperties(N); } }
void LateUpdate() { if (!LevelBuilder.inst.levelBuilderIsShowing) { return; } float fadeSpeed = 3f; Color newc = Color.Lerp(lr.material.color, Color.clear, Time.unscaledDeltaTime * fadeSpeed); lr.material.SetColor("_Color", newc); lineTimer -= Time.unscaledDeltaTime; destroyTimer -= Time.unscaledDeltaTime; if (lineTimer < 0) { lr.SetVertexCount(0); } else { } // if (Input.GetMouseButtonDown(0)){ // JsonLevelSaver.inst.LevelBuilderUndo(); // } activeTarget = GetTarget(); if (activeTarget == null) { return; } UserEditableObject ueo = activeTarget.ueo; if (!ueo) { moveObj = null; copyObj = null; return; } if (Input.GetKey(KeyCode.Backspace) && destroyTimer < 0) { if (LevelBuilder.inst.levelBuilderIsShowing) { if (activeTarget.ueo) { destroyTimer = 0.5f; LevelBuilder.inst.DeleteObject(activeTarget.ueo.gameObject); DrawTargetLine(Color.red, activeTarget.p); } } } float wd = Input.mouseScrollDelta.y; // could be 0.1, 0.5, or 4, 5 agt high speeds if (wd != 0) { wd = wd > 0 ? Mathf.Max(wd, 0.5f) : Mathf.Min(-0.5f, wd); ueo.transform.position += Vector3.up * Mathf.RoundToInt((wd * 0.5f) * 4) * 0.5f; DrawTargetLine(Color.blue, activeTarget.p); } float moveFactor = 0.5f; if (Input.GetKey(KeyCode.RightBracket)) { ueo.transform.position += Vector3.up * moveFactor; DrawTargetLine(Color.green, activeTarget.p); } else if (Input.GetKey(KeyCode.LeftBracket)) { ueo.transform.position += Vector3.down * moveFactor; DrawTargetLine(Color.green, activeTarget.p); } else if (Input.GetKey(KeyCode.F)) { ueo.transform.position += Utils.FlattenVector(transform.forward).normalized *moveFactor; DrawTargetLine(Color.green, activeTarget.p); } else if (Input.GetKey(KeyCode.B)) { ueo.transform.position += Utils.FlattenVector(-transform.forward).normalized *moveFactor; DrawTargetLine(Color.green, activeTarget.p); } else if (Input.GetKey(KeyCode.R)) { ueo.transform.position += Utils.FlattenVector(transform.right).normalized *moveFactor; DrawTargetLine(Color.green, activeTarget.p); } else if (Input.GetKey(KeyCode.L)) { ueo.transform.position += Utils.FlattenVector(-transform.right).normalized *moveFactor; DrawTargetLine(Color.green, activeTarget.p); } else if (Input.GetKeyDown(KeyCode.Equals)) { UEO_ScaleManipulator scale = ueo.GetComponentInChildren <UEO_ScaleManipulator>(); if (scale) { scale.transform.localScale += scale.scaleFactor * Vector3.one; DrawTargetLine(Color.magenta, activeTarget.p); } } else if (Input.GetKeyDown(KeyCode.Minus)) { UEO_ScaleManipulator scale = ueo.GetComponentInChildren <UEO_ScaleManipulator>(); if (scale) { scale.transform.localScale -= scale.scaleFactor * Vector3.one; DrawTargetLine(Color.magenta, activeTarget.p); } } if (Input.GetKeyDown(KeyCode.C)) { carryingCopyObjecty = true; copyObj = LevelBuilder.inst.DuplicateObject(ueo.transform.position, ueo.gameObject); copyObjDist = Vector3.Distance(copyObj.transform.position, transform.position); } if (copyObj) { copyObj.transform.position = transform.position + transform.forward * copyObjDist; DrawTargetLine(Color.yellow, copyObj.transform.position); } if (Input.GetKeyUp(KeyCode.C)) { copyObj = null; carryingCopyObjecty = false; } int shift = Input.GetKey(KeyCode.LeftShift) ? 9 : 1; // if hold shift, rotate 45 degrees instead of 5 if (Input.GetMouseButtonDown(1)) { ueo.transform.Rotate(Vector3.up, 5 * shift); DrawTargetLine(Color.green, ueo.transform.position); } if (Input.GetMouseButtonDown(2)) { ueo.transform.Rotate(Vector3.up, -5 * shift); DrawTargetLine(Color.green, ueo.transform.position); } if (Input.GetMouseButtonDown(0)) { // hold right mouse to begin moving // Debug.Log("mousdown got:"+moveObj); moveObj = ueo.gameObject; moveObjOffset = transform.InverseTransformVector(moveObj.transform.position - transform.position); // moveObjDist = Vector3.Distance(moveObj.transform.position,transform.position); } if (moveObj) { moveObj.transform.position = transform.position + transform.TransformVector(moveObjOffset); // moveObj.transform.position = transform.position + transform.forward * moveObjDist + moveObjOffset; DrawTargetLine(Color.blue, transform.position + transform.forward * 10f); } if (Input.GetMouseButtonUp(0)) { moveObj = null; } }