Esempio n. 1
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            var selection = hit.transform;

            if (hit.collider.tag.Equals("Vertex"))
            {
                vertex1 = hit.transform.gameObject.GetComponent <CreateVertex>();
                if (!vertex1.isCabled)
                {
                    hitFlag = true;

                    nullObject         = new GameObject("Pointer");
                    currentCableObject = Instantiate(cableObject, GameObject.Find("Cables").transform);
                    cable       = currentCableObject.GetComponent <CableComponent>();
                    cable.Begin = hit.transform;
                    cable.End   = nullObject.transform;
                }
                else
                {
                    vertex1 = null;
                }
            }
        }
    }
Esempio n. 2
0
        private void OnGetExamineVerbs(EntityUid uid, CableComponent component, GetVerbsEvent <ExamineVerb> args)
        {
            // Must be in details range to try this.
            // Theoretically there should be a separate range at which a multitool works, but this does just fine.
            if (_examineSystem.IsInDetailsRange(args.User, args.Target))
            {
                var held = args.Using;

                // Pulsing is hardcoded here because I don't think it needs to be more complex than that right now.
                // Update if I'm wrong.
                var enabled = held != null && _toolSystem.HasQuality(held.Value, "Pulsing");
                var verb    = new ExamineVerb
                {
                    Disabled    = !enabled,
                    Message     = Loc.GetString("cable-multitool-system-verb-tooltip"),
                    Text        = Loc.GetString("cable-multitool-system-verb-name"),
                    Category    = VerbCategory.Examine,
                    IconTexture = "/Textures/Interface/VerbIcons/zap.svg.192dpi.png",
                    Act         = () =>
                    {
                        var markup = FormattedMessage.FromMarkup(GenerateCableMarkup(uid));
                        _examineSystem.SendExamineTooltip(args.User, uid, markup, false, false);
                    }
                };

                args.Verbs.Add(verb);
            }
        }
Esempio n. 3
0
    public void SetCable(CableComponent itemComponent)
    {
        _isCable       = true;
        cableComponent = itemComponent;

        nameObject.text  = cableComponent.cableName;
        priceObject.text = cableComponent.price.ToString() + " $";

        imageObject.sprite   = cableComponent.image;
        firstEntrance.sprite = cableComponent.firstEntrance;

        if (cableComponent.secondEntrance != null)
        {
            secondEntrance.sprite = cableComponent.secondEntrance;
        }
        else
        {
            secondEntrance.gameObject.SetActive(false);
        }

        if (cableComponent.IsAvailabe)
        {
            buyButton.interactable = false;
        }
    }
Esempio n. 4
0
    private void OnCableCut(EntityUid uid, CableComponent cable, CuttingFinishedEvent args)
    {
        if (_electrocutionSystem.TryDoElectrifiedAct(uid, args.User))
        {
            return;
        }

        Spawn(cable.CableDroppedOnCutPrototype, Transform(uid).Coordinates);
        QueueDel(uid);
    }
    private void OnInteractUsing(EntityUid uid, CableComponent cable, InteractUsingEvent args)
    {
        if (args.Handled)
        {
            return;
        }

        var ev = new CuttingFinishedEvent(args.User);

        _toolSystem.UseTool(args.Used, args.User, uid, 0, cable.CuttingDelay, new[] { cable.CuttingQuality }, doAfterCompleteEvent: ev, doAfterEventTarget: uid);
        args.Handled = true;
    }
    private void OnCableCut(EntityUid uid, CableComponent cable, CuttingFinishedEvent args)
    {
        if (_electrocutionSystem.TryDoElectrifiedAct(uid, args.User))
        {
            return;
        }

        _adminLogs.Add(LogType.CableCut, LogImpact.Medium, $"The {ToPrettyString(uid)} at {Transform(uid).Coordinates} was cut by {ToPrettyString(args.User)}.");

        Spawn(cable.CableDroppedOnCutPrototype, Transform(uid).Coordinates);
        QueueDel(uid);
    }
