protected void Awake()
        {
            this.collisionEffect = (GameObject)Resources.Load(SIGVerseUtils.CollisionEffectPath);

            this.exclusionColliderList = new List <Collider>();

            foreach (string exclusionColliderTag in exclusionColliderTags)
            {
                List <GameObject> exclusionColliderObjects = GameObject.FindGameObjectsWithTag(exclusionColliderTag).ToList <GameObject>();

                foreach (GameObject exclusionColliderObject in exclusionColliderObjects)
                {
                    List <Collider> colliders = exclusionColliderObject.GetComponentsInChildren <Collider>().ToList <Collider>();

                    this.exclusionColliderList.AddRange(colliders);
                }
            }

            this.colliders          = this.GetComponentsInChildren <Collider>();
            this.colliderVelocities = new float[this.colliders.Length];
            this.prePoss            = new Vector3[this.colliders.Length];

            this.collisionAudioSource = this.transform.root.gameObject.GetComponent <AudioSource>();

            this.collisionClip = (AudioClip)Resources.Load(SIGVerseUtils.CollisionAudioClip2Path);

            SIGVerseLogger.Info("CollisionDetector collider count=" + this.colliders.Length);
        }
        private void ExecCollisionProcess(Collision collision)
        {
            float collisionVelocity = this.colliderVelocities[Array.IndexOf(this.colliders, collision.contacts[0].thisCollider)];

            SIGVerseLogger.Info("CollisionDetector Collision Detection! Time=" + Time.time + ", Collision Velocity=" + collisionVelocity +
                                ", Part=" + collision.contacts[0].thisCollider.name + ", Collided object=" + SIGVerseUtils.GetHierarchyPath(collision.collider.transform));

            // Effect
            GameObject effect = MonoBehaviour.Instantiate(this.collisionEffect);

            Vector3 contactPoint = SIGVerseUtils.CalcContactAveragePoint(collision);

            effect.transform.position   = contactPoint;
            effect.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

            Destroy(effect, 1.0f);


            // Sound
            this.collisionAudioSource.PlayOneShot(this.collisionClip);


            // Send the collision notification
            foreach (GameObject destination in this.collisionNotificationDestinations)
            {
                ExecuteEvents.Execute <IRobotCollisionHandler>
                (
                    target: destination,
                    eventData: null,
                    functor: (reciever, eventData) => reciever.OnRobotCollisionEnter(collision, collisionVelocity, 0.5f)
                );
            }

            this.collidedTime = Time.time;
        }
示例#3
0
        private void StartRecording()
        {
//			DateTime dateTime = DateTime.Now;

            //this.outputFilePath = outputFolderPath.TrimEnd(' ', '\\') + "\\Motions_" + dateTime.ToString("yyyyMMddHHmmsss") + ".dat";
            this.outputFilePath = outputFolderPath.text.TrimEnd(' ', '\\') + "\\Motions.dat";
            SIGVerseLogger.Info("StartRecording outputFilePath=" + this.outputFilePath);

            // File open
            this.swMotionsDataWriter = new StreamWriter(this.outputFilePath, false);

            this.targetTransformInstances = new List <Transform>();

            // Write header line and get transform instances
            string definitionLine = string.Empty;

            definitionLine += "0.0," + DataType1Motion + "," + DataType2MotionDefinition;             // Elapsed time is dummy.

            foreach (GameObject targetObj in targetObjects)
            {
                foreach (Transform transform in targetObj.transform.GetComponentsInChildren <Transform>())
                {
                    // Save Transform instance list
                    this.targetTransformInstances.Add(transform);

                    // Make a header line
                    definitionLine += "\t" + GetLinkPath(transform);
                }
            }

            this.swMotionsDataWriter.WriteLine(definitionLine);

            this.savedMotionStrings = new List <string>();

            // Change Buttons
            this.recordButtonText.text   = ButtonTextStop;
            this.playButton.interactable = false;

            // Reset elapsed time
            this.elapsedTime          = 0.0f;
            this.previousRecordedTime = 0.0f;

            this.isRecording = true;
        }
        protected virtual void Grasp(Rigidbody collidedRigidbody)
        {
            this.savedParentObj = collidedRigidbody.gameObject.transform.parent;

            collidedRigidbody.gameObject.transform.parent = this.handPalm.transform;

            collidedRigidbody.useGravity = false;
//			collidedRigidbody.isKinematic = true;
            collidedRigidbody.constraints = RigidbodyConstraints.FreezeAll;

            collidedRigidbody.gameObject.AddComponent <GraspedObjectFixer>();

            this.graspedRigidbody = collidedRigidbody;

            this.SendGraspedObjectInfo(this.graspedRigidbody.gameObject);

            SIGVerseLogger.Info("Grasped: " + this.graspedRigidbody.gameObject.name);

            this.latestReleaseTime = 0.0f;
        }
