private void OnTriggerEnter(Collider other)
    {
        if (ReferenceEquals(keywords, null))
        {
            keywords = (Tapestry_KeywordRegistry)ScriptableObject.CreateInstance("Tapestry_KeywordRegistry");
        }

        if (keywords.Count == 0)
        {
            touching.Add(other);

            if (!isOn && touching.Count > 0)
            {
                SwitchOn();
            }
        }
        else if (!fireOnlyOnce || (fireOnlyOnce && !hasFired))
        {
            Tapestry_Activatable a = other.gameObject.GetComponentInParent <Tapestry_Activatable>();

            if (a != null)
            {
                if (a.keywords.ContainsOne(keywords))
                {
                    if (!isOn)
                    {
                        SwitchOn();
                    }
                }
            }
        }
    }
    protected void DrawTabTarget(Tapestry_Switch s)
    {
        string targetTooltip = "What object, if any, this switch affects. Modifyable controls will appear based on what Tapestry components are detected.";

        GUILayout.BeginVertical("box");
        GUILayout.BeginHorizontal();
        GUILayout.Label(new GUIContent("Target Object", targetTooltip));
        s.target = (GameObject)EditorGUILayout.ObjectField(s.target, typeof(GameObject), true);
        GUILayout.EndHorizontal();

        if (s.target != null)
        {
            Tapestry_Activatable comp = s.target.GetComponent <Tapestry_Activatable>();

            if (comp.GetType() == typeof(Tapestry_Door))
            {
                DrawSubTabDoor(s);
            }

            if (comp.GetType() == typeof(Tapestry_AnimatedLight))
            {
                DrawSubTabAnimatedLight(s);
            }

            if (comp.GetType() == typeof(Tapestry_ItemSource))
            {
                DrawSubTabItemSource(s);
            }
        }
        GUILayout.EndVertical();
    }
Exemplo n.º 3
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?");
     }
 }
Exemplo n.º 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;
    }
Exemplo n.º 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?");
     }
 }