void Update() { if (targetPosition == null) { GameObject target = GameObject.Find(userId); if (target == null) { return; } targetPosition = target.GetComponent <IsometricPosition>(); return; } // Move the camera accordingly. if (targetPosition.Vector() != cameraPosition.Vector()) { Vector2 gridPosition = Vector2.SmoothDamp( cameraPosition.Vector(), targetPosition.Vector(), ref velocity, DampTime, Mathf.Infinity, Time.deltaTime); cameraPosition.Set(gridPosition.x, gridPosition.y, Offset); } else { cameraPosition.x = targetPosition.x; cameraPosition.y = targetPosition.y; } }
void Start() { anim = GetComponent <Animator>(); isoPos = GetComponent <IsometricPosition>(); var eo = GetComponent <EntityObject>(); // Set the initial position var pos = eo.GetEData <EPositionData>().Pos; this.position = pos; this.position.z = 1; isoPos.SetPosition(this.position); eo.AddUpdateListener <PositionUpdate>((position) => { this.position = position.Pos; this.position.z = 1; velocity = position.Vel; }); eo.AddUpdateListener <PathUpdate>((path) => { done = false; Path = path.Path; dest = path.Dest; nodeNum = 0; }); eo.AddUpdateListener <StateUpdate>((state) => { State = state.State; }); }
private void RegisterNextPosition(float diffX, float diffY) { IsometricPosition pos = transform.gameObject.GetComponent <IsometricPosition>(); float x = pos.x + diffX; float y = pos.y + diffY; pos.Set(x, y, -1.0f); }
public PlayerControllerWrapper(float x, float y) { IsometricPosition position = context.AddComponent <IsometricPosition>(); position.Set(x, y); playerController = context.AddComponent <PlayerController>(); }
// Move current selection. private static void MoveObjects(float x, float y) { GameObject[] gameObjects = Selection.gameObjects; foreach (GameObject gameObject in gameObjects) { IsometricPosition position = gameObject.GetComponent <IsometricPosition>(); position.Set(position.x + x, position.y + y); } }
public void TestIsometricDepth( float x, float y, float relativeDepth, float expectedDepth) { GameObject empty = new GameObject(); IsometricPosition position = empty.AddComponent <IsometricPosition>(); position.Set(x, y, relativeDepth); Assert.AreEqual(position.depth, expectedDepth); }
public void TestChangingRelativeDepth(float x, float y, float depthChange) { Assert.AreNotEqual(depthChange, 0.0f); GameObject empty = new GameObject(); IsometricPosition position = empty.AddComponent <IsometricPosition>(); position.Set(x, y); Vector3 initialPosition = empty.transform.position; position.ChangeRelativeDepth(depthChange); Assert.AreNotEqual(initialPosition, empty.transform.position); position.ChangeRelativeDepth(0.0f); Assert.AreEqual(initialPosition, empty.transform.position); }
// Turns the list of the serializable objects into a single string // that should be exportable to the backend. private string serializeObjects(LinkedList <GameObject> serializableObjects) { List <string> jsonSerializedObjectList = new List <string>(); foreach (GameObject obj in serializableObjects) { // The Builder is attached to the game obejct. This is why // the Builder has to be serializable to persist after the // game ends. var builder = obj.GetComponent <SpriteGeneratorBuilder> (); var generator = builder.Build(); string exportString = null; // This is how we can check is some the actual type of the generator // is a subclass of SpriteGenerator. if (typeof(SpriteGenerator).IsAssignableFrom(generator.GetType())) { // All the attributes should be set from here. The ones that are // not set are kept to the values kept inside the Builder that // was attached to the game object when the object was generated. IsometricPosition pos = obj.GetComponent <IsometricPosition> (); float x = pos.x; float y = pos.y; // We have to do the same thing for lights that are attached to the object Light lightObject = obj.GetComponentInChildren <Light>(); if (lightObject != null) { GameObject lightAttachedTo = lightObject.gameObject; float lightX = lightAttachedTo.transform.position.x; float lightY = lightAttachedTo.transform.position.y; builder = builder.ByLightCoord(lightX, lightY); } IGenerator exportGenerator = (IGenerator)builder.ByCoord(x, y).Build(); exportString = exportGenerator.ToJson(); } if (exportString != null) { jsonSerializedObjectList.Add(exportString); } } return("[" + String.Join(",", jsonSerializedObjectList.ToArray()) + "]"); }
public void TestIsometricCalculation( float isometricX, float isometricY, float realX, float realY, float realZ) { GameObject empty = new GameObject(); IsometricPosition position = empty.AddComponent <IsometricPosition>(); position.Set(isometricX, isometricY); Vector3 realPosition = new Vector3(realX, realY, realZ); float diff = Vector3.Distance(empty.transform.position, realPosition); Assert.IsTrue(diff < epsilon); }
public void TestCreatingMapFeatureAddsComponents() { var wrapper = new MapFeatureManagerWrapper("id3"); var mapFeatureManager = wrapper.mapFeatureManager; Assert.IsTrue(mapFeatureManager.Create(wrapper.id, mapFeatureData)); GameObject go = GameObject.Find(wrapper.id); Assert.IsNotNull(go.GetComponent <IsometricPosition>()); Assert.AreEqual( go.transform.rotation, Quaternion.Euler(0.0f, 0.0f, 0.0f)); IsometricPosition component = go.GetComponent <IsometricPosition>(); Vector2 position = new Vector2(1.0f, 2.0f); Assert.AreEqual(component.Vector(), position); }
public void TestIsometricPositionSetters(float x, float y) { GameObject[] gameObjects = new GameObject[3]; IsometricPosition[] isometricPositions = new IsometricPosition[3]; for (int i = 0; i < gameObjects.Length; i++) { gameObjects[i] = new GameObject(); isometricPositions[i] = gameObjects[i].AddComponent <IsometricPosition>(); } isometricPositions[0].Set(x, y, 0.0f); isometricPositions[1].Set(x, y); isometricPositions[2].Set(new Vector2(x, y)); Assert.AreEqual(isometricPositions[0], isometricPositions[1]); Assert.AreEqual(isometricPositions[1], isometricPositions[2]); Assert.AreEqual(isometricPositions[2], isometricPositions[0]); }
public void TestChangingSpriteRenderersSortingOrder(int sortingOrder) { GameObject empty = new GameObject(); IsometricPosition position = empty.AddComponent <IsometricPosition>(); position.depth = (float)-sortingOrder; SpriteRenderer renderer = empty.AddComponent <SpriteRenderer>(); renderer.sortingOrder = -10; GameObject child = new GameObject(); SpriteRenderer childRenderer = child.AddComponent <SpriteRenderer>(); childRenderer.sortingOrder = 12; child.transform.parent = empty.transform; position.ChangeAllSpriteRenderersSortingOrder(); Assert.AreEqual(renderer.sortingOrder, sortingOrder); Assert.AreEqual(childRenderer.sortingOrder, sortingOrder); }
void Awake() { cameraPosition = transform.GetComponent <IsometricPosition>(); }
public void Init(float x, float y) { IsometricPosition position = transform.gameObject.AddComponent <IsometricPosition>(); position.Set(x + 0.5f, y + 0.5f, -1.0f); }
public Vector2 GetPosition() { IsometricPosition position = context.GetComponent <IsometricPosition>(); return(position.Vector()); }