Example #1
0
 // Use this for initialization
 void Start()
 {
     //set the default Targets
     foreach (NCARDefaultState dst in ruleset.defaultStates)
     {
         NCARappDB.GetModelByName(dst.ModelName).GetComponent <NCARModelData> ().defaultTargetAttached = NCARappDB.GetTargetByName(dst.TargetName);
     }
 }
Example #2
0
 public static void RebuildAppDB()
 {
     NCARappDB.Rebuild();
 }
Example #3
0
        // Update is called once per frame
        void Update()
        {
            //Set all the trigger flags of the models to false, and reset the targetAttached to default;
            foreach (GameObject go in NCARappDB.sceneModels)
            {
                NCARModelData md = go.GetComponent <NCARModelData> ();
                //set the trigger of this model false
                md.isTriggered = false;
                //set the target attached to the model to the default one
                md.targetAttached = md.defaultTargetAttached;
            }

            //Set all the configure flag of the target to false.
            foreach (GameObject go in NCARappDB.targets)
            {
                go.GetComponent <NCARTrackableEventHandler> ().isTargetConfigured = false;
            }


            //iterate through the rules in ruleset
            foreach (NCARRule rule in ruleset.rules)
            {
                bool isConditionsMet = true;

                //iterate through conditions in a rule
                foreach (ARTargetPairwiseCondition condition in rule.pairWiseConditions)
                {
                    Ncte t1 = NCARappDB.GetTargetByName(condition.target1Name).GetComponent <Ncte> ();
                    Ncte t2 = NCARappDB.GetTargetByName(condition.target2Name).GetComponent <Ncte> ();
                    //if any target in the condition is already configured, break
                    if (t1.isTargetConfigured || t2.isTargetConfigured)
                    {
                        isConditionsMet = false;
                        break;
                    }

                    //if the current condition is not met, break;
                    if (!NCARappDB.conditionDeligates [condition.deligateIndex].Invoke(t1, t2, ruleset.angleThreshold, ruleset.distanceThreshold))
                    {
                        isConditionsMet = false;
                        break;
                    }
                }

                //if all conditions are met
                if (isConditionsMet)
                {
                    //mark all the target as configured
                    //for each condition
                    foreach (ARTargetPairwiseCondition condition in rule.pairWiseConditions)
                    {
                        NCARappDB.GetTargetByName(condition.target1Name).GetComponent <Ncte> ().isTargetConfigured = true;
                        NCARappDB.GetTargetByName(condition.target2Name).GetComponent <Ncte> ().isTargetConfigured = true;
                    }
                    //for each show event
                    foreach (NCARShowEvent showEvent in rule.showEvents)
                    {
                        //for each model in show event
                        foreach (string modelName in showEvent.modelNames)
                        {
                            // if model is not triggered in this loop, trigger it and attach target to models
                            NCARModelData md = NCARappDB.GetModelByName(modelName).GetComponent <NCARModelData> ();
                            if (!md.isTriggered)
                            {
                                md.targetAttached = NCARappDB.GetTargetByName(showEvent.targetName);
                                md.isTriggered    = true;
                            }
                        }
                    }

                    //for each model in hide event,
                    foreach (NCARHideEvent hideEvent in rule.hideEvents)
                    {
                        //set target to null if exist

                        if (hideEvent != null && hideEvent.modelName != "")
                        {
                            NCARModelData md = NCARappDB.GetModelByName(hideEvent.modelName).GetComponent <NCARModelData> ();
                            md.targetAttached = null;
                        }
                    }
                }
            }

            //now update model state
            //for each model
            foreach (GameObject go in NCARappDB.sceneModels)
            {
                NCARModelData md = go.GetComponent <NCARModelData> ();

                //if this model is not attached to any target or the attached target is not being tracked, hide this model
                if (md.targetAttached == null || !md.targetAttached.GetComponent <Ncte> ().IsBeingTracked)
                {
                    DeactivateGameObject(md);
                }

                //if this model is attached any target that is being tracked,
                if ((md.targetAttached != null) &&
                    md.targetAttached.GetComponent <Ncte> ().IsBeingTracked)
                {
                    //move this model on that target
                    md.targetAttached.GetComponent <Ncte> ().MoveModelOnThis(md);
                    //and show it, and show it
                    ActivateGameObject(md);
                }
            }
        }
