Esempio n. 1
0
        private void UpdateTooltip(ElementPrototype baseElementPrototype, ElementPrototype bodyElementPrototype, ElementPrototype weaponElementPrototype)
        {
            var title = string.Format("Tower: {0}, {1}, {2}", baseElementPrototype.Name,
                                      bodyElementPrototype.Name, weaponElementPrototype.Name);

            var    percent = (GameManager.Instance.Game.GameTime - Plot.Tower.LastShot) / Plot.Tower.GetSpeed();
            string stats   = "Range: " + Plot.Tower.GetRange() + Environment.NewLine +
                             "Speed: Shoot every " + Plot.Tower.GetSpeed() + " seconds" + Environment.NewLine +
                             //"Shoot% " + percent * 100 + "%" + Environment.NewLine +
                             //"delta " + (GameManager.Instance.Game.GameTime - Plot.Tower.LastShot) + Environment.NewLine +
                             "Damages: " + Environment.NewLine;
            var damages = Plot.Tower.GetDamage();

            foreach (var damage in damages)
            {
                if (damage.Value != 0)
                {
                    stats += "\t" + damage.Value + " " + damage.Key + Environment.NewLine;
                }
            }

            tooltip.MultipleContent = new Dictionary <string, string>
            {
                { "default", title },
                { "ElementsStats", stats }
            };
        }
Esempio n. 2
0
 /// <inheritdoc cref="NotuiElement"/>
 public PolygonElement(ElementPrototype prototype, NotuiContext context, NotuiElement parent = null) :
     base(prototype, context, parent)
 {
     if (prototype is PolygonElementPrototype prot)
     {
         Vertices = prot.Vertices.ToList();
     }
 }
Esempio n. 3
0
 /// <inheritdoc cref="NotuiElement"/>
 public override void UpdateFrom(ElementPrototype other)
 {
     base.UpdateFrom(other);
     if (other is PolygonElementPrototype prot)
     {
         Vertices = prot.Vertices.ToList();
     }
 }
Esempio n. 4
0
 /// <inheritdoc cref="ElementPrototype"/>
 public override void UpdateFrom(ElementPrototype other)
 {
     base.UpdateFrom(other);
     if (other is BoxElementPrototype prot)
     {
         Size = prot.Size;
     }
 }
Esempio n. 5
0
 /// <inheritdoc cref="NotuiElement"/>
 public BoxElement(ElementPrototype prototype, NotuiContext context, NotuiElement parent = null) :
     base(prototype, context, parent)
 {
     if (prototype is BoxElementPrototype prot)
     {
         Size = prot.Size;
     }
 }
Esempio n. 6
0
 /// <inheritdoc cref="NotuiElement"/>
 public override void UpdateFrom(ElementPrototype other)
 {
     base.UpdateFrom(other);
     if (other is SegmentElementPrototype prot)
     {
         HoleRadius = prot.HoleRadius;
         Cycles     = prot.Cycles;
         Phase      = prot.Phase;
     }
 }
Esempio n. 7
0
 /// <inheritdoc cref="NotuiElement"/>
 public SegmentElement(ElementPrototype prototype, NotuiContext context, NotuiElement parent = null) :
     base(prototype, context, parent)
 {
     if (prototype is SegmentElementPrototype seprot)
     {
         HoleRadius = seprot.HoleRadius;
         Cycles     = seprot.Cycles;
         Phase      = seprot.Phase;
     }
 }
        public void Build()
        {
            if (Element == null)
            {
                Destroy(gameObject);
            }

            if (ElementPrototype == null)
            {
                ElementPrototype = PrototypeManager.Instance.GetPrototype <ElementPrototype>(Element.Uri);
            }

            var sprite = SpriteManager.Instance.GetChached("Images/Elements", ElementPrototype.SpritePath);

            FrontFace.material.SetTexture("_MainTex", sprite.texture);
            BackFace.material.SetTexture("_MainTex", sprite.texture);

            var tooltip = gameObject.AddComponent <WorldTooltipProvider>();

            tooltip.content = "Wild element: " + ElementPrototype.Name + " <i>(click to collect)</i>";
        }
