예제 #1
0
    public static void Door_UpdateAction(InstalledObject installedObject, float deltaTime)
    {
        // If the door isOpening is 'true' open the door a little bit more
        if (installedObject.GetParameter("isOpening") >= 1)
        {
            installedObject.ChangeParameter("OpenValue", (deltaTime * 4));

            // If door is fully opened, close it again (right away)
            if (installedObject.GetParameter("OpenValue") >= 1)
            {
                installedObject.SetParameter("isOpening", 0);
            }
        }
        // Close door again
        else
        {
            installedObject.ChangeParameter("OpenValue", (deltaTime * -4));
        }

        // Clamp value between 0 & 1
        installedObject.SetParameter("OpenValue", Mathf.Clamp01(installedObject.GetParameter("OpenValue")));

        // Call the callback if there is any
        if (installedObject.cb_OnChanged != null)
        {
            installedObject.cb_OnChanged(installedObject);
        }
    }
예제 #2
0
    public static void Door_UpdateAction(InstalledObject _inObj, float _deltaTime)
    {
        //if (Debug.isDebugBuild)
        //    Debug.Log("Door_UpdateAction: " + _inObj.inObjParameters["openness"]);

        if (_inObj.GetParameter("is_opening") >= 1)
        {
            _inObj.ChangeParameter("openness", _deltaTime * 4);
            if (_inObj.GetParameter("openness") >= 1)
            {
                _inObj.SetParameter("is_opening", 0);
            }
        }
        else
        {
            _inObj.ChangeParameter("openness", -_deltaTime * 4);
        }

        _inObj.SetParameter("openness", Mathf.Clamp01(_inObj.GetParameter("openness")));

        if (_inObj.cbOnChanged != null)
        {
            _inObj.cbOnChanged(_inObj);
        }
    }
    void OnInstalledObjectChanged(InstalledObject obj)
    {
        GameObject inst_go;

        if (!_installedObjectGameObjectMap.TryGetValue(obj, out inst_go))
        {
            Debug.LogError("_installedObjectGameObjectMap doesn't contain the installed object!");
            return;
        }
        inst_go.GetComponent <SpriteRenderer>().sprite = GetSpriteForInstalledObject(obj);
        //inst_go.GetComponent<SpriteRenderer>().color = obj.Tint;

        //Change Door sprite alpha to simulate opening/closing
        if (obj.ObjectType == "Door")
        {
            if (obj.GetParameter("openness") < 0.1f)
            {
                inst_go.GetComponent <SpriteRenderer>().DOFade(1f, 0.25f);
            }
            else if (obj.GetParameter("openness") < 0.5f)
            {
                inst_go.GetComponent <SpriteRenderer>().DOFade(0.66f, 0.25f);
            }
            else if (obj.GetParameter("openness") < 0.9f)
            {
                inst_go.GetComponent <SpriteRenderer>().DOFade(0.33f, 0.25f);
            }
            else
            {
                inst_go.GetComponent <SpriteRenderer>().DOFade(0f, 0.25f);
            }
        }
    }
    public static EnterableState Door_EnterableState(InstalledObject obj)
    {
        obj.SetParameter("openingState", 1);

        if (obj.GetParameter("openness") >= 1)
        {
            return(EnterableState.Yes);
        }
        return(EnterableState.Soon);
    }
예제 #5
0
    public static ENTERABILITY Door_IsEnterable(InstalledObject _inObj)
    {
        //if(Debug.isDebugBuild)
        //    Debug.Log("Door_IsEnterable");

        _inObj.SetParameter("is_opening", 1);

        if (_inObj.GetParameter("openness") >= 1)
        {
            return(ENTERABILITY.Yes);
        }
        return(ENTERABILITY.Soon);
    }
    public static void Door_UpdateAction(InstalledObject obj, float deltaTime)
    {
        //Debug.Log("Door_UpdateAction");
        if (obj.GetParameter("openingState") >= 1)
        {
            obj.ChangeParameter("openness", deltaTime * 4);
            if (obj.GetParameter("openness") >= 1)
            {
                obj.SetParameter("openingState", 0);
            }
        }
        else
        {
            obj.ChangeParameter("openness", deltaTime * -4);
        }

        obj.SetParameter("openness", Mathf.Clamp01(obj.GetParameter("openness")));

        if (obj.CbOnInstalledObjectChanged != null)
        {
            obj.CbOnInstalledObjectChanged(obj);
        }
    }
