示例#1
0
    private void Start()
    {
        look = GetComponent <LookAtConstraint>();

        player = look.GetSource(0);
        target = look.GetSource(1);
    }
    public override void TargetPlayer(GameObject player)
    {
        IsActive = true;
        Target   = player;
        mainBody.TargetPlayer(Target.transform);
        foreach (PlayerFlowing target in followTargets)
        {
            target.TargetPlayer(Target.transform);
        }
        ConstraintSource aimAtSource = new ConstraintSource();

        aimAtSource.weight          = 1;
        aimAtSource.sourceTransform = Target.transform;
        GetComponent <LookAtConstraint>().AddSource(aimAtSource);
        GetComponent <LookAtConstraint>().constraintActive = true;
        foreach (Transform t in fireLocations)
        {
            if (t.GetComponent <LookAtConstraint>())
            {
                t.GetComponent <LookAtConstraint>().AddSource(aimAtSource);
                t.GetComponent <LookAtConstraint>().constraintActive = true;
            }
        }
        StartCoroutine("WaitToAttack");
    }
示例#3
0
    IEnumerator Start()
    {
        if (fireSound)
        {
            if (!audioSource)
            {
                audioSource = GetComponent <AudioSource>();
            }
        }

        if (!audioSource)
        {
            audioSource = gameObject.AddComponent <AudioSource>();
            audioSource.spatialBlend = 1f;
        }

        yield return(new WaitForEndOfFrame());

        playerTr = WheelDriveCustom.s_player.transform;

        //if (fireAtStart)
        //{
        //    yield return new WaitForSeconds(2f);
        //    FireRandomDelayLoop();
        //}

        ConstraintSource cs = new ConstraintSource {
            sourceTransform = playerTr, weight = 1
        };

        lookAtConstraint.RemoveSource(0);
        lookAtConstraint.AddSource(cs);
    }
    // Update is called once per frame
    void Update()
    {
        ConstraintSource Current = constraint.GetSource(0);
        ConstraintSource Option  = constraint.GetSource(1);


        //float d = Vector3.Distance(Current.sourceTransform.position, Option.sourceTransform.position);

        //float offset = 3f;
        //d = Mathf.Clamp(d, 0f, offset);
        //d /= offset;

        Current.weight = 1;
        Option.weight  = 0;


        Current.weight -= ballWeight;
        Option.weight  += ballWeight;

        //Current.weight = Mathf.Clamp(Current.weight, 0f, 1f);
        //Option.weight = Mathf.Clamp(Option.weight, 0f, 1f);


        constraint.SetSource(0, Current);
        constraint.SetSource(1, Option);
    }
    void Start()
    {
        // Aim Constraint
        aimConstraint = gameObject.GetComponent <AimConstraint>();
        aController   = GetComponent <Animator>();
        ConstraintSource cc = new ConstraintSource();

        cc.sourceTransform = lookAtObject.transform;
        cc.weight          = 1.0f;
        aimConstraint.AddSource(cc);
        aimConstraint.rotationAxis = Axis.Y | Axis.Z;
        // Aim Constraint

        // populating waypoints
        foreach (Transform i in GameObject.Find("targets").GetComponentsInChildren <Transform>())
        {
            targets.Add(i);
        }
        targets.RemoveAt(0); // done populating waypoints

        agent = GetComponent <NavMeshAgent>();
        StartCoroutine("AnimationState");
        NextTarget();
        GotoTargetIndex();
    }