示例#5
0
        private static void Init()
        {
            if (GameObject.FindObjectOfType <SIGVerseMenu>() != null)
            {
                return;
            }
            ;

            if (!ConfigManager.Instance.configInfo.useSigverseMenu)
            {
                return;
            }

            GameObject sigverseMenuObjPrefab = (GameObject)Resources.Load(SIGVerseCommon.SIGVerseMenuResourcePath);

            GameObject sigverseMenuObj = Instantiate(sigverseMenuObjPrefab);

            sigverseMenuObj.name = SIGVerseMenuName;

            SIGVerseLogger.Info("SIGVerseMenu Start");
        }
        protected virtual void Release()
        {
            this.graspedRigidbody.transform.parent = this.savedParentObj;

            this.graspedRigidbody.useGravity = true;
//			this.graspedRigidbody.isKinematic = false;

            GraspedObjectFixer graspedObjectFixer = this.graspedRigidbody.gameObject.GetComponent <GraspedObjectFixer>();

            graspedObjectFixer.enabled = false;
            Destroy(graspedObjectFixer);

            this.graspedRigidbody.constraints = RigidbodyConstraints.None;

            this.graspedRigidbody = null;
            this.savedParentObj   = null;

            this.SendGraspedObjectInfo(null);

            SIGVerseLogger.Info("Released the object");

            this.latestReleaseTime = Time.time;
        }
示例#7
0
        private void StartPlaying()
        {
            if (!File.Exists(inputFilePath.text))
            {
                SIGVerseLogger.Info("Input File NOT found.");
                return;
            }

            // File open
            StreamReader srMotionsDataReader = new StreamReader(inputFilePath.text);

            this.timeSeriesMotionsQue = new Queue <TimeSeriesMotionsData>();

            List <Transform> transformOrder = new List <Transform>();

            while (srMotionsDataReader.Peek() >= 0)
            {
                string lineStr = srMotionsDataReader.ReadLine();

                string[] columnArray = lineStr.Split(new char[] { '\t' }, 2);

                if (columnArray.Length < 2)
                {
                    continue;
                }

                string headerStr = columnArray[0];
                string dataStr   = columnArray[1];

                string[] headerArray = headerStr.Split(',');

                // Motion data
                if (headerArray[1] == DataType1Motion)
                {
                    string[] dataArray = dataStr.Split('\t');

                    // Definition
                    if (headerArray[2] == DataType2MotionDefinition)
                    {
                        transformOrder.Clear();

                        Debug.Log("data num=" + dataArray.Length);

                        foreach (string transformPath in dataArray)
                        {
                            transformOrder.Add(GameObject.Find(transformPath).transform);
                        }
                    }
                    // Value
                    else if (headerArray[2] == DataType2MotionValue)
                    {
                        if (transformOrder.Count == 0)
                        {
                            continue;
                        }

                        TimeSeriesMotionsData timeSeriesMotionsData = new TimeSeriesMotionsData();

                        timeSeriesMotionsData.ElapsedTime = float.Parse(headerArray[0]);

                        for (int i = 0; i < dataArray.Length; i++)
                        {
                            string[] transformValues = dataArray[i].Split(',');

                            GameObjUpdateData transform = new GameObjUpdateData();
                            transform.SetUpdatingTargetTransform(transformOrder[i]);

                            transform.SetPostion(new Vector3(float.Parse(transformValues[0]), float.Parse(transformValues[1]), float.Parse(transformValues[2])));
                            transform.SetRotation(new Vector3(float.Parse(transformValues[3]), float.Parse(transformValues[4]), float.Parse(transformValues[5])));

                            if (transformValues.Length == 6)
                            {
                                transform.SetScale(Vector3.one);
                            }
                            else if (transformValues.Length == 9)
                            {
                                transform.SetScale(new Vector3(float.Parse(transformValues[6]), float.Parse(transformValues[7]), float.Parse(transformValues[8])));
                            }

                            timeSeriesMotionsData.AddGameObjUpdateData(transform);
                        }

                        this.timeSeriesMotionsQue.Enqueue(timeSeriesMotionsData);
                    }
                }
            }

            srMotionsDataReader.Close();

            // Change Buttons
            this.playButtonText.text       = ButtonTextStop;
            this.recordButton.interactable = false;

            // Disable Animator
            foreach (GameObject targetObj in targetObjects)
            {
                // Disable only one animator component
                targetObj.transform.GetComponent <Animator>().enabled = false;
            }

            // Reset elapsed time
            this.elapsedTime          = 0.0f;
            this.previousRecordedTime = 0.0f;

            this.isPlaying = true;
        }