/** Executes an action, and returns the action that is executed. * The node becomes the action's target. * @warning Starting from v0.8 actions don't retain their target anymore. * @since v0.7.1 * @return An Action pointer */ public CCAction runAction(CCAction action) { NSUtils.Assert(action != null, "Argument must be non-nil"); _actionManager.addAction(action, this, !_isRunning); return(action); }
public new virtual CCActionFiniteTime copy() { CCActionFiniteTime act = (CCActionFiniteTime)copyImpl(); NSUtils.Assert(act != null, "{0}:copyImpl not implemented", GetType().Name); return(act); }
public virtual CCActionFiniteTime reverse() { CCActionFiniteTime act = (CCActionFiniteTime)reverseImpl(); NSUtils.Assert(act != null, "{0}:reverseImpl not implemented", GetType().Name); return(act); }
/** Schedules the 'update' selector for a given target with a given priority. * The 'update' selector will be called every frame. * The lower the priority, the earlier it is called. * @since v0.99.3 */ public void scheduleUpdate(System.Object target, int priority, bool paused) { tHashUpdateEntry hashElement = hashForUpdates.HASH_FIND_INT(target.GetHashCode()); if (hashElement != null) { if (CCDebug.COCOS2D_DEBUG >= 1) { NSUtils.Assert(hashElement.entry.obj.markedForDeletion, "CCScheduler: You can't re-schedule an 'update' selector'. Unschedule it first"); } // TODO : check if priority has changed! hashElement.entry.obj.markedForDeletion = false; return; } // most of the updates are going to be 0, that's way there // is an special list for updates with priority 0 if (priority == 0) { appendIn(updates0, target, paused); } else if (priority < 0) { priorityIn(updatesNeg, target, priority, paused); } else // priority > 0 { priorityIn(updatesPos, target, priority, paused); } }
/** initializes the action */ public void initWithAction(CCActionInterval action) { NSUtils.Assert(action != null, "Ease: arguments must be non-nil"); base.initWithDuration(action.duration); _inner = action; }
public override void startWithTarget(object aTarget) { NSUtils.Assert(aTarget is CC3Node, "CC3Scale only supports with CC3Node, and target is {0}.", aTarget); base.startWithTarget(aTarget); _startScaleZ = (_target as CC3Node).scaleZ; _deltaZ = _endScaleZ - _startScaleZ; }
public void DL_REPLACE_ELEM(utNode <T> el, utNode <T> add) { NSUtils.Assert(head != null, "utList#DL_REPLACE_ELEM: head should not be null"); NSUtils.Assert(el != null, "utList#DL_REPLACE_ELEM: el should not be null"); NSUtils.Assert(add != null, "utList#DL_REPLACE_ELEM: add should not be null"); if ((_head) == (el)) { _head = add; (add).next = (el).next; if ((el).next == null) { (add).prev = (add); } else { (add).prev = (el).prev; (add).next.prev = (add); } } else { (add).next = (el).next; (add).prev = (el).prev; (add).prev.next = (add); if ((el).next == null) { (head).prev = (add); } else { (add).next.prev = (add); } } }
public static string ReadTextFileFromResources(string path, ZipDelegate zip = null) { string result = null; if (Application.isPlaying) { string ext = Path.GetExtension(path); NSUtils.Assert(string.IsNullOrEmpty(ext) || ext == ".txt" || ext == ".json", "FileUtils: Text file in Resources folder must be '*.txt', '*.json' or none extends format!"); if (!string.IsNullOrEmpty(ext)) { path = path.Replace(ext, ""); } TextAsset txt = Resources.Load <TextAsset> (path); NSUtils.Assert(txt != null, "No file found at {0}", path); result = txt.text; } else if (File.Exists(path)) { // result = System.IO.File.ReadAllText(path); result = ReadStringFromPath(path); } if (zip != null) { result = zip.unZip(result); } return(result); }
public void DL_DELETE(utNode <T> del) { NSUtils.Assert((del).prev != null, "utList#DL_DELETE: del.prev should not be null."); if ((del).prev == (del)) { (_head) = null; } else if ((del) == (_head)) { if (del.next != null) { (del).next.prev = (del).prev; } (_head) = (del).next; } else { (del).prev.next = (del).next; if ((del).next != null) { (del).next.prev = (del).prev; } else { (_head).prev = (del).prev; } } }
/** initializes the action with an Animation and will restore the original frame when the animation is over */ public void initWithAnimation(CCAnimation anim) { NSUtils.Assert(anim != null, "Animate: argument Animation must be non-nil"); float singleDuration = anim.duration; base.initWithDuration(singleDuration * anim.loops); _nextFrame = 0; this.animation = anim; _origFrame = null; _executedLoops = 0; _splitTimes = new List <float> (anim.frames.Count); float accumUnitsOfTime = 0; float newUnitOfTimeValue = singleDuration / anim.totalDelayUnits; var enumerator = anim.frames.GetEnumerator(); while (enumerator.MoveNext()) { var frame = enumerator.Current; float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; accumUnitsOfTime += frame.delayUnits; _splitTimes.Add(value); } }
public void generateGearsInEditMode(string category, Type[] componentTypes, int num) { NSUtils.Assert(!Application.isPlaying, "CCFactory:generateGearsInEditMode works in edit mode only!"); if (componentTypes == null) { componentTypes = new Type[0]; } Storage storage = getStorage(category, true); storage.componentTypeNames = new string[componentTypes.Length]; for (int i = 0; i < componentTypes.Length; i++) { storage.componentTypeNames[i] = componentTypes[i].AssemblyQualifiedName; } for (int i = 0; i < num; i++) { CCFactoryGear gear = buildGear(componentTypes); gear.gameObject.name = string.Format("{0}-{1}", category, i); gear.gameObject.transform.SetParent(transform); gear.gameObject.hideFlags = HideFlags.HideInHierarchy; gear.gameObject.SetActive(false); storage.gears.Add(gear); } }
public void gotoAndStop(string label) { int frame = getFrame(label); NSUtils.Assert(frame != -1, "BBFlashMovie:gotoAndStop: Label {0} not found.", label); gotoAndStop(frame); }
/** * repeat will execute the action repeat + 1 times, for a continues action use kCCRepeatForever * delay is the amount of time the action will wait before execution */ public void schedule(TICK_IMP selector, float interval = 0, uint repeat = CCScheduler.kCCRepeatForever, float delay = 0) { NSUtils.Assert(selector != null, "Argument must be non-nil"); NSUtils.Assert(FloatUtils.EB(interval, 0), "Arguemnt must be positive"); _scheduler.schedule(selector, this, interval, repeat, !_isRunning, delay); }
public void runWithScene(CCScene scene) { NSUtils.Assert(scene != null, "Argument must be non-nil"); NSUtils.Assert(_runningScene == null, "This command can only be used to start the CCDirector. There is already a scene present."); pushScene(scene); startAnimation(); }
public void initWithAction(CCActionFiniteTime action) { NSUtils.Assert(action != null, "CCReverseTime: action should not be nil"); NSUtils.Assert(action != _other, "CCReverseTime: re-init doesn't support using the same arguments"); base.initWithDuration(action.duration); _other = action; }
public virtual void reorderChild(CCNode child, int z) { NSUtils.Assert(child != null, "Child must be non-nil"); _isReorderChildDirty = true; child.orderOfArrival = globalOrderOfArrival++; child._setZOrder(z); }
public virtual void removeChildAndCleanup(CCNode child, bool cleanup) { if (child == null) { return; } NSUtils.Assert(_children.Contains(child), "This node does not contain the specified child."); detachChild(child, cleanup); }
static CCTMXLayer ParseLayer(XmlNode nodeData, int cols, int rows, Dictionary <int, string> gidToFiles, Dictionary <int, Dictionary <string, string> > gidToTileProperties) { XmlNode data = nodeData.SelectSingleNode("data"); string name = nodeData.Attributes["name"].InnerText; string encoding = data.Attributes["encoding"].InnerText; NSUtils.Assert(encoding == "csv", "cocos2d:CCTMXMapParser: Unsupported encoding {0} found. Only csv is supported now.", encoding); string csvData = data.InnerText; CCTMXTiledLayer layer = new CCTMXTiledLayer(); layer.name = name; layer.visiable = nodeData.Attributes["visible"] != null && nodeData.Attributes["visible"].InnerText == "0"; layer.tiles = new CCTMXTile[rows][]; for (int row = 0; row < rows; row++) { layer.tiles[row] = new CCTMXTile[cols]; } string[] layerData = csvData.Split(','); int totalTiles = cols * rows; for (int i = 0; i < totalTiles; i++) { int col = i % cols; int row = Mathf.FloorToInt(i / cols); int tileId = int.Parse(layerData[i].ToString().Trim()); if (tileId > 0) { CCTMXTile tile = new CCTMXTile(); tile.gid = tileId; tile.col = col; tile.row = row; try{ tile.file = gidToFiles[tile.gid]; }catch { throw new UnityEngine.UnityException(string.Format("cocos2d: CCTMXMapParser: gid [{0}] not found", tile.gid)); } Dictionary <string, string> tileProperties = null; if (!gidToTileProperties.TryGetValue(tile.gid, out tileProperties)) { tileProperties = null; } tile.sharedProperties = tileProperties; layer.tiles[row][col] = tile; } } XmlNode propertiesNode = nodeData.SelectSingleNode("properties"); if (propertiesNode != null) { layer.properties = new Dictionary <string, string>(); ParseProperties(propertiesNode, layer.properties); } return(layer); }
public void gotoAndPlay(string start, string end, BBFlashMovieCallback callback = null) { int startFrame = getFrame(start); NSUtils.Assert(startFrame != -1, "BBFlashMovie:gotoAndPlay: Label {0} not found.", start); int endFrame = getFrame(end); NSUtils.Assert(endFrame != -1, "BBFlashMovie:gotoAndPlay: Label {0} not found.", end); gotoAndPlay(startFrame, endFrame, callback); }
static string LoadText(string file) { NSUtils.Assert(file.EndsWith(".txt"), "Text file in Resources folder must be '*.txt' format!"); string ext = Path.GetExtension(file); file = file.Replace(ext, ""); TextAsset asset = Resources.Load <TextAsset> (file); NSUtils.Assert(asset != null, "cocos2d: CCTmxParser:File not found :{0}.", file); return(asset.text); }
Tile addTile(CCSpriteFrame frame, CGAffineTransform transform) { NSUtils.Assert(_texture == frame.texture, "cocos2d:CCTileSprite#setTile: only support one texture in a tile sprite."); Tile tile = new Tile(); tile.spriteFrame = frame; tile.transform = transform; _tiles.DL_APPEND(tile); _meshDirty = true; return(tile); }
/** Adds an animation from a plist file. * Make sure that the frames were previously loaded in the CCSpriteFrameCache. * @since v1.1 */ public void addAnimationsWithFile(string plist) { NSUtils.Assert(plist != null, "Invalid texture file name"); NSDictionary dict = NSDictionary.DictionaryWithContentsOfFileFromResources(plist); NSUtils.Assert(dict != null, "CCAnimationCache: File could not be found: {0}", plist); addAnimationsWithDictionary(dict); }
// // Designated initializer // protected void initWithString(string value, CCMenuItemDelegate block) { NSUtils.Assert(value.Length > 0, "Value length must be greater than 0"); _fontName = _globalFontName; _fontSize = _globalFontSize; CCLabelTTF label = new CCLabelTTF(value, _fontName, _fontSize); initWithLabel(label, block); }
public static CCActionFiniteTime ActionWithArray(CCActionFiniteTime[] actions) { NSUtils.Assert(actions != null && actions.Length > 0, "CCActionSequence: actions should not be null."); CCActionFiniteTime prev = actions [0]; for (int i = 1; i < actions.Length; i++) { prev = ActionWithOneTwo(prev, actions [i]); } return(prev); }
public void unscheduleBlockForKey(string key, System.Object target) { // explicity handle nil arguments when removing an object if (target == null && key == null) { return; } NSUtils.Assert(target != null, "Target MUST not be nil"); NSUtils.Assert(key != null, "key MUST not be NULL"); tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode()); if (element != null) { for (int i = 0; i < element.timers.Count; i++) { CCTimer timer = element.timers[i]; if (timer is CCTimerBlock && key == ((CCTimerBlock)timer).key) { if (timer == element.currentTimer && !element.currentTimerSalvaged) { element.currentTimerSalvaged = true; } element.timers.RemoveAt(i); // update timerIndex in case we are in tick:, looping over the actions if (element.timerIndex >= i) { element.timerIndex--; } if (element.timers.Count == 0) { if (currentTarget == element) { currentTargetSalvaged = true; } else { removeHashElement(element); } } return; } } } // Not Found // NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString); }
protected void initWithAction(CCActionFiniteTime one, CCActionFiniteTime two) { NSUtils.Assert(one != null && two != null, "Sequence: arguments must be non-nil"); NSUtils.Assert(one != _actions[0] && one != _actions[1], "Sequence: re-init using the same parameters is not supported"); NSUtils.Assert(two != _actions[1] && two != _actions[0], "Sequence: re-init using the same parameters is not supported"); float d = one.duration + two.duration; base.initWithDuration(d); _actions [0] = one; _actions [1] = two; }
public void pushScene(CCScene scene) { NSUtils.Assert(scene != null, "Argument must be non-nil"); _sendCleanupToScene = false; if (_runningScene != null) { _runningScene.gameObject.SetActive(false); } _scenesStack.Push(scene); _nextScene = scene; // _nextScene is a weak ref }
protected override void initWithPrefabObj(GameObject obj) { base.initWithPrefabObj(obj); _isAutoDestory = true; _callback = null; NSUtils.Assert(this.particleSystems != null && this.particleSystems.Length != 0, "CC3Particle({0}): ParticleSystem not found at path {1}.", this.gameObject.activeSelf, _path); _controllers = new CC3ParticleController[this.particleSystems.Length]; for (int i = 0; i < _controllers.Length; i++) { _controllers[i] = new CC3ParticleController(this.particleSystems[i]); _controllers[i].callback = onControllerCallback; } }
public void gotoAndPlay(int start, int end, BBFlashMovieCallback callback = null) { NSUtils.Assert(start <= end, "BBFlashMovie:gotoAndPlay: reverse play is not supported at current version."); _movieCtrl.callback = delegate { if (callback != null) { callback(this); } }; _movieCtrl.startFrame = start; _movieCtrl.endFrame = end; _movieCtrl.start(); }
protected virtual void loadComponents() { _fbxAnimator = _prefabObj.GetComponent <Animator>(); NSUtils.Assert(_fbxAnimator != null, "{0}#initWithPrefabObj: Animator not found", GetType().Name); _fbxAnimator.speed = 1; _evtScript = _prefabObj.GetComponent <CC3FbxEventScript>(); if (_evtScript == null) { _evtScript = _prefabObj.AddComponent <CC3FbxEventScript>(); } _evtScript.eventHandler = null; _transitionDuration = 0.25f; }