Inheritance: UnityEngine.ScriptableObject
示例#1
0
    public static T GetComponentFromPath <T>(PathOrder pathOrder) where T : MonoBehaviour
    {
        GameObject targetHolder = GetObject(pathOrder.path);
        List <T>   components   = new List <T>(targetHolder.GetComponents <T>());

        return(components[pathOrder.order]);
    }
示例#2
0
 public void Add_Order(PathOrder order)
 {
     if (orders.Exists(x => x.Node.Coordinates.Equals(order.Node.Coordinates)))
     {
         CustomLogger.Instance.Warning(string.Format("Node {0} already has orders defined", order.Node.Coordinates.ToString()));
         return;
     }
     orders.Add(order);
 }
示例#3
0
    public Entity(Entity prototype, Tile tile, Building spawner)
    {
        Id = current_id;
        current_id++;
        Tile    = tile;
        Spawner = spawner;
        if (Spawner != null)
        {
            Spawner.Entities_Spawned.Add(this);
        }
        Tile.Entities.Add(this);
        Map.Instance.Entities.Add(this);

        Internal_Name    = prototype.Internal_Name;
        Type             = prototype.Type;
        Max_Duration     = prototype.Max_Duration;
        Min_Duration     = prototype.Min_Duration;
        Current_Duration = Limited_Duration ? Min_Duration + (RNG.Instance.Next_F() * (Max_Duration - Min_Duration)) : 0.0f;
        Sprites          = new List <SpriteData>();
        foreach (SpriteData data in prototype.Sprites)
        {
            Sprites.Add(data.Clone());
        }
        orders         = new List <PathOrder>();
        wait_time_left = 0.0f;
        current_order  = null;

        GameObject = GameObject.Instantiate(
            PrefabManager.Instance.Entity,
            new Vector3(
                tile.GameObject.transform.position.x,
                tile.GameObject.transform.position.y,
                tile.GameObject.transform.position.z
                ),
            Quaternion.identity,
            Map.Instance.Entity_Container.transform
            );
        GameObject.name = ToString();
        SpriteRenderer.sortingLayerName = "Buildings";

        Sprite = RNG.Instance.Item(Sprites);
        SpriteRenderer.sprite = SpriteManager.Instance.Get(Sprite.Name, Sprite.Type);

        if (Is_Animated)
        {
            animations_cooldown = Sprite.Animation_Frame_Time;
            animation_index     = 0;
        }
        if (Type == EntityType.Ship && Sprites.Count != 4)
        {
            CustomLogger.Instance.Error("Ship has invalid sprite count");
        }
    }
示例#4
0
 public Entity(string name, EntityType type, List <SpriteData> sprites, int min_duration, int max_duration)
 {
     Id            = -1;
     Internal_Name = name;
     Type          = type;
     Min_Duration  = min_duration;
     Max_Duration  = max_duration;
     Sprites       = new List <SpriteData>();
     foreach (SpriteData data in sprites)
     {
         Sprites.Add(data.Clone());
     }
     orders         = new List <PathOrder>();
     wait_time_left = 0.0f;
     current_order  = null;
 }
示例#5
0
    public void OnSave()
    {
        selectHolderPath = Node.GetObjectPath(selectManager.gameObject);
        functionList     = new InputPathPair[functions.Count];
        int cnt = 0;

        foreach (var item in functions)
        {
            PathOrder path = Node.GetComponentPath <Function>(item.Value);
            functionList[cnt]       = ScriptableObject.CreateInstance <InputPathPair>();
            functionList[cnt].input = item.Key;
            functionList[cnt].path  = path;
            cnt++;
        }
        EditorUtility.SetDirty(this);
    }