Esempio n. 7
0
    public void OnEndDrag(PointerEventData eventData)
    {
        hitFlag = false;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            var selection = hit.transform;
            if (hit.collider.tag.Equals("Vertex"))
            {
                // Запись второй вершины
                //
                vertex2 = hit.transform.gameObject.GetComponent <CreateVertex>();

                // Исключение взаимно обратных рёбер и петель
                // Ограничение степени вершины
                // Создание ребра
                //
                if (!vertex2.isCabled)
                {
                    currentCableObject.GetComponent <CreateEdge>().AddEdge(vertex1, vertex2);
                    vertex1.isCabled = true;
                    vertex2.isCabled = true;

                    currentCableObject = null;
                    // Защита от переназначения точек соединения кабеля
                    //
                    if (cable)
                    {
                        cable.End = hit.transform;
                        cable     = null;

                        Destroy(nullObject);
                    }
                }
                else
                {
                    Destroy(currentCableObject);
                    Destroy(nullObject);
                }
            }
            else
            {
                Destroy(currentCableObject);
                Destroy(nullObject);
            }
        }
    }
    public static Dictionary <string, CableComponent> GetAllCables()
    {
        SetCablePrefabList();

        foreach (GameObject g in _cablePrefabs)
        {
            CableComponent componentComponent = g.GetComponentInChildren <CableComponent>(true);
            if (!_cableList.ContainsKey(DeviceComponentHelper.ComponentName(componentComponent.componentType)))
            {
                _cableList.Add(DeviceComponentHelper.ComponentName(componentComponent.componentType), componentComponent);
            }
        }

        return(_cableList);
    }
    public static void AddCableSelection(CableComponent component)
    {
        if (_selectedCables == null || _selectedCables.Count == 0)
        {
            _selectedCables = new List <GameObject>();
        }

        foreach (GameObject g in _cablePrefabs)
        {
            if ((DeviceComponentHelper.ComponentName(g.GetComponentInChildren <CableComponent>(true).componentType) ==
                 DeviceComponentHelper.ComponentName(component.componentType)) && !_selectedCables.Contains(g))
            {
                _selectedCables.Add(g);
                break;
            }
        }
    }
    private void OnAnchorChanged(EntityUid uid, CableComponent cable, ref AnchorStateChangedEvent args)
    {
        if (args.Anchored)
        {
            return; // huh? it wasn't anchored?
        }
        // anchor state can change as a result of deletion (detach to null).
        // We don't want to spawn an entity when deleted.
        if (!TryLifeStage(uid, out var life) || life >= EntityLifeStage.Terminating)
        {
            return;
        }

        // This entity should not be un-anchorable. But this can happen if the grid-tile is deleted (RCD, explosion,
        // etc). In that case: behave as if the cable had been cut.
        Spawn(cable.CableDroppedOnCutPrototype, Transform(uid).Coordinates);
        QueueDel(uid);
    }
Esempio n. 11
0
 private void OnExamined(EntityUid uid, CableComponent component, ExaminedEvent args)
 {
     // Must be in details range to try this.
     // Theoretically there should be a separate range at which a multitool works, but this does just fine.
     if (args.IsInDetailsRange)
     {
         // Determine if they are holding a multitool.
         if (EntityManager.TryGetComponent <HandsComponent?>(args.Examiner, out var hands) && hands.TryGetActiveHand(out var hand))
         {
             var held = hand.HeldEntity;
             // Pulsing is hardcoded here because I don't think it needs to be more complex than that right now.
             // Update if I'm wrong.
             if ((held != null) && _toolSystem.HasQuality(held, "Pulsing"))
             {
                 args.PushMarkup(GenerateCableMarkup(uid));
                 // args.PushFancyUpdatingPowerGraphs(uid);
             }
         }
     }
 }
Esempio n. 12
0
    void TargetLaunch(NetworkConnection _target, Vector2 _p0, Vector2 _p1, Vector2 _p2, Vector2 _dir, float _dist)
    {
        currentHook = Instantiate(Hook, _p0, Quaternion.identity);
        Hook h = currentHook.GetComponent <Hook>();

        currentHook.GetComponent <ObjectSceneId>().SceneName = ManagerScene.GetManagerScene.GetActiveSceneName();
        h.RefActivity = this;
        h.P0          = _p0;
        h.P2          = _p2;
        h.P1          = _p1;

        fishingRod = null;

        if (_dir.x > 0.0f && _dir.y == 0.0f)
        {
            fishingRod = Instantiate(fishingRods[2], transform);
        }
        if (_dir.x < 0.0f && _dir.y == 0.0f)
        {
            fishingRod = Instantiate(fishingRods[3], transform);
        }

        if (_dir.x == 0.0f && _dir.y > 0.0f)
        {
            fishingRod = Instantiate(fishingRods[1], transform);
        }
        if (_dir.x == 0.0f && _dir.y < 0.0f)
        {
            fishingRod = Instantiate(fishingRods[0], transform);
        }

        GameObject     gm        = Instantiate(h.CablePref, transform.position, Quaternion.identity);
        CableComponent cableComp = gm.GetComponentInChildren <CableComponent>();

        cableComp.ObjectToFollow = h.transform;
        cableComp.CableLength    = _dist;

        cableComp.transform.position = fishingRod.transform.GetChild(0).transform.position;
    }
