/// <summary>
        /// Creates a full interactive object including interactions, conditions... By using
        /// S_IODefinition as an argument
        /// NOTE :This method can be only be called from the SpatialStories API.
        /// </summary>
        /// <param name="_definition">An interactive object definition</param>
        /// <param name="_wireDependencies"> Do the dependencies will be wired now ? (set that to false if you have circular dependencies that need
        /// to be post processed when all the ios and interactions have been created) </param>
        /// <returns>An interactive object ready to use</returns>
        internal static Gaze_InteractiveObject CreateInteractiveObject(S_IODefinition _definition, bool _wireDependencies)
        {
            // Create the interactive object from the prefab
            GameObject ioGameObject = GameObject.Instantiate(Resources.Load("Interactive Object") as GameObject);

            // Add the GUID to the io in order to be able to identify it between platforms and executions
            ioGameObject.AddComponent <S_Guid>().SetGUID(_definition.GUID);

            // Begin the crafting process
            ioGameObject.name = _definition.Name + " (IO)";
            ioGameObject.transform.position   = _definition.Position;
            ioGameObject.transform.rotation   = _definition.Rotation;
            ioGameObject.transform.localScale = _definition.Scale;

            // Create the interactions once the IO is ready
            Gaze_InteractiveObject io = ioGameObject.GetComponent <Gaze_InteractiveObject>();

            // If some visuals where specified add them to the new game object.
            if (_definition.Visuals != null)
            {
                AddNestedVisuals(_definition.Visuals, io);
            }

            CreateInteractionsForGameObject(_definition, io, _wireDependencies);

            return(io);
        }
        /// <summary>
        /// Sets the object given as a parameter as visuals of the io in process of creation and copies its transform
        /// if necessary.
        /// </summary>
        /// <param name="_visuals"> The object that will represent the visuals of the io </param>
        /// <param name="_io"> The io in process of creation</param>
        private static void AddNestedVisuals(GameObject _visuals, Gaze_InteractiveObject _io)
        {
            Gaze_InteractiveObjectVisuals visualsParent = _io.GetComponentInChildren <Gaze_InteractiveObjectVisuals>();

            _visuals.transform.SetParent(visualsParent.transform);
            _visuals.transform.localPosition = Vector3.zero;
            _visuals.transform.localRotation = Quaternion.identity;
        }