示例#6
0
    public static PathOrder GetComponentPath <T>(T component) where T : MonoBehaviour
    {
        string   path       = GetObjectPath(component.gameObject);
        int      order      = 0;
        List <T> components = new List <T>(component.gameObject.GetComponents <T>());

        for (int cnt = 0; cnt < components.Count; cnt++)
        {
            if (component == components[cnt])
            {
                order = cnt;
                break;
            }
        }

        PathOrder pathOrder = ScriptableObject.CreateInstance <PathOrder>();

        pathOrder.path  = path;
        pathOrder.order = order;
        return(pathOrder);
    }
示例#7
0
    protected void AddConnections(List <Connection> connections)
    {
        for (int c = 0; c < connections.Count; c++)
        {
            Connection info = connections[c];

            Vec2i a = info.a * new Vec2i(Room.Width, Room.Height);
            Vec2i b = info.b * new Vec2i(Room.Width, Room.Height);

            PathOrder order = new PathOrder(TileType.TempWall, floorType);

            if (info.xAxis)
            {
                if (b.x < a.x)
                {
                    Swap(ref a, ref b);
                    Swap(ref order.a, ref order.b);
                }

                int startX = a.x + Room.LimX, y = a.y + Room.HalfSizeY;

                floor.SetTile(startX, y, order.a);
                floor.SetTile(startX + 1, y, order.b);
            }
            else
            {
                if (b.y < a.y)
                {
                    Swap(ref a, ref b);
                    Swap(ref order.a, ref order.b);
                }

                int startY = a.y + Room.LimY, x = a.x + Room.HalfSizeX;

                floor.SetTile(x, startY, order.a);
                floor.SetTile(x, startY + 1, order.b);
            }
        }
    }