Esempio n. 13
0
    private void instantiatePatte()
    {
        GameObject instance;

        patteInstances = new GameObject[nombreDePattes];

        for (int i = 0; i < nombreDePattes; i++)
        {
            instance = GameObject.Instantiate(patteAraigneePrefab);
            CableComponent cb = instance.AddComponent <CableComponent>();
            cb.cableEnd = CorpDeLaraignee.transform;

            cb.cableMaterial    = CableMaterial;
            cb.cableEndOffset   = CableOffset;
            cb.cableLength      = CableLength;
            cb.totalSegments    = TotalSegments;
            cb.segmentsPerUnit  = SegmentsPerUnit;
            cb.solverIterations = SolverIterations;

            patteInstances[i] = instance;
        }
    }
Esempio n. 14
0
 void Start()
 {
     theController = FindObjectOfType <Controller>();
     theCable      = FindObjectOfType <CableComponent>();
 }
Esempio n. 15
0
 // Start is called before the first frame update
 void Start()
 {
     wireDirection  = target.transform.position - cameraPosition;
     cableComponent = GetComponent <CableComponent>();
     position       = transform.position;
 }
Esempio n. 16
0
    public void LaunchHook(Vector2 _dir, Vector2 _position)
    {
        if (!currentHook && !PlayerManager.GetPlayerManager.playerController.IsStunned &&
            !PlayerManager.GetPlayerManager.playerController.IsHarvesting)
        {
            if (_dir.x == 0.0f || _dir.y == 0.0f)
            {
                if (InputManager.GetInputManager.GetButton("Jump"))
                {
                    lauchingTimer += Time.deltaTime * 0.5f;
                }

                if (InputManager.GetInputManager.GetButtonUp("Jump"))
                {
                    IsLaunched  = true;
                    currentHook = Instantiate(Hook, _position, Quaternion.identity);
                    currentHook.GetComponent <ObjectSceneId>().SceneName = ManagerScene.GetManagerScene.GetActiveSceneName();
                    Hook h = currentHook.GetComponent <Hook>();
                    dist          = Mathf.Clamp((lauchingTimer * 10.0f), 0.0f, maxDist);
                    h.RefActivity = this;
                    h.P0          = _position;
                    h.P2          = _position + _dir.normalized * dist + Random.insideUnitCircle * Random.Range(-0.7f, 0.7f);
                    h.P1          = h.P0 + (h.P2 - h.P0) / 2 + (Vector2.up * dist);
                    lauchingTimer = 0.0f;

                    fishingRod = null;

                    if (_dir.x > 0.0f && _dir.y == 0.0f)
                    {
                        fishingRod = Instantiate(fishingRods[2], transform);
                    }
                    if (_dir.x < 0.0f && _dir.y == 0.0f)
                    {
                        fishingRod = Instantiate(fishingRods[3], transform);
                    }

                    if (_dir.x == 0.0f && _dir.y > 0.0f)
                    {
                        fishingRod = Instantiate(fishingRods[1], transform);
                    }
                    if (_dir.x == 0.0f && _dir.y < 0.0f)
                    {
                        fishingRod = Instantiate(fishingRods[0], transform);
                    }



                    GameObject     gm        = Instantiate(h.CablePref, transform.position, Quaternion.identity);
                    CableComponent cableComp = gm.GetComponentInChildren <CableComponent>();
                    cableComp.ObjectToFollow = h.transform;
                    cableComp.CableLength    = (dist) / 3;

                    cableComp.transform.position = fishingRod.transform.GetChild(0).transform.position;

                    CmdLaunch(h.P0, h.P1, h.P2, _dir, cableComp.CableLength);
                }
            }

            if (!currentHook)
            {
                if (fishingRod)
                {
                    Destroy(fishingRod);
                }
            }
        }
    }
Esempio n. 17
0
    private Transform attachTarget;//ワイヤーを付けたオブジェクト

    // Start is called before the first frame update
    void Start()
    {
        cable         = wireStart.GetComponent <CableComponent>();
        defaultParent = wireEnd.parent;
    }