コード例 #1
0
 public void EvaluateOffState()
 {
     hasFired = true;
     isOn     = false;
     if (target != null)
     {
         Tapestry_Activatable comp = target.GetComponent <Tapestry_Activatable>();
         if (comp.GetType() == typeof(Tapestry_Door))
         {
             Tapestry_Door d = target.GetComponent <Tapestry_Door>();
             if (data.off_setOpen)
             {
                 d.Open();
             }
             if (data.off_setClosed)
             {
                 d.Close();
             }
             if (data.off_setLocked)
             {
                 d.security.isLocked = true;
             }
             if (data.off_setUnlocked)
             {
                 d.security.isLocked = false;
             }
             if (data.off_setBypassable)
             {
                 d.security.canBeBypassed = data.off_setBypassable;
             }
             if (data.off_setInteractable)
             {
                 d.isInteractable = data.off_setInteractable;
             }
         }
         if (comp.GetType() == typeof(Tapestry_AnimatedLight))
         {
             Tapestry_AnimatedLight al = target.GetComponent <Tapestry_AnimatedLight>();
             if (data.off_setOpen)
             {
                 al.TurnOn();
             }
             if (data.off_setClosed)
             {
                 al.TurnOff();
             }
             if (data.off_setInteractable)
             {
                 al.isInteractable = data.on_setInteractable;
             }
         }
     }
     else
     {
         Debug.Log("TAPESTRY WARNING: Switch does not have a target object. Did you forget to set one?");
     }
 }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        Tapestry_Door d = target as Tapestry_Door;

        if (d.security == null)
        {
            d.security = new Tapestry_Lock(false, 0, "");
        }
        if (d.curve == null)
        {
            d.curve = new AnimationCurve(new Keyframe(0, 0, 0, 0), new Keyframe(1, 1, 0, 0));
        }

        string
            displayTooltip      = "What string will display on the player's HUD when looking at this object.",
            changeTimeTooltip   = "The amount of time, in seconds, it takes for the door to open or close.",
            changeCurveTooltip  = "Animation controls for how the door eases between states.",
            interactableTooltip = "Can the player interact with this door?",
            displayNameTooltip  = "Should the object still show its display name when the player's cursor is hovering over the object?";

        GUILayout.BeginVertical("box");

        GUILayout.BeginHorizontal();
        GUILayout.Label(new GUIContent("Display Name", displayTooltip));
        GUILayout.FlexibleSpace();
        d.displayName = EditorGUILayout.DelayedTextField(d.displayName, GUILayout.Width(270));
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label(new GUIContent("Change Time", changeTimeTooltip));
        d.openTime = EditorGUILayout.DelayedFloatField(d.openTime, GUILayout.Width(30));
        GUILayout.FlexibleSpace();
        GUILayout.Label(new GUIContent("Change Curve", changeCurveTooltip));
        d.curve = EditorGUILayout.CurveField(d.curve, GUILayout.Width(150));
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        d.isInteractable = EditorGUILayout.Toggle(d.isInteractable, GUILayout.Width(12));
        GUILayout.Label(new GUIContent("Interactable?", interactableTooltip));
        GUILayout.Space(20);
        if (!d.isInteractable)
        {
            d.displayNameWhenUnactivatable = EditorGUILayout.Toggle(d.displayNameWhenUnactivatable, GUILayout.Width(12));
            GUILayout.Label(new GUIContent("Display Name Anyway?", displayNameTooltip));
            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();

        DrawSecurityTab(d);

        string
            openTransformTooltip   = "The transform data for the door's open state. Don't worry about the actual numbers too much, but if they're the same as the closed values, you need to bake your open and closed states.",
            closedTransformTooltip = "The transform data for the door's closed state. Don't worry about the actual numbers too much, but if they're the same as the closed values, you need to bake your open and closed states.",
            openSoundTooltip       = "The sound to play when the door is opened, if any.",
            closedSoundTooltip     = "The sound to play when the door is closed, if any.";

        GUILayout.BeginVertical("box");

        GUILayout.BeginHorizontal();
        GUILayout.Label("Open");
        GUILayout.FlexibleSpace();
        GUILayout.Label(new GUIContent(d.GetOpenInspectorString(), openTransformTooltip));
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical("box");
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Open Door"))
        {
            if (Application.isPlaying)
            {
                d.Open();
            }
            else
            {
                d.Open(true);
            }
        }
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Bake Open Pivot Transform"))
        {
            d.BakeOpenState();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label(new GUIContent("Sound", openSoundTooltip));
        d.openSound = (AudioClip)EditorGUILayout.ObjectField(d.openSound, typeof(AudioClip), true, GUILayout.Width(250));
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        GUILayout.EndVertical();

        GUILayout.BeginVertical("box");

        GUILayout.BeginHorizontal();
        GUILayout.Label("Closed");
        GUILayout.FlexibleSpace();
        GUILayout.Label(new GUIContent(d.GetClosedInspectorString(), closedTransformTooltip));
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical("box");
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Close Door"))
        {
            if (Application.isPlaying)
            {
                d.Close();
            }
            else
            {
                d.Close(true);
            }
        }
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Bake Closed Pivot Transform"))
        {
            d.BakeClosedState();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label(new GUIContent("Sound", closedSoundTooltip));
        d.closeSound = (AudioClip)EditorGUILayout.ObjectField(d.closeSound, typeof(AudioClip), true, GUILayout.Width(250));
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        GUILayout.EndVertical();
    }
コード例 #3
0
    protected void DrawSecurityTab(Tapestry_Door d)
    {
        string lockedTooltip = "Is this container locked?";

        GUILayout.BeginVertical("box");

        GUILayout.BeginHorizontal();
        d.security.isLocked = EditorGUILayout.Toggle(d.security.isLocked, GUILayout.Width(12));
        GUILayout.Label(new GUIContent("Locked?", lockedTooltip));
        GUILayout.EndHorizontal();

        if (d.security == null)
        {
            d.security = new Tapestry_Lock(false, 0, "");
        }

        if (d.security.isLocked)
        {
            GUILayout.BeginVertical("box");
            GUILayout.BeginHorizontal();

            string
                bypassableTooltip      = "Can the player bypass this lock with " + Tapestry_Config.lockBypassSkill.ToString() + "?",
                levelTooltip           = "How difficult this lock is to bypass.",
                keyTooltip             = "Entities with a key with this ID can open this door when locked. After passing through the door, the Entity will re-lock it.",
                lockedJiggleTooltip    = "If this door is locked, does it jiggle when activated?",
                jiggleIntensityTooltip = "How much this door jiggles on activation when locked. This is a percentage of the difference between the closed state and the open state.",
                lockedSoundTooltip     = "The sound that plays when the door is unsuccessfully opened when locked, if any.",
                relockTooltip          = "Should this door relock itself once closed?",
                consumeKeyTooltip      = "Should the key for this door be removed from the player's inventory when the door is unlocked?";

            d.security.canBeBypassed = EditorGUILayout.Toggle(d.security.canBeBypassed, GUILayout.Width(12));
            GUILayout.Label(new GUIContent("Bypassable?", bypassableTooltip));
            GUILayout.FlexibleSpace();
            if (d.security.canBeBypassed)
            {
                GUILayout.Label(new GUIContent("Level", levelTooltip));
                d.security.LockLevel = EditorGUILayout.DelayedIntField(d.security.LockLevel, GUILayout.Width(30));
                GUILayout.FlexibleSpace();
            }
            GUILayout.Label(new GUIContent("Key", keyTooltip));
            d.security.keyID = EditorGUILayout.DelayedTextField(d.security.keyID, GUILayout.Width(100));

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            d.jiggleOnActivateWhenLocked = EditorGUILayout.Toggle(d.jiggleOnActivateWhenLocked, GUILayout.Width(12));
            GUILayout.Label(new GUIContent("Jiggle?", lockedJiggleTooltip));
            if (d.jiggleOnActivateWhenLocked)
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label(new GUIContent("Intensity", jiggleIntensityTooltip));
                d.lockJiggleIntensity = EditorGUILayout.DelayedFloatField(d.lockJiggleIntensity, GUILayout.Width(40));
                GUILayout.FlexibleSpace();
                GUILayout.Label(new GUIContent("Sound", lockedSoundTooltip));
                d.lockedSound = (AudioClip)EditorGUILayout.ObjectField(d.lockedSound, typeof(AudioClip), true, GUILayout.Width(120));
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            d.relockWhenClosed = EditorGUILayout.Toggle(d.relockWhenClosed, GUILayout.Width(12));
            GUILayout.Label(new GUIContent("Relock When Closed?", relockTooltip));
            if (!d.relockWhenClosed)
            {
                GUILayout.FlexibleSpace();
                d.consumeKeyOnUnlock = EditorGUILayout.Toggle(d.consumeKeyOnUnlock, GUILayout.Width(12));
                GUILayout.Label(new GUIContent("Consume Key on Unlock?", consumeKeyTooltip));
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }

        GUILayout.EndVertical();
    }
コード例 #4
0
    private void HandleActivation()
    {
        bool activate = Input.GetKey(Tapestry_Config.KeyboardInput_Activate);
        bool push     = Input.GetKey(Tapestry_Config.KeyboardInput_Push);
        bool lift     = Input.GetKey(Tapestry_Config.KeyboardInput_Lift);

        objectInSights = null;

        RaycastHit hit;
        bool       rayHit = Physics.Raycast(
            Camera.main.transform.position,
            Camera.main.transform.forward,
            out hit,
            reach.Value,
            ~(LayerMask.GetMask("Ignore Raycast") | LayerMask.GetMask("Tapestry Held Items"))
            );

        if (rayHit)
        {
            objectInSights = hit.transform.gameObject.GetComponentInParent <Tapestry_Activatable>();

            if (objectInSights != null)
            {
                objectInSights.Hover();

                if (activateLastFrame && !activate && objectInSights.GetComponent <Tapestry_Activatable>().isInteractable)
                {
                    if ((typeof(Tapestry_Item).IsAssignableFrom(objectInSights.GetType())))
                    {
                        Tapestry_Item i = (Tapestry_Item)objectInSights;
                        if (ReferenceEquals(inventory, null))
                        {
                            inventory = (Tapestry_Inventory)ScriptableObject.CreateInstance("Tapestry_Inventory");
                        }

                        inventory.AddItem(i, 1);
                        objectInSights.Activate(this);
                    }
                    else if (objectInSights.GetType() == typeof(Tapestry_Door))
                    {
                        Tapestry_Door d = (Tapestry_Door)objectInSights;
                        if (d.security.isLocked)
                        {
                            if (ReferenceEquals(inventory, null))
                            {
                                inventory = (Tapestry_Inventory)ScriptableObject.CreateInstance("Tapestry_Inventory");
                            }

                            if (!d.GetIsOpen())
                            {
                                if (inventory.ContainsKeyID(d.security.keyID))
                                {
                                    d.security.isLocked = false;
                                    if (d.consumeKeyOnUnlock)
                                    {
                                        inventory.RemoveKeyWithID(d.security.keyID);
                                    }
                                }
                                objectInSights.Activate(this);
                            }
                        }
                        else
                        {
                            objectInSights.Activate(this);
                        }
                    }
                    else if (objectInSights.GetType() == typeof(Tapestry_Container))
                    {
                        Tapestry_Container c = (Tapestry_Container)objectInSights;
                        if (inventoryUI == null)
                        {
                            inventoryUI = FindObjectOfType <Tapestry_UI_Inventory>();
                        }

                        Debug.Log(c.inventory.items.Count + " in target container.");
                        inventoryUI.Open(inventory, null, c.inventory, "Inventory", c.displayName);
                    }
                    else
                    {
                        objectInSights.Activate(this);
                    }
                }
                if (pushLastFrame && !push && objectInSights.GetComponent <Tapestry_Activatable>().isPushable)
                {
                    objectInSights.Push(this);
                }
                if (liftLastFrame && !lift && objectInSights.GetComponent <Tapestry_Activatable>().isLiftable)
                {
                    objectInSights.Lift(this);
                }
            }
        }

        //End of frame
        activateLastFrame = activate;
        pushLastFrame     = push;
        liftLastFrame     = lift;
    }
コード例 #5
0
 public void EvaluateOnState()
 {
     hasFired = true;
     isOn     = true;
     if (target != null)
     {
         Tapestry_Activatable comp = target.GetComponent <Tapestry_Activatable>();
         if (pingPong)
         {
             if (comp.GetType() == typeof(Tapestry_Door))
             {
                 Tapestry_Door d = target.GetComponent <Tapestry_Door>();
                 if (data.pp_swapOpenState)
                 {
                     if (d.GetIsOpen())
                     {
                         d.Close();
                     }
                     else
                     {
                         d.Open();
                     }
                 }
                 if (data.pp_swapLockedState)
                 {
                     d.security.isLocked = !d.security.isLocked;
                 }
                 if (data.pp_swapBypassableState)
                 {
                     d.security.canBeBypassed = !d.security.canBeBypassed;
                 }
                 if (data.pp_swapInteractivityState)
                 {
                     d.isInteractable = !d.isInteractable;
                 }
             }
             if (comp.GetType() == typeof(Tapestry_AnimatedLight))
             {
                 Tapestry_AnimatedLight al = target.GetComponent <Tapestry_AnimatedLight>();
                 if (data.pp_swapOpenState)
                 {
                     if (al.GetIsOn())
                     {
                         al.TurnOff();
                     }
                     else
                     {
                         al.TurnOn();
                     }
                 }
                 if (data.pp_swapInteractivityState)
                 {
                     al.isInteractable = !al.isInteractable;
                 }
             }
             if (comp.GetType() == typeof(Tapestry_ItemSource))
             {
                 Tapestry_ItemSource i = target.GetComponent <Tapestry_ItemSource>();
                 if (data.pp_swapInteractivityState)
                 {
                     i.isInteractable = !i.isInteractable;
                 }
                 if (data.pp_setSourceHarvestable)
                 {
                     i.SetHarvestability(true);
                 }
             }
         }
         else
         {
             if (comp.GetType() == typeof(Tapestry_Door))
             {
                 Tapestry_Door d = target.GetComponent <Tapestry_Door>();
                 if (data.on_setOpen)
                 {
                     d.Open();
                 }
                 if (data.on_setClosed)
                 {
                     d.Close();
                 }
                 if (data.on_setLocked)
                 {
                     d.security.isLocked = true;
                 }
                 if (data.on_setUnlocked)
                 {
                     d.security.isLocked = false;
                 }
                 if (data.on_setBypassable)
                 {
                     d.security.canBeBypassed = data.on_setBypassable;
                 }
                 if (data.on_setInteractable)
                 {
                     d.isInteractable = data.on_setInteractable;
                 }
             }
             if (comp.GetType() == typeof(Tapestry_AnimatedLight))
             {
                 Tapestry_AnimatedLight al = target.GetComponent <Tapestry_AnimatedLight>();
                 if (data.on_setOpen)
                 {
                     al.TurnOn();
                 }
                 if (data.on_setClosed)
                 {
                     al.TurnOff();
                 }
                 if (data.on_setInteractable)
                 {
                     al.isInteractable = data.on_setInteractable;
                 }
             }
             if (comp.GetType() == typeof(Tapestry_ItemSource))
             {
                 Tapestry_ItemSource i = target.GetComponent <Tapestry_ItemSource>();
                 if (data.on_setInteractable)
                 {
                     i.isInteractable = data.on_setInteractable;
                 }
             }
         }
     }
     else
     {
         Debug.Log("TAPESTRY WARNING: Switch does not have a target object. Did you forget to set one?");
     }
 }