Пример #3
0
    private void GenerateBehaivour()
    {
        if (HasEmptyObjects(objectsToPlace, this))
        {
            return;
        }

        S_IODefinition ioDef = SpatialStoriesAPI.CreateIODefinition(behaviourName);

        int counter = objectsToPlace.Count;

        S_InteractionDefinition start = ioDef.CreateInteractionDefinition(string.Concat("Start ", behaviourName));
        S_InteractionDefinition place = ioDef.CreateInteractionDefinition(string.Concat("Instantiate ", behaviourName));

        place.CreateArkitInstantiateAction((Gaze_ArkitPlaceConstraints)constraintsIndex, heightOffset, distanceFromCamera, ChooseMode.RANDOM == (ChooseMode)chooseModeIndex, NumInstantiatiations.FINITE == (NumInstantiatiations)numInstantiationsIndex, numObjectsToInstantiate, objectsToPlace, objectsToPlaceCursor);
        place.CreateDependency(start.GUID);

        place.CreateTouchCondition();
        S_InteractionDefinition end = null;

        if (numInstantiationsIndex == (int)NumInstantiatiations.FINITE)
        {
            end       = ioDef.CreateInteractionDefinition(string.Concat("End ", behaviourName));
            end.Delay = 0.03f;
        }

        if (constraintsIndex == (int)Gaze_ArkitPlaceConstraints.OVER_A_PLANE)
        {
            place.CreateGazeCondition(ioDef.GUID, Gaze_HoverStates.IN, Gaze_GazeConstraints.PLANE);
        }
        else if (constraintsIndex == (int)Gaze_ArkitPlaceConstraints.OVER_AN_OBJECT)
        {
            place.CreateGazeCondition(ioDef.GUID, Gaze_HoverStates.IN, Gaze_GazeConstraints.ANY_OBJECT);
        }
        else if (constraintsIndex == (int)Gaze_ArkitPlaceConstraints.OVER_AN_IMAGE)
        {
            place.CreateGazeCondition(ioDef.GUID, Gaze_HoverStates.IN, Gaze_GazeConstraints.IMAGE);
        }


        Gaze_InteractiveObject obj = SpatialStoriesAPI.CreateInteractiveObject(ioDef, false);

        SpatialStoriesAPI.WirePendingDependencies();

        // Set the trigger counter condition
        if (numInstantiationsIndex == (int)NumInstantiatiations.FINITE)
        {
            CC_CountTriggers c = SpatialStoriesAPI.GetObjectOfTypeWithGUID(end.GUID).gameObject.AddComponent <CC_CountTriggers>();
            c.NumTimes    = numObjectsToInstantiate;
            c.Interaction = SpatialStoriesAPI.GetObjectOfTypeWithGUID(place.GUID).GetComponent <Gaze_Conditions>();
            Gaze_Conditions conditions = c.GetComponent <Gaze_Conditions>();
            conditions.customConditionsEnabled = true;
            conditions.customConditions.Add(c);
        }

        Close();
    }
        /// <summary>
        /// Creates all the interactions specified in the IO definition and binds them into the
        /// newly created Interactive Object
        /// </summary>
        /// <param name="_ioDef"> The definition of the IO in process of creation </param>
        /// <param name="_io"> The instance of the interactive object being created </param>
        /// <param name="_wireDependencies"> Do the dependencies will be wired now ? (set that to false if you have circular dependencies that need
        /// to be post processed when all the ios and interactions have been created) </param>
        private static void CreateInteractionsForGameObject(S_IODefinition _ioDef, Gaze_InteractiveObject _io, bool _wireDependencies)
        {
            // Get the base interaction in order to replicate it as many times as needed
            Gaze_Interaction modelInteraction = _io.GetComponentInChildren <Gaze_Interaction>();

            // Create all the interactions specified on the io definition
            int numInteractions = _ioDef.Interactions.Count;

            for (int i = 0; i < numInteractions; i++)
            {
                // Create a new copy of the model interation and parent it to the interactions of the io
                GameObject interaction = GameObject.Instantiate(modelInteraction.gameObject, modelInteraction.transform.parent);

                // Get the interaction definition
                S_InteractionDefinition interDef = _ioDef.Interactions[i];

                // Add a GUID in order to identify in a unique way across all the apps and runtimes
                interaction.AddComponent <S_Guid>().SetGUID(interDef.GUID);

                // Set the interaction name
                interaction.name = interDef.Name;

                // Create the interaction conditions
                CreateConditionsForInteraction(interDef, interaction);

                // Create the interaction Actions
                CreateActionsForInteraction(interDef, interaction);

                // Add the Delay to the interaction
                if (interDef.Delay > 0)
                {
                    Gaze_Conditions cond = interaction.GetComponent <Gaze_Conditions>();
                    cond.delayed       = true;
                    cond.delayDuration = interDef.Delay;
                }

                // Destroy the game object used to hold the monobehaivours before
                // the creation of the interaction
                interDef.DestroyComponentHolder();


                // Create the interaction dependencies if necessary
                if (_wireDependencies)
                {
                    CreateDependenciesForInteraction(interDef, interaction);
                }
                else
                {
                    depenenciesToWire.Add(new KeyValuePair <GameObject, S_InteractionDefinition>(interaction, interDef));
                }
            }
        }
    private void Start()
    {
        if (Application.isEditor)
        {
            io             = GetComponentInParent <Gaze_InteractiveObject>();
            frontReference = io.transform.Find("Reference_");

            if (frontReference == null)
            {
                frontReference = new GameObject("Reference_").transform;
            }

            frontReference.hideFlags = HideFlags.HideInHierarchy;
        }
    }
Пример #6
0
        /// <summary>
        /// Finds an interactive object using it's GUID
        /// </summary>
        /// <param name="_guid">Guid of the Interactive Object</param>
        /// <returns></returns>
        public static Gaze_InteractiveObject GetInteractiveObjectWithGUID(string _guid)
        {
            // Get the object to touch
            GameObject             ioObj = SpatialStoriesAPI.GetObjectOfTypeWithGUID(_guid);
            Gaze_InteractiveObject io    = null;

            if (ioObj != null)
            {
                io = ioObj.GetComponent <Gaze_InteractiveObject>();
            }
            else
            {
                Debug.LogError(string.Format("IO with GUID {0} Not found", _guid));
            }
            return(io);
        }