示例#6
0
    public void AddDevicePrefab(string deviceTypeStr)
    {
#if UNITY_EDITOR
        if (!AvatarCheck())
        {
            return;
        }

        DestroyDevicePrefab(deviceTypeStr);

        string prefabName = GetDevicePrefabName(deviceTypeStr);
        string path       = FindAssetPath(prefabName);
        if (path == null)
        {
            Debug.LogErrorFormat("BhapticsVRCEditor / Cannot find asset {0}", deviceTypeStr);
            return;
        }
        var ins = Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(path), transform);
        ins.name = prefabName;
        Undo.RegisterCreatedObjectUndo(ins, "Create New GameObject");
        Undo.RecordObjects(ins.GetComponentsInChildren <Transform>(), "Change Transform Position");
        var deviceTypeNames = Enum.GetNames(typeof(BhapticsDeviceType));
        for (int i = 0; i < deviceTypeNames.Length; ++i)
        {
            if (deviceTypeStr != deviceTypeNames[i])
            {
                continue;
            }
            SetObjectScaleFromPrefab(ins, i);
            deviceGameObjects[i] = ins;
            if (deviceTypeNames[i] == "LeftHand" || deviceTypeNames[i] == "RightHand")
            {
                ins.transform.SetParent(anim.GetBoneTransform(handBoneDic[i * 10]));
                SetObjectOffetsFromPrefab(ins, i);
                var joints = ins.GetComponentsInChildren <ParentConstraint>();
                for (int jointIndex = 0; jointIndex < joints.Length; ++jointIndex)
                {
                    var constraintSource = new ConstraintSource();
                    constraintSource.weight          = 1f;
                    constraintSource.sourceTransform = anim.GetBoneTransform(handBoneDic[jointIndex + i * 10]);
                    if (constraintSource.sourceTransform != null)
                    {
                        joints[jointIndex].SetSource(0, constraintSource);
                    }
                    else
                    {
                        Debug.LogError("BhapticsVRCEditor / " + deviceTypeNames[i] + " device's parentConstraint setting is wrong!"
                                       + "\n" + "<color=red>" + handBoneDic[jointIndex + i * 10] + " is null.</color>");
                    }
                }
            }
            else
            {
                ins.transform.SetParent(anim.GetBoneTransform(humanBodyBoneDic[i]));
                SetObjectOffetsFromPrefab(ins, i);
            }
            break;
        }
#endif
    }
示例#7
0
        public static GameObject NewPlayer(PlayerData playerData, bool isLocal)
        {
            var obj = GameObject.Instantiate(ActorMgr.playerPrefab, playerData.position, playerData.rotation);

            obj.name = playerData.fd;
            obj.GetComponent <Identity>().fd = playerData.fd;
            obj.GetComponent <Battle>().hp   = playerData.hp;
            ActorMgr.playerMap.Add(playerData.fd, obj);

            if (isLocal)
            {
                var camera = GameObject.FindWithTag("MainCamera");
                var con    = camera.GetComponent <ParentConstraint>();
                var source = new ConstraintSource()
                {
                    sourceTransform = obj.transform,
                    weight          = 1
                };

                con.translationOffsets = new Vector3[] { camera.transform.position };
                con.rotationOffsets    = new Vector3[] { camera.transform.rotation.eulerAngles };
                con.AddSource(source);
            }

            return(obj);
        }
示例#8
0
        public int TestConstraintAnimation(System.Type componentType, float[] keyTimes, float[] keyValues, string propertyName)
        {
            var go     = new GameObject("root");
            var source = new GameObject("source");

            source.transform.parent = go.transform;

            var constraint = go.AddComponent(componentType) as IConstraint;

            Assert.That(constraint, Is.Not.Null);

            var cSource = new ConstraintSource();

            cSource.sourceTransform = source.transform;

            int index = constraint.AddSource(cSource);

            Assert.That(index, Is.EqualTo(0));

            var keyData = new FbxAnimationTest.PropertyKeyData
            {
                targetObject   = go,
                componentType  = componentType,
                propertyName   = propertyName,
                keyTimes       = keyTimes,
                keyFloatValues = keyValues
            };
            var tester = new FbxAnimationTest.AnimTester {
                keyData = keyData, testName = "ConstraintAnim_" + propertyName, path = GetRandomFbxFilePath()
            };

            return(tester.DoIt());
        }
示例#9
0
    private void Start()
    {
        ConstraintSource constraint = new ConstraintSource();

        constraint.sourceTransform = Camera.main.transform;
        constraint.weight          = 1;
        GetComponent <AimConstraint>().AddSource(constraint);
    }
