public void LoadGeoGroupInfo(GeoGroupInfo ggi) { Cur_GGI = ggi.Clone(); foreach (GeoElement geo in GeoElements) { geo.PoolRecycle(); } GeoElements.Clear(); MyState = States.None; StartDragMove = false; IsMouseIn = false; MouseLeftDown = false; SortingOrder = 2; foreach (GeoInfo gi in ggi.GeoInfos) { GeoElement ge = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoElement].AllocateGameObject <GeoElement>(transform); ge.transform.localPosition = gi.Position; ge.transform.rotation = gi.Rotation; ge.Initialize(gi.GeoType, gi.Size * GameManager.Instance.ScaleFactor * GameManager.Instance.ScaleFactor, gi.Color, gi.SortingOrder); SortingOrder = Mathf.Max(SortingOrder, gi.SortingOrder + 1); GeoElements.Add(ge); } }
public void Init(Species species, GeoGroupInfo ci, float _size, bool randomSize = false) { MyGeoGroupInfo = ci; Rigidbody2D.mass = MyGeoGroupInfo.Mass; if (randomSize) { Size = Random.Range(MyGeoGroupInfo.MinSize, MyGeoGroupInfo.MaxSize); } else { Size = _size; } Life = ci.Life * Size / ci.MaxSize; Damage = ci.Damage * Size / ci.MaxSize; GeoGroup?.PoolRecycle(); GeoGroup = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoGroup].AllocateGameObject <GeoGroup>(transform); My_Species = species; M_SpeciesName = species.MyGeoGroupInfo.Name; foreach (GeoInfo gi in species.MyGeoGroupInfo.GeoInfos) { GeoElement ge = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoElement].AllocateGameObject <GeoElement>(GeoGroup.transform); ge.Collider.enabled = false; GeoGroup.AllGeos.Add(ge); GeoGroup.GeoGroupInfo = species.MyGeoGroupInfo; ge.transform.localPosition = (gi.Position - ci.Center) / GameManager.Instance.ScaleFactor / GameManager.Instance.ScaleFactor; ge.transform.rotation = gi.Rotation; ge.Initialize(gi.GeoType, gi.Size, gi.Color, gi.SortingOrder); } MyCollider.radius = MyGeoGroupInfo.ColliderRadius; }
public void OnMouseLeftDrag() { Vector2 startPos = MouseLeftDownPos; endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); switch (MyState) { case States.None: { break; } case States.Select: { if (StartDragMove) { if (CurrentEditGeoElement != null) { CurrentEditGeoElement.transform.Translate(endPos.x - lastMousePos.x, endPos.y - lastMousePos.y, 0, Space.World); } } break; } case States.Draw: { break; } case States.DuringDrawing: { GeoTypes gt = UIManager.Instance.GetBaseUIForm <CreatureEditorPanel>().CurrentDrawGeoType; GeoManager.GeoDrawingSetting gds = GeoManager.Instance.GeoDrawingSettingsDict[gt]; Color c = UIManager.Instance.GetBaseUIForm <CreatureEditorPanel>().GetCurrentColor(); if (CurrentEditGeoElement == null) { CurrentEditGeoElement = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.GeoElement].AllocateGameObject <GeoElement>(transform); CurrentEditGeoElement.transform.position = startPos; CurrentEditGeoElement.transform.localRotation = Quaternion.AngleAxis(gds.DefaultRotation, Vector3.back); float size = (endPos - startPos).magnitude * gds.SizeRatio; SortingOrder += 2; CurrentEditGeoElement.Initialize(gt, Vector2.one * size, c, SortingOrder); GeoElements.Add(CurrentEditGeoElement); break; } else { float rotateAngle = Vector2.SignedAngle(endPos - startPos, Vector2.right) + gds.DefaultRotation; CurrentEditGeoElement.transform.localRotation = Quaternion.AngleAxis(rotateAngle, Vector3.back); float size = (endPos - startPos).magnitude * gds.SizeRatio; CurrentEditGeoElement.Initialize(gt, Vector2.one * size, c, SortingOrder); Vector2 rotatedOffset = new Vector2(gds.PivotOffset.x * Mathf.Cos(Mathf.Deg2Rad * rotateAngle) + gds.PivotOffset.y * Mathf.Sin(Mathf.Deg2Rad * rotateAngle), -gds.PivotOffset.x * Mathf.Sin(Mathf.Deg2Rad * rotateAngle) + gds.PivotOffset.y * Mathf.Cos(Mathf.Deg2Rad * rotateAngle)); Vector2 pivotPos = startPos + rotatedOffset * size / GameManager.Instance.ScaleFactor / GameManager.Instance.ScaleFactor; CurrentEditGeoElement.transform.position = pivotPos; break; } } case States.Delete: { break; } } lastMousePos = endPos; }