Example #4
0
        //		public override void OnGUI_original (Rect pos, SerializedProperty prop, GUIContent label)
        //		{
        //			//refresh AR database
        //			NCARappDB.Rebuild ();
        //
        //			//ArCondition의 property
        //			SerializedProperty target1 = prop.FindPropertyRelative ("target1Index");
        //			SerializedProperty deligateIndex = prop.FindPropertyRelative ("deligateIndex");
        //			SerializedProperty target2 = prop.FindPropertyRelative ("target2Index");
        //
        //			//start property. this enables the manipulation of a label.
        //			label = EditorGUI.BeginProperty (pos, label, prop);
        //
        //			//draw label and return the adjusted rect
        //			Rect posNew = EditorGUI.PrefixLabel (pos, new GUIContent ("Check If"));
        //
        //			//save original indent
        //			int indentOriginal = EditorGUI.indentLevel;
        //			EditorGUI.indentLevel = 0;
        //
        //			//Set the popup bar width
        //			float elemWidth = posNew.width * (1f / 3f);
        //
        //			//define positions of popups
        //			Rect t1rect = new Rect (posNew.x, posNew.y, elemWidth, posNew.height);
        //			Rect relrect = new Rect (posNew.x + posNew.width - (elemWidth * 2f), posNew.y, elemWidth, posNew.height);
        //			Rect t2rect = new Rect (posNew.x + posNew.width - elemWidth, posNew.y, elemWidth, posNew.height);
        //			//
        //			//			//create popups
        //			target1.intValue = EditorGUI.Popup (t1rect, target1.intValue, NCARappDB.targetNames);
        //			deligateIndex.intValue = EditorGUI.Popup (relrect, deligateIndex.intValue, NCARappDB.conditionNames);
        //			target2.intValue = EditorGUI.Popup (t2rect, target2.intValue, NCARappDB.targetNames);
        //
        //			//end property
        //			EditorGUI.EndProperty ();
        //
        //			//revert indentlevel
        //			EditorGUI.indentLevel = indentOriginal;
        //		}

        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            //refresh AR database
            NCARappDB.Rebuild();

            //ArCondition의 property
            SerializedProperty target1       = prop.FindPropertyRelative("target1Name");
            SerializedProperty deligateIndex = prop.FindPropertyRelative("deligateIndex");
            SerializedProperty target2       = prop.FindPropertyRelative("target2Name");

            //start property. this enables the manipulation of a label.
            label = EditorGUI.BeginProperty(pos, label, prop);

            //draw label and return the adjusted rect
            Rect posNew = EditorGUI.PrefixLabel(pos, new GUIContent("Check If"));

            //save original indent
            int indentOriginal = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            //Set the popup bar width
            float elemWidth = posNew.width * (1f / 3f);

            //define positions of popups
            Rect t1rect  = new Rect(posNew.x, posNew.y, elemWidth, posNew.height);
            Rect relrect = new Rect(posNew.x + posNew.width - (elemWidth * 2f), posNew.y, elemWidth, posNew.height);
            Rect t2rect  = new Rect(posNew.x + posNew.width - elemWidth, posNew.y, elemWidth, posNew.height);

            //create popups
            //target1
            int target1_index_old = System.Array.IndexOf(NCARappDB.targetNames, target1.stringValue.ToString());

            if (target1_index_old == -1)
            {
                Debug.Log(" Image Targets are not properly set. Target1 is set to the first target");
                target1_index_old = 0;
            }
            int target1_index_new = EditorGUI.Popup(t1rect, target1_index_old, NCARappDB.targetNames);

            target1.stringValue = NCARappDB.targetNames [target1_index_new];

            //deligate
            deligateIndex.intValue = EditorGUI.Popup(relrect, deligateIndex.intValue, NCARappDB.conditionNames);

            //target2 as GUID
            int target2_index_old = System.Array.IndexOf(NCARappDB.targetNames, target2.stringValue.ToString());

            if (target2_index_old == -1)
            {
                Debug.Log(" Image Targets are not properly set. Target1 is set to the first target");
                target2_index_old = 0;
            }
            int target2_index_new = EditorGUI.Popup(t2rect, target2_index_old, NCARappDB.targetNames);

            target2.stringValue = NCARappDB.targetNames [target2_index_new];


            //end property
            EditorGUI.EndProperty();

            //revert indentlevel
            EditorGUI.indentLevel = indentOriginal;
        }