예제 #7
0
    public static EnterAbility Door_IsEnterable(InstalledObject installedObject)
    {
        // Door 'isOpening' = 1, means door is opening = true
        installedObject.SetParameter("isOpening", 1);

        // If door is fully open, character can enter.
        if (installedObject.GetParameter("OpenValue") >= 1)
        {
            return(EnterAbility.Yes);
        }

        // Soon, door is going to open soonTM
        return(EnterAbility.Soon);
    }
    public Sprite GetSpriteForInstalledObject(InstalledObject _inObj)
    {
        string spriteName = _inObj.ObjectType;

        if (_inObj.LinksToNeighbour == false)
        {
            //if this is a door check openness and update sprite
            if (_inObj.ObjectType == "Door")
            {
                if (_inObj.GetParameter("openness") < 0.1f)
                {
                    //Door is closed
                    spriteName = "Door";
                }
                else if (_inObj.GetParameter("openness") < 0.5f)
                {
                    //Door is open a little bit
                    spriteName = "Door_openness_1";
                }
                else if (_inObj.GetParameter("openness") < 0.9f)
                {
                    //Door is almost entirely open
                    spriteName = "Door_openness_2";
                }
                else
                {
                    //Door is open
                    spriteName = "Door_openness_3";
                }
            }

            return(installedObjectSprites[spriteName]);
        }
        spriteName = _inObj.ObjectType + "_";

        //This region checks for neighbors and remanes the sprite accorrdingly
        #region NeighbourCheck
        //check for neighbours North, East, South, West
        int  x = _inObj.Tile.X;
        int  y = _inObj.Tile.Y;
        Tile t;

        //This code will see if it has neighbours next to it, and if so add a letter to the name
        //For example, a wall with wall above and below it will be first be named Wall_N then Wall_NS
        t = world.GetTileAt(x, y + 1);
        //if there is a tile above us, it has an object on it, and that object matches ours
        if (t != null && t.InstalledObject != null && t.InstalledObject.ObjectType == _inObj.ObjectType)
        {
            spriteName += "N";
        }

        t = world.GetTileAt(x + 1, y);
        //if there is a tile to the right, it has an object on it, and that object matches ours
        if (t != null && t.InstalledObject != null && t.InstalledObject.ObjectType == _inObj.ObjectType)
        {
            spriteName += "E";
        }

        t = world.GetTileAt(x, y - 1);
        //if there is a tile below us, it has an object on it, and that object matches ours
        if (t != null && t.InstalledObject != null && t.InstalledObject.ObjectType == _inObj.ObjectType)
        {
            spriteName += "S";
        }

        t = world.GetTileAt(x - 1, y);
        //if there is a tile to the left, it has an object on it, and that object matches ours
        if (t != null && t.InstalledObject != null && t.InstalledObject.ObjectType == _inObj.ObjectType)
        {
            spriteName += "W";
        }
        #endregion

        //return name that matches the sprite name
        if (installedObjectSprites.ContainsKey(spriteName) == false)
        {
            Debug.LogError("GetSpriteForInstalledObject -- The Sprite for the " + spriteName + " object does not exist!");
            return(null);
        }

        return(installedObjectSprites[spriteName]);
    }
    /// <summary>
    /// Return the correct sprite for a given installedObject
    /// </summary>
    /// <param name="installedObject">The installedObject that needs a sprite.</param>
    /// <returns>Sprite</returns>
    public Sprite GetSpriteForInstalledObject(InstalledObject installedObject)
    {
        string spriteName = installedObject.ObjectType;

        // Return sprite with the same name as installedObject.ObjectType
        if (installedObject.IsLinkedToNeighbour == false)
        {
            // If it's a door, do something extra for the animation
            if (installedObject.ObjectType == "Door")
            {
                // Door is fully closed
                if (installedObject.GetParameter("OpenValue") < 0.1f)
                {
                    spriteName = "Door_Opening_0";
                }
                // Door is almost fully closed
                else if (installedObject.GetParameter("OpenValue") < 0.34f)
                {
                    spriteName = "Door_Opening_1";
                }
                // Door is half open
                else if (installedObject.GetParameter("OpenValue") < 0.67f)
                {
                    spriteName = "Door_Opening_2";
                }
                // Door is mostly open
                else if (installedObject.GetParameter("OpenValue") < 0.95f)
                {
                    spriteName = "Door_Opening_3";
                }
                // Door is fully open
                else
                {
                    spriteName = "Door_Opening_4";
                }
            }
            return(installedObjectSpritesMap[spriteName]);
        }

        spriteName = installedObject.ObjectType + "_";

        /* Check for neighbours: North, East, South & West (in that order)
         * Check if: there are neighbouring tiles,
         * if those tiles have installedObject on them
         * if those objects are of the same type. */
        Tile tile;
        int  x = installedObject.Tile.X;
        int  y = installedObject.Tile.Y;

        // Check North
        tile = World.GetTileAt(x, (y + 1));
        if (TileCheck(tile, installedObject))
        {
            spriteName += "N";
        }

        // Check East
        tile = World.GetTileAt((x + 1), y);
        if (TileCheck(tile, installedObject))
        {
            spriteName += "E";
        }

        // Check South
        tile = World.GetTileAt(x, (y - 1));
        if (TileCheck(tile, installedObject))
        {
            spriteName += "S";
        }

        // Check West
        tile = World.GetTileAt((x - 1), y);
        if (TileCheck(tile, installedObject))
        {
            spriteName += "W";
        }

        // If there isn't a sprite with this current spritename, throw error and return null
        if (installedObjectSpritesMap.ContainsKey(spriteName) == false)
        {
            Debug.LogError("installedObjectSpritesMap doesn't contain a sprite with the name: " + spriteName);
            return(null);
        }

        return(installedObjectSpritesMap[spriteName]);
    }