// Use this for initialization public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (try_pick_up) { try_pick_up = false; locked = cntr.m_particles.ToList().Select((v, i) => new IdMass(i, v.invMass)) .Where(v => Vector3.Distance(cntr.m_particles[v.idx].pos, ball.bounds.center) < 1.0f) .ToList(); Debug.LogFormat("Locked {0} points", locked.Count()); } else if (try_drop) { try_drop = false; locked.Select(l => cntr.m_particles[l.idx].invMass = l.inv_mass); locked.Clear(); } else if (locked.Count() > 0) { var locked_ctr = locked.Select(l => cntr.m_particles[l.idx].pos) .Aggregate((lhs, rhs) => lhs + rhs) / locked.Count(); var delta = ball.bounds.center - locked_ctr; foreach (var l in locked) { cntr.m_particles[l.idx].pos += delta; cntr.m_velocities[l.idx] = delta / Time.fixedTime; } } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) //public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (long_knife_held) { queue_work(lk_pts); } if (scalpel_held) { queue_work(sl_pts); } if (scissors_closed.gameObject.activeInHierarchy && scissors_held) { queue_work(sc_pts); } if (Time.time > 3 && Time.time < 6 && !has_cut) { has_cut = true; queue_work(tmp_cut_pts); } if (Time.time > 6 && has_cut) { has_cut = false; var ovr = GameObject.Find("UI").GetComponent <OverController>(); ovr.restore_mesh_public(); } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { solver.m_solverSubSteps = (int)solverSubSteps; parameters.m_numIterations = (int)numOfIterations; if (m_FlexParticleLocker.picked) { //TODO: check if the labeled behavior already contains a behavior and append to that behavior if (m_createBehavior.labeledBehavior.Count == 0) { print("No behaviors in Serilazable Map"); tempIVD = new SerializableMap <int, Vector3>(); tempIVD.Add(m_FlexParticleLocker.pMouseParticleID, m_FlexParticleLocker.pMouseParticlePos); m_createBehavior.labeledBehavior.Add(m_behaviorName.text, tempIVD); } else { print("There are behaviors"); foreach (var index in m_createBehavior.labeledBehavior) { if (m_behaviorName.text == index.Key) { foreach (var behavior in m_createBehavior.labeledBehavior.Values) { print(behavior.Keys); behavior.Add(m_FlexParticleLocker.pMouseParticleID, m_FlexParticleLocker.pMouseParticlePos); //m_createBehavior.labeledBehavior.Add(m_behaviorName.text, behavior); } } } } //this.GetComponent<CreateBehavior>().labeledBehavior.Add(this.GetComponent<CreateBehavior>().behaviorName.text, tempIVD); m_FlexParticleLocker.picked = false; } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //print("number of locked particles: " + m_lockedParticlesMasses.Count); m_cntr = cntr; // cache local reference for Gizmo drawing if (m_triggerParent == null) { // have to potentially look for TriggerParent again, since it's added dynamically // TODO: rethink this logic, there are many TriggerParents, but this only looks for one! m_triggerParent = FindObjectOfType <TriggerParent>(); } if (m_triggerParent.changeCollider || moveCol) { //print("change collider"); // update the locked particles: first clear, then call FlexStart again //print("number of locked particles before clear: " + m_lockedParticlesMasses.Count); //this.m_lockedParticlesIds.Clear(); /*this.*/ this.m_lockedParticlesMasses.Clear(); //Equate invMass to 0.0f in for loop below to accumulate locked particles for (int i = 0; i < m_lockedParticlesIds.Count; i++) { cntr.m_particles[m_lockedParticlesIds[i]].invMass = /*0.0f*/ m_Particles.m_mass /*1.0f*/; } this.m_lockedParticlesIds.Clear(); base.FlexStart(solver, cntr, parameters); //for (int i = 0; i < m_lockedParticlesMasses.Count; i++) //{ // print("After clearing, locked particle index: " + m_lockedParticlesIds[i] + " and inv. mass of each locked particle: " + m_lockedParticlesMasses[i]); //} moveCol = false; m_triggerParent.changeCollider = false; } base.PostContainerUpdate(solver, cntr, parameters); }
public void FlexContainerAlignContent() { tlog.Debug(tag, $"FlexContainerAlignContent START"); var testingTarget = new FlexContainer(); Assert.IsNotNull(testingTarget, "Can't create success object FlexContainer"); Assert.IsInstanceOf <FlexContainer>(testingTarget, "Should be an instance of FlexContainer type."); testingTarget.AlignContent = FlexContainer.Alignment.AlignAuto; Assert.AreEqual(FlexContainer.Alignment.AlignAuto, testingTarget.AlignContent, "Should be equal!"); testingTarget.AlignContent = FlexContainer.Alignment.AlignCenter; Assert.AreEqual(FlexContainer.Alignment.AlignCenter, testingTarget.AlignContent, "Should be equal!"); testingTarget.AlignContent = FlexContainer.Alignment.AlignFlexEnd; Assert.AreEqual(FlexContainer.Alignment.AlignFlexEnd, testingTarget.AlignContent, "Should be equal!"); testingTarget.AlignContent = FlexContainer.Alignment.AlignFlexStart; Assert.AreEqual(FlexContainer.Alignment.AlignFlexStart, testingTarget.AlignContent, "Should be equal!"); testingTarget.AlignContent = FlexContainer.Alignment.AlignStretch; Assert.AreEqual(FlexContainer.Alignment.AlignStretch, testingTarget.AlignContent, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"FlexContainerAlignContent END (OK)"); }
public override void OnInitialize() { // Create a container for the star images _container = new FlexContainer(); _container.FlexDirection = FlexContainer.FlexDirectionType.Row; _container.WidthResizePolicy = ResizePolicyType.FillToParent; _container.HeightResizePolicy = ResizePolicyType.FillToParent; this.Add(_container); // Create the images _images = new ImageView[5]; for (int i = 0; i < 5; i++) { _images[i] = new ImageView(resources + "/images/star-dim.png"); _container.Add(_images[i]); } // Update the images according to the rating (dimmed star by default) _myRating = 0; UpdateStartImages(_myRating); // Enable pan gesture detection EnableGestureDetection(Gesture.GestureType.Pan); _myDragEnabled = true; // Allow dragging by default (can be disabled) }
public void FlexContainerJustifyContent() { tlog.Debug(tag, $"FlexContainerJustifyContent START"); var testingTarget = new FlexContainer(); Assert.IsNotNull(testingTarget, "Can't create success object FlexContainer"); Assert.IsInstanceOf <FlexContainer>(testingTarget, "Should be an instance of FlexContainer type."); testingTarget.JustifyContent = FlexContainer.Justification.JustifyCenter; Assert.AreEqual(FlexContainer.Justification.JustifyCenter, testingTarget.JustifyContent, "Should be equal!"); testingTarget.JustifyContent = FlexContainer.Justification.JustifyFlexEnd; Assert.AreEqual(FlexContainer.Justification.JustifyFlexEnd, testingTarget.JustifyContent, "Should be equal!"); testingTarget.JustifyContent = FlexContainer.Justification.JustifyFlexStart; Assert.AreEqual(FlexContainer.Justification.JustifyFlexStart, testingTarget.JustifyContent, "Should be equal!"); testingTarget.JustifyContent = FlexContainer.Justification.JustifySpaceAround; Assert.AreEqual(FlexContainer.Justification.JustifySpaceAround, testingTarget.JustifyContent, "Should be equal!"); testingTarget.JustifyContent = FlexContainer.Justification.JustifySpaceBetween; Assert.AreEqual(FlexContainer.Justification.JustifySpaceBetween, testingTarget.JustifyContent, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"FlexContainerJustifyContent END (OK)"); }
public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (enabled == false) { return; } if (firstRun) { firstRun = false; _cachedVertices = skinnedMeshRenderer.sharedMesh.vertices; _cachedBindposes = skinnedMeshRenderer.sharedMesh.bindposes; _cachedBoneWeights = skinnedMeshRenderer.sharedMesh.boneWeights; bool createAsset = vertMapAsset == null || rebuildVertMapAsset; if (vertMapAsset == null) { #if UNITY_EDITOR vertMapAsset = ScriptableObject.CreateInstance <VertMapAsset>(); AssetDatabase.CreateAsset(vertMapAsset, "Assets/" + this.name + "VertMapAsset.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = vertMapAsset; #endif } if (createAsset) { vertMapAsset.vertexParticleMap = new List <int>(); VertMapAssetBuilder vertMapAssetBuilder = new VertMapAssetBuilder(flexShapeMatching, vertMapAsset, skinnedMeshRenderer); vertMapAssetBuilder.CreateAsset(); } particlePositions = new Vector3[vertMapAsset.particleRestPositions.Count]; print("particle rest positions count:" + particlePositions.Length); //Debug.Log(this.skinnedMeshRenderer.name); UpdateParticlePositions(); } else { if (timeDelta < refreshRate) { return; } // Only process once 30 times a second UpdateParticlePositions(); MatchShapes(); // apply to soft body while (timeDelta >= refreshRate) { timeDelta -= refreshRate; } } }
// Start is called before the first frame update void Start() { fsa = GetComponent <FlexSoftActor>(); fc = fsa.container; cam = /*GetComponent<CameraController>().transform;*/ Camera.main.transform; last_pos = transform.position; dashing = false; clock_dash = 0; }
/// <summary> /// Initantiates and initializes a new flex container. /// </summary> /// <param name="maxParticles">Maximum number of particles of flex container.</param> /// <param name="particleRadius">Radius of flex particles.</param> void InitializeFlexContainer(int maxParticles, float particleRadius) { flexContainer = ScriptableObject.CreateInstance <FlexContainer>(); // number of particles of all FleX objects, in this case 8 agent and 8 target particles flexContainer.maxParticles = maxParticles; flexContainer.radius = particleRadius; flexContainer.solidRest = particleRadius; flexContainer.collisionDistance = particleRadius / 2.0f; }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (Input.GetKey(m_key)) { for (int index = 0; index < cntr.m_velocities.Length; ++index) { cntr.m_velocities[index] = new Vector3((Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR); } } }
public void Initialize() { Window window = Window.Instance; window.BackgroundColor = Color.White; // Create a container to layout the rows of image and rating vertically FlexContainer container = new FlexContainer(); container.ParentOrigin = ParentOrigin.TopLeft; container.PivotPoint = PivotPoint.TopLeft; container.FlexDirection = (int)FlexContainer.FlexDirectionType.Column; container.WidthResizePolicy = ResizePolicyType.FillToParent; container.HeightResizePolicy = ResizePolicyType.FillToParent; window.Add(container); Random random = new Random(); for (int i = 0; i < 6; i++) // 6 rows in total { // Create a container to layout the image and rating (in each row) horizontally FlexContainer imageRow = new FlexContainer(); imageRow.ParentOrigin = ParentOrigin.TopLeft; imageRow.PivotPoint = PivotPoint.TopLeft; imageRow.FlexDirection = FlexContainer.FlexDirectionType.Row; imageRow.Flex = 1.0f; container.Add(imageRow); // Add the image view to the row ImageView image = new ImageView(resources + "/images/gallery-" + i + ".jpg"); image.Size2D = new Size2D(120, 120); image.WidthResizePolicy = ResizePolicyType.Fixed; image.HeightResizePolicy = ResizePolicyType.Fixed; image.AlignSelf = (int)FlexContainer.Alignment.AlignCenter; image.Flex = 0.3f; image.FlexMargin = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); imageRow.Add(image); // Create a rating control StarRating view = new StarRating(); // Add the rating control to the row view.ParentOrigin = ParentOrigin.Center; view.PivotPoint = PivotPoint.Center; view.Size2D = new Size2D(200, 40); view.Flex = 0.7f; view.AlignSelf = (int)FlexContainer.Alignment.AlignCenter; view.FlexMargin = new Vector4(30.0f, 0.0f, 0.0f, 0.0f); imageRow.Add(view); // Set the initial rating randomly between 1 and 5 view.Rating = random.Next(1, 6); } }
public void FlexContainerConstructor() { tlog.Debug(tag, $"FlexContainerConstructor START"); var testingTarget = new FlexContainer(); Assert.IsNotNull(testingTarget, "Can't create success object FlexContainer"); Assert.IsInstanceOf <FlexContainer>(testingTarget, "Should be an instance of FlexContainer type."); testingTarget.Dispose(); tlog.Debug(tag, $"FlexContainerConstructor END (OK)"); }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { var particles = fParticles.m_particles; if (Input.GetKey(m_key)) { for (int pId = 0; pId < fParticles.m_particlesCount; pId++) { particles[pId].pos -= new Vector3((Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR, (Random.value - 0.5f) * MAX_JIGGLE_FACTOR) * Time.deltaTime; } } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { parameters.m_numIterations = iterations; if (m_flAgent.reset) { Reset(); print("reset"); } if (m_flAgent.check) { if (iterations <= 25) { print("affect:" + iterations); iterations += 1; } } }
public void FlexContainerFlexWrap() { tlog.Debug(tag, $"FlexContainerFlexWrap START"); var testingTarget = new FlexContainer(); Assert.IsNotNull(testingTarget, "Can't create success object FlexContainer"); Assert.IsInstanceOf <FlexContainer>(testingTarget, "Should be an instance of FlexContainer type."); testingTarget.FlexWrap = FlexContainer.WrapType.NoWrap; Assert.AreEqual(FlexContainer.WrapType.NoWrap, testingTarget.FlexWrap, "Should be equal!"); testingTarget.FlexWrap = FlexContainer.WrapType.Wrap; Assert.AreEqual(FlexContainer.WrapType.Wrap, testingTarget.FlexWrap, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"FlexContainerFlexWrap END (OK)"); }
public override void PreContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //if (UnityObjectHasMoved()) ///* if (UnityObjectTransformchanged())*/ //{ // // copy over movement // //Debug.Log("detected movement"); // Vector3 movement = this.transform.position - new Vector3(transformX, transformY, transformZ); // TranslateFlexPositions(movement); // // and then update transform cache: // CacheTransform(); //} if (transform.hasChanged) { TransformFlexPositions(transforms); CacheLocalTransform(); } }
public void FlexContainerContentDirection() { tlog.Debug(tag, $"FlexContainerContentDirection START"); var testingTarget = new FlexContainer(); Assert.IsNotNull(testingTarget, "Can't create success object FlexContainer"); Assert.IsInstanceOf <FlexContainer>(testingTarget, "Should be an instance of FlexContainer type."); testingTarget.ContentDirection = FlexContainer.ContentDirectionType.Inherit; Assert.AreEqual(FlexContainer.ContentDirectionType.Inherit, testingTarget.ContentDirection, "Should be equal!"); testingTarget.ContentDirection = FlexContainer.ContentDirectionType.LTR; Assert.AreEqual(FlexContainer.ContentDirectionType.LTR, testingTarget.ContentDirection, "Should be equal!"); testingTarget.ContentDirection = FlexContainer.ContentDirectionType.RTL; Assert.AreEqual(FlexContainer.ContentDirectionType.RTL, testingTarget.ContentDirection, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"FlexContainerContentDirection END (OK)"); }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (Input.GetKeyDown(m_key)) { //for (int index = 0; index < cntr.m_velocities.Length; ++index) //{ // cntr.m_velocities[index] = new Vector3(0.0f, -MAX_MELT_FACTOR, 0.0f); //} //melt_object.GetComponent<FlexAnimation>().enabled = false; melt_object.GetComponent <FlexShapeMatching>().enabled = false; } if (Input.GetKeyUp(m_key)) { //for (int index = 0; index < cntr.m_velocities.Length; ++index) //{ // cntr.m_velocities[index] = new Vector3(0.0f, -MAX_MELT_FACTOR, 0.0f); //} //melt_object.GetComponent<FlexAnimation>().enabled = true; melt_object.GetComponent <FlexShapeMatching>().enabled = true; } }
// Update is called once per frame public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { moveCol = false; if (Input.GetKeyDown("o")) { //myCol.center += new Vector3(0.0f, 2.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("k")) { //myCol.center += new Vector3(0.0f, -2.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("j")) { //myCol.center += new Vector3(2.0f, 0.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("l")) { //myCol.center += new Vector3(-2.0f, 0.0f, 0.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("i")) { //myCol.center += new Vector3(0.0f, 0.0f, 2.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } if (Input.GetKeyDown("p")) { //myCol.center += new Vector3(0.0f, 0.0f, -2.0f); moveCol = true; base.PostContainerUpdate(solver, cntr, parameters); } }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //base.PostContainerUpdate(solver, cntr, parameters); int tmp_part_id = -1; if (Input.GetMouseButtonUp(0)) { if (m_mouseParticle != -1) { // we got the end of a mouse drag with a particle selected, // notify whoever needs to know! picked = true; pMouseParticleID = m_mouseParticle; pMouseParticlePos = m_mousePos; //TODO: move the following to a class that is appropriately named //print(m_mouseParticle); //print(m_mousePos); //this.GetComponent<CreateBehavior>().behavior.dictionary.Add(m_mouseParticle, mousePos); //TODO: check if the labeled behavior already contains a behavior and append to that behavior //SerializableMap<int, Vector3> tempIVD = new SerializableMap<int, Vector3>(); //tempIVD.Add(m_mouseParticle, m_mousePos); //this.GetComponent<CreateBehavior>().labeledBehavior.Add(this.GetComponent<CreateBehavior>().behaviorName.text, tempIVD); // remember particle id, since we need to undo parent's setting it back to non-zero mass: tmp_part_id = m_mouseParticle; } } base.PostContainerUpdate(solver, cntr, parameters); // make the base class do its thing first // undo what the parent did, i.e. set the mass back to 0, we want to keep it locked: // TODO: think about this again? if (tmp_part_id != -1) { cntr.m_particles[tmp_part_id].invMass = 0.0f; } }
public override void OnInspectorGUI() { FlexContainer script = (FlexContainer)target; serializedObject.Update(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(RootContainer); EditorGUILayout.PropertyField(ChildContainer); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Get Children of Container")) { script.GetChildren(); } if (GUILayout.Button("Child Container Fill To Preferred Size")) { script.SetContainerSize(); } display.intValue = EditorGUILayout.Popup("Display Type", display.intValue, displaytypes); flexdir.intValue = EditorGUILayout.Popup("Flex Direction", flexdir.intValue, flexdirection); flexwr.intValue = EditorGUILayout.Popup("Flex Wrap", flexwr.intValue, flexwrap); justcon.intValue = EditorGUILayout.Popup("Justify Content", justcon.intValue, justifyContent); aligni.intValue = EditorGUILayout.Popup("Align Items", aligni.intValue, alignitems); alignc.intValue = EditorGUILayout.Popup("Align Content", alignc.intValue, aligncontent); serializedObject.ApplyModifiedProperties(); }
public void FlexContainerFlexDirection() { tlog.Debug(tag, $"FlexContainerFlexDirection START"); var testingTarget = new FlexContainer(); Assert.IsNotNull(testingTarget, "Can't create success object FlexContainer"); Assert.IsInstanceOf <FlexContainer>(testingTarget, "Should be an instance of FlexContainer type."); testingTarget.FlexDirection = FlexContainer.FlexDirectionType.Column; Assert.AreEqual(FlexContainer.FlexDirectionType.Column, testingTarget.FlexDirection, "Should be equal!"); testingTarget.FlexDirection = FlexContainer.FlexDirectionType.ColumnReverse; Assert.AreEqual(FlexContainer.FlexDirectionType.ColumnReverse, testingTarget.FlexDirection, "Should be equal!"); testingTarget.FlexDirection = FlexContainer.FlexDirectionType.Row; Assert.AreEqual(FlexContainer.FlexDirectionType.Row, testingTarget.FlexDirection, "Should be equal!"); testingTarget.FlexDirection = FlexContainer.FlexDirectionType.RowReverse; Assert.AreEqual(FlexContainer.FlexDirectionType.RowReverse, testingTarget.FlexDirection, "Should be equal!"); testingTarget.Dispose(); tlog.Debug(tag, $"FlexContainerFlexDirection END (OK)"); }
// Start is called before the first frame update //public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) //{ // parameters.m_numIterations = Random.Range(0, 5); // //iterations = parameters.m_numIterations; // //base.FlexStart(solver, cntr, parameters); // print("test in Env reset" + parameters.m_numIterations); //} public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { if (flAgent.check) { parameters.m_numIterations = iterations; //base.PostContainerUpdate(solver, cntr, parameters); if (parameters.m_numIterations > 15 & parameters.m_numIterations < 20) { //AddReward(1.0f); addReward = true; } if (parameters.m_numIterations < 15 || parameters.m_numIterations > 20) { addReward1 = true; } if (parameters.m_numIterations <= 25) { print(parameters.m_numIterations); iterations += 1; } } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FlexContainer obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public override void Create() { Window window = Window.Instance; View01 = new View() { BackgroundColor = Color.Green, Position2D = new Position2D(0, window.Size.Height / 8), Size2D = new Size2D(window.Size.Width / 2, (window.Size.Height / 8) * 7), Name = "View01" }; window.Add(View01); View02 = new View() { Position2D = new Position2D(window.Size.Width / 2, window.Size.Height / 8), WidthSpecification = (window.Size.Width / 2), HeightSpecification = (window.Size.Height / 8) * 7, BackgroundColor = Color.Blue, Layout = new LinearLayout(), Name = "View02LinearView", }; window.Add(View02); View03 = new View() { BackgroundColor = Color.Yellow, Name = "View03", Size2D = new Size2D(20, (window.Size.Height / 8) * 7) }; View01.Add(View03); LinearLayout verticalLayout = new LinearLayout(); verticalLayout.LinearOrientation = LinearLayout.Orientation.Vertical; View04 = new View() { BackgroundColor = Color.Cyan, PositionX = View03.Size2D.Width, WidthSpecification = LayoutParamPolicies.WrapContent, HeightSpecification = LayoutParamPolicies.MatchParent, Layout = verticalLayout, Name = "View04LinearView", }; View01.Add(View04); View07 = new View() { BackgroundColor = Color.Blue, Size2D = new Size2D(200, 200), Name = "View07" }; View03.Add(View07); ImageView06 = LayoutingExample.CreateChildImageView("res/images/application-icon-101.png", new Size2D(100, 100)); ImageView06.Name = "imageView-06"; View04.Add(ImageView06); ImageView04 = LayoutingExample.CreateChildImageView("res/images/application-icon-101.png", new Size2D(200, 200)); ImageView04.Name = "imageView-04"; View07.Add(ImageView04); View08 = new View() { BackgroundColor = Color.Magenta, Size2D = new Size2D(280, 280), Name = "View08" }; View04.Add(View08); ImageView03 = LayoutingExample.CreateChildImageView("res/images/application-icon-101.png", new Size2D(100, 100)); ImageView03.Name = "imageView-03"; View08.Add(ImageView03); View05 = new View() { BackgroundColor = Color.Yellow, Name = "View05", Size2D = new Size2D(10, 100) }; View02.Add(View05); FlexContainer legacyContainer = new FlexContainer(); legacyContainer.FlexDirection = FlexContainer.FlexDirectionType.Column; legacyContainer.Size2D = new Size2D(View02.Size2D.Width / 2, 280); legacyContainer.Name = "legacyFlexContainer"; View02.Add(legacyContainer); ImageView02 = LayoutingExample.CreateChildImageView("res/images/application-icon-103.png", new Size2D(100, 100)); ImageView02.Name = "imageView-02"; legacyContainer.Add(ImageView02); ImageView01 = LayoutingExample.CreateChildImageView("res/images/application-icon-104.png", new Size2D(100, 100)); ImageView01.Name = "imageView-01"; legacyContainer.Add(ImageView01); ImageView05 = LayoutingExample.CreateChildImageView("res/images/application-icon-102.png", new Size2D(100, 100)); ImageView05.Name = "imageView-05"; View05.Add(ImageView05); CreateHelpButton(); LayoutingExample.GetToolbar().Add(helpButton); }
/// <summary> /// Flex Container Sample Application initialisation. /// </summary> public void Initialize() { Window.Instance.BackgroundColor = new Color(0.8f, 0.8f, 0.8f, 1.0f); // Create FlexContainer flexContainer = new FlexContainer(); flexContainer.PositionUsesPivotPoint = true; flexContainer.PivotPoint = PivotPoint.TopLeft; flexContainer.ParentOrigin = ParentOrigin.TopLeft; flexContainer.Position = new Position(220, 160, 0); flexContainer.SizeWidth = 700; flexContainer.SizeHeight = 700; flexContainer.BackgroundColor = Color.Yellow; flexContainer.FlexDirection = FlexContainer.FlexDirectionType.Column; Window.Instance.GetDefaultLayer().Add(flexContainer); // Create flex items and add them to the container for (int i = 0; i < NUM_FLEX_ITEMS; i++) { TextLabel flexItem = new TextLabel(); flexItem.PositionUsesPivotPoint = true; flexItem.PivotPoint = PivotPoint.TopLeft; flexItem.ParentOrigin = ParentOrigin.TopLeft; // Set different background colour to help to identify different items flexItem.BackgroundColor = new Vector4(((float)i) / NUM_FLEX_ITEMS, ((float)(NUM_FLEX_ITEMS - i)) / NUM_FLEX_ITEMS, 1.0f, 1.0f); flexItem.Text = i + ""; flexItem.Name = i + ""; flexItem.HorizontalAlignment = HorizontalAlignment.Center; flexItem.VerticalAlignment = VerticalAlignment.Center; // Set a fixed size to the items so that we can wrap the line and test these // flex properties that only work when there are multiple lines in the layout flexItem.WidthResizePolicy = ResizePolicyType.Fixed; flexItem.HeightResizePolicy = ResizePolicyType.Fixed; // Make sure there are still extra space in the line after wrapping flexItem.SizeWidth = flexContainer.SizeWidth / NUM_FLEX_ITEMS * 1.25f; flexItem.SizeHeight = flexContainer.SizeHeight / NUM_FLEX_ITEMS * 1.25f; flexContainer.Add(flexItem); } // Create the tableView which is the parent of the Pushbuttons // which can change the flexcontainer's properties tableView = new TableView(6, 1); tableView.SizeWidth = 500; tableView.SizeHeight = 400; tableView.CellPadding = new Vector2(5, 5); tableView.PositionUsesPivotPoint = true; tableView.PivotPoint = PivotPoint.BottomRight; tableView.ParentOrigin = ParentOrigin.BottomRight; tableView.Position = new Position(-100, -100, 0); Window.Instance.GetDefaultLayer().Add(tableView); // Create the pushbutton which can change the property of ContentDirection. // The default value of flexcontainer's ContentDirection // is FlexContainer.ContentDirectionType.Inherit. PushButton button0 = new PushButton(); button0.Name = "ContentDirection"; button0.Label = CreateText("ContentDirection : Inherit"); button0.SizeWidth = tableView.SizeWidth; button0.Focusable = true; button0.Clicked += ButtonClick; tableView.AddChild(button0, new TableView.CellPosition(0, 0)); // Create the pushbutton which can change the property of FlexDirection. // The current value of flexcontainer's FlexDirection // is FlexContainer.ContentDirectionType.Column PushButton button1 = new PushButton(); button1.Name = "FlexDirection"; button1.Label = CreateText("FlexDirection : Column"); button1.SizeWidth = tableView.SizeWidth; button1.Clicked += ButtonClick; tableView.AddChild(button1, new TableView.CellPosition(1, 0)); // Create the pushbutton which can change the property of FlexWrap // The current value of flexcontainer's FlexWrap // is FlexContainer.WrapType.NoWrap PushButton button2 = new PushButton(); button2.Name = "FlexWrap"; button2.Label = CreateText("FlexWrap : NoWrap"); button2.SizeWidth = tableView.SizeWidth; button2.Clicked += ButtonClick; tableView.AddChild(button2, new TableView.CellPosition(2, 0)); // Create the pushbutton which can change the property of JustifyContent // The current value of flexcontainer's JustifyContent // is FlexContainer.Justification.JustifyFlexStart PushButton button3 = new PushButton(); button3.Name = "JustifyContent"; button3.Label = CreateText("JustifyContent : JustifyFlexStart"); button3.SizeWidth = tableView.SizeWidth; button3.Clicked += ButtonClick; tableView.AddChild(button3, new TableView.CellPosition(3, 0)); // Create the pushbutton which can change the property of AlignItems // The current value of flexcontainer's AlignItems // is FlexContainer.Alignment.AlignStretch PushButton button4 = new PushButton(); button4.Name = "AlignItems"; button4.Label = CreateText("AlignItems : AlignStretch"); button4.SizeWidth = tableView.SizeWidth; button4.Clicked += ButtonClick; tableView.AddChild(button4, new TableView.CellPosition(4, 0)); // Create the pushbutton which can change the property of AlignContent // The current value of flexcontainer's AlignContent // is FlexContainer.Alignment.AlignFlexStart PushButton button5 = new PushButton(); button5.Name = "AlignContent"; button5.Label = CreateText("AlignContent : AlignFlexStart"); button5.SizeWidth = tableView.SizeWidth; button5.Clicked += ButtonClick; tableView.AddChild(button5, new TableView.CellPosition(5, 0)); FocusManager.Instance.SetCurrentFocusView(button0); Window.Instance.KeyEvent += AppBack; }
//public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) //{ // print(Time.fixedTime); // print(flAnim.particlePositions.Length); // for (int i = 0; i < flAnim.particlePositions.Length; i++) // { // print("index: " + i + "anim particle velocity at start: " + flAnim.particlePositions[i] / Time.fixedTime); // } //} // Start is called before the first frame update public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //for (int i = 0; i < flAnim.particlePositions.Length; i++) //{ // Debug.DrawLine(flAnim.flexParticles.m_particles[i].pos, flAnim.vertMapAsset.particleRestPositions[i], Color.green); //} if (firstRun) { firstRun = false; for (int i = 0; i < flAnim.particlePositions.Length; i++) { //print("index: " + i + " anim particle pos at post containter update: " + flAnim.particlePositions[i]); //print("index: " + i + " velocity: " + flParticles.m_velocities[i]); //print("temp" + temp[i]); //print("time. Delta time: " + Time.deltaTime); Vector3 delta = new Vector3(); delta = Vector3.zero; velFirst = delta / Time.deltaTime; //print("first anim particle: " + flAnim.particlePositions[i]); //print("delta: " + delta); //print("vel: " + velFirst); temp[i] = flAnim.particlePositions[i]; } } else { for (int i = 0; i < flAnim.particlePositions.Length; i++) { //print("index: " + i + " anim particle pos at post containter update: " + flAnim.particlePositions[i]); //print("index: " + i + " velocity: " + flParticles.m_velocities[i]); //print("temp" + temp[i]); //print("time. Delta time: " + Time.deltaTime); Vector3 delta = new Vector3(); Vector3 vel = new Vector3(); delta = (flAnim.particlePositions[i] - temp[i]); vel = delta / Time.deltaTime; //vel = vel / flAnim.particlePositions.Length; //print("first anim particle: " + flAnim.particlePositions[i]); //print("delta: " + delta); //print("vel: " + vel); velAccumAnim += vel; temp[i] = flAnim.particlePositions[i]; } } print("Avg. velocity of animPaticles: " + (velAccumAnim + velFirst).magnitude / flAnim.particlePositions.Length); for (int i = 0; i < flParticles.m_velocities.Length; i++) { //print(flParticles.m_initialVelocity); //print("index: " + i + "velocity: " + flParticles.m_velocities[i]); flParticles.m_velocities[i] = flParticles.m_velocities[i] /*/ flParticles.m_velocities.Length*/; velAccumFlex += flParticles.m_velocities[i]; } print("Avg. velocity of flexPaticles: " + velAccumFlex.magnitude / flParticles.m_velocities.Length); }
public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters) { //Note: might need to use a Coroutine instead! //Stop flex animation first then track particle positions for this object; if (m_UIController.turnOffAnim) { flyCamEnable = true; //List<Vector3> templist = null; //Vector3 temp; this.GetComponent <FlexAnimation>().enabled = false; //might have to move this to start to optimize flyCam.enabled = true; playerController.enabled = false; //StartCoroutine(MoveParticle()); //int x = this.GetComponent<FlexMouseDrag>().m_mouseParticle; if (m_UIController.doneMoving) { m_UIController.turnOffAnim = false; m_UIController.doneMoving = false; //print(reset.position); playerController.enabled = true; } } if (m_UIController.turnOnAnim) { //Note: need to save the behavior as an asset possibly or JSON?, need to ask stefan. //string jsonData = JSONSerializer.ToJson<Dictionary<int, Vector3>>(behavior); //File.WriteAllText(Application.persistentDataPath + "/test.json", jsonData); // test C# way of serializing: XmlSerializer xmlserializer = new XmlSerializer(labeledBehavior.GetType()); //FileStream file = File.Open( "C:/Users/siciit/AppData/LocalLow/DefaultCompany/Nvidia_softAnim_trials/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Write); //FileStream file = File.Open(Application.persistentDataPath + "/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Read); if (!System.IO.File.Exists(Application.persistentDataPath + "/labbehaviorTrial3.xml")) { /* FileStream*/ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.OpenOrCreate, FileAccess.Write); } else { /*FileStream */ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.Open, FileAccess.Write); } xmlserializer.Serialize(file, labeledBehavior); file.Flush(); file.Close(); flyCamEnable = false; //JSONSerializer.Save<Dictionary<int, Vector3>>("test", behavior); //if (behaviorName != null) // { // print(behaviorName.text); // } this.GetComponent <FlexAnimation>().enabled = true; m_UIController.turnOnAnim = false; } if (m_UIController.showAnim) { m_UIController.showAnim = false; XmlSerializer readSerialize = new XmlSerializer(typeof(SerializableMap <string, SerializableMap <int, Vector3> >)); //FileStream file = new FileStream(Application.persistentDataPath + "/labbehaviorTrial2.xml", FileMode.Open); ///*FileStream */file = File.Open("C:/Users/siciit/AppData/LocalLow/DefaultCompany/Nvidia_softAnim_trials/labbehaviorTrial2.xml", FileMode.Open, FileAccess.Read); /*FileStream*/ file = File.Open(Application.persistentDataPath + "/labbehaviorTrial3.xml", FileMode.Open, FileAccess.Read); print(file.Name); container = readSerialize.Deserialize(file) as SerializableMap <string, SerializableMap <int, Vector3> >; foreach (var var in container) { print(var.Key); print(var.Value); } //this.GetComponent<GetBehaviors>().localContainer = container; //this.GetComponent<GetBehaviors>().gotXML = true; getBehaviors.localContainer = container; getBehaviors.gotXML = true; //FindObjectOfType<GetBehaviors> ().localContainer = container; //FindObjectOfType<GetBehaviors>().gotXML = true; file.Flush(); file.Close(); } //store list ofvectors that have changed positions; }
/// <summary> /// Flex Container Sample Application initialisation. /// </summary> public void Initialize() { Window.Instance.BackgroundColor = Color.Black; View focusIndicator = new View(); FocusManager.Instance.FocusIndicator = focusIndicator; //Create a title, and add it to window guide = new TextLabel(); guide.HorizontalAlignment = HorizontalAlignment.Center; guide.VerticalAlignment = VerticalAlignment.Center; guide.PositionUsesPivotPoint = true; guide.ParentOrigin = ParentOrigin.TopLeft; guide.PivotPoint = PivotPoint.TopLeft; guide.Size2D = new Size2D(1920, 96); guide.FontFamily = "Samsung One 600"; guide.Position2D = new Position2D(0, 94); guide.MultiLine = false; //guide.PointSize = 15.0f; guide.PointSize = DeviceCheck.PointSize15; guide.Text = "FlexContainer Sample \n"; guide.TextColor = Color.White; //guide.BackgroundColor = new Color(43.0f / 255.0f, 145.0f / 255.0f, 175.0f / 255.0f, 1.0f); Window.Instance.GetDefaultLayer().Add(guide); // Create FlexContainer flexContainer = new FlexContainer(); flexContainer.PositionUsesPivotPoint = true; flexContainer.PivotPoint = PivotPoint.TopLeft; flexContainer.ParentOrigin = ParentOrigin.TopLeft; flexContainer.Position = new Position(710, 275, 0); flexContainer.SizeWidth = 400; flexContainer.SizeHeight = 400; flexContainer.BackgroundColor = Color.White; flexContainer.FlexDirection = FlexContainer.FlexDirectionType.Column; Window.Instance.GetDefaultLayer().Add(flexContainer); // Create flex items and add them to the container for (int i = 0; i < NUM_FLEX_ITEMS; i++) { TextLabel flexItem = new TextLabel(); flexItem.PositionUsesPivotPoint = true; flexItem.PivotPoint = PivotPoint.TopLeft; flexItem.ParentOrigin = ParentOrigin.TopLeft; // Set different background colour to help to identify different items flexItem.BackgroundColor = new Vector4(((float)i) / NUM_FLEX_ITEMS, ((float)(NUM_FLEX_ITEMS - i)) / NUM_FLEX_ITEMS, 1.0f, 1.0f); //flexItem.Text = i + ""; flexItem.Name = i + ""; flexItem.HorizontalAlignment = HorizontalAlignment.Center; flexItem.VerticalAlignment = VerticalAlignment.Center; // Set a fixed size to the items so that we can wrap the line and test these // flex properties that only work when there are multiple lines in the layout flexItem.WidthResizePolicy = ResizePolicyType.Fixed; flexItem.HeightResizePolicy = ResizePolicyType.Fixed; // Make sure there are still extra space in the line after wrapping flexItem.SizeWidth = flexContainer.SizeWidth / NUM_FLEX_ITEMS * 1.25f; flexItem.SizeHeight = flexContainer.SizeHeight / NUM_FLEX_ITEMS * 1.25f; flexContainer.Add(flexItem); } // Create the tableView which is the parent of the Pushbuttons // which can change the flexcontainer's properties tableView = new TableView(2, 3); tableView.Position2D = new Position2D(80, 880); tableView.SizeWidth = 1800; tableView.SizeHeight = 180; tableView.PivotPoint = PivotPoint.TopLeft; tableView.ParentOrigin = ParentOrigin.TopLeft; //tableView.CellPadding = new Vector2(15, 10); Window.Instance.GetDefaultLayer().Add(tableView); string[] btnName = { "ContentDirection", "FlexDirection", "FlexWrap", "JustifyContent", "AlignItems", "AlignContent" }; string[] btnLabel = { "ContentDirection : Inherit", "FlexDirection : Column", "FlexWrap : NoWrap", "JustifyContent : JustifyFlexStart", "AlignItems : AlignStretch", "AlignContent : AlignFlexStart" }; for (uint row = 0; row < 2; row++) { for (uint column = 0; column < 3; column++) { PushButton button = CreateButton(btnName[row * 3 + column], btnLabel[row * 3 + column]); button.SizeWidth = 560; button.SizeHeight = 80; button.Focusable = true; button.Clicked += ButtonClick; tableView.AddChild(button, new TableView.CellPosition(row, column)); if (0 == row && column == 0) { FocusManager.Instance.SetCurrentFocusView(button); } buttonArray[row * 3 + column] = button; } } buttonArray[5].Opacity = 0.0f; Window.Instance.KeyEvent += AppBack; }