Esempio n. 1
0
        public static void TryInstantiatingAnimatable(OvrAvatar.HandType hand, ShelfObject shelfObj)
        {
            if (RecognitionState != GestureRecognizerState.Default && RecognitionState != GestureRecognizerState.Recognizing)
            {
                return;
            }

            if (hand == OvrAvatar.HandType.Right &&
                (rightAlmostPointOn || rightPointOn || rightGrabOn || rightPinchOn))
            {
                var anim = shelfObj.InstantiateAnimatable();
                if (anim != null)
                {
                    ObjectInstantiator      = shelfObj;
                    ObjectBeingInstantiated = anim;
                    SetRecognitionState(GestureRecognizerState.Instantiating);
                }
            }
            else if (hand == OvrAvatar.HandType.Left &&
                     (leftAlmostPointOn || leftPointOn || leftGrabOn || leftPinchOn))
            {
                var anim = shelfObj.InstantiateAnimatable();
                if (anim != null)
                {
                    ObjectInstantiator      = shelfObj;
                    ObjectBeingInstantiated = anim;
                    SetRecognitionState(GestureRecognizerState.Instantiating);
                }
            }
        }
Esempio n. 2
0
        private static void InstantiateFromSaved(SerializableAnimatable obj, Dictionary <string, ShelfObject> shelfObjMap)
        {
            bool        isShelfObjectAvailable = false;
            ShelfObject shelfObj = null;

            isShelfObjectAvailable = shelfObjMap.TryGetValue(obj.ShelfParent, out shelfObj);

            if (!isShelfObjectAvailable)
            {
                Debug.LogWarning("File load warning: Could not find a shelfobject named " + obj.ShelfParent);
                return;
            }

            var sceneObject = shelfObj.InstantiateAnimatable();

            SetPropertiesFromJsonObject(sceneObject, obj);

            // Emitters are only supported on top-level objects
            var emitter = obj.Emitter;

            // Assuming that for no "Emitter" in the JSON, its default value
            // is created, and so a list subfield should be empty
            if (emitter.CurveControlPoints != null &&
                emitter.CurveControlPoints.Count > 0)
            {
                var sceneEmitter = sceneObject.GetComponentInChildren <ParticleEmitter>();
                if (sceneEmitter == null)
                {
                    Debug.LogWarning(
                        "JSON indicated the presence of a particle emitter for " +
                        shelfObj.name +
                        " but no emitter was found on the object!");
                }

                var ctrlPoints = new List <Vector3>(emitter.CurveControlPoints.Count);
                foreach (var pt in emitter.CurveControlPoints)
                {
                    ctrlPoints.Add(pt);
                }

                sceneEmitter.SetEmissionConeFromFile(
                    ctrlPoints,
                    emitter.TimeCache,
                    emitter.EmissionDataKeys);

                sceneEmitter.GravityInfluence = emitter.GravityInfluence;
                sceneEmitter.WindInfluence    = emitter.WindInfluence;

                sceneEmitter.MaxPositionNoise = emitter.MaxPositionNoise;
                sceneEmitter.MaxRotationNoise = emitter.MaxRotationNoise;

                sceneEmitter.PositionNoiseFrequency = emitter.PositionNoiseFrequency;
                sceneEmitter.RotationNoiseFrequency = emitter.RotationNoiseFrequency;

                sceneEmitter.SpiralFrequency = emitter.SpiralFrequency;

                sceneEmitter.InitialParticleRotation = emitter.InitialParticleRotation;
                sceneEmitter.ParticleScale           = emitter.ParticleScale;

                if (emitter.ParticleShelfObject != null)
                {
                    bool res = shelfObjMap.TryGetValue(emitter.ParticleShelfObject, out ShelfObject particleMeshParent);
                    if (res)
                    {
                        sceneEmitter.TryChangeParticleShapeFromDroppedObject(particleMeshParent);
                    }
                }

                sceneEmitter.TestMode = false;
            }

            sceneObject.Init(shelfObj);
        }