示例#10
0
    //Add Sourcer
    public static void AddTransform(this LookAtConstraint posCons, Transform source, float weight = 1)
    {
        ConstraintSource constraint = new ConstraintSource();

        constraint.sourceTransform = source;
        constraint.weight          = weight;

        posCons.AddSource(constraint);
    }
示例#11
0
    private void Start()
    {
        mainCamera = Camera.main;

        source = new ConstraintSource {
            sourceTransform = transformToLook,
            weight          = lookWeight
        };
    }
示例#12
0
    private void Start()
    {
        LookAtConstraint c = GetComponent <LookAtConstraint>();
        ConstraintSource constraintSource = new ConstraintSource {
            sourceTransform = Camera.main.transform, weight = 1
        };

        c.AddSource(constraintSource);
    }
示例#13
0
    /// <summary>
    /// Clears all sources and adds a new source with transform.
    /// </summary>
    /// <returns>The new constraint.</returns>
    public static ConstraintSource SetSource(this IConstraint constraint, Transform transform)
    {
        ConstraintSource source = new ConstraintSource();

        source.sourceTransform = transform;
        source.weight          = 1;
        constraint.SetSources(new List <ConstraintSource>());
        constraint.AddSource(source);
        return(source);
    }
    private void Start()
    {
        // todo quick fix
        var constraintSource = new ConstraintSource
        {
            sourceTransform = GameObject.Find("Ground").transform, weight = 1f
        };

        staminaImage.GetComponent <RotationConstraint>().AddSource(constraintSource);
    }
示例#15
0
 // ********************************************************************
 public static void AddSourceTransform(this ParentConstraint _constraint, Transform _transform)
 {
     if (_transform != null)
     {
         ConstraintSource source = new ConstraintSource();
         source.sourceTransform = _transform;
         source.weight          = 100;
         _constraint.AddSource(source);
     }
 }
示例#16
0
    // Start is called before the first frame update
    void Start()
    {
        var source = new ConstraintSource
        {
            sourceTransform = Camera.main.transform,
            weight          = 1.0f
        };

        GetComponent <ParentConstraint>().AddSource(source);
    }
示例#17
0
    // Start is called before the first frame update
    void Start()
    {
        LookAtConstraint lac = GetComponent <LookAtConstraint>();

        if (lac)
        {
            ConstraintSource src = new ConstraintSource();
            src.sourceTransform = UnityEngine.GameObject.FindGameObjectWithTag("Player").transform;
            src.weight          = 1;
            lac.AddSource(src);
            lac.constraintActive = true;
        }

        float max_audio_len = 0, max_part_len = 0;

        foreach (AudioSource aud in GetComponentsInChildren <AudioSource>())
        {
            if (!aud.clip)
            {
                continue;
            }
            if (vol != -1)
            {
                aud.volume = vol;
            }
            aud.outputAudioMixerGroup = mixerGroup;
            aud.pitch  += Random.Range(-pitch_range, pitch_range);
            aud.volume += Random.Range(-amp_range, 0);
            if (mixerGroup)
            {
                aud.outputAudioMixerGroup = mixerGroup;
            }
            if (aud.clip.length > max_audio_len)
            {
                max_audio_len = aud.clip.length;
            }
        }
        foreach (ParticleSystem part in GetComponentsInChildren <ParticleSystem>())
        {
            if (part.main.duration > max_part_len)
            {
                max_part_len = part.main.duration;
            }
        }
        if (live_forever)
        {
            lifetime = float.MaxValue;
        }
        else
        {
            lifetime = Mathf.Max(lifetime, max_audio_len);
            lifetime = Mathf.Max(lifetime, max_part_len);
            Destroy(gameObject, lifetime);
        }
    }
