Ejemplo n.º 1
0
    private void Update()
    {
        isCreating = player.controls.Player.Create.phase == UnityEngine.InputSystem.InputActionPhase.Performed;

        //Unselect creatable if not creating
        if (!isCreating && creatable)
        {
            creatable.UnSelect();
            creatable = null;
        }

        spawnPosition = Vector2.SmoothDamp(spawnPosition, spawnGoalPosition, ref smoothVelocity, 0.1f);
    }
Ejemplo n.º 2
0
    /**
     * Instantiates a tray before a Customer.
     */
    public void onClick(Customer customer)
    {
        if (customer.CurrentState == Customer.State.EMPTY_HANDED)
        {
            Transform customerTransform = customer.transform;
            Vector3   trayPosition      = customerTransform.position;

            trayPosition   += customerTransform.forward * TRAY_DISTANCE;
            trayPosition.y += TRAY_HEIGHT;

            customer.HeldItem     = Creatable.Create <Tray>(tray, trayPosition, customerTransform.rotation, customerTransform);
            customer.CurrentState = Customer.State.HOLDING_ITEM;
        }
    }
Ejemplo n.º 3
0
    /**
     * Hands the Customer a glass, if they're not holding anything already.
     *
     * <param name="customer">The Customer.</param>
     */
    public void onClick(Customer customer)
    {
        if (customer.CurrentState == Customer.State.EMPTY_HANDED)
        {
            Transform customerTransform = customer.transform;
            Vector3   glassPosition     = customerTransform.position;

            glassPosition   += customerTransform.forward * GLASS_DISTANCE;
            glassPosition.y += GLASS_HEIGHT;

            customer.HeldItem     = Creatable.Create <Cup>(glass, glassPosition, customerTransform.rotation, customerTransform);
            customer.CurrentState = Customer.State.HOLDING_ITEM;
        }
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates a Creatable instance by using a definition
        /// contained in a node specified by an xpath.
        /// If the specified xpath gives more than one result,
        /// a Creatable is selected randomly.
        /// </summary>
        /// <param name="xpath">The xpath to the node
        /// containing the Creatable definition</param>
        /// <returns>The generated Creatable instance</returns>
        public Creatable Generate(string xpath)
        {
            XmlNodeList nodes = doc.SelectNodes(xpath);

            if (nodes.Count == 0)
            {
                throw new InvalidOperationException("No matching Creatable definition found in " + filename);
            }
            XmlElement prototype    = (XmlElement)nodes[Rng.Random.Next(nodes.Count)];
            string     typeName     = prototype.Attributes[TYPE_NAME].Value;
            string     assemblyName = prototype.Attributes[ASSEMBLY_NAME].Value;
            Assembly   assembly     = AssemblyCache.GetAssembly(Application.StartupPath + "/" + assemblyName);
            Creatable  creatable    = (Creatable)assembly.CreateInstance(typeName);

            creatable.Create(prototype);
            return(creatable);
        }
    /**
     * Adds a plate to the Customer's Tray, if one is held.
     *
     * <param name="customer">The Customer.</param>
     */
    public void onClick(Customer customer)
    {
        if (customer.CurrentState == Customer.State.HOLDING_ITEM &&
            customer.HeldItem is Tray)
        {
            Tray tray = (Tray)customer.HeldItem;

            Transform trayTransform = tray.transform;
            Vector3   aboveTray     = trayTransform.position + (Vector3.up * 0.3f) + (Vector3.back * .1f);

            Plate plateObject = Creatable.Create <Plate>(plate, aboveTray, trayTransform.rotation, trayTransform);

            // Prevent the Plate from interacting with the Player's collider when spawned/placed on the Tray.
            Physics.IgnoreCollision(plateObject.GetComponent <Collider>(), customer.GetComponent <Collider>());

            tray.addItem(plateObject.gameObject);
            plateObject.HeldTray = tray;
        }
    }
Ejemplo n.º 6
0
 private void find_texture()
 {
     if (Directory.Exists(ProgramData.Project.OtherResourcesPath))
     {
         foreach (var file in Directory.GetFiles(ProgramData.Project.OtherResourcesPath))
         {
             if (System.IO.Path.GetExtension(file).ToLower() == ".json")
             {
                 Creatable item = File.ReadAllText(file).ToObject <Creatable>();
                 if (item.id == (int)nudId.Value)
                 {
                     string path = ProgramData.Project.ItemsOpaquePath + item.texture.name + "_" + item.texture.meta + ".png";
                     if (!File.Exists(path))
                     {
                         path = ProgramData.Project.TerrainAtlasPath + item.texture.name + "_" + item.texture.meta + ".png";
                     }
                     if (!File.Exists(path))
                     {
                         MessageBox.Show("Cannot find texture for id: " + nudId.Value);
                         return;
                     }
                     checkedNow.BackgroundImage = new Bitmap(path);
                     return;
                 }
             }
         }
     }
     try
     {
         checkedNow.BackgroundImage = new Bitmap("icons\\items\\" + (int)nudId.Value + "_" + (int)nudMeta.Value + ".png");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Cannot find texture for id: " + nudId.Value);
     }
 }
Ejemplo n.º 7
0
    public void Creating(Vector2 input)
    {
        input = input.normalized;
        int   sections   = 10;
        float deltaAngle = 360 / (sections);

        //Find Collision in Radius with Circular raycasts
        Vector2      rod = input * createRadius;
        RaycastHit2D hit;

        for (int i = 0; i < 5; i++)
        {
            //right
            float   angle   = deltaAngle * i;
            Vector2 dir     = rod.Rotate(angle);
            Vector2 nextDir = rod.Rotate(angle + deltaAngle);
            Vector3 orthDir = nextDir - dir;

            hit = Physics2D.Raycast((Vector2)transform.position, dir, dir.magnitude, createLayer);

            if (!hit)
            {
                hit = Physics2D.Raycast((Vector2)transform.position + dir, orthDir, orthDir.magnitude, createLayer);
                Debug.DrawRay((Vector2)transform.position + dir, orthDir);
            }

            //right
            if (!hit)
            {
                angle   = -deltaAngle * i;
                dir     = rod.Rotate(angle);
                nextDir = rod.Rotate(angle - deltaAngle);
                orthDir = nextDir - dir;

                hit = Physics2D.Raycast((Vector2)transform.position, dir, dir.magnitude, createLayer);

                if (!hit)
                {
                    hit = Physics2D.Raycast((Vector2)transform.position + dir, orthDir, orthDir.magnitude, createLayer);
                    Debug.DrawRay((Vector2)transform.position + dir, orthDir);
                }
            }
            // Impossible to spawn rigids on dynamic rigids...
            if (hit && hit.rigidbody && hit.rigidbody.bodyType == RigidbodyType2D.Dynamic)
            {
                continue;
            }

            //Found hit and its a creatable (Can spawn stuff on it)
            if (hit && hit.transform.GetComponent <Creatable>())
            {
                //Set Information for Creators
                spawnGoalPosition = hit.point;
                this.spawnDir     = hit.normal;
                canCreate         = true;

                //Unselect old selection
                Creatable newCreatable = hit.transform.GetComponent <Creatable>();
                if (creatable != newCreatable)
                {
                    spawnPosition = spawnGoalPosition;
                    if (creatable)
                    {
                        creatable.UnSelect();
                    }
                }
                //Select creatable
                creatable = newCreatable;
                creatable.Select(spawnPosition, player.color);

                //Happy with first creatable.
                return;
            }
        }
        //Couldn't find any creatable
        canCreate = false;
        //Unselect creatable
        if (creatable)
        {
            creatable.UnSelect();
            creatable = null;
        }
    }
Ejemplo n.º 8
0
 public ControlMenuItem(Creatable creatable, string destinationMenu)
     : this(creatable, destinationMenu, false)
 {
 }
Ejemplo n.º 9
0
 public ControlMenuItem(Creatable creatable)
     : this(creatable, null, false)
 {
 }
Ejemplo n.º 10
0
 public ControlMenuItem(Creatable creatable, string destinationMenu, bool requiresPower)
     : this(creatable.ControlCode, destinationMenu, requiresPower)
 {
     Creatable = creatable;
 }
Ejemplo n.º 11
0
 public ControlMenuItem(Creatable creatable, bool requiresPower)
     : this(creatable, null, requiresPower)
 {
 }