Exemple #1
0
 protected override void Load()
 {
     this.name = "Cafe Room";
     floor     = new GameObject("Floor");
     walls     = new GameObject("Walls");
     floor.transform.SetParent(this.transform);
     walls.transform.SetParent(this.transform);
     //UnityUtils.CreateMesh(floor, "cafe_room", "cafe_floor", "cafe_floor_material");
     //UnityUtils.CreateMesh(walls, "cafe_room", "cafe_walls", "cafe_wall_material");
     tiles = new List <TileTuple>();
     for (int i = 0; i < Model.Width - 1; i++)
     {
         for (int j = 0; j < Model.Height - 1; j++)
         {
             var tile = new GameObject("tile");
             tile.transform.position = TurtleUtils.CafeSpaceToWorldCoordinates(new Vector2(i + 0.5f, j + 0.5f), 0.01f);
             tile.transform.SetParent(this.transform);
             UnityUtils.CreateMesh(tile, "quad", "quad", "default");
             tile.transform.localScale = 0.1f * Vector3.one;
             tile.GetComponent <MeshRenderer>().material.color = Color.Lerp(Color.red, Color.white, 0.5f);
             tiles.Add(new TileTuple()
             {
                 X = i, Y = j, Tile = tile
             });
         }
     }
 }
Exemple #2
0
        protected override void Load()
        {
            mainCamera = GameObject.Find("Camera").GetComponent <Camera>();
            offset     = TurtleUtils.CafeSpaceToWorldCoordinates(new Vector2(-2, 0));
            // Load animation data
            IJsonObject globalSpriteData = ReadOnlyData.JsonData["sprites"];
            IJsonObject mySpriteData     = globalSpriteData["sprites"][Model.SpriteReferenceTag];
            IJsonObject templateData     = mySpriteData["template"] == null ? null : globalSpriteData["templates"][mySpriteData["template"].AsString];

            resourceName = GetDataFromNodeWithFallback("resourceName", mySpriteData, templateData).AsString;
            columns      = GetDataFromNodeWithFallback("columns", mySpriteData, templateData).AsInt;
            rows         = GetDataFromNodeWithFallback("rows", mySpriteData, templateData).AsInt;
            int numFrames = columns * rows;

            // Initialize animation data
            animationDataDictionary = new Dictionary <string, AnimationData>();
            IJsonObject animationData = GetDataFromNodeWithFallback("animations", mySpriteData, templateData);

            foreach (String jsonObjectName in animationData.AsDictionary.Keys)
            {
                IJsonObject        jsonAnimationData = animationData[jsonObjectName];
                List <IJsonObject> startAndEnd       = jsonAnimationData["range"].AsList;
                int start = startAndEnd[0].AsInt;
                int end   = start;
                if (startAndEnd.Count > 1)
                {
                    end = startAndEnd[1].AsInt;
                }
                int  frameDuration = GetDataFromNodeWithFallback("frameDuration", jsonAnimationData, mySpriteData, templateData).AsInt;
                bool flipX = false, flipY = false;
                if (jsonAnimationData["flip"] != null)
                {
                    flipX = jsonAnimationData["flip"].AsString.ToLower().Contains("x");
                    flipY = jsonAnimationData["flip"].AsString.ToLower().Contains("y");
                }
                animationDataDictionary.Add(jsonObjectName, new AnimationData()
                {
                    Name = jsonObjectName, Start = start, End = end, FlipX = flipX, FlipY = flipY, FrameDuration = frameDuration
                });
                if (start == 0)
                {
                    currentAnimationRange = animationDataDictionary[jsonObjectName];
                }
            }

            spriteRenderer = gameObject.AddComponent <SpriteRenderer>();
            sprites        = new List <Sprite>();
            sprites.AddRange(Resources.LoadAll <Sprite>("Sprites/" + resourceName));
            spriteRenderer.sprite = sprites[currentAnimationFrame];
        }
        public bool Intersects(WorldObjectModel physicalModel)
        {
            Plane p = new Plane(Vector3.up, 0);
            float enter;
            bool  intersects = p.Raycast(WorldSpaceRay, out enter);

            if (intersects)
            {
                Vector3 entryPoint = TurtleUtils.WorldSpacePointToCafeCoordinates(WorldSpaceRay.GetPoint(enter));
                intersects = intersects && Math.Abs(entryPoint.x - physicalModel.Position.x) < physicalModel.Width / 2f;
                intersects = intersects && Math.Abs(entryPoint.y - physicalModel.Position.y) < physicalModel.Height / 2f;
            }
            return(intersects);
        }
Exemple #4
0
 protected override void UpdateView()
 {
     transform.position = TurtleUtils.CafeSpaceToWorldCoordinates(Model.Position) + offset + new Vector3(0, 0, 0.001f * SortOrder);
     transform.rotation = mainCamera.transform.rotation;
     timer++;
     if (timer == currentAnimationRange.FrameDuration)
     {
         currentAnimationFrame++;
         if (currentAnimationFrame > currentAnimationRange.End)
         {
             currentAnimationFrame = currentAnimationRange.Start;
         }
         spriteRenderer.sprite = sprites[currentAnimationFrame];
     }
     if (!CurrentAnimation.Equals(currentAnimationRange.Name))
     {
         timer = 0;
         currentAnimationRange = animationDataDictionary[CurrentAnimation];
         currentAnimationFrame = currentAnimationRange.Start;
         spriteRenderer.sprite = sprites[currentAnimationFrame];
     }
 }