示例#18
0
    IEnumerator GetText()
    {
        Debug.Log("WWW started Start");

        for (int i = 0; i < Urls.Count; i++)
        {
            using (UnityWebRequest www = UnityWebRequest.Get(Urls[i]))
            {
                yield return(www.Send());

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    byte[] results = www.downloadHandler.data;
                    Debug.Log("Saved");
                    Debug.Log(results);
                    GameObject obj = Importer.LoadFromBytes(results);
                    // InteractionObj.Add(obj);
                    obj.AddComponent <BoxCollider>();
                    obj.AddComponent <XRGrabInteractable>();
                    obj.GetComponent <XRGrabInteractable>().colliders.Add(gameObject.GetComponent <BoxCollider>());
                    obj.GetComponent <Rigidbody>().isKinematic = true;

                    obj.GetComponent <XRGrabInteractable>().colliders.RemoveAt(obj.GetComponent <XRGrabInteractable>().colliders.Count - 1);
                    obj.AddComponent <InteractEquipment>();
                    obj.AddComponent <ScaleConstraint>();
                    obj.AddComponent <ScaleConstraint>();
                    ConstraintSource source = new ConstraintSource();
                    source.sourceTransform = GameObject.Find("Cube").transform;
                    source.weight          = 1;
                    obj.GetComponent <ScaleConstraint>().AddSource(source);
                    obj.GetComponent <ScaleConstraint>().constraintActive = true;
                    //  obj.AddComponent<WindowsGrap>();

                    for (int j = 0; j < PositionsOfObj.Count; j++)
                    {
                        if (PositionsOfObj[j].transform.childCount == 0)
                        {
                            obj.transform.parent   = PositionsOfObj[j].transform;
                            obj.transform.position = PositionsOfObj[j].transform.position;
                        }
                    }


                    // obj.GetComponent<InteractEquipment>().detailsIfo[0].Label = "Test";
                    //   obj.GetComponent<InteractEquipment>().detailsIfo[0].description = "kjhgsdhfyd";

                    //Debug.Log(obj.GetComponent<InteractEquipment>().detailsIfo.description);
                }
            }
        }
    }
示例#19
0
        public void Collect(Transform collector)
        {
            var sc = new ConstraintSource {
                sourceTransform = collector, weight = 1f
            };

            pc.AddSource(sc);
            col.enabled = false;
            IsCollected = true;
            Collected?.Invoke();
        }
示例#20
0
        protected virtual void CreateFootPrints()
        {
            _footprints = Instantiate <GameObject>(Resources.Load <GameObject>("Footprints/Footprints")).GetOrCreateComponent <PositionConstraint>();
            _footprints.transform.ResetTransformation();
            ConstraintSource source = new ConstraintSource();

            source.sourceTransform = transform;
            source.weight          = 1.0f;
            _footprints.AddSource(source);
            _footprints.constraintActive = true;
        }
示例#21
0
    public void SetOwner(GameObject owner)
    {
        ConstraintSource cs = new ConstraintSource();

        cs.sourceTransform = owner.transform;
        cs.weight          = 1;
        pc.SetSource(0, cs);
        //pc.translationOffset = new Vector3(0, 1, -1);
        pc.locked = true;
        //pc.translationOffset = Vector3.back;
    }
    public static void SetSource(this IConstraint constraint, Transform target)
    {
        ConstraintSource source = new ConstraintSource();

        source.sourceTransform = target;
        source.weight          = 1;
        constraint.SetSources(new List <ConstraintSource>()
        {
            source
        });
    }