Esempio n. 9
0
        private GameObject AddTowerPart(ElementPrototype elementPrototype, TowerSlotType slotType, Vector3 position, GameObject instance)
        {
            var    stat       = elementPrototype.ElementStats.FirstOrDefault(s => s.InSlot == slotType);
            string prefabName = "tower:base";

            if (stat == null)
            {
                Debug.LogWarningFormat("AddTowerPart Failed for {0} part not found {1}", elementPrototype.Name, slotType);
            }
            else
            {
                prefabName = stat.ModelPrefab;
            }
            var prefab       = PrefabManager.Instance.GetPrefab(prefabName);
            var part         = Instantiate(prefab, position, Quaternion.identity, instance.transform);
            var partRenderer = part.GetComponent <MeshRenderer>();
            var albedo       = partRenderer.material.GetTexture("_MainTex");

            partRenderer.material = Instantiate(PrefabManager.Instance.ProgressMaterial);
            partRenderer.material.SetColor("_Color", Color.white);
            partRenderer.material.SetTexture("_MainTex", albedo);
            partRenderer.material.SetFloat("shiftY", 30f);
            return(part);
        }
Esempio n. 10
0
    public static Level CreateNewLevel(int nodesCount, int nodesSize, Vector2Int gridSize)
    {
        var gridElements = new GridElementsArray(gridSize.x, gridSize.y);

        //define available positions
        var        cellsCount         = gridSize.x * gridSize.y;
        List <int> availablePositions = new List <int>();

        for (int i = 0; i < cellsCount; i++)
        {
            availablePositions.Add(i);
        }

        //store nodes to clear their paths
        var nodes       = new List <ElementPrototype>();
        var connections = new List <ElementPrototype>();

        for (int i = 0; i < nodesCount; i++)
        {
            //get an available position
            var nodeIndex         = UnityEngine.Random.Range(0, availablePositions.Count);
            var nodePositionIndex = availablePositions[nodeIndex];
            availablePositions.RemoveAt(nodeIndex);

            //create new node
            var(x, y) = Grid.IndexToPosition(nodePositionIndex, gridSize);
            var node = new ElementPrototype();
            nodes.Add(node);
            node.MaxPositions = nodesSize;
            gridElements.AddElement(node, x, y);

            //create a path to a connection
            var(prevX, prevY) = (x, y);
            for (int j = 0; j < nodesSize; j++)
            {
                //start with a random direction
                var dirIndex           = UnityEngine.Random.Range(0, 4);
                var foundValidPosition = false;
                for (int ind = 0; ind < 4; ind++)
                {
                    //shift position direction index each try
                    dirIndex = ++dirIndex % 4;
                    var dir = GetDirection(dirIndex);

                    //check if direction is available
                    var(nx, ny)        = (prevX + dir.x, prevY + dir.y);
                    foundValidPosition = CheckPosition(nx, ny, gridSize, ref gridElements);

                    //if position is not available try the next
                    if (!foundValidPosition)
                    {
                        continue;
                    }

                    //FOUND AN EMPTY CELL

                    //mark position as taken, update previous position and continue looking for the next position
                    gridElements.AddElementPositionOwnership(node, nx, ny);
                    var index = Grid.PositionToIndex(nx, ny, gridSize);
                    availablePositions.Remove(index);
                    (prevX, prevY) = (nx, ny);
                    break;
                }

                //if couldn't find any available position
                if (!foundValidPosition)
                {
                    if (j == 0) //if is confined destroy node
                    {
                        gridElements.RemoveElement(node);
                        nodes.Remove(node);
                    }
                    else //if still could manage to create some path use it...
                    {
                        node.MaxPositions = j;
                        gridElements.RemoveElementPositionOwnership(node, prevX, prevY);

                        var connection = new ElementPrototype();
                        connections.Add(connection);
                        gridElements.AddElement(connection, prevX, prevY);

                        var index = Grid.PositionToIndex(prevX, prevY, gridSize);
                        availablePositions.Remove(index);
                    }
                    break;
                }

                //if is the last position add a connection
                if (j == nodesSize - 1)
                {
                    gridElements.RemoveElementPositionOwnership(node, prevX, prevY);

                    var connection = new ElementPrototype();
                    connections.Add(connection);
                    gridElements.AddElement(connection, prevX, prevY);

                    var index = Grid.PositionToIndex(prevX, prevY, gridSize);
                    availablePositions.Remove(index);
                }
            }
        }

        return(new Level(nodes.ToArray(), connections.ToArray()));
    }
