示例#1
0
    public void CreateTask()  //create all objects for the current task
    {
        Vector3 targHolder_scale = new Vector3(1.2f * 0.07f, 0.0001f, 1.2f * 0.07f);

        for (int i = 0; i < objNumber; i++)
        {
            GameObject oriObj = CreateObject(); //orignal object has shape,color,transform

            //oriObj.AddComponent<BoxCollider>();
            oriObj.AddComponent <Rigidbody>();
            oriObj.GetComponent <Rigidbody>().isKinematic = true;
            GameObject targHolder = GameObject.CreatePrimitive(PrimitiveType.Cube);//target holder to hold the object, its a plane
            targHolder.transform.position   = targetPosition[i];
            targHolder.transform.localScale = targHolder_scale;
            //Material tmp = Resources.Load<Material>("c1"); //give a color to the holder
            //tmp.color = new Color(0.5f,1,1);
            //targHolder.GetComponent<Renderer>().material = tmp;

            GameObject grabHolder = Instantiate(oriObj);  //the position for agent to grab the object
            Destroy(grabHolder.GetComponent <BoxCollider>());
            Destroy(grabHolder.GetComponent <MeshRenderer>());

            GameObject releaseHolder = Instantiate(oriObj); //the position for agent to release the object
            releaseHolder.transform.position = new Vector3(targetPosition[i].x, oriObj.transform.position.y, targetPosition[i].z);
            Destroy(releaseHolder.GetComponent <BoxCollider>());
            Destroy(releaseHolder.GetComponent <MeshRenderer>());


            //ObjDict od = new ObjDict((i+1).ToString(),materials.Count,prefabs.Count,oriObj,targObj,targHolder,false);//now fill the dictionary
            ObjDict od = gameObject.AddComponent <ObjDict>();
            od.Initialize((i + 1).ToString(), materials.Count, prefabs.Count, oriObj, targHolder, grabHolder, releaseHolder, false);
            dict.Add(i, od);
        }
    }
示例#2
0
 public object GetObj(int id)
 {
     lock (Locker)
     {
         if (ObjDict.ContainsKey(id))
         {
             return(ObjDict[id]);
         }
         return(null);
     }
 }
示例#3
0
        private void OnValidate()
        {
            if (cache == null)
            {
                cache = new ObjDict();
            }
            var emtpyOnes = cache.Filter(o => IsDefaultKey(o.Key) && o.Value != null).ToList();

            foreach (var x in emtpyOnes)
            {
                cache.Add(CalcKey(x.Value), x.Value);
                cache.Remove(x.Key);
            }
        }
        public ReturnObject PerformAction(ObjDict objDict)
        {
            ReturnObject rc = new ReturnObject();

            foreach (var item in objDict.ControlKeys)
            {
                objDict.MoveNext();

                if (objDict.CurrentControlKey is string)
                {
                    PerformAction(objDict.CurrentControlKey.ToString(), objDict.CurrentAction, objDict.CurrentValue.ToString(), (int)objDict.CurrentWaitTime);
                }
                else if (objDict.CurrentControlKey is UIControl)
                {
                    PerformAction((UIControl)objDict.CurrentControlKey, objDict.CurrentAction, objDict.CurrentValue.ToString(), (int)objDict.CurrentWaitTime);
                }
            }

            return(rc);
        }