示例#8
0
    public void Update(float delta_time)
    {
        if (Limited_Duration)
        {
            Current_Duration -= TimeManager.Instance.Multiplier * delta_time;
            if (Current_Duration <= 0.0f)
            {
                Map.Instance.Delete_Entity(this);
            }
        }
        if (Is_Animated)
        {
            animations_cooldown -= delta_time;
            if (animations_cooldown <= 0.0f)
            {
                animation_index++;
                if (animation_index == Sprite.Animation_Sprites.Count)
                {
                    animation_index = 0;
                }
                SpriteRenderer.sprite = SpriteManager.Instance.Get(Sprite.Animation_Sprites[animation_index], Sprite.Type);
                animations_cooldown  += Sprite.Animation_Frame_Time;
            }
        }
        if (wait_time_left > 0.0f)
        {
            wait_time_left -= delta_time * TimeManager.Instance.Multiplier;
            return;
        }
        bool moving_road_south = false;

        if (Type == EntityType.Road_Path && !TimeManager.Instance.Paused)
        {
            if (Path == null || Path.Count == 0)
            {
                Map.Instance.Delete_Entity(this);
                CustomLogger.Instance.Error("Missing path");
                return;
            }

            if (Tile.Building == null || !Tile.Building.Is_Road)
            {
                Map.Instance.Delete_Entity(this);
                return;
            }

            Current_Movement = Mathf.Clamp01(Current_Movement + (delta_time * Speed * TimeManager.Instance.Multiplier));
            if (Current_Movement == 1.0f)
            {
                if (Path_Index == Path.Count - 2)
                {
                    Map.Instance.Delete_Entity(this);
                    return;
                }
                Change_Tile(Next_Node.Coordinates);
                GameObject.transform.position = new Vector3(Tile.GameObject.transform.position.x, Tile.GameObject.transform.position.y + (Tile.Building.Tags.Contains(Building.Tag.Bridge) ? BRIDGE_HEIGHT : 0.0f),
                                                            Tile.GameObject.transform.position.z);
                Path_Index++;
                Current_Node     = Path[Path_Index];
                Next_Node        = Path[Path_Index + 1];
                Current_Movement = 0.0f;
            }
            else
            {
                Vector3 current = new Vector3(
                    Tile.GameObject.transform.position.x,
                    Tile.GameObject.transform.position.y + (Tile.Building.Tags.Contains(Building.Tag.Bridge) ? BRIDGE_HEIGHT : 0.0f),
                    Tile.GameObject.transform.position.z
                    );
                Tile    next_tile = Map.Instance.Get_Tile_At(Next_Node.Coordinates);
                Vector3 next      = new Vector3(
                    next_tile.GameObject.transform.position.x,
                    next_tile.GameObject.transform.position.y + (next_tile.Building.Tags.Contains(Building.Tag.Bridge) ? BRIDGE_HEIGHT : 0.0f),
                    next_tile.GameObject.transform.position.z
                    );
                GameObject.transform.position = Vector3.Lerp(
                    current,
                    next,
                    Current_Movement
                    );
                moving_road_south = next_tile.Y < Tile.Y;
            }
        }
        else if (Type == EntityType.Ship && !TimeManager.Instance.Paused)
        {
            if (Path == null || Path.Count == 0)
            {
                Map.Instance.Delete_Entity(this);
                CustomLogger.Instance.Error("Missing path");
                return;
            }

            if (Tile.Building != null || !Tile.Has_Ship_Access)
            {
                Map.Instance.Delete_Entity(this);
                return;
            }

            Current_Movement = Mathf.Clamp01(Current_Movement + (delta_time * Speed * TimeManager.Instance.Multiplier));
            if (Current_Movement == 1.0f)
            {
                if (Path_Index == Path.Count - 2)
                {
                    Map.Instance.Delete_Entity(this);
                    return;
                }
                Change_Tile(Next_Node.Coordinates);
                GameObject.transform.position = new Vector3(Tile.GameObject.transform.position.x, Tile.GameObject.transform.position.y, Tile.GameObject.transform.position.z);
                Path_Index++;
                Current_Node     = Path[Path_Index];
                Next_Node        = Path[Path_Index + 1];
                Current_Movement = 0.0f;
            }
            else
            {
                Vector3 current = new Vector3(
                    Tile.GameObject.transform.position.x,
                    Tile.GameObject.transform.position.y,
                    Tile.GameObject.transform.position.z
                    );
                Tile    next_tile = Map.Instance.Get_Tile_At(Next_Node.Coordinates);
                Vector3 next      = new Vector3(
                    next_tile.GameObject.transform.position.x,
                    next_tile.GameObject.transform.position.y,
                    next_tile.GameObject.transform.position.z
                    );
                GameObject.transform.position = Vector3.Lerp(
                    current,
                    next,
                    Current_Movement
                    );
                bool orientation_change = false;
                if (next.x > current.x && Sprite != Sprites[1])
                {
                    //Facing east
                    Sprite             = Sprites[1];
                    orientation_change = true;
                }
                else if (next.x < current.x && Sprite != Sprites[3])
                {
                    //Facing west
                    Sprite             = Sprites[3];
                    orientation_change = true;
                }
                else if (next.y > current.y && Sprite != Sprites[0])
                {
                    //Facing north
                    Sprite             = Sprites[0];
                    orientation_change = true;
                }
                else if (next.y < current.y && Sprite != Sprites[2])
                {
                    //Facign south
                    Sprite             = Sprites[2];
                    orientation_change = true;
                }
                if (orientation_change)
                {
                    SpriteRenderer.sprite = SpriteManager.Instance.Get(Sprite.Name, Sprite.Type);
                }
                PathOrder order = orders.FirstOrDefault(x => x.Node.Coordinates.Equals(Tile.Coordinates));
                if (order != null && current_order != order)
                {
                    wait_time_left = order.Wait_Time;
                    current_order  = order;
                }
            }
        }
        int sorting_order = Map.Instance.Height - Tile.Coordinates.Y + 1 + (moving_road_south ? 1 : 0);

        if (SpriteRenderer.sortingOrder != sorting_order)
        {
            SpriteRenderer.sortingOrder = sorting_order;
        }
    }