Esempio n. 11
0
 /// <summary>
 /// Regular constructor
 /// </summary>
 /// <param name="id">If null generate a new ID with System.GUID</param>
 /// <param name="parent">Optional parent element if this prototype is a child</param>
 public SphereElementPrototype(string id = null, ElementPrototype parent = null) :
     base(typeof(SphereElement), id, parent)
 {
 }
Esempio n. 12
0
 /// <inheritdoc cref="NotuiElement"/>
 public SphereElement(ElementPrototype prototype, NotuiContext context, NotuiElement parent = null) :
     base(prototype, context, parent)
 {
 }
Esempio n. 13
0
 /// <summary>
 /// Regular constructor
 /// </summary>
 /// <param name="id">If null generate a new ID with System.GUID</param>
 /// <param name="parent">Optional parent element if this prototype is a child</param>
 public VoidElementPrototype(string id = null, ElementPrototype parent = null) :
     base(typeof(VoidElement), id, parent)
 {
 }
Esempio n. 14
0
 /// <summary>
 /// Regular constructor
 /// </summary>
 /// <param name="id">If null generate a new ID with System.GUID</param>
 /// <param name="parent">Optional parent element if this prototype is a child</param>
 public InfinitePlaneElementPrototype(string id = null, ElementPrototype parent = null) :
     base(typeof(InfinitePlaneElement), id, parent)
 {
 }
Esempio n. 15
0
 /// <summary></summary>
 /// <param name="prototype"></param>
 /// <param name="context"></param>
 /// <param name="parent"></param>
 protected PlanarElement(ElementPrototype prototype, NotuiContext context, NotuiElement parent = null) :
     base(prototype, context, parent)
 {
 }
Esempio n. 16
0
 /// <summary>
 /// Regular constructor
 /// </summary>
 /// <param name="id">If null generate a new ID with System.GUID</param>
 /// <param name="parent">Optional parent element if this prototype is a child</param>
 public PolygonElementPrototype(string id = null, ElementPrototype parent = null) :
     base(typeof(PolygonElement), id, parent)
 {
 }
Esempio n. 17
0
 /// <inheritdoc cref="NotuiElement"/>
 public InfinitePlaneElement(ElementPrototype prototype, NotuiContext context, NotuiElement parent = null) :
     base(prototype, context, parent)
 {
 }
Esempio n. 18
0
 /// <summary>
 /// Regular constructor
 /// </summary>
 /// <param name="id">If null generate a new ID with System.GUID</param>
 /// <param name="parent">Optional parent element if this prototype is a child</param>
 public RectangleElementPrototype(string id = null, ElementPrototype parent = null) :
     base(typeof(RectangleElement), id, parent)
 {
 }
Esempio n. 19
0
 /// <summary>
 /// Regular constructor
 /// </summary>
 /// <param name="id">If null generate a new ID with System.GUID</param>
 /// <param name="parent">Optional parent element if this prototype is a child</param>
 public CircleElementPrototype(string id = null, ElementPrototype parent = null) :
     base(typeof(CircleElement), id, parent)
 {
 }