示例#23
0
    public void AddItem(Item _item)
    {
        item = _item;
        //item.transform.SetParent(socket);
        ConstraintSource source = new ConstraintSource();

        source.sourceTransform = socket;
        source.weight          = 1f;
        _item.parentConstraint.AddSource(source);
        _item.HandlePickUp();
        //item.transform.localPosition = Vector3.zero;
    }
    ConstraintStatus AddConstraint(string boneToConstrain, string sourceBone, float weight, Axis freeze)
    {
        var  transform = GameObject.Find(boneToConstrain);
        bool catsUsed  = false;

        if (transform == null)
        {
            transform = GameObject.Find(boneToConstrain.Replace(".", "_"));
            catsUsed  = true;
        }

        if (transform == null)
        {
            EditorUtility.DisplayDialog("Error Twist bone not found!", "The twist bone: " + boneToConstrain + " Could not be found!", "ok");
            return(ConstraintStatus.Error);
        }
        var bone = transform.gameObject;

        if (bone == null)
        {
            EditorUtility.DisplayDialog("Error Twist bone not found!", "The twist bone: " + boneToConstrain + " Could not be found!", "ok");
            return(ConstraintStatus.Error);
        }

        RotationConstraint rc = bone.AddComponent(typeof(RotationConstraint)) as RotationConstraint;

        if (rc != null)
        {
            rc.weight       = weight;
            rc.rotationAxis = freeze;
            var sourceTransform = GameObject.Find(sourceBone).transform;
            var source          = new ConstraintSource();
            source.sourceTransform = sourceTransform;
            source.weight          = 1;
            rc.AddSource(source);
            rc.locked           = false;
            rc.constraintActive = true;
            newConstraints.Add(rc);
            if (catsUsed)
            {
                return(ConstraintStatus.Success);
            }
            else
            {
                return(ConstraintStatus.CATSUsedSuccess);
            }
        }
        else
        {
            Debug.LogWarning("Rotation constraint probably already setup for: " + boneToConstrain);
            return(ConstraintStatus.Warning);
        }
    }
示例#25
0
    IEnumerator AddConstraints()
    {
        yield return(new WaitForSeconds(0.05f));

        ConstraintSource lookAt = new ConstraintSource();

        lookAt.sourceTransform = itemController.lookAtTarget;
        lookAt.weight          = 0.7f;

        lowerSpineConstraint.AddSource(lookAt);
        headConstraint.AddSource(lookAt);
    }
示例#26
0
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        ConstraintSource cameraSource = new ConstraintSource {
            sourceTransform = cameraControl.targetFocus.transform,
            weight          = 1
        };

        positionConstraint.translationOffset = cameraControl.transform.position - cameraControl.targetFocus.transform.position;
        positionConstraint.AddSource(cameraSource);
        positionConstraint.constraintActive = true;
        positionConstraint.locked           = true;
    }
示例#27
0
    public void SetPhysicalBody(Transform t)
    {
        var constraint = gameObject.AddComponent <PositionConstraint>();
        var s          = new ConstraintSource
        {
            sourceTransform = t,
            weight          = 1
        };

        constraint.AddSource(s);
        constraint.constraintActive = true;
    }
示例#28
0
        private void BindPlayerToChampion(PlayerInput player, TeamDefinition teamDefinition)
        {
            var targetTransform  = teamDefinition.Champion.transform;
            var playerInputProxy = player.GetComponent <PlayerInputProxy>();
            var parentConstraint = player.GetComponent <ParentConstraint>();
            var constraintSource = new ConstraintSource {
                sourceTransform = targetTransform, weight = 1f
            };

            parentConstraint.AddSource(constraintSource);
            playerInputProxy.UpdateTeam(teamDefinition.Team);
        }
示例#29
0
        public void Follow(Transform target)
        {
            ConstraintSource source     = this.constraint.GetSource(0);
            ConstraintSource sourceLook = this.lookat.GetSource(0);

            sourceLook.sourceTransform = target;
            sourceLook.weight          = 1;
            source.sourceTransform     = target;
            source.weight = 1;

            this.constraint.SetSource(0, source);
            this.lookat.SetSource(0, sourceLook);
        }
示例#30
0
文件: Unit.cs 项目: bobemv/swarm
    private void CreateAndLinkLivesText()
    {
        lives             = _maxLives;
        livesTextInstance = Instantiate(_livesTextPrefab);
        livesText         = livesTextInstance.GetComponent <TextMesh>();
        livesText.text    = "";

        ConstraintSource source = new ConstraintSource();

        source.sourceTransform = transform;
        source.weight          = 1.0f;
        livesTextInstance.GetComponent <PositionConstraint>().AddSource(source);
    }
示例#31
0
 //[DebuggerStepThrough]
 ////[DebuggerHidden]
 public ConstraintViolation(string name, ConstraintSource constraint, object value)
 {
     this.Name = name;
     this.Constraint = constraint;
     this